Commit 58776193 authored by Jamie McClelland's avatar Jamie McClelland Committed by mattwire

Always try to update a credit card

Otherwise we may ignore a credit card provided by a user
and instead charge the one associated with their account.

https://lab.civicrm.org/extensions/stripe/issues/4
parent 4df2ca40
...@@ -486,23 +486,15 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment { ...@@ -486,23 +486,15 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
} }
} }
// Avoid the 'use same token twice' issue while still using latest card. $stripeCustomer->card = $card_token;
if (!empty($params['is_secondary_financial_transaction'])) { $updatedStripeCustomer = $this->stripeCatchErrors('save', $stripeCustomer, $params);
// This is a Contribution page with "Separate Membership Payment". if ($this->isErrorReturn($updatedStripeCustomer)) {
// Charge is coming through for the 2nd time. if (($updatedStripeCustomer['type'] == 'invalid_request_error') && ($updatedStripeCustomer['code'] == 'token_already_used')) {
// Don't update customer again or we will get "token_already_used" error from Stripe. // This error is ok, we've already used the token during create_customer
} }
else { else {
$stripeCustomer->card = $card_token; self::handleErrorNotification($updatedStripeCustomer, $params['stripe_error_url']);
$updatedStripeCustomer = $this->stripeCatchErrors('save', $stripeCustomer, $params); return $updatedStripeCustomer;
if ($this->isErrorReturn($updatedStripeCustomer)) {
if (($updatedStripeCustomer['type'] == 'invalid_request_error') && ($updatedStripeCustomer['code'] == 'token_already_used')) {
// This error is ok, we've already used the token during create_customer
}
else {
self::handleErrorNotification($updatedStripeCustomer, $params['stripe_error_url']);
return $updatedStripeCustomer;
}
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment