Skip to content

Commit

Permalink
refs #40102, do not render page on ipn endpoint of allpay
Browse files Browse the repository at this point in the history
  • Loading branch information
jimyhuang committed Jun 13, 2024
1 parent 4920be8 commit d03a32c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
7 changes: 4 additions & 3 deletions CRM/Core/Payment/ALLPAY.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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();
}
}

20 changes: 17 additions & 3 deletions tests/phpunit/CRM/Core/Payment/ALLPAYTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
}
}

0 comments on commit d03a32c

Please sign in to comment.