mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Updated handler for checkout to not require member
no-issue This will allow the flow to start from the frontend.
This commit is contained in:
parent
f7630ec05b
commit
d67ad13057
1 changed files with 12 additions and 11 deletions
|
@ -117,38 +117,39 @@ module.exports = function MembersApi({
|
|||
const plan = req.body.plan;
|
||||
const identity = req.body.identity;
|
||||
|
||||
if (!plan || !identity) {
|
||||
if (!plan) {
|
||||
res.writeHead(400);
|
||||
return res.end('Bad Request.');
|
||||
}
|
||||
|
||||
let email;
|
||||
try {
|
||||
const claims = await decodeToken(identity);
|
||||
email = claims.sub;
|
||||
if (!identity) {
|
||||
email = null;
|
||||
} else {
|
||||
const claims = await decodeToken(identity);
|
||||
email = claims.sub;
|
||||
}
|
||||
} catch (err) {
|
||||
res.writeHead(401);
|
||||
return res.end('Unauthorized');
|
||||
}
|
||||
|
||||
const member = await users.get({email});
|
||||
const member = email ? await users.get({email}) : null;
|
||||
|
||||
// Do not allow members already with a plan to initiate a new checkout session
|
||||
if (member.plans.length > 0) {
|
||||
// Do not allow members already with a subscription to initiate a new checkout session
|
||||
if (member && member.stripe.subscriptions.length > 0) {
|
||||
res.writeHead(403);
|
||||
return res.end('No permission');
|
||||
}
|
||||
|
||||
const session = await stripe.createCheckoutSession(member, plan);
|
||||
const sessionInfo = await stripe.createCheckoutSession(member, plan);
|
||||
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
res.end(JSON.stringify({
|
||||
sessionId: session.id,
|
||||
publicKey: stripe.getPublicConfig().publicKey
|
||||
}));
|
||||
res.end(JSON.stringify(sessionInfo));
|
||||
});
|
||||
|
||||
apiInstance.post('/handle-stripe-webhook', ensureStripe, body.raw({type: 'application/json'}), async function (req, res) {
|
||||
|
|
Loading…
Add table
Reference in a new issue