Skip to content

Commit

Permalink
[REF] Retrieve the token if it is avaliable from the Payment Token ta…
Browse files Browse the repository at this point in the history
…ble if no processor_id is set

Update the updateBilling and updateSubscription forms as well
  • Loading branch information
seamuslee001 committed Jun 2, 2020
1 parent 3e401df commit 02f3e80
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions CRM/Contribute/BAO/ContributionRecur.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ public static function getSubscriptionDetails($entityID, $entity = 'recur') {
SELECT rec.id as recur_id,
rec.processor_id as subscription_id,
rec.frequency_interval,
rec.payment_token_id as token_id,
rec.installments,
rec.frequency_unit,
rec.amount,
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Form/CancelSubscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public function postProcess() {
$propertyBag->setIsNotifyProcessorOnCancelRecur(!empty($params['send_cancel_request']));
}
$propertyBag->setContributionRecurID($this->getSubscriptionDetails()->recur_id);
$propertyBag->setRecurProcessorID($this->getSubscriptionDetails()->subscription_id);
$propertyBag->setRecurProcessorID($this->getSubscriptionID());
$message = $this->_paymentProcessorObj->doCancelRecurring($propertyBag)['message'];
}
catch (\Civi\Payment\Exception\PaymentProcessorException $e) {
Expand Down
11 changes: 11 additions & 0 deletions CRM/Contribute/Form/ContributionRecur.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,17 @@ protected function getSubscriptionContactID() {
return $sub->contact_id ?? FALSE;
}

protected function getSubscriptionID() {
$sub = $this->getSubscriptionDetails();
if (empty($sub->subscription_id) && !empty($sub->token_id)) {
$tokenDetails = civicrm_api3('PaymentToken', 'get', ['id' => $sub->token_id]);
if (!empty($tokenDetails['values'])) {
return $tokenDetails['values'][$tokenDetails['id']]['token'];
}
}
return $sub->subscription_id;
}

/**
* Is this being used by a front end user to update their own recurring.
*
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Form/UpdateBilling.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public function postProcess() {
$processorParams['country'] = CRM_Core_PseudoConstant::country($params["billing_country_id-{$this->_bltID}"], FALSE);
$processorParams['month'] = $processorParams['credit_card_exp_date']['M'];
$processorParams['year'] = $processorParams['credit_card_exp_date']['Y'];
$processorParams['subscriptionId'] = $this->_subscriptionDetails->subscription_id;
$processorParams['subscriptionId'] = $this->getSubscriptionID();
$processorParams['amount'] = $this->_subscriptionDetails->amount;
$updateSubscription = $this->_paymentProcessor['object']->updateSubscriptionBillingInfo($message, $processorParams);
if (is_a($updateSubscription, 'CRM_Core_Error')) {
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Form/UpdateSubscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function postProcess() {
$params['id'] = $this->_subscriptionDetails->recur_id;
$message = '';

$params['subscriptionId'] = $this->_subscriptionDetails->subscription_id;
$params['subscriptionId'] = $this->getSubscriptionID();
$updateSubscription = TRUE;
if ($this->_paymentProcessorObj->supports('changeSubscriptionAmount')) {
try {
Expand Down

0 comments on commit 02f3e80

Please sign in to comment.