Skip to content
Snippets Groups Projects
Commit 40a37004 authored by mattwire's avatar mattwire Committed by mattwire
Browse files

Fixes to 3dsecure for paymentIntents and setupIntents on thankyou page

parent a9a6b3df
No related branches found
No related tags found
1 merge request!1526.6 to master
...@@ -11,51 +11,46 @@ ...@@ -11,51 +11,46 @@
/** /**
* Handle the response from the server for the payment/setupIntent * Handle the response from the server for the payment/setupIntent
* @param result * @param paymentIntentProcessResponse
*/ */
handleIntentServerResponse: function(result) { handleIntentServerResponse: function(paymentIntentProcessResponse) {
CRM.payment.debugging(confirm.scriptName, 'handleServerResponse'); CRM.payment.debugging(confirm.scriptName, 'handleIntentServerResponse');
if (result.error) { if (paymentIntentProcessResponse.requires_action) {
// Show error from server on payment form // Use Stripe.js to handle required card action
CRM.payment.debugging(confirm.scriptName, result.error.message); if (CRM.vars.stripe.hasOwnProperty('paymentIntentID')) {
confirm.handlePaymentIntentAction(paymentIntentProcessResponse);
}
else if (CRM.vars.stripe.hasOwnProperty('setupIntentID')) {
confirm.handleCardConfirm();
}
}
else {
// All good, nothing more to do
CRM.payment.debugging(confirm.scriptName, 'success - payment captured');
confirm.swalFire({ confirm.swalFire({
title: '', title: ts('Payment successful'),
text: result.error.message, icon: 'success'
icon: 'error'
}, '', true); }, '', true);
} }
else
if (result.requires_action) {
// Use Stripe.js to handle required card action
if (CRM.vars.stripe.hasOwnProperty('paymentIntentID')) {
confirm.handlePaymentIntentAction(result);
}
else if (CRM.vars.stripe.hasOwnProperty('setupIntentID')) {
confirm.handleCardConfirm();
}
}
else {
// All good, nothing more to do
CRM.payment.debugging(confirm.scriptName, 'success - payment captured');
confirm.swalFire({
title: ts('Payment successful'),
icon: 'success'
}, '', true);
}
}, },
/** /**
* Handle the next action for the paymentIntent * Handle the next action for the paymentIntent
* @param response * @param paymentIntentProcessResponse
*/ */
handlePaymentIntentAction: function(response) { handlePaymentIntentAction: function(paymentIntentProcessResponse) {
switch (CRM.vars.stripe.paymentIntentMethod) { switch (CRM.vars.stripe.paymentIntentMethod) {
case 'automatic': case 'automatic':
confirm.stripe.handleCardPayment(response.paymentIntentClientSecret) confirm.stripe.handleCardPayment(paymentIntentProcessResponse.paymentIntentClientSecret)
.then(function(result) { .then(function(handleCardPaymentResult) {
if (result.error) { if (handleCardPaymentResult.error) {
// Show error in payment form // Show error in payment form
confirm.handleCardConfirm(); CRM.payment.debugging(confirm.scriptName, handleCardPaymentResult.error.message);
confirm.swalFire({
title: '',
text: handleCardPaymentResult.error.message,
icon: 'error'
}, '', true);
} }
else { else {
// The card action has been handled // The card action has been handled
...@@ -66,11 +61,16 @@ ...@@ -66,11 +61,16 @@
break; break;
case 'manual': case 'manual':
confirm.stripe.handleCardAction(response.paymentIntentClientSecret) confirm.stripe.handleCardAction(paymentIntentProcessResponse.paymentIntentClientSecret)
.then(function(result) { .then(function(handleCardActionResult) {
if (result.error) { if (handleCardActionResult.error) {
// Show error in payment form // Show error in payment form
confirm.handleCardConfirm(); CRM.payment.debugging(confirm.scriptName, handleCardActionResult.error.message);
confirm.swalFire({
title: '',
text: handleCardActionResult.error.message,
icon: 'error'
}, '', true);
} }
else { else {
// The card action has been handled // The card action has been handled
...@@ -97,35 +97,72 @@ ...@@ -97,35 +97,72 @@
description: document.title, description: document.title,
csrfToken: CRM.vars.stripe.csrfToken csrfToken: CRM.vars.stripe.csrfToken
}) })
.done(function(result) { .done(function(paymentIntentProcessResponse) {
confirm.swalClose(); confirm.swalClose();
// Handle server response (see Step 3) // Handle server response (see Step 3)
confirm.handleIntentServerResponse(result); CRM.payment.debugging(confirm.scriptName, 'StripePaymentintent.Process done');
if (paymentIntentProcessResponse.is_error) {
// Triggered for api3_create_error or Exception
confirm.swalFire({
title: '',
text: paymentIntentProcessResponse.error_message,
icon: 'error'
}, '', true);
}
else {
paymentIntentProcessResponse = paymentIntentProcessResponse.values;
confirm.handleIntentServerResponse(paymentIntentProcessResponse);
}
}) })
.fail(function() { .fail(function(object) {
confirm.swalClose(); var error = 'Unknown error';
if (object.hasOwnProperty('statusText') && (object.statusText !== 'OK')) {
// A PHP exit can return 200 "OK" but we don't want to display "OK" as the error!
error = object.statusText;
}
CRM.payment.debugging(confirm.scriptName, error);
confirm.swalFire({
title: '',
text: error,
icon: 'error'
}, '', true);
}); });
} }
else if (CRM.vars.stripe.hasOwnProperty('setupIntentID')) { else if (CRM.vars.stripe.hasOwnProperty('setupIntentID')) {
if (CRM.vars.stripe.setupIntentNextAction.type === 'use_stripe_sdk') { if (CRM.vars.stripe.setupIntentNextAction.type === 'use_stripe_sdk') {
confirm.swalClose(); confirm.swalClose();
confirm.stripe.confirmCardSetup(CRM.vars.stripe.setupIntentClientSecret) confirm.stripe.confirmCardSetup(CRM.vars.stripe.setupIntentClientSecret)
.then(function(result) { .then(function(confirmCardSetupResult) {
if (result.error) { // Handle confirmCardSetupResult.error or confirmCardSetupResult.setupIntent
if (confirmCardSetupResult.error) {
// Record error and display message to user
CRM.api3('StripePaymentintent', 'createorupdate', { CRM.api3('StripePaymentintent', 'createorupdate', {
stripe_intent_id: CRM.vars.stripe.setupIntentID, stripe_intent_id: CRM.vars.stripe.setupIntentID,
status: 'error', status: 'error',
csrfToken: CRM.vars.stripe.csrfToken csrfToken: CRM.vars.stripe.csrfToken
}); });
CRM.payment.debugging(confirm.scriptName, confirmCardSetupResult.error.message);
confirm.swalFire({
title: '',
text: confirmCardSetupResult.error.message,
icon: 'error'
}, '', true);
} }
else { else {
// Record success and display message to user
CRM.api3('StripePaymentintent', 'createorupdate', { CRM.api3('StripePaymentintent', 'createorupdate', {
stripe_intent_id: CRM.vars.stripe.setupIntentID, stripe_intent_id: CRM.vars.stripe.setupIntentID,
status: result.setupIntent.status, status: confirmCardSetupResult.setupIntent.status,
csrfToken: CRM.vars.stripe.csrfToken csrfToken: CRM.vars.stripe.csrfToken
}); });
CRM.payment.debugging(confirm.scriptName, 'success - payment captured');
confirm.swalFire({
title: ts('Payment successful'),
icon: 'success'
}, '', true);
} }
confirm.handleIntentServerResponse(result);
}); });
} }
} }
...@@ -162,7 +199,7 @@ ...@@ -162,7 +199,7 @@
}) })
.fail(function() { .fail(function() {
confirm.stripeLoading = false; confirm.stripeLoading = false;
debugging('Failed to load Stripe.js'); CRM.payment.debugging(confirm.scriptName, 'Failed to load Stripe.js');
}); });
} }
}, },
...@@ -193,6 +230,7 @@ ...@@ -193,6 +230,7 @@
Swal.close(); Swal.close();
} }
} }
}; };
if (typeof CRM.payment === 'undefined') { if (typeof CRM.payment === 'undefined') {
......
...@@ -273,7 +273,6 @@ ...@@ -273,7 +273,6 @@
} }
}) })
.fail(function(object) { .fail(function(object) {
// Triggered when http code !== 200 (eg. 400 Bad request)
var error = 'Unknown error'; var error = 'Unknown error';
if (object.hasOwnProperty('statusText') && (object.statusText !== 'OK')) { if (object.hasOwnProperty('statusText') && (object.statusText !== 'OK')) {
// A PHP exit can return 200 "OK" but we don't want to display "OK" as the error! // A PHP exit can return 200 "OK" but we don't want to display "OK" as the error!
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment