Skip to content

Commit

Permalink
Always use cancelSubscription form instead of enable/disable entity f…
Browse files Browse the repository at this point in the history
…orm if cancel is not supported by processor
  • Loading branch information
mattwire committed Feb 18, 2022
1 parent 9775afa commit ca0fa1e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
7 changes: 7 additions & 0 deletions CRM/Contribute/Form/CancelSubscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ public function preProcess() {
$this->setTitle($this->_mid ? ts('Cancel Auto-renewal') : ts('Cancel Recurring Contribution'));
$this->assign('mode', $this->_mode);

// If the processor does not support cancelling recur disable option to send cancellation request to the processor.
if (!$this->_paymentProcessorObj->supports('cancelRecurring')) {
unset($this->entityFields['send_cancel_request']);
}

// If we are self service (contact is cancelling for themselves via a cancel link) don't give the option to notify
// or send cancellation request. They will be set automatically in postProcess
if ($this->isSelfService()) {
unset($this->entityFields['send_cancel_request'], $this->entityFields['is_notify']);
}
Expand Down
9 changes: 2 additions & 7 deletions CRM/Contribute/Page/Tab.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,10 @@ public static function recurLinks(int $recurID, $context = 'contribution') {
$links[CRM_Core_Action::DISABLE] = [
'name' => ts('Cancel'),
'title' => ts('Cancel'),
'ref' => 'crm-enable-disable',
'url' => 'civicrm/contribute/unsubscribe',
'qs' => "reset=1&crid=%%crid%%&cid=%%cid%%&context={$context}",
];

if ($paymentProcessorObj->supports('cancelRecurring')) {
unset($links[CRM_Core_Action::DISABLE]['extra'], $links[CRM_Core_Action::DISABLE]['ref']);
$links[CRM_Core_Action::DISABLE]['url'] = "civicrm/contribute/unsubscribe";
$links[CRM_Core_Action::DISABLE]['qs'] = "reset=1&crid=%%crid%%&cid=%%cid%%&context={$context}";
}

if ($paymentProcessorObj->supports('UpdateSubscriptionBillingInfo')) {
$links[CRM_Core_Action::RENEW] = [
'name' => ts('Change Billing Details'),
Expand Down
36 changes: 18 additions & 18 deletions CRM/Financial/BAO/PaymentProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,24 @@ public static function getAllPaymentProcessors($mode = 'all', $reset = FALSE, $i
}

$processors = civicrm_api3('payment_processor', 'get', $retrievalParameters);
// Add the pay-later pseudo-processor.
$processors['values'][0] = [
'id' => 0,
'payment_processor_type_id' => 0,
// This shouldn't be required but there are still some processors hacked into core with nasty 'if's.
'api.payment_processor_type.getsingle' => ['name' => 'Manual'],
'class_name' => 'Payment_Manual',
'name' => 'pay_later',
'billing_mode' => '',
'is_default' => 0,
'payment_instrument_id' => key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1')),
// Making this optionally recur would give lots of options -but it should
// be a row in the payment processor table before we do that.
'is_recur' => FALSE,
'is_test' => FALSE,
'domain_id' => CRM_Core_Config::domainID(),
'is_active' => 1,
];
foreach ($processors['values'] as $processor) {
$fieldsToProvide = [
'id',
Expand Down Expand Up @@ -334,24 +352,6 @@ public static function getAllPaymentProcessors($mode = 'all', $reset = FALSE, $i
$processors['values'][$processor['id']]['object'] = Civi\Payment\System::singleton()->getByProcessor($processors['values'][$processor['id']]);
}

// Add the pay-later pseudo-processor.
$processors['values'][0] = [
'object' => new CRM_Core_Payment_Manual(),
'id' => 0,
'payment_processor_type_id' => 0,
// This shouldn't be required but there are still some processors hacked into core with nasty 'if's.
'payment_processor_type' => 'Manual',
'class_name' => 'Payment_Manual',
'name' => 'pay_later',
'billing_mode' => '',
'is_default' => 0,
'payment_instrument_id' => key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1')),
// Making this optionally recur would give lots of options -but it should
// be a row in the payment processor table before we do that.
'is_recur' => FALSE,
'is_test' => FALSE,
];

CRM_Utils_Cache::singleton()->set($cacheKey, $processors['values']);

return $processors['values'];
Expand Down
4 changes: 1 addition & 3 deletions tests/phpunit/CRM/Contribute/Form/CancelSubscriptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,8 @@ public function testCancelSubscriptionForm(): void {
]);

$actions = CRM_Contribute_Page_Tab::recurLinks($this->getContributionRecurID());
// Using "crm-enable-disable"
$this->assertEquals($actions[CRM_Core_Action::DISABLE]['ref'], 'crm-enable-disable');
// Using "Cancel Recurring" form
// $this->assertEquals($actions[CRM_Core_Action::DISABLE]['url'], 'civicrm/contribute/unsubscribe');
$this->assertEquals($actions[CRM_Core_Action::DISABLE]['url'], 'civicrm/contribute/unsubscribe');
}

}

0 comments on commit ca0fa1e

Please sign in to comment.