0
Fork 0
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:
Rishabh Garg 2021-05-04 21:02:20 +05:30 committed by GitHub
parent da33a4ee65
commit 75169b705b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View file

@ -43,13 +43,15 @@ const StripeCustomerSubscription = ghostBookshelf.Model.extend({
nickname: defaultSerializedObject.stripePrice.nickname,
amount: defaultSerializedObject.stripePrice.amount,
interval: defaultSerializedObject.stripePrice.interval,
type: defaultSerializedObject.stripePrice.type,
currency: String.prototype.toUpperCase.call(defaultSerializedObject.stripePrice.currency)
};
if (defaultSerializedObject.stripePrice.stripeProduct) {
const productData = defaultSerializedObject.stripePrice.stripeProduct.product || {};
serialized.price.product = {
id: defaultSerializedObject.stripePrice.stripeProduct.stripe_product_id,
name: defaultSerializedObject.stripePrice.stripeProduct.name,
name: productData.name,
product_id: defaultSerializedObject.stripePrice.stripeProduct.product_id
};
}

View file

@ -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 isStripeConfigured = membersService.config.isStripeConnected();
const domain = urlUtils.urlFor('home', true).match(new RegExp('^https?://([^/:?#]+)(?:[/:?#]|$)', 'i'));
@ -86,6 +99,7 @@ const getMemberSiteData = async function (req, res) {
if (!supportAddress.includes('@')) {
supportAddress = `${supportAddress}@${blogDomain}`;
}
const defaultPrices = await getDefaultProductPrices();
const response = {
title: settingsCache.get('title'),
description: settingsCache.get('description'),
@ -95,6 +109,7 @@ const getMemberSiteData = async function (req, res) {
url: urlUtils.urlFor('home', true),
version: ghostVersion.safe,
plans: membersService.config.getPublicPlans(),
prices: defaultPrices,
allow_self_signup: membersService.config.getAllowSelfSignup(),
members_signup_access: settingsCache.get('members_signup_access'),
is_stripe_configured: isStripeConfigured,