Fixed issues with checkout when not using coupon

no-issue

We were incorrectly checking for the existence of a coupon id - instead
we simplify the signature, and make sure the check is correct.
This commit is contained in:
Fabien O'Carroll 2021-10-21 18:06:36 +02:00
parent 93a37f98be
commit e78b2f80bc
2 changed files with 4 additions and 3 deletions

View File

@ -196,7 +196,7 @@ module.exports = class RouterController {
if (!member) {
const customer = null;
const session = await this._stripeAPIService.createCheckoutSession(priceId, customer, {
coupon: {id: couponId},
coupon: couponId,
successUrl: req.body.successUrl || this._config.checkoutSuccessUrl,
cancelUrl: req.body.cancelUrl || this._config.checkoutCancelUrl,
customerEmail: req.body.customerEmail,
@ -241,7 +241,7 @@ module.exports = class RouterController {
try {
const session = await this._stripeAPIService.createCheckoutSession(priceId, stripeCustomer, {
coupon: {id: couponId},
coupon: couponId,
successUrl: req.body.successUrl || this._config.checkoutSuccessUrl,
cancelUrl: req.body.cancelUrl || this._config.checkoutCancelUrl,
metadata: metadata

View File

@ -351,6 +351,7 @@ module.exports = class StripeService {
* @param {string} options.successUrl
* @param {string} options.cancelUrl
* @param {string} options.customerEmail
* @param {string} [options.coupon]
*
* @returns {Promise<import('stripe').Stripe.Checkout.Session>}
*/
@ -360,7 +361,7 @@ module.exports = class StripeService {
await this._rateLimitBucket.throttle();
let discounts;
if (options.coupon) {
discounts = [{coupon: options.coupon.id}];
discounts = [{coupon: options.coupon}];
}
const session = await this._stripe.checkout.sessions.create({
payment_method_types: ['card'],