mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-27 10:42:45 +03:00
Added 1-day version of Offers
refs https://github.com/TryGhost/Team/issues/1090 This 1-day version of Offers allows us to test the full flow of the Offers feature without having to implement all of it. The focus here is that we can pass an Offer ID when creating a Stripe Checkout session and have it apply. Here we use hardcoded Stripe Coupons as we haven't yet got persistence implemented for Offers & their related Stripe Coupons
This commit is contained in:
parent
e5b0cf8686
commit
cd6e87774a
@ -169,6 +169,7 @@ module.exports = function MembersAPI({
|
|||||||
stripeAPIService,
|
stripeAPIService,
|
||||||
tokenService,
|
tokenService,
|
||||||
sendEmailWithMagicLink,
|
sendEmailWithMagicLink,
|
||||||
|
labsService,
|
||||||
config: {
|
config: {
|
||||||
checkoutSuccessUrl: stripeConfig.checkoutSuccessUrl,
|
checkoutSuccessUrl: stripeConfig.checkoutSuccessUrl,
|
||||||
checkoutCancelUrl: stripeConfig.checkoutCancelUrl,
|
checkoutCancelUrl: stripeConfig.checkoutCancelUrl,
|
||||||
|
@ -11,6 +11,7 @@ const _ = require('lodash');
|
|||||||
* @param {any} deps.magicLinkService
|
* @param {any} deps.magicLinkService
|
||||||
* @param {import('@tryghost/members-stripe-service')} deps.stripeAPIService
|
* @param {import('@tryghost/members-stripe-service')} deps.stripeAPIService
|
||||||
* @param {any} deps.tokenService
|
* @param {any} deps.tokenService
|
||||||
|
* @param {{isSet(name: string): boolean}} deps.labsService
|
||||||
* @param {any} deps.config
|
* @param {any} deps.config
|
||||||
* @param {any} deps.logging
|
* @param {any} deps.logging
|
||||||
*/
|
*/
|
||||||
@ -23,6 +24,7 @@ module.exports = class RouterController {
|
|||||||
stripeAPIService,
|
stripeAPIService,
|
||||||
tokenService,
|
tokenService,
|
||||||
sendEmailWithMagicLink,
|
sendEmailWithMagicLink,
|
||||||
|
labsService,
|
||||||
config,
|
config,
|
||||||
logging
|
logging
|
||||||
}) {
|
}) {
|
||||||
@ -33,6 +35,7 @@ module.exports = class RouterController {
|
|||||||
this._stripeAPIService = stripeAPIService;
|
this._stripeAPIService = stripeAPIService;
|
||||||
this._tokenService = tokenService;
|
this._tokenService = tokenService;
|
||||||
this._sendEmailWithMagicLink = sendEmailWithMagicLink;
|
this._sendEmailWithMagicLink = sendEmailWithMagicLink;
|
||||||
|
this.labsService = labsService;
|
||||||
this._config = config;
|
this._config = config;
|
||||||
this._logging = logging;
|
this._logging = logging;
|
||||||
}
|
}
|
||||||
@ -115,6 +118,7 @@ module.exports = class RouterController {
|
|||||||
async createCheckoutSession(req, res) {
|
async createCheckoutSession(req, res) {
|
||||||
const ghostPriceId = req.body.priceId;
|
const ghostPriceId = req.body.priceId;
|
||||||
const identity = req.body.identity;
|
const identity = req.body.identity;
|
||||||
|
const offerId = req.body.offerId;
|
||||||
|
|
||||||
if (!ghostPriceId) {
|
if (!ghostPriceId) {
|
||||||
res.writeHead(400);
|
res.writeHead(400);
|
||||||
@ -147,9 +151,18 @@ module.exports = class RouterController {
|
|||||||
|
|
||||||
const member = email ? await this._memberRepository.get({email}, {withRelated: ['stripeCustomers', 'products']}) : null;
|
const member = email ? await this._memberRepository.get({email}, {withRelated: ['stripeCustomers', 'products']}) : null;
|
||||||
|
|
||||||
|
let coupon = null;
|
||||||
|
if (offerId && this.labsService.isSet('offers')) {
|
||||||
|
coupon = await this._stripeAPIService.createCoupon({
|
||||||
|
duration: 'forever',
|
||||||
|
percent_off: 50
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (!member) {
|
if (!member) {
|
||||||
const customer = null;
|
const customer = null;
|
||||||
const session = await this._stripeAPIService.createCheckoutSession(priceId, customer, {
|
const session = await this._stripeAPIService.createCheckoutSession(priceId, customer, {
|
||||||
|
coupon,
|
||||||
successUrl: req.body.successUrl || this._config.checkoutSuccessUrl,
|
successUrl: req.body.successUrl || this._config.checkoutSuccessUrl,
|
||||||
cancelUrl: req.body.cancelUrl || this._config.checkoutCancelUrl,
|
cancelUrl: req.body.cancelUrl || this._config.checkoutCancelUrl,
|
||||||
customerEmail: req.body.customerEmail,
|
customerEmail: req.body.customerEmail,
|
||||||
@ -194,6 +207,7 @@ module.exports = class RouterController {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const session = await this._stripeAPIService.createCheckoutSession(priceId, stripeCustomer, {
|
const session = await this._stripeAPIService.createCheckoutSession(priceId, stripeCustomer, {
|
||||||
|
coupon,
|
||||||
successUrl: req.body.successUrl || this._config.checkoutSuccessUrl,
|
successUrl: req.body.successUrl || this._config.checkoutSuccessUrl,
|
||||||
cancelUrl: req.body.cancelUrl || this._config.checkoutCancelUrl,
|
cancelUrl: req.body.cancelUrl || this._config.checkoutCancelUrl,
|
||||||
metadata: req.body.metadata
|
metadata: req.body.metadata
|
||||||
|
Loading…
Reference in New Issue
Block a user