Catch A.net exception & ignore
authoreileen <emcnaughton@wikimedia.org>
Tue, 23 Jul 2019 06:26:20 +0000 (18:26 +1200)
committereileen <emcnaughton@wikimedia.org>
Tue, 23 Jul 2019 06:26:59 +0000 (18:26 +1200)
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
CRM/Contribute/Form/Contribution/Confirm.php
CRM/Core/BAO/Note.php
tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php

index 79a4db615d218cb5b76314712ecac8ebd9ed9073..23ec91d2d943ecb9e8971a40e69553e3d2a4e54f 100644 (file)
@@ -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;
index ffd9a524cee08a4aed0d9cc2b18d4657ee507b34..236a98cccfc5a7a5da129a83f2a39ebfe7e804e6 100644 (file)
@@ -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,
index 244ca4c25a6a1439de8bdd673326ec69b696e767..7ef3e23230265d726bc89c7db68d1385595d5d0e 100644 (file)
@@ -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');
       }
     }
 
index 75fc3a28b13c246ebb27f76461f15ab74afc4601..67b81caae58820ca14b38b00101ccc0811227dea 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+use Civi\Payment\Exception\PaymentProcessorException;
+
 /**
  * Class CRM_Core_Payment_PayPalProIPNTest
  * @group headless
@@ -37,6 +39,9 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase {
   /**
    * Ensure recurring contributions from Contribution Pages
    * with receipt turned off don't send a receipt.
+   *
+   * @throws \CiviCRM_API3_Exception
+   * @throws \CRM_Core_Exception
    */
   public function testIPNPaymentRecurNoReceipt() {
     $mut = new CiviMailUtils($this, TRUE);
@@ -57,40 +62,44 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase {
     // has is_email_receipt set to 0.
     $form = new CRM_Contribute_Form_Contribution();
     $form->_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 = [