dev/core#2034 Fix paypal standard cancel url
authoreileen <emcnaughton@wikimedia.org>
Mon, 21 Sep 2020 02:20:25 +0000 (14:20 +1200)
committereileen <emcnaughton@wikimedia.org>
Mon, 21 Sep 2020 04:48:03 +0000 (16:48 +1200)
Per https://lab.civicrm.org/dev/core/-/issues/2034 the wrong urls are included in paypal standard emails for cancellation

I think this likely regressed a long time ago - but the symptoms changed a little this year - so I am just putting
against master

CRM/Core/Payment.php
CRM/Core/Payment/PayPalImpl.php
tests/phpunit/CRM/Core/Payment/PayPalIPNTest.php

index b312c8e8d9318fe1d12426f75638cb074bb8c686..d191dcfc3b72c8c6e21bef9d2e3477f2babe2cb1 100644 (file)
@@ -1688,7 +1688,8 @@ abstract class CRM_Core_Payment {
    * @param null $entity
    * @param string $action
    *
-   * @return string
+   * @return string|null
+   * @throws \CRM_Core_Exception
    */
   public function subscriptionURL($entityID = NULL, $entity = NULL, $action = 'cancel') {
     // Set URL
index c473588a1d2cb61d95ffca9c1a03f93e4719acb2..839702f1d004ff8c1732ab06892897c2661df273 100644 (file)
@@ -644,16 +644,23 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment {
   }
 
   /**
-   * @return null|string
-   * @throws \Civi\Payment\Exception\PaymentProcessorException
+   * Get url for users to manage this recurring contribution for this processor.
+   *
+   * @param int $entityID
+   * @param null $entity
+   * @param string $action
+   *
+   * @return string|null
+   * @throws \CRM_Core_Exception
    */
-  public function cancelSubscriptionURL() {
+  public function subscriptionURL($entityID = NULL, $entity = NULL, $action = 'cancel') {
     if ($this->isPayPalType($this::PAYPAL_STANDARD)) {
+      if ($action !== 'cancel') {
+        return NULL;
+      }
       return "{$this->_paymentProcessor['url_site']}cgi-bin/webscr?cmd=_subscr-find&alias=" . urlencode($this->_paymentProcessor['user_name']);
     }
-    else {
-      return NULL;
-    }
+    return parent::subscriptionURL($entityID, $entity, $action);
   }
 
   /**
index a073033f90974b05d17ab51c318930d7de89b3a5..80a030be6ab99585cd62ea2940c379b450101375 100644 (file)
@@ -104,8 +104,11 @@ class CRM_Core_Payment_PayPalIPNTest extends CiviUnitTestCase {
    */
   public function testIPNPaymentRecurSuccess() {
     $this->setupRecurringPaymentProcessorTransaction([], ['total_amount' => '15.00']);
+    $mut = new CiviMailUtils($this, TRUE);
     $paypalIPN = new CRM_Core_Payment_PayPalIPN($this->getPaypalRecurTransaction());
     $paypalIPN->main();
+    $mut->checkMailLog(['https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_subscr-find'], ['civicrm/contribute/unsubscribe', 'civicrm/contribute/updatebilling']);
+    $mut->stop();
     $contribution1 = $this->callAPISuccess('Contribution', 'getsingle', ['id' => $this->_contributionID]);
     $this->assertEquals(1, $contribution1['contribution_status_id']);
     $this->assertEquals('8XA571746W2698126', $contribution1['trxn_id']);