From 2f90c9762956c50c2e92dfbc4c4030d713d971dd Mon Sep 17 00:00:00 2001 From: Rish Date: Tue, 19 May 2020 13:41:03 +0530 Subject: [PATCH] Added metadata option to stripe checkout session refs TryGhost/members.js#29 - Allows passing metadata to checkout session API - Metadata is passed to stripe's checkout session on creation and read back from webhook event - Allows clients like members.js to pass custom info like member name to Stripe flow --- ghost/members-api/index.js | 3 ++- ghost/members-api/lib/stripe/index.js | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ghost/members-api/index.js b/ghost/members-api/index.js index 1b6f099156..9ec6c9416e 100644 --- a/ghost/members-api/index.js +++ b/ghost/members-api/index.js @@ -218,7 +218,8 @@ module.exports = function MembersApi({ const sessionInfo = await stripe.createCheckoutSession(member, plan, { successUrl: req.body.successUrl, cancelUrl: req.body.cancelUrl, - customerEmail: req.body.customerEmail + customerEmail: req.body.customerEmail, + metadata: req.body.metadata }); res.writeHead(200, { diff --git a/ghost/members-api/lib/stripe/index.js b/ghost/members-api/lib/stripe/index.js index 293913a2a9..c1857af5bf 100644 --- a/ghost/members-api/lib/stripe/index.js +++ b/ghost/members-api/lib/stripe/index.js @@ -115,12 +115,14 @@ module.exports = class StripePaymentProcessor { } const plan = this._plans.find(plan => plan.nickname === planName); const customerEmail = (!customer && options.customerEmail) ? options.customerEmail : undefined; + const metadata = options.metadata || 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, + metadata, subscription_data: { items: [{ plan: plan.id