mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-27 00:52:36 +03:00
Wired up additional payment types with labs flag
ref ENG-812 ref https://linear.app/tryghost/issue/ENG-812
This commit is contained in:
parent
781599de62
commit
c1b72b3997
@ -11,6 +11,7 @@ const {getConfig} = require('./config');
|
||||
const settingsHelpers = require('../settings-helpers');
|
||||
const donationService = require('../donations');
|
||||
const staffService = require('../staff');
|
||||
const labs = require('../../../shared/labs');
|
||||
|
||||
async function configureApi() {
|
||||
const cfg = getConfig({settingsHelpers, config, urlUtils});
|
||||
@ -30,6 +31,7 @@ const debouncedConfigureApi = _.debounce(() => {
|
||||
}, 600);
|
||||
|
||||
module.exports = new StripeService({
|
||||
labs,
|
||||
membersService,
|
||||
models: _.pick(models, [
|
||||
'Product',
|
||||
|
@ -41,14 +41,19 @@ module.exports = class StripeAPI {
|
||||
/**
|
||||
* StripeAPI
|
||||
*/
|
||||
constructor() {
|
||||
constructor(deps) {
|
||||
/** @type {Stripe} */
|
||||
this._stripe = null;
|
||||
this._configured = false;
|
||||
this.labs = deps.labs;
|
||||
}
|
||||
|
||||
get PAYMENT_METHOD_TYPES() {
|
||||
return ['card'];
|
||||
if (this.labs.isSet('additionalPaymentMethods')) {
|
||||
return undefined;
|
||||
} else {
|
||||
return ['card'];
|
||||
}
|
||||
}
|
||||
|
||||
get configured() {
|
||||
|
@ -7,13 +7,14 @@ const {StripeLiveEnabledEvent, StripeLiveDisabledEvent} = require('./events');
|
||||
|
||||
module.exports = class StripeService {
|
||||
constructor({
|
||||
labs,
|
||||
membersService,
|
||||
donationService,
|
||||
staffService,
|
||||
StripeWebhook,
|
||||
models
|
||||
}) {
|
||||
const api = new StripeAPI();
|
||||
const api = new StripeAPI({labs});
|
||||
const webhookManager = new WebhookManager({
|
||||
StripeWebhook,
|
||||
api
|
||||
|
@ -2,12 +2,17 @@ const sinon = require('sinon');
|
||||
const should = require('should');
|
||||
const rewire = require('rewire');
|
||||
const StripeAPI = rewire('../../../lib/StripeAPI');
|
||||
const api = new StripeAPI();
|
||||
|
||||
describe('StripeAPI', function () {
|
||||
const mockCustomerEmail = 'foo@example.com';
|
||||
const mockCustomerId = 'cust_mock_123456';
|
||||
const mockCustomerName = 'Example Customer';
|
||||
let mockLabs = {
|
||||
isSet() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
const api = new StripeAPI({labs: mockLabs});
|
||||
|
||||
let mockStripe;
|
||||
|
||||
@ -20,6 +25,7 @@ describe('StripeAPI', function () {
|
||||
}
|
||||
}
|
||||
};
|
||||
sinon.stub(mockLabs, 'isSet');
|
||||
const mockStripeConstructor = sinon.stub().returns(mockStripe);
|
||||
StripeAPI.__set__('Stripe', mockStripeConstructor);
|
||||
api.configure({
|
||||
@ -35,6 +41,19 @@ describe('StripeAPI', function () {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
it('Sends card as payment method if labs flag not enabled', async function () {
|
||||
await api.createCheckoutSession('priceId', null, {});
|
||||
|
||||
should.deepEqual(mockStripe.checkout.sessions.create.firstCall.firstArg.payment_method_types, ['card']);
|
||||
});
|
||||
|
||||
it('Sends no payment methods if labs flag is enabled', async function () {
|
||||
mockLabs.isSet.withArgs('additionalPaymentMethods').returns(true);
|
||||
await api.createCheckoutSession('priceId', null, {});
|
||||
|
||||
should.deepEqual(mockStripe.checkout.sessions.create.firstCall.firstArg.payment_method_types, undefined);
|
||||
});
|
||||
|
||||
it('sends success_url and cancel_url', async function () {
|
||||
await api.createCheckoutSession('priceId', null, {});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user