mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-18 02:21:47 -05:00
✨ Added currency and currency_symbol properties to plans
no issue - Adding these properties allows specifying which currency is currently used on member's plan. - Supported currencies list: USD, AUD, CAD, GBP, EUR - They were chosen based on the most used/requested currencies within Ghost - With adding multiple available currencies that can be setup also had to add handling of Stripes limitation of having single currency per paying customer
This commit is contained in:
parent
7fb1c2e07e
commit
076e328f20
1 changed files with 23 additions and 2 deletions
|
@ -4,6 +4,14 @@ const api = require('./api');
|
|||
|
||||
const STRIPE_API_VERSION = '2019-09-09';
|
||||
|
||||
const CURRENCY_SYMBOLS = {
|
||||
usd: '$',
|
||||
aud: '$',
|
||||
cad: '$',
|
||||
gbp: '£',
|
||||
eur: '€'
|
||||
};
|
||||
|
||||
module.exports = class StripePaymentProcessor {
|
||||
constructor(config, storage, logging) {
|
||||
this.logging = logging;
|
||||
|
@ -207,7 +215,8 @@ module.exports = class StripePaymentProcessor {
|
|||
nickname: subscription.plan_nickname,
|
||||
interval: subscription.plan_interval,
|
||||
amount: subscription.plan_amount,
|
||||
currency: subscription.plan_currency
|
||||
currency: String.prototype.toUpperCase.call(subscription.plan_currency),
|
||||
currency_symbol: CURRENCY_SYMBOLS[subscription.plan_currency]
|
||||
},
|
||||
status: subscription.status,
|
||||
start_date: subscription.start_date,
|
||||
|
@ -220,7 +229,19 @@ module.exports = class StripePaymentProcessor {
|
|||
|
||||
async setComplimentarySubscription(member) {
|
||||
const subscriptions = await this.getActiveSubscriptions(member);
|
||||
const complimentaryPlan = this._plans.find(plan => (plan.nickname === 'Complimentary'));
|
||||
|
||||
// NOTE: Because we allow for multiple Complimentary plans, need to take into account currently availalbe
|
||||
// plan currencies so that we don't end up giving a member complimentary subscription in wrong currency.
|
||||
// Giving member a subscription in different currency would prevent them from resubscribing with a regular
|
||||
// plan if Complimentary is cancelled (ref. https://stripe.com/docs/billing/customer#currency)
|
||||
let complimentaryCurrency = this._plans.find(plan => plan.interval === 'month').currency.toLowerCase();
|
||||
|
||||
if (subscriptions.length) {
|
||||
complimentaryCurrency = subscriptions[0].plan.currency.toLowerCase();
|
||||
}
|
||||
|
||||
const complimentaryFilter = plan => (plan.nickname === 'Complimentary' && plan.currency === complimentaryCurrency);
|
||||
const complimentaryPlan = this._plans.find(complimentaryFilter);
|
||||
|
||||
const customer = await this._customerForMemberCheckoutSession(member);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue