From dbb9e6fcf10384d5b46b4c92950f90e0219890fb Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 7 May 2018 16:30:51 +1200 Subject: [PATCH] Fix issues cancelling paypal express subscriptions --- CRM/Core/Payment/PayPalImpl.php | 5 ++--- CRM/Core/Payment/PayPalProIPN.php | 21 ++++++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/CRM/Core/Payment/PayPalImpl.php b/CRM/Core/Payment/PayPalImpl.php index d60f5403d458..fa1c435fc7d2 100644 --- a/CRM/Core/Payment/PayPalImpl.php +++ b/CRM/Core/Payment/PayPalImpl.php @@ -414,8 +414,7 @@ public function createRecurringPayments(&$params) { * 'ack' => 'Success', * 'version' => '56.0', * 'build' => '39949200',) - */ - + */ $params['trxn_id'] = $result['profileid']; $params['payment_status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending'); @@ -676,7 +675,7 @@ public function isSuppressSubmitButtons() { * @return array|bool|object */ public function cancelSubscription(&$message = '', $params = array()) { - if ($this->_paymentProcessor['payment_processor_type'] == 'PayPal') { + if ($this->_paymentProcessor['payment_processor_type'] == 'PayPal' || $this->_paymentProcessor['payment_processor_type'] == 'PayPal_Express') { $args = array(); $this->initialize($args, 'ManageRecurringPaymentsProfileStatus'); diff --git a/CRM/Core/Payment/PayPalProIPN.php b/CRM/Core/Payment/PayPalProIPN.php index d230762395c7..73b6a55f9b99 100644 --- a/CRM/Core/Payment/PayPalProIPN.php +++ b/CRM/Core/Payment/PayPalProIPN.php @@ -542,6 +542,7 @@ public function getInput(&$input, &$ids) { /** * Handle payment express IPNs. + * * For one off IPNS no actual response is required * Recurring is more difficult as we have limited confirmation material * lets look up invoice id in recur_contribution & rely on the unique transaction id to ensure no @@ -560,23 +561,25 @@ public function handlePaymentExpress() { // as membership id etc can be derived by the load objects fn $objects = $ids = $input = array(); $isFirst = FALSE; + $input['invoice'] = self::getValue('i', FALSE); $input['txnType'] = $this->retrieve('txn_type', 'String'); - if ($input['txnType'] != 'recurring_payment') { + $contributionRecur = civicrm_api3('contribution_recur', 'getsingle', array( + 'return' => 'contact_id, id', + 'invoice_id' => $input['invoice'], + )); + + if ($input['txnType'] !== 'recurring_payment' && $input['txnType'] !== 'recurring_payment_profile_created') { throw new CRM_Core_Exception('Paypal IPNS not handled other than recurring_payments'); } - $input['invoice'] = self::getValue('i', FALSE); + $this->getInput($input, $ids); - if ($this->transactionExists($input['trxn_id'])) { + if ($input['txnType'] === 'recurring_payment' && $this->transactionExists($input['trxn_id'])) { throw new CRM_Core_Exception('This transaction has already been processed'); } - $contributionRecur = civicrm_api3('contribution_recur', 'getsingle', array( - 'return' => 'contact_id, id', - 'invoice_id' => $input['invoice'], - )); $ids['contact'] = $contributionRecur['contact_id']; $ids['contributionRecur'] = $contributionRecur['id']; - $result = civicrm_api3('contribution', 'getsingle', array('invoice_id' => $input['invoice'])); + $result = civicrm_api3('contribution', 'getsingle', ['invoice_id' => $input['invoice'], 'contribution_test' => '']); $ids['contribution'] = $result['id']; //@todo hard - coding 'pending' for now @@ -600,7 +603,7 @@ public function handlePaymentExpress() { if (!$this->validateData($input, $ids, $objects, TRUE, $paymentProcessorID)) { throw new CRM_Core_Exception('Data did not validate'); } - return $this->recur($input, $ids, $objects, $isFirst); + $this->recur($input, $ids, $objects, $isFirst); } /**