0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-24 23:48:13 -05:00

Cleaned add subscription prices for member details

closes https://github.com/TryGhost/Team/issues/678
closes https://github.com/TryGhost/Team/issues/681

The prices in "Add subscription" modal should follow the same ordering as on the product detail screen, ie. currency, amount. Also, we only want to allow adding subscriptions for active prices, so the list is filtered on that. Since a Stripe customer is not allowed to have subscriptions in multiple currencies, this also filters the available currency prices based on any active subscription for a member.
This commit is contained in:
Rishabh 2021-05-10 22:25:01 +05:30
parent d3efc29f08
commit c449e32121

View file

@ -32,6 +32,7 @@ export default class ModalMemberProduct extends ModalComponent {
async fetchProducts() {
this.products = await this.store.query('product', {include: 'stripe_prices'});
this.product = this.products.firstObject;
this.price = this.prices ? this.prices[0] : null;
}
get member() {
@ -47,9 +48,27 @@ export default class ModalMemberProduct extends ModalComponent {
return [];
}
if (this.product) {
return this.products.find((product) => {
return product.id === this.product.id;
}).stripePrices.map((price) => {
let subscriptions = this.member.get('subscriptions') || [];
let activeCurrency;
if (subscriptions.length > 0) {
activeCurrency = subscriptions[0].price?.currency;
}
const product = this.products.find((_product) => {
return _product.id === this.product.id;
});
return product.stripePrices.sort((a, b) => {
return a.amount - b.amount;
}).filter((price) => {
return price.active;
}).filter((price) => {
if (activeCurrency) {
return price.currency?.toLowerCase() === activeCurrency.toLowerCase();
}
return true;
}).sort((a, b) => {
return a.currency.localeCompare(b.currency, undefined, {ignorePunctuation: true});
}).map((price) => {
return {
...price,
label: `${price.nickname} (${getSymbol(price.currency)}${getNonDecimal(price.amount)}/${price.interval})`