Skip to content

Commit

Permalink
Fix issues cancelling paypal express subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed May 16, 2018
1 parent 2dc51a5 commit dbb9e6f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
5 changes: 2 additions & 3 deletions CRM/Core/Payment/PayPalImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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');

Expand Down
21 changes: 12 additions & 9 deletions CRM/Core/Payment/PayPalProIPN.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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);
}

/**
Expand Down

0 comments on commit dbb9e6f

Please sign in to comment.