From 4f2c0e2a79a2d123da2de1058d8d0e7e06f227b2 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 21 Sep 2020 14:20:25 +1200 Subject: [PATCH] dev/core#2034 Fix paypal standard cancel url 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 | 3 ++- CRM/Core/Payment/PayPalImpl.php | 19 +++++++++++++------ .../CRM/Core/Payment/PayPalIPNTest.php | 3 +++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index b312c8e8d9..d191dcfc3b 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -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 diff --git a/CRM/Core/Payment/PayPalImpl.php b/CRM/Core/Payment/PayPalImpl.php index c473588a1d..839702f1d0 100644 --- a/CRM/Core/Payment/PayPalImpl.php +++ b/CRM/Core/Payment/PayPalImpl.php @@ -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); } /** diff --git a/tests/phpunit/CRM/Core/Payment/PayPalIPNTest.php b/tests/phpunit/CRM/Core/Payment/PayPalIPNTest.php index a073033f90..80a030be6a 100644 --- a/tests/phpunit/CRM/Core/Payment/PayPalIPNTest.php +++ b/tests/phpunit/CRM/Core/Payment/PayPalIPNTest.php @@ -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']); -- 2.25.1