mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-25 02:31:59 -05:00
Updated createCheckoutSession to work w/o member
no-issue This will allow us to do a payment first flow, in which a payment is taken, before creating a member
This commit is contained in:
parent
0527304376
commit
f7630ec05b
1 changed files with 11 additions and 3 deletions
|
@ -63,13 +63,18 @@ module.exports = class StripePaymentProcessor {
|
|||
}
|
||||
|
||||
async createCheckoutSession(member, planName) {
|
||||
const customer = await api.customers.ensure(this._stripe, member, member.email);
|
||||
let customer;
|
||||
if (member) {
|
||||
customer = await this._customerForMember(member);
|
||||
} else {
|
||||
customer = null;
|
||||
}
|
||||
const plan = this._plans.find(plan => plan.nickname === planName);
|
||||
const session = await this._stripe.checkout.sessions.create({
|
||||
payment_method_types: ['card'],
|
||||
success_url: this._checkoutSuccessUrl,
|
||||
cancel_url: this._checkoutCancelUrl,
|
||||
customer: customer.id,
|
||||
customer: customer ? customer.id : undefined,
|
||||
subscription_data: {
|
||||
items: [{
|
||||
plan: plan.id
|
||||
|
@ -77,7 +82,10 @@ module.exports = class StripePaymentProcessor {
|
|||
}
|
||||
});
|
||||
|
||||
return session;
|
||||
return {
|
||||
sessionId: session.id,
|
||||
publicKey: this._public_token
|
||||
};
|
||||
}
|
||||
|
||||
async getActiveSubscriptions(member) {
|
||||
|
|
Loading…
Add table
Reference in a new issue