mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-25 02:31:59 -05:00
Added ability to prefill customer email for anonymous checkouts
refs https://github.com/TryGhost/members.js/issues/10 - Allows passing an additional `customerEmail` value to our checkout creation API - This value is used to pass `customer_email` option to stripe's checkout session - https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-customer_email. The `customer_email` allows pre-filling the customer's email field in case of an anonymous checkout as customer doesn't exist already, and also ensures the stripe subscription is created with same email address as given by user during signup flow.
This commit is contained in:
parent
2c14a337ad
commit
fac6c3d97e
2 changed files with 4 additions and 1 deletions
|
@ -217,7 +217,8 @@ module.exports = function MembersApi({
|
|||
|
||||
const sessionInfo = await stripe.createCheckoutSession(member, plan, {
|
||||
successUrl: req.body.successUrl,
|
||||
cancelUrl: req.body.cancelUrl
|
||||
cancelUrl: req.body.cancelUrl,
|
||||
customerEmail: req.body.customerEmail
|
||||
});
|
||||
|
||||
res.writeHead(200, {
|
||||
|
|
|
@ -113,11 +113,13 @@ module.exports = class StripePaymentProcessor {
|
|||
customer = null;
|
||||
}
|
||||
const plan = this._plans.find(plan => plan.nickname === planName);
|
||||
const customerEmail = (!customer && options.customerEmail) ? options.customerEmail : undefined;
|
||||
const session = await this._stripe.checkout.sessions.create({
|
||||
payment_method_types: ['card'],
|
||||
success_url: options.successUrl || this._checkoutSuccessUrl,
|
||||
cancel_url: options.cancelUrl || this._checkoutCancelUrl,
|
||||
customer: customer ? customer.id : undefined,
|
||||
customer_email: customerEmail,
|
||||
subscription_data: {
|
||||
items: [{
|
||||
plan: plan.id
|
||||
|
|
Loading…
Add table
Reference in a new issue