Skip to content

Commit

Permalink
Merge pull request #16501 from eileenmcnaughton/cancel_recur
Browse files Browse the repository at this point in the history
Update cancelSubscription  form to use updated methodology
  • Loading branch information
mattwire authored Mar 10, 2020
2 parents f75168a + 11ec1f9 commit 2ae6888
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
12 changes: 6 additions & 6 deletions CRM/Contribute/Form/CancelSubscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
use Civi\Payment\PropertyBag;

/**
*
Expand Down Expand Up @@ -187,7 +188,7 @@ public function setDefaultValues() {
* Process the form submission.
*/
public function postProcess() {
$status = $message = NULL;
$message = NULL;
$cancelSubscription = TRUE;
$params = $this->controller->exportValues($this->_name);

Expand All @@ -207,17 +208,16 @@ public function postProcess() {
// civicrm_contribution_recur.processor_id
$cancelParams = ['subscriptionId' => $this->_subscriptionDetails->subscription_id];
try {
$cancelSubscription = $this->_paymentProcessorObj->cancelSubscription($message, $cancelParams);
$propertyBag = new PropertyBag();
$propertyBag->setRecurProcessorID($this->_subscriptionDetails->subscription_id);
$message = $this->_paymentProcessorObj->doCancelRecurring($propertyBag)['message'];
}
catch (\Civi\Payment\Exception\PaymentProcessorException $e) {
CRM_Core_Error::statusBounce($e->getMessage());
}
}

if (is_a($cancelSubscription, 'CRM_Core_Error')) {
CRM_Core_Error::displaySessionError($cancelSubscription);
}
elseif ($cancelSubscription) {
if ($cancelSubscription) {
try {
civicrm_api3('ContributionRecur', 'cancel', [
'id' => $this->_subscriptionDetails->recur_id,
Expand Down
28 changes: 28 additions & 0 deletions CRM/Core/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,34 @@ public function doPayment(&$params, $component = 'contribute') {
return $result;
}

/**
* Cancel a recurring subscription.
*
* Payment processor classes should override this rather than implementing cancelSubscription.
*
* A PaymentProcessorException should be thrown if the update of the contribution_recur
* record should not proceed (in many cases this function does nothing
* as the payment processor does not need to take any action & this should silently
* proceed. Note the form layer will only call this after calling
* $processor->supports('cancelRecurring');
*
* @param \Civi\Payment\PropertyBag $propertyBag
*
* @return array
*
* @throws \Civi\Payment\Exception\PaymentProcessorException
*/
public function doCancelRecurring(PropertyBag $propertyBag) {
if (method_exists($this, 'cancelSubscription')) {
$message = NULL;
if ($this->cancelSubscription($message, $propertyBag)) {
return ['message' => $message];
}
throw new PaymentProcessorException($message);
}
return ['message' => ts('Recurring contribution cancelled')];
}

/**
* Refunds payment
*
Expand Down
1 change: 1 addition & 0 deletions Civi/Payment/PropertyBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class PropertyBag implements \ArrayAccess {
'frequency_interval' => 'recurFrequencyInterval',
'recurFrequencyUnit' => TRUE,
'frequency_unit' => 'recurFrequencyUnit',
'subscriptionId' => 'recurProcessorID',
'recurProcessorID' => TRUE,
'transactionID' => TRUE,
'transaction_id' => 'transactionID',
Expand Down

0 comments on commit 2ae6888

Please sign in to comment.