From d03a32caf38038ec4001d4df50a7bb920277f9a2 Mon Sep 17 00:00:00 2001 From: Jimmy Huang Date: Thu, 13 Jun 2024 15:48:29 +0800 Subject: [PATCH] refs #40102, do not render page on ipn endpoint of allpay --- CRM/Core/Payment/ALLPAY.php | 7 ++++--- tests/phpunit/CRM/Core/Payment/ALLPAYTest.php | 20 ++++++++++++++++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/CRM/Core/Payment/ALLPAY.php b/CRM/Core/Payment/ALLPAY.php index 9fa05432b..42bc7e22d 100644 --- a/CRM/Core/Payment/ALLPAY.php +++ b/CRM/Core/Payment/ALLPAY.php @@ -758,7 +758,7 @@ public static function recurCheck($rid, $order = NULL) { } // manually trigger ipn - self::doIPN('Credit', $post, $get, FALSE); + self::doIPN(array('allpay', 'ipn', 'Credit'), $post, $get, FALSE); } } } @@ -844,7 +844,7 @@ public static function tradeCheck($orderId, $order = NULL) { $ipnPost['do_not_email'] = 1; } */ - $result = self::doIPN('Credit', $ipnPost, $ipnGet, FALSE); + $result = self::doIPN(array('allpay', 'ipn', 'Credit'), $ipnPost, $ipnGet, FALSE); return $result; } } @@ -985,7 +985,7 @@ function cancelRecuringMessage($recurID){ /** * Execute ipn as called from allpay transaction. Original civicrm_allpay_ipn * - * @param string $instrument The code of used instrument like 'Credit' or 'ATM'. + * @param array $instrument The code of used instrument like 'Credit' or 'ATM'. * @param array $post Bring post variables if you need test. * @param array $get Bring get variables if you need test. * @param boolean $print Does server echo the result, or just return that. Default is TRUE. @@ -1030,6 +1030,7 @@ static function doIPN($arguments, $post = NULL, $get = NULL, $print = TRUE) { CRM_Core_Error::debug_log_message( "civicrm_allpay: Could not get module name from request url", TRUE); } } + CRM_Utils_System::civiExit(); } } diff --git a/tests/phpunit/CRM/Core/Payment/ALLPAYTest.php b/tests/phpunit/CRM/Core/Payment/ALLPAYTest.php index ecf176fef..ca877d002 100644 --- a/tests/phpunit/CRM/Core/Payment/ALLPAYTest.php +++ b/tests/phpunit/CRM/Core/Payment/ALLPAYTest.php @@ -166,7 +166,7 @@ function testSinglePaymentNotify(){ 'TradeDate' => date('Y-m-d H:i:s', $now), 'SimulatePaid' => '1', ); - CRM_Core_Payment_ALLPAY::doIPN('Credit', $post, $get); + $this->doIPN(array('allpay', 'ipn', 'Credit'), $post, $get, __LINE__); // verify contribution status after trigger $this->assertDBCompareValue( @@ -266,7 +266,7 @@ function testRecurringPaymentNotify(){ 'TradeDate' => date('Y-m-d H:i:s', $now), 'SimulatePaid' => '1', ); - CRM_Core_Payment_ALLPAY::doIPN('Credit', $post, $get); + $this->doIPN(array('allpay', 'ipn', 'Credit'), $post, $get, __LINE__); // verify contribution status after trigger $this->assertDBCompareValue( @@ -313,7 +313,7 @@ function testRecurringPaymentNotify(){ 'TotalSuccessTimes' => 2, 'SimulatePaid' => '1', ); - CRM_Core_Payment_ALLPAY::doIPN('Credit', $post, $get); + $this->doIPN(array('allpay', 'ipn', 'Credit'), $post, $get, __LINE__); $trxn_id2 = CRM_Core_Payment_ALLPAY::generateRecurTrxn($trxn_id, $gwsr1); // check second payment contribution exists @@ -523,4 +523,18 @@ function testNonCreditNotify(){ CRM_Core_Payment_ALLPAYIPN::doRecordData(array('allpay', 'record', $cid)); $this->assertDBQuery($cid, "SELECT cid FROM civicrm_contribution_allpay WHERE data LIKE '%#info%TEST1%' AND cid = $cid"); } + + function doIPN($args, $post, $get, $line) { + try { + CRM_Core_Payment_ALLPAY::doIPN($args, $post, $get); + } + catch (CRM_Core_Exception $e) { + $message = $e->getMessage(); + $data = $e->getErrorData(); + $code = $e->getErrorCode(); + if ($code != CRM_Core_Error::NO_ERROR) { + throw new Exception($message.' at line '.$line, $code); + } + } + } }