Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add try catch to main loops on core ipn classes #18384

Merged
merged 1 commit into from
Sep 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions CRM/Core/Payment/AuthorizeNetIPN.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct($inputData) {
* @return bool|void
*/
public function main($component = 'contribute') {

try {
//we only get invoice num as a key player from payment gateway response.
//for ARB we get x_subscription_id and x_subscription_paynum
$x_subscription_id = $this->retrieve('x_subscription_id', 'String');
Expand Down Expand Up @@ -91,6 +91,11 @@ public function main($component = 'contribute') {
}
return TRUE;
}
catch (CRM_Core_Exception $e) {
Civi::log()->debug($e->getMessage());
echo 'Invalid or missing data';
}
}

/**
* @param array $input
Expand All @@ -107,9 +112,7 @@ public function recur($input, $ids, $objects, $first) {

// do a subscription check
if ($recur->processor_id != $input['subscription_id']) {
CRM_Core_Error::debug_log_message('Unrecognized subscription.');
echo 'Failure: Unrecognized subscription<p>';
return FALSE;
throw new CRM_Core_Exception('Unrecognized subscription.');
}

$contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
Expand Down
8 changes: 6 additions & 2 deletions CRM/Core/Payment/PayPalIPN.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ public function __construct($inputData) {
public function retrieve($name, $type, $abort = TRUE) {
$value = CRM_Utils_Type::validate(CRM_Utils_Array::value($name, $this->_inputParameters), $type, FALSE);
if ($abort && $value === NULL) {
Civi::log()->debug("PayPalIPN: Could not find an entry for $name");
echo "Failure: Missing Parameter<p>" . CRM_Utils_Type::escape($name, 'String');
throw new CRM_Core_Exception("PayPalIPN: Could not find an entry for $name");
}
return $value;
Expand Down Expand Up @@ -286,6 +284,7 @@ public function single($input, $ids, $objects, $recur = FALSE, $first = FALSE) {
* @throws \CiviCRM_API3_Exception
*/
public function main() {
try {
$objects = $ids = $input = [];
$component = $this->retrieve('module', 'String');
$input['component'] = $component;
Expand Down Expand Up @@ -365,6 +364,11 @@ public function main() {
}
$this->single($input, $ids, $objects);
}
catch (CRM_Core_Exception $e) {
Civi::log()->debug($e->getMessage());
echo 'Invalid or missing data';
}
}

/**
* @param array $input
Expand Down
6 changes: 6 additions & 0 deletions CRM/Core/Payment/PayPalProIPN.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ public function getPayPalPaymentProcessorID() {
public function main() {
CRM_Core_Error::debug_var('GET', $_GET, TRUE, TRUE);
CRM_Core_Error::debug_var('POST', $_POST, TRUE, TRUE);
try {
if ($this->_isPaymentExpress) {
$this->handlePaymentExpress();
return;
Expand Down Expand Up @@ -484,6 +485,11 @@ public function main() {
}
$this->single($input, $ids, $objects, FALSE, FALSE);
}
catch (CRM_Core_Exception $e) {
Civi::log()->debug($e->getMessage());
echo 'Invalid or missing data';
}
}

/**
* @param array $input
Expand Down
12 changes: 1 addition & 11 deletions tests/phpunit/CRM/Core/Payment/PayPalProIPNTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,25 +167,15 @@ public function testIPNPaymentCRM13743() {
* However, for Paypal Pro users payment express transactions can't work as they don't hold the component
* which is required for them to be handled by either the Pro or Express class
*
* So, the point of this test is simply to ensure it fails in a known way & with a better message than
* previously & that refactorings don't mess with that
*
* Obviously if the behaviour is fixed then the test should be updated!
* So, the point of this test is simply to ensure it fails in a known way
*/
public function testIPNPaymentExpressNoError() {
$this->setupRecurringPaymentProcessorTransaction();
$paypalIPN = new CRM_Core_Payment_PayPalProIPN($this->getPaypalExpressTransactionIPN());
try {
$paypalIPN->main();
}
catch (CRM_Core_Exception $e) {
$contribution = $this->callAPISuccess('contribution', 'getsingle', ['id' => $this->_contributionID]);
// no change
$this->assertEquals(2, $contribution['contribution_status_id']);
$this->assertEquals('Paypal IPNS not handled other than recurring_payments', $e->getMessage());
return;
}
$this->fail('The Paypal Express IPN should have caused an exception');
}

/**
Expand Down