From 12fde6aeea2496ce0425c29577aa95604228870b Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 23 Jul 2019 18:26:20 +1200 Subject: [PATCH] Catch A.net exception & ignore Hopefully we can avoid false negatives like https://test.civicrm.org/job/CiviCRM-Core-PR/27923/testReport/junit/(root)/CRM_Core_Payment_AuthorizeNetIPNTest/testIPNPaymentRecurNoReceipt/ without losing too much --- CRM/Contribute/Form/Contribution.php | 13 +++- CRM/Contribute/Form/Contribution/Confirm.php | 4 +- CRM/Core/BAO/Note.php | 4 +- .../CRM/Core/Payment/AuthorizeNetIPNTest.php | 77 +++++++++++-------- 4 files changed, 59 insertions(+), 39 deletions(-) diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 79a4db615d..23ec91d2d9 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -1023,8 +1023,10 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP * Contact ID * * @return bool|\CRM_Contribute_DAO_Contribution + * * @throws \CRM_Core_Exception * @throws \Civi\Payment\Exception\PaymentProcessorException + * @throws \CiviCRM_API3_Exception */ protected function processCreditCard($submittedValues, $lineItem, $contactID) { $isTest = ($this->_mode == 'test') ? 1 : 0; @@ -1287,7 +1289,11 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP * @param int $action * @param string|null $creditCardMode * + * @return CRM_Contribute_BAO_Contribution + * + * @throws \CRM_Core_Exception * @throws \CiviCRM_API3_Exception + * @throws \Civi\Payment\Exception\PaymentProcessorException */ public function testSubmit($params, $action, $creditCardMode = NULL) { $defaults = [ @@ -1347,8 +1353,11 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP * * @param $pledgePaymentID * - * @return array - * @throws \Exception + * @return \CRM_Contribute_BAO_Contribution + * + * @throws \CRM_Core_Exception + * @throws \CiviCRM_API3_Exception + * @throws \Civi\Payment\Exception\PaymentProcessorException */ protected function submit($submittedValues, $action, $pledgePaymentID) { $pId = $contribution = $isRelatedId = FALSE; diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index ffd9a524ce..236a98cccf 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -893,7 +893,9 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr * Is this recurring? * * @return \CRM_Contribute_DAO_Contribution - * @throws \Exception + * + * @throws \CRM_Core_Exception + * @throws \CiviCRM_API3_Exception */ public static function processFormContribution( &$form, diff --git a/CRM/Core/BAO/Note.php b/CRM/Core/BAO/Note.php index 244ca4c25a..7ef3e23230 100644 --- a/CRM/Core/BAO/Note.php +++ b/CRM/Core/BAO/Note.php @@ -135,7 +135,7 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note { * (deprecated) associated array with note id - preferably set $params['id']. * @return null|object * $note CRM_Core_BAO_Note object - * @throws \CRM_Exception + * @throws \CRM_Core_Exception */ public static function add(&$params, $ids = array()) { $dataExists = self::dataExists($params); @@ -145,7 +145,7 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note { if (!empty($params['entity_table']) && $params['entity_table'] == 'civicrm_contact' && !empty($params['check_permissions'])) { if (!CRM_Contact_BAO_Contact_Permission::allow($params['entity_id'], CRM_Core_Permission::EDIT)) { - throw new CRM_Exception('Permission denied to modify contact record'); + throw new CRM_Core_Exception('Permission denied to modify contact record'); } } diff --git a/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php b/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php index 75fc3a28b1..67b81caae5 100644 --- a/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php +++ b/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php @@ -1,5 +1,7 @@ _mode = 'Live'; - $contribution = $form->testSubmit([ - 'total_amount' => 200, - 'financial_type_id' => 1, - 'receive_date' => date('m/d/Y'), - 'receive_date_time' => date('H:i:s'), - 'contact_id' => $this->_contactID, - 'contribution_status_id' => 1, - 'credit_card_number' => 4444333322221111, - 'cvv2' => 123, - 'credit_card_exp_date' => [ - 'M' => 9, - 'Y' => 2025, - ], - 'credit_card_type' => 'Visa', - 'billing_first_name' => 'Junko', - 'billing_middle_name' => '', - 'billing_last_name' => 'Adams', - 'billing_street_address-5' => time() . ' Lincoln St S', - 'billing_city-5' => 'Maryknoll', - 'billing_state_province_id-5' => 1031, - 'billing_postal_code-5' => 10545, - 'billing_country_id-5' => 1228, - 'frequency_interval' => 1, - 'frequency_unit' => 'month', - 'installments' => '', - 'hidden_AdditionalDetail' => 1, - 'hidden_Premium' => 1, - 'payment_processor_id' => $this->_paymentProcessorID, - 'currency' => 'USD', - 'source' => 'bob sled race', - 'contribution_page_id' => $this->_contributionPageID, - 'is_recur' => TRUE, - ], CRM_Core_Action::ADD); - + try { + $contribution = $form->testSubmit([ + 'total_amount' => 200, + 'financial_type_id' => 1, + 'receive_date' => date('m/d/Y'), + 'receive_date_time' => date('H:i:s'), + 'contact_id' => $this->_contactID, + 'contribution_status_id' => 1, + 'credit_card_number' => 4444333322221111, + 'cvv2' => 123, + 'credit_card_exp_date' => [ + 'M' => 9, + 'Y' => 2025, + ], + 'credit_card_type' => 'Visa', + 'billing_first_name' => 'Junko', + 'billing_middle_name' => '', + 'billing_last_name' => 'Adams', + 'billing_street_address-5' => time() . ' Lincoln St S', + 'billing_city-5' => 'Maryknoll', + 'billing_state_province_id-5' => 1031, + 'billing_postal_code-5' => 10545, + 'billing_country_id-5' => 1228, + 'frequency_interval' => 1, + 'frequency_unit' => 'month', + 'installments' => '', + 'hidden_AdditionalDetail' => 1, + 'hidden_Premium' => 1, + 'payment_processor_id' => $this->_paymentProcessorID, + 'currency' => 'USD', + 'source' => 'bob sled race', + 'contribution_page_id' => $this->_contributionPageID, + 'is_recur' => TRUE, + ], CRM_Core_Action::ADD); + } + catch (PaymentProcessorException $e) { + $this->markTestSkipped('Error from A.net - cannot proceed'); + } $this->_contributionID = $contribution->id; $this->_contributionRecurID = $contribution->contribution_recur_id; $recur_params = [ -- 2.25.1