CRM-18426 pay later receipts not going out
authoreileenmcnaugton <eileen@fuzion.co.nz>
Sun, 17 Apr 2016 15:01:11 +0000 (03:01 +1200)
committereileenmcnaugton <eileen@fuzion.co.nz>
Sun, 24 Apr 2016 20:34:18 +0000 (08:34 +1200)
CRM/Contribute/BAO/Contribution/Utils.php
CRM/Core/Payment.php
CRM/Core/Payment/Manual.php

index f99f910511bcde84a007d1c46ab8b1a01555b07f..01356aef8a2285433245a68f941ed680343fe99a 100644 (file)
@@ -141,6 +141,18 @@ class CRM_Contribute_BAO_Contribution_Utils {
       if ($form->_values['is_recur'] && $contribution->contribution_recur_id) {
         $paymentParams['contributionRecurID'] = $contribution->contribution_recur_id;
       }
+      if (isset($paymentParams['contribution_source'])) {
+        $form->_params['source'] = $paymentParams['contribution_source'];
+      }
+
+      // get the price set values for receipt.
+      if ($form->_priceSetId && $form->_lineItem) {
+        $form->_values['lineItem'] = $form->_lineItem;
+        $form->_values['priceSetID'] = $form->_priceSetId;
+      }
+
+      $form->_values['contribution_id'] = $contribution->id;
+      $form->_values['contribution_page_id'] = $contribution->contribution_page_id;
 
       if (!empty($form->_paymentProcessor)) {
         try {
@@ -160,6 +172,13 @@ class CRM_Contribute_BAO_Contribution_Utils {
             $contribution->payment_status_id = $result['payment_status_id'];
           }
           $result['contribution'] = $contribution;
+          if ($contribution->payment_status_id == CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution',
+            'status_id', 'Pending') && $payment->isSendReceiptForPending()) {
+            CRM_Contribute_BAO_ContributionPage::sendMail($contactID,
+              $form->_values,
+              $contribution->is_test
+            );
+          }
           return $result;
         }
         catch (\Civi\Payment\Exception\PaymentProcessorException $e) {
@@ -179,22 +198,10 @@ class CRM_Contribute_BAO_Contribution_Utils {
       }
     }
 
-    // Only pay later or unpaid should reach this point. The theory is that paylater should get a receipt now &
-    // processor
-    // transaction receipts should be outcome driven.
+    // Only pay later or unpaid should reach this point, although pay later likely does not & is handled via the
+    // manual processor, so it's unclear what this set is for and whether the following send ever fires.
     $form->set('params', $form->_params);
-    if (isset($paymentParams['contribution_source'])) {
-      $form->_params['source'] = $paymentParams['contribution_source'];
-    }
-
-    // get the price set values for receipt.
-    if ($form->_priceSetId && $form->_lineItem) {
-      $form->_values['lineItem'] = $form->_lineItem;
-      $form->_values['priceSetID'] = $form->_priceSetId;
-    }
 
-    $form->_values['contribution_id'] = $contribution->id;
-    $form->_values['contribution_page_id'] = $contribution->contribution_page_id;
     if ($form->_params['amount'] == 0) {
       // This is kind of a back-up for pay-later $0 transactions.
       // In other flows they pick up the manual processor & get dealt with above (I
index 69a831f6209be2c6b87e68f697ad061a2009f934..dcec384ee373da4a45695f8a40930a2ba0eef4d5 100644 (file)
@@ -1336,4 +1336,13 @@ INNER JOIN civicrm_contribution con ON ( con.contribution_recur_id = rec.id )
     return FALSE;
   }
 
+  /**
+   * Should a receipt be sent out for a pending payment.
+   *
+   * e.g for traditional pay later & ones with a delayed settlement a pending receipt makes sense.
+   */
+  public function isSendReceiptForPending() {
+    return FALSE;
+  }
+
 }
index 1072f340101ab5517004a324159415ac498d9f32..ecc3c92520042f31815fa12c7ba231cebf0f68e2 100644 (file)
@@ -192,4 +192,13 @@ class CRM_Core_Payment_Manual extends CRM_Core_Payment {
     return $result;
   }
 
+  /**
+   * Should a receipt be sent out for a pending payment.
+   *
+   * e.g for traditional pay later & ones with a delayed settlement a pending receipt makes sense.
+   */
+  public function isSendReceiptForPending() {
+    return TRUE;
+  }
+
 }