0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Fixed creating checkout sessions with data-attribute-plan

refs https://github.com/TryGhost/Team/issues/2199

The data-attribute handler was not using the utils/api package but
instead reimplemnted the logic to create checkout sessions, this was
missed when moving to a redirect for checkout and so wasn't working
correctly.
This commit is contained in:
Fabien "egg" O'Carroll 2022-11-02 15:18:46 +07:00 committed by Fabien 'egg' O'Carroll
parent 592e282f5b
commit bd5243b3bd

View file

@ -121,15 +121,18 @@ export function planClickHandler({event, el, errorEl, siteUrl, site, member, cli
}
return res.json();
});
}).then(function (result) {
let stripe = window.Stripe(result.publicKey);
return stripe.redirectToCheckout({
sessionId: result.sessionId
});
}).then(function (result) {
if (result.error) {
throw new Error(result.error.message);
}).then(function (responseBody) {
if (responseBody.url) {
return window.location.assign(responseBody.url);
}
const stripe = window.Stripe(responseBody.publicKey);
return stripe.redirectToCheckout({
sessionId: responseBody.sessionId
}).then(function (redirectResult) {
if (redirectResult.error) {
throw new Error(redirectResult.error.message);
}
});
}).catch(function (err) {
console.error(err);
el.addEventListener('click', clickHandler);