Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add stripe 3DS to checkout page(WIP) #710

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion src/payment/payment-methods/stripe/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,44 @@ import { handleApiError } from '../../data/handleRequestError';

ensureConfig(['ECOMMERCE_BASE_URL', 'STRIPE_RESPONSE_URL'], 'Stripe API service');

const handleServerResponse = async (response, stripe, setLocation, skus) => {
if (response.data.requiresAction) {
// Call stripe handleNextAction to open the 3ds authentication page
const { error: errorAction, paymentIntent } = await stripe.handleNextAction(
{ clientSecret: response.data.clientSecret },
);
if (errorAction) {
logError(errorAction, {
messagePrefix: 'Stripe 3DS Error',
paymentMethod: 'Stripe',
paymentErrorType: '3DS Error',
});
handleApiError(errorAction);
} else {
const postData = formurlencoded({
payment_intent_id: paymentIntent.id,
skus,
});
// TODO: move this out as part of REV-3187 to confirm based on where ecommerce redirects.
// If 3DS is successful tell ecommerce to finish the payment
await getAuthenticatedHttpClient()
.post(
`${process.env.STRIPE_RESPONSE_URL}`,
postData,
{
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
},
)
.then(actionsResponse => {
handleServerResponse(actionsResponse, stripe, setLocation, skus);
});
}
} else {
// If no actions needed go to receipt page
setLocation(response.data.receipt_page_url);
}
};

/**
* Checkout with Stripe
*
Expand Down Expand Up @@ -77,7 +115,7 @@ export default async function checkout(
},
)
.then(response => {
setLocation(response.data.receipt_page_url);
handleServerResponse(response, stripe, setLocation, skus);
})
.catch(error => {
const errorData = error.response ? error.response.data : null;
Expand Down