mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-23 22:11:09 +03:00
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:
parent
c13be723e6
commit
e5b0cf8686
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user