From 1f988b06937115016c5048cd96e78f5e3526ac80 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Mon, 9 Mar 2020 12:36:18 +0000 Subject: [PATCH] Always use cancelSubscription form instead of enable/disable entity form if cancel is not supported by processor --- CRM/Contribute/Page/Tab.php | 49 ++++++++++++-------------- CRM/Financial/BAO/PaymentProcessor.php | 36 +++++++++---------- 2 files changed, 40 insertions(+), 45 deletions(-) diff --git a/CRM/Contribute/Page/Tab.php b/CRM/Contribute/Page/Tab.php index a3fb460d0039..4484ea32f144 100644 --- a/CRM/Contribute/Page/Tab.php +++ b/CRM/Contribute/Page/Tab.php @@ -48,31 +48,34 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page { * @return array */ public static function recurLinks(int $recurID, $context = 'contribution') { - $links = [ - CRM_Core_Action::VIEW => [ - 'name' => ts('View'), - 'title' => ts('View Recurring Payment'), - 'url' => 'civicrm/contact/view/contributionrecur', - 'qs' => "reset=1&id=%%crid%%&cid=%%cid%%&context={$context}", - ], - CRM_Core_Action::UPDATE => [ + $links[CRM_Core_Action::VIEW] = [ + 'name' => ts('View'), + 'title' => ts('View Recurring Payment'), + 'url' => 'civicrm/contact/view/contributionrecur', + 'qs' => "reset=1&id=%%crid%%&cid=%%cid%%&context={$context}", + ]; + + $paymentProcessorObj = CRM_Contribute_BAO_ContributionRecur::getPaymentProcessorObject($recurID); + if ( + (!CRM_Core_Permission::check('edit contributions') && $context === 'contribution') || + (!$paymentProcessorObj->supports('ChangeSubscriptionAmount') + && !$paymentProcessorObj->supports('EditRecurringContribution') + )) { + $links[CRM_Core_Action::UPDATE] = [ 'name' => ts('Edit'), 'title' => ts('Edit Recurring Payment'), 'url' => 'civicrm/contribute/updaterecur', 'qs' => "reset=1&action=update&crid=%%crid%%&cid=%%cid%%&context={$context}", - ], - CRM_Core_Action::DISABLE => [ - 'name' => ts('Cancel'), - 'title' => ts('Cancel'), - 'ref' => 'crm-enable-disable', - ], - ]; + ]; + } - $paymentProcessorObj = Civi\Payment\System::singleton()->getById(CRM_Contribute_BAO_ContributionRecur::getPaymentProcessorID($recurID)); 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}"; + $links[CRM_Core_Action::DISABLE] = [ + 'name' => ts('Cancel'), + 'title' => ts('Cancel'), + 'url' => 'civicrm/contribute/unsubscribe', + 'qs' => "reset=1&crid=%%crid%%&cid=%%cid%%&context={$context}", + ]; } if ($paymentProcessorObj->supports('UpdateSubscriptionBillingInfo')) { @@ -84,14 +87,6 @@ public static function recurLinks(int $recurID, $context = 'contribution') { ]; } - if ( - (!CRM_Core_Permission::check('edit contributions') && $context === 'contribution') || - (!$paymentProcessorObj->supports('ChangeSubscriptionAmount') - && !$paymentProcessorObj->supports('EditRecurringContribution') - )) { - unset($links[CRM_Core_Action::UPDATE]); - } - return $links; } diff --git a/CRM/Financial/BAO/PaymentProcessor.php b/CRM/Financial/BAO/PaymentProcessor.php index a24cde25ea74..4938eee5f2c4 100644 --- a/CRM/Financial/BAO/PaymentProcessor.php +++ b/CRM/Financial/BAO/PaymentProcessor.php @@ -313,6 +313,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', @@ -343,24 +361,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'];