dev/financial#152 simplify interaction with membership, deprecate function
authoreileen <emcnaughton@wikimedia.org>
Sun, 11 Oct 2020 20:36:18 +0000 (09:36 +1300)
committereileen <emcnaughton@wikimedia.org>
Sun, 11 Oct 2020 20:42:54 +0000 (09:42 +1300)
ids['membership'] is only calculated in the Authorize.net IPN flow for the purpose of determining
the autoRenew membership parameter for recurringNotify. This is currently passed to sendRecurringStartOrEndNotification
but that does not add any simplification & cannot be used elsewhere - so deprecating.

This is tested in testIPNPaymentMembershipRecurSuccessNoLeakage

CRM/Contribute/BAO/ContributionRecur.php
CRM/Core/Payment/AuthorizeNetIPN.php
tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php

index b7e12eb2c06cb95ac0043e3e9ba6ca705f604e41..c44cd2f3bcb7a1bfc80e48dd247c6da7439dd8f1 100644 (file)
@@ -528,6 +528,7 @@ INNER JOIN civicrm_contribution       con ON ( con.id = mp.contribution_id )
    * @param bool $isFirstOrLastRecurringPayment
    */
   public static function sendRecurringStartOrEndNotification($ids, $recur, $isFirstOrLastRecurringPayment) {
+    CRM_Core_Error::deprecatedFunctionWarning('use CRM_Contribute_BAO_ContributionPage::recurringNotify');
     if ($isFirstOrLastRecurringPayment) {
       $autoRenewMembership = FALSE;
       if ($recur->id &&
index d72dc82fa22d430397b5f4430701bd729dc6d0d3..4aa8cdddbd267a96a34ad0707d07aa85639990b1 100644 (file)
@@ -139,7 +139,6 @@ class CRM_Core_Payment_AuthorizeNetIPN extends CRM_Core_Payment_BaseIPN {
             'related_contact' => $ids['related_contact'] ?? NULL,
             'participant' => !empty($objects['participant']) ? $objects['participant']->id : NULL,
             'contributionRecur' => !empty($objects['contributionRecur']) ? $objects['contributionRecur']->id : NULL,
-            'membership' => $ids['membership'] ?? NULL,
             'contact' => $ids['contact'] ?? NULL,
             'contributionPage' => $ids['contributionPage'] ?? NULL,
           ], $objects, $first);
@@ -165,6 +164,7 @@ class CRM_Core_Payment_AuthorizeNetIPN extends CRM_Core_Payment_BaseIPN {
    */
   public function recur($input, $ids, $objects, $first) {
     $recur = &$objects['contributionRecur'];
+    $contribution = &$objects['contribution'];
 
     // do a subscription check
     if ($recur->processor_id != $input['subscription_id']) {
@@ -225,15 +225,15 @@ class CRM_Core_Payment_AuthorizeNetIPN extends CRM_Core_Payment_BaseIPN {
 
     CRM_Contribute_BAO_Contribution::completeOrder($input, $ids, $objects['contribution']);
 
-    // Only Authorize.net does this so it is on the a.net class. If there is a need for other processors
-    // to do this we should make it available via the api, e.g as a parameter, changing the nuance
-    // from isSentReceipt to an array of which receipts to send.
-    // Note that there is site-by-site opinions on which notifications are good to send.
     if ($isFirstOrLastRecurringPayment) {
-      CRM_Contribute_BAO_ContributionRecur::sendRecurringStartOrEndNotification($ids, $recur,
-        $isFirstOrLastRecurringPayment);
+      //send recurring Notification email for user
+      CRM_Contribute_BAO_ContributionPage::recurringNotify(TRUE,
+        $ids['contact'],
+        $ids['contributionPage'],
+        $recur,
+        (bool) $this->getMembershipID($contribution->id, $recur->id)
+      );
     }
-
   }
 
   /**
@@ -314,7 +314,6 @@ INNER JOIN civicrm_contribution co ON co.contribution_recur_id = cr.id
       $log->error('payment_notification', ['message' => $message, 'ids' => $ids, 'input' => $input]);
       throw new CRM_Core_Exception($message);
     }
-    $ids['membership'] = $this->getMembershipID($ids['contribution'], $ids['contributionRecur']);
   }
 
   /**
index 12ee0cdc564621adf0b63a20e434f433039050b5..2b04f7a484f721a24408e081e482d5216cb89731 100644 (file)
@@ -257,7 +257,7 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase {
   /**
    * Test IPN response mails don't leak.
    *
-   * @throws \CRM_Core_Exception
+   * @throws \CRM_Core_Exception|\CiviCRM_API3_Exception
    */
   public function testIPNPaymentMembershipRecurSuccessNoLeakage() {
     $mut = new CiviMailUtils($this, TRUE);