Passed default URLs when creating checkout session (#235)

* Passed default URLs when creating checkout session

no-issue

This fixes a bug when a checkout session is created without passing
custom redirect URLs
This commit is contained in:
Fabien 'egg' O'Carroll 2021-01-27 15:19:09 +00:00 committed by GitHub
parent 80e2f4d817
commit ef9cb0862c
2 changed files with 15 additions and 6 deletions

View File

@ -97,7 +97,13 @@ module.exports = function MembersApi({
stripeAPIService, stripeAPIService,
stripePlansService, stripePlansService,
tokenService, tokenService,
sendEmailWithMagicLink sendEmailWithMagicLink,
config: {
checkoutSuccessUrl: stripeConfig.checkoutSuccessUrl,
checkoutCancelUrl: stripeConfig.checkoutCancelUrl,
billingSuccessUrl: stripeConfig.billingSuccessUrl,
billingCancelUrl: stripeConfig.billingCancelUrl
}
}); });
const ready = paymentConfig.stripe ? Promise.all([ const ready = paymentConfig.stripe ? Promise.all([

View File

@ -12,6 +12,7 @@ const errors = require('ghost-ignition').errors;
* @param {any} deps.stripeAPIService * @param {any} deps.stripeAPIService
* @param {any} deps.stripePlanService * @param {any} deps.stripePlanService
* @param {any} deps.tokenService * @param {any} deps.tokenService
* @param {any} deps.config
*/ */
module.exports = class RouterController { module.exports = class RouterController {
constructor({ constructor({
@ -21,7 +22,8 @@ module.exports = class RouterController {
stripeAPIService, stripeAPIService,
stripePlansService, stripePlansService,
tokenService, tokenService,
sendEmailWithMagicLink sendEmailWithMagicLink,
config
}) { }) {
this._memberRepository = memberRepository; this._memberRepository = memberRepository;
this._allowSelfSignup = allowSelfSignup; this._allowSelfSignup = allowSelfSignup;
@ -30,6 +32,7 @@ module.exports = class RouterController {
this._stripePlansService = stripePlansService; this._stripePlansService = stripePlansService;
this._tokenService = tokenService; this._tokenService = tokenService;
this._sendEmailWithMagicLink = sendEmailWithMagicLink; this._sendEmailWithMagicLink = sendEmailWithMagicLink;
this._config = config;
} }
async ensureStripe(_req, res, next) { async ensureStripe(_req, res, next) {
@ -172,8 +175,8 @@ module.exports = class RouterController {
const customer = await this._stripeAPIService.getCustomerForMemberCheckoutSession(member); const customer = await this._stripeAPIService.getCustomerForMemberCheckoutSession(member);
const session = await this._stripeAPIService.createCheckoutSetupSession(customer, { const session = await this._stripeAPIService.createCheckoutSetupSession(customer, {
successUrl: req.body.successUrl, successUrl: req.body.successUrl || this._config.billingSuccessUrl,
cancelUrl: req.body.cancelUrl cancelUrl: req.body.cancelUrl || this._config.billingCancelUrl
}); });
const publicKey = this._stripeAPIService.getPublicKey(); const publicKey = this._stripeAPIService.getPublicKey();
const sessionInfo = { const sessionInfo = {
@ -222,8 +225,8 @@ module.exports = class RouterController {
if (!member) { if (!member) {
const customer = null; const customer = null;
const session = await this._stripeAPIService.createCheckoutSession(plan, customer, { const session = await this._stripeAPIService.createCheckoutSession(plan, customer, {
successUrl: req.body.successUrl, successUrl: req.body.successUrl || this._config.checkoutSuccessUrl,
cancelUrl: req.body.cancelUrl, cancelUrl: req.body.cancelUrl || this._config.checkoutCancelUrl,
customerEmail: req.body.customerEmail, customerEmail: req.body.customerEmail,
metadata: req.body.metadata metadata: req.body.metadata
}); });