mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Added custom prices list to portal settings (#12912)
refs https://github.com/TryGhost/Team/issues/637 With custom prices, Portal now needs to show all available custom prices in the UI instead of just `monthly` and `yearly` prices. This change adds a list of all custom prices to Portal site settings for the default product which Portal will use to show the available prices in UI. Note: As part of cleanup, the stripe price ids will be removed from the prices list. Also: - Fixes product name in serialised subscriptions - Adds `type` value in serialised price object
This commit is contained in:
parent
da33a4ee65
commit
75169b705b
2 changed files with 18 additions and 1 deletions
|
@ -43,13 +43,15 @@ const StripeCustomerSubscription = ghostBookshelf.Model.extend({
|
||||||
nickname: defaultSerializedObject.stripePrice.nickname,
|
nickname: defaultSerializedObject.stripePrice.nickname,
|
||||||
amount: defaultSerializedObject.stripePrice.amount,
|
amount: defaultSerializedObject.stripePrice.amount,
|
||||||
interval: defaultSerializedObject.stripePrice.interval,
|
interval: defaultSerializedObject.stripePrice.interval,
|
||||||
|
type: defaultSerializedObject.stripePrice.type,
|
||||||
currency: String.prototype.toUpperCase.call(defaultSerializedObject.stripePrice.currency)
|
currency: String.prototype.toUpperCase.call(defaultSerializedObject.stripePrice.currency)
|
||||||
};
|
};
|
||||||
|
|
||||||
if (defaultSerializedObject.stripePrice.stripeProduct) {
|
if (defaultSerializedObject.stripePrice.stripeProduct) {
|
||||||
|
const productData = defaultSerializedObject.stripePrice.stripeProduct.product || {};
|
||||||
serialized.price.product = {
|
serialized.price.product = {
|
||||||
id: defaultSerializedObject.stripePrice.stripeProduct.stripe_product_id,
|
id: defaultSerializedObject.stripePrice.stripeProduct.stripe_product_id,
|
||||||
name: defaultSerializedObject.stripePrice.stripeProduct.name,
|
name: productData.name,
|
||||||
product_id: defaultSerializedObject.stripePrice.stripeProduct.product_id
|
product_id: defaultSerializedObject.stripePrice.stripeProduct.product_id
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,6 +77,19 @@ const updateMemberData = async function (req, res) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getDefaultProductPrices = async function () {
|
||||||
|
const page = await membersService.api.productRepository.list({
|
||||||
|
limit: 1
|
||||||
|
});
|
||||||
|
const [product] = page.data;
|
||||||
|
if (product) {
|
||||||
|
const model = await membersService.api.productRepository.get({id: product.get('id')}, {withRelated: ['stripePrices']});
|
||||||
|
const productData = model.toJSON();
|
||||||
|
return productData.stripePrices || [];
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
};
|
||||||
|
|
||||||
const getMemberSiteData = async function (req, res) {
|
const getMemberSiteData = async function (req, res) {
|
||||||
const isStripeConfigured = membersService.config.isStripeConnected();
|
const isStripeConfigured = membersService.config.isStripeConnected();
|
||||||
const domain = urlUtils.urlFor('home', true).match(new RegExp('^https?://([^/:?#]+)(?:[/:?#]|$)', 'i'));
|
const domain = urlUtils.urlFor('home', true).match(new RegExp('^https?://([^/:?#]+)(?:[/:?#]|$)', 'i'));
|
||||||
|
@ -86,6 +99,7 @@ const getMemberSiteData = async function (req, res) {
|
||||||
if (!supportAddress.includes('@')) {
|
if (!supportAddress.includes('@')) {
|
||||||
supportAddress = `${supportAddress}@${blogDomain}`;
|
supportAddress = `${supportAddress}@${blogDomain}`;
|
||||||
}
|
}
|
||||||
|
const defaultPrices = await getDefaultProductPrices();
|
||||||
const response = {
|
const response = {
|
||||||
title: settingsCache.get('title'),
|
title: settingsCache.get('title'),
|
||||||
description: settingsCache.get('description'),
|
description: settingsCache.get('description'),
|
||||||
|
@ -95,6 +109,7 @@ const getMemberSiteData = async function (req, res) {
|
||||||
url: urlUtils.urlFor('home', true),
|
url: urlUtils.urlFor('home', true),
|
||||||
version: ghostVersion.safe,
|
version: ghostVersion.safe,
|
||||||
plans: membersService.config.getPublicPlans(),
|
plans: membersService.config.getPublicPlans(),
|
||||||
|
prices: defaultPrices,
|
||||||
allow_self_signup: membersService.config.getAllowSelfSignup(),
|
allow_self_signup: membersService.config.getAllowSelfSignup(),
|
||||||
members_signup_access: settingsCache.get('members_signup_access'),
|
members_signup_access: settingsCache.get('members_signup_access'),
|
||||||
is_stripe_configured: isStripeConfigured,
|
is_stripe_configured: isStripeConfigured,
|
||||||
|
|
Loading…
Add table
Reference in a new issue