Skip to content

Commit 39a2630

Browse files
authored
Merge pull request civicrm#14861 from eileenmcnaughton/anet
[test] Catch A.net exception & ignore
2 parents f4e89ad + 12fde6a commit 39a2630

4 files changed

Lines changed: 59 additions & 39 deletions

File tree

CRM/Contribute/Form/Contribution.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,8 +1023,10 @@ public function postProcess() {
10231023
* Contact ID
10241024
*
10251025
* @return bool|\CRM_Contribute_DAO_Contribution
1026+
*
10261027
* @throws \CRM_Core_Exception
10271028
* @throws \Civi\Payment\Exception\PaymentProcessorException
1029+
* @throws \CiviCRM_API3_Exception
10281030
*/
10291031
protected function processCreditCard($submittedValues, $lineItem, $contactID) {
10301032
$isTest = ($this->_mode == 'test') ? 1 : 0;
@@ -1287,7 +1289,11 @@ protected function generatePane($type, $defaults) {
12871289
* @param int $action
12881290
* @param string|null $creditCardMode
12891291
*
1292+
* @return CRM_Contribute_BAO_Contribution
1293+
*
1294+
* @throws \CRM_Core_Exception
12901295
* @throws \CiviCRM_API3_Exception
1296+
* @throws \Civi\Payment\Exception\PaymentProcessorException
12911297
*/
12921298
public function testSubmit($params, $action, $creditCardMode = NULL) {
12931299
$defaults = [
@@ -1347,8 +1353,11 @@ public function testSubmit($params, $action, $creditCardMode = NULL) {
13471353
*
13481354
* @param $pledgePaymentID
13491355
*
1350-
* @return array
1351-
* @throws \Exception
1356+
* @return \CRM_Contribute_BAO_Contribution
1357+
*
1358+
* @throws \CRM_Core_Exception
1359+
* @throws \CiviCRM_API3_Exception
1360+
* @throws \Civi\Payment\Exception\PaymentProcessorException
13521361
*/
13531362
protected function submit($submittedValues, $action, $pledgePaymentID) {
13541363
$pId = $contribution = $isRelatedId = FALSE;

CRM/Contribute/Form/Contribution/Confirm.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,9 @@ protected function postProcessPremium($premiumParams, $contribution) {
893893
* Is this recurring?
894894
*
895895
* @return \CRM_Contribute_DAO_Contribution
896-
* @throws \Exception
896+
*
897+
* @throws \CRM_Core_Exception
898+
* @throws \CiviCRM_API3_Exception
897899
*/
898900
public static function processFormContribution(
899901
&$form,

CRM/Core/BAO/Note.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public static function getNotePrivacyHidden($note) {
135135
* (deprecated) associated array with note id - preferably set $params['id'].
136136
* @return null|object
137137
* $note CRM_Core_BAO_Note object
138-
* @throws \CRM_Exception
138+
* @throws \CRM_Core_Exception
139139
*/
140140
public static function add(&$params, $ids = array()) {
141141
$dataExists = self::dataExists($params);
@@ -145,7 +145,7 @@ public static function add(&$params, $ids = array()) {
145145

146146
if (!empty($params['entity_table']) && $params['entity_table'] == 'civicrm_contact' && !empty($params['check_permissions'])) {
147147
if (!CRM_Contact_BAO_Contact_Permission::allow($params['entity_id'], CRM_Core_Permission::EDIT)) {
148-
throw new CRM_Exception('Permission denied to modify contact record');
148+
throw new CRM_Core_Exception('Permission denied to modify contact record');
149149
}
150150
}
151151

tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use Civi\Payment\Exception\PaymentProcessorException;
4+
35
/**
46
* Class CRM_Core_Payment_PayPalProIPNTest
57
* @group headless
@@ -37,6 +39,9 @@ public function tearDown() {
3739
/**
3840
* Ensure recurring contributions from Contribution Pages
3941
* with receipt turned off don't send a receipt.
42+
*
43+
* @throws \CiviCRM_API3_Exception
44+
* @throws \CRM_Core_Exception
4045
*/
4146
public function testIPNPaymentRecurNoReceipt() {
4247
$mut = new CiviMailUtils($this, TRUE);
@@ -57,40 +62,44 @@ public function testIPNPaymentRecurNoReceipt() {
5762
// has is_email_receipt set to 0.
5863
$form = new CRM_Contribute_Form_Contribution();
5964
$form->_mode = 'Live';
60-
$contribution = $form->testSubmit([
61-
'total_amount' => 200,
62-
'financial_type_id' => 1,
63-
'receive_date' => date('m/d/Y'),
64-
'receive_date_time' => date('H:i:s'),
65-
'contact_id' => $this->_contactID,
66-
'contribution_status_id' => 1,
67-
'credit_card_number' => 4444333322221111,
68-
'cvv2' => 123,
69-
'credit_card_exp_date' => [
70-
'M' => 9,
71-
'Y' => 2025,
72-
],
73-
'credit_card_type' => 'Visa',
74-
'billing_first_name' => 'Junko',
75-
'billing_middle_name' => '',
76-
'billing_last_name' => 'Adams',
77-
'billing_street_address-5' => time() . ' Lincoln St S',
78-
'billing_city-5' => 'Maryknoll',
79-
'billing_state_province_id-5' => 1031,
80-
'billing_postal_code-5' => 10545,
81-
'billing_country_id-5' => 1228,
82-
'frequency_interval' => 1,
83-
'frequency_unit' => 'month',
84-
'installments' => '',
85-
'hidden_AdditionalDetail' => 1,
86-
'hidden_Premium' => 1,
87-
'payment_processor_id' => $this->_paymentProcessorID,
88-
'currency' => 'USD',
89-
'source' => 'bob sled race',
90-
'contribution_page_id' => $this->_contributionPageID,
91-
'is_recur' => TRUE,
92-
], CRM_Core_Action::ADD);
93-
65+
try {
66+
$contribution = $form->testSubmit([
67+
'total_amount' => 200,
68+
'financial_type_id' => 1,
69+
'receive_date' => date('m/d/Y'),
70+
'receive_date_time' => date('H:i:s'),
71+
'contact_id' => $this->_contactID,
72+
'contribution_status_id' => 1,
73+
'credit_card_number' => 4444333322221111,
74+
'cvv2' => 123,
75+
'credit_card_exp_date' => [
76+
'M' => 9,
77+
'Y' => 2025,
78+
],
79+
'credit_card_type' => 'Visa',
80+
'billing_first_name' => 'Junko',
81+
'billing_middle_name' => '',
82+
'billing_last_name' => 'Adams',
83+
'billing_street_address-5' => time() . ' Lincoln St S',
84+
'billing_city-5' => 'Maryknoll',
85+
'billing_state_province_id-5' => 1031,
86+
'billing_postal_code-5' => 10545,
87+
'billing_country_id-5' => 1228,
88+
'frequency_interval' => 1,
89+
'frequency_unit' => 'month',
90+
'installments' => '',
91+
'hidden_AdditionalDetail' => 1,
92+
'hidden_Premium' => 1,
93+
'payment_processor_id' => $this->_paymentProcessorID,
94+
'currency' => 'USD',
95+
'source' => 'bob sled race',
96+
'contribution_page_id' => $this->_contributionPageID,
97+
'is_recur' => TRUE,
98+
], CRM_Core_Action::ADD);
99+
}
100+
catch (PaymentProcessorException $e) {
101+
$this->markTestSkipped('Error from A.net - cannot proceed');
102+
}
94103
$this->_contributionID = $contribution->id;
95104
$this->_contributionRecurID = $contribution->contribution_recur_id;
96105
$recur_params = [

0 commit comments

Comments
 (0)