Used subscription currency for setup session (#19991)
ref https://linear.app/tryghost/issue/ENG-812 ref https://github.com/TryGhost/Ghost/commit/5b694761bc We wanna use the currency of the subscription to avoid the edge-case where the subscription currency doesn't match the sites current tiers currency.
This commit is contained in:
parent
50a1ef1cd8
commit
56d984f05f
@ -111,11 +111,18 @@ module.exports = class RouterController {
|
||||
return res.end('Bad Request.');
|
||||
}
|
||||
|
||||
const subscriptions = await member.related('stripeSubscriptions').fetch();
|
||||
|
||||
const activeSubscription = subscriptions.models.find((sub) => {
|
||||
return ['active', 'trialing', 'unpaid', 'past_due'].includes(sub.get('status'));
|
||||
});
|
||||
|
||||
let currency = activeSubscription?.get('plan_currency') || undefined;
|
||||
|
||||
let customer;
|
||||
if (!req.body.subscription_id) {
|
||||
customer = await this._stripeAPIService.getCustomerForMemberCheckoutSession(member);
|
||||
} else {
|
||||
const subscriptions = await member.related('stripeSubscriptions').fetch();
|
||||
const subscription = subscriptions.models.find((sub) => {
|
||||
return sub.get('subscription_id') === req.body.subscription_id;
|
||||
});
|
||||
@ -126,12 +133,10 @@ module.exports = class RouterController {
|
||||
});
|
||||
return res.end(`Could not find subscription ${req.body.subscription_id}`);
|
||||
}
|
||||
currency = subscription.get('plan_currency') || undefined;
|
||||
customer = await this._stripeAPIService.getCustomer(subscription.get('customer_id'));
|
||||
}
|
||||
|
||||
const defaultTier = await this._tiersService.api.readDefaultTier();
|
||||
const currency = defaultTier?.currency?.toLowerCase() || 'usd';
|
||||
|
||||
const session = await this._stripeAPIService.createCheckoutSetupSession(customer, {
|
||||
successUrl: req.body.successUrl,
|
||||
cancelUrl: req.body.cancelUrl,
|
||||
|
Loading…
Reference in New Issue
Block a user