Commit 84d00048 authored by mattwire's avatar mattwire

Fix token_already_used

parent a26693c6
...@@ -124,13 +124,15 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment { ...@@ -124,13 +124,15 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
* @return string errorMessage (or statusbounce if URL is specified) * @return string errorMessage (or statusbounce if URL is specified)
*/ */
public function handleErrorNotification($err, $bounceURL = NULL) { public function handleErrorNotification($err, $bounceURL = NULL) {
$errorMessage = 'Oops! Looks like there was an error. Payment Response: <br />' . $errorMessage = 'Payment Response: <br />' .
'Type: ' . $err['type'] . '<br />' . 'Type: ' . $err['type'] . '<br />' .
'Code: ' . $err['code'] . '<br />' . 'Code: ' . $err['code'] . '<br />' .
'Message: ' . $err['message'] . '<br />'; 'Message: ' . $err['message'] . '<br />';
Civi::log()->debug('Stripe Payment Error: ' . $errorMessage);
if ($bounceURL) { if ($bounceURL) {
CRM_Core_Error::statusBounce($errorMessage, $bounceURL); CRM_Core_Error::statusBounce($errorMessage, $bounceURL, 'Payment Error');
} }
return $errorMessage; return $errorMessage;
} }
...@@ -483,6 +485,7 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment { ...@@ -483,6 +485,7 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
return $stripeCustomer; return $stripeCustomer;
} }
} }
// Avoid the 'use same token twice' issue while still using latest card. // Avoid the 'use same token twice' issue while still using latest card.
if (!empty($params['is_secondary_financial_transaction'])) { if (!empty($params['is_secondary_financial_transaction'])) {
// This is a Contribution page with "Separate Membership Payment". // This is a Contribution page with "Separate Membership Payment".
...@@ -491,11 +494,16 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment { ...@@ -491,11 +494,16 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
} }
else { else {
$stripeCustomer->card = $card_token; $stripeCustomer->card = $card_token;
$response = $this->stripeCatchErrors('save', $stripeCustomer, $params); $stripeCustomer = $this->stripeCatchErrors('save', $stripeCustomer, $params);
if (isset($response) && $this->isErrorReturn($response)) { if ($this->isErrorReturn($stripeCustomer)) {
self::handleErrorNotification($response, $params['stripe_error_url']); if (($stripeCustomer['type'] == 'invalid_request_error') && ($stripeCustomer['code'] == 'token_already_used')) {
return $response; // This error is ok, we've already used the token during create_customer
} }
else {
self::handleErrorNotification($stripeCustomer, $params['stripe_error_url']);
return $stripeCustomer;
}
}
} }
} }
else { else {
......
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