Added basic support for coupons

refs https://github.com/TryGhost/Team/issues/1090

This allows us to create Stripe Coupons and use them with Stripe
Checkout from the members-api module whilst we develop the Offers
feature.
This commit is contained in:
Fabien O'Carroll 2021-09-28 13:35:23 +02:00
parent c13be723e6
commit e5b0cf8686

View File

@ -78,6 +78,16 @@ module.exports = class StripeService {
this._configured = true;
}
/**
* @param {object} options
*/
async createCoupon(options) {
await this._rateLimitBucket.throttle();
const coupon = await this._stripe.coupons.create(options);
return coupon;
}
/**
* @param {object} options
* @param {string} options.name
@ -348,14 +358,19 @@ module.exports = class StripeService {
const metadata = options.metadata || undefined;
const customerEmail = customer ? customer.email : options.customerEmail;
await this._rateLimitBucket.throttle();
let discounts;
if (options.coupon) {
discounts = [{coupon: options.coupon.id}];
}
const session = await this._stripe.checkout.sessions.create({
payment_method_types: ['card'],
success_url: options.successUrl,
cancel_url: options.cancelUrl,
customer_email: customerEmail,
// @ts-ignore - we need to update to latest stripe library to correctly use newer features
allow_promotion_codes: this._config.enablePromoCodes,
allow_promotion_codes: discounts ? undefined : this._config.enablePromoCodes,
metadata,
discounts,
/*
line_items: [{
price: priceId