mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-24 06:35:49 +03:00
Handled error for stripe checkout rejection
refs https://github.com/TryGhost/members.js/issues/38 - In case of incomplete Stripe setup like Account name, checkout session creation fails and throws error, which was not being handled and 200 returned after long timeout - This change catches the error and returns correct status along with message for clients to handle it downstream
This commit is contained in:
parent
ec81ccfbeb
commit
11e2732d50
@ -237,18 +237,24 @@ module.exports = function MembersApi({
|
||||
return res.end('No permission');
|
||||
}
|
||||
|
||||
const sessionInfo = await stripe.createCheckoutSession(member, plan, {
|
||||
successUrl: req.body.successUrl,
|
||||
cancelUrl: req.body.cancelUrl,
|
||||
customerEmail: req.body.customerEmail,
|
||||
metadata: req.body.metadata
|
||||
});
|
||||
try {
|
||||
const sessionInfo = await stripe.createCheckoutSession(member, plan, {
|
||||
successUrl: req.body.successUrl,
|
||||
cancelUrl: req.body.cancelUrl,
|
||||
customerEmail: req.body.customerEmail,
|
||||
metadata: req.body.metadata
|
||||
});
|
||||
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
res.end(JSON.stringify(sessionInfo));
|
||||
res.end(JSON.stringify(sessionInfo));
|
||||
} catch (e) {
|
||||
const error = e.message || 'Unable to initiate checkout session';
|
||||
res.writeHead(400);
|
||||
return res.end(error);
|
||||
}
|
||||
});
|
||||
|
||||
middleware.createCheckoutSetupSession.use(ensureStripe, body.json(), async function (req, res) {
|
||||
|
Loading…
Reference in New Issue
Block a user