From dd566b3d29218aac4ba8de1d3b7bdede36b639cb Mon Sep 17 00:00:00 2001 From: Fabien O'Carroll Date: Thu, 3 Oct 2019 17:18:31 +0700 Subject: [PATCH] Added support for custome success/cancel urls no-issue This will allow clients to customise where they are redirecting to after the stripe checkout session is exited. --- ghost/members-api/index.js | 5 ++++- ghost/members-api/lib/stripe/index.js | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ghost/members-api/index.js b/ghost/members-api/index.js index d7ca525727..7ec086e479 100644 --- a/ghost/members-api/index.js +++ b/ghost/members-api/index.js @@ -162,7 +162,10 @@ module.exports = function MembersApi({ return res.end('No permission'); } - const sessionInfo = await stripe.createCheckoutSession(member, plan); + const sessionInfo = await stripe.createCheckoutSession(member, plan, { + successUrl: req.body.successUrl, + cancelUrl: req.body.cancelUrl + }); res.writeHead(200, { 'Content-Type': 'application/json' diff --git a/ghost/members-api/lib/stripe/index.js b/ghost/members-api/lib/stripe/index.js index 145e80d0c9..e05905d7d3 100644 --- a/ghost/members-api/lib/stripe/index.js +++ b/ghost/members-api/lib/stripe/index.js @@ -77,7 +77,7 @@ module.exports = class StripePaymentProcessor { return this._stripe.webhooks.constructEvent(body, signature, this._webhookSecret); } - async createCheckoutSession(member, planName) { + async createCheckoutSession(member, planName, options) { let customer; if (member) { try { @@ -92,8 +92,8 @@ module.exports = class StripePaymentProcessor { 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, + success_url: options.successUrl || this._checkoutSuccessUrl, + cancel_url: options.cancelUrl || this._checkoutCancelUrl, customer: customer ? customer.id : undefined, subscription_data: { items: [{