mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-01 23:37:43 +03:00
Added config endpoint to Member API (#10467)
no-issue * Added getPublicConfig method to stripe payment processor * Added getPublicConfig method to subscriptions service * Added initial config endpoint for members api * Added getConfig method to members gateway
This commit is contained in:
parent
36547a9c3a
commit
5472aa61ac
@ -75,6 +75,17 @@ module.exports = function MembersApi({
|
||||
.catch(handleError(403, res));
|
||||
});
|
||||
|
||||
apiRouter.get('/config', (req, res) => {
|
||||
subscriptions.getAdapters()
|
||||
.then((adapters) => {
|
||||
return Promise.all(adapters.map((adapter) => {
|
||||
return subscriptions.getPublicConfig(adapter);
|
||||
}));
|
||||
})
|
||||
.then(data => res.json(data))
|
||||
.catch(handleError(500, res));
|
||||
});
|
||||
|
||||
/* security */
|
||||
function ssoOriginCheck(req, res, next) {
|
||||
if (!req.data.origin || req.data.origin !== ssoOrigin) {
|
||||
|
@ -150,6 +150,14 @@
|
||||
});
|
||||
});
|
||||
|
||||
addMethod('getConfig', function getConfig() {
|
||||
return fetch(`${membersApi}/config`, {
|
||||
method: 'GET'
|
||||
}).then((res) => {
|
||||
return res.json();
|
||||
});
|
||||
});
|
||||
|
||||
window.addEventListener('storage', function (event) {
|
||||
if (event.storageArea !== storage) {
|
||||
return;
|
||||
|
@ -39,6 +39,16 @@ module.exports = class PaymentProcessorService {
|
||||
});
|
||||
}
|
||||
|
||||
getPublicConfig(adapter) {
|
||||
if (!adapter) {
|
||||
return Promise.reject(new Error('getPublicConfig(adapter) requires an adapter'));
|
||||
}
|
||||
|
||||
return this._ready.then(() => {
|
||||
return this._processors[adapter].getPublicConfig();
|
||||
});
|
||||
}
|
||||
|
||||
createSubscription(member, metadata) {
|
||||
if (!metadata.adapter) {
|
||||
return Promise.reject(new Error('createSubscription(member, { adapter }) requires an adapter'));
|
||||
|
@ -15,6 +15,7 @@ module.exports = class StripePaymentProcessor {
|
||||
this._stripe = stripe;
|
||||
this._product = product;
|
||||
this._plans = plans;
|
||||
this._public_token = config.public_token;
|
||||
return {
|
||||
product,
|
||||
plans
|
||||
@ -35,6 +36,25 @@ module.exports = class StripePaymentProcessor {
|
||||
});
|
||||
}
|
||||
|
||||
getPublicConfig() {
|
||||
if (!this._plans) {
|
||||
throw new Error('StripePaymentProcessor must be configured()');
|
||||
}
|
||||
|
||||
return this._ready.then(() => {
|
||||
return {
|
||||
adapter: 'stripe',
|
||||
config: {
|
||||
public_token: this._public_token,
|
||||
plans: this._plans.map(({id, currency, amount, interval, nickname}) => ({
|
||||
id, currency, amount, interval,
|
||||
name: nickname
|
||||
}))
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
createSubscription(member, metadata) {
|
||||
if (!this._stripe) {
|
||||
throw new Error('StripePaymentProcessor must be configured()');
|
||||
|
Loading…
Reference in New Issue
Block a user