mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-11 00:37:55 +03:00
Added plan nickname fallback to empty string (#126)
no issue - This solves a problem when connected Stripe plan doesn't have plan `nickname` filled out (possible with older versions of Stripe API) - Defaulting to empty string instead of creating a migration because SQLite doesn't support `ALTER ... MODIFY` syntax and thus knex can't altter the table that easy - "Marks the column as an alter / modify, instead of the default add. Note: This only works in .alterTable() and is not supported by SQlite or Amazon Redshift. Alter is not done incrementally over older column type so if you like to add notNull and keep the old default value, the alter statement must contain both .notNull().defaultTo(1).alter(). If one just tries to add .notNull().alter() the old default value will be dropped." (ref. https://knexjs.org/#Chainable)
This commit is contained in:
parent
6de6a15376
commit
f2a7790cc9
@ -126,6 +126,8 @@ module.exports = class StripePaymentProcessor {
|
|||||||
|
|
||||||
await this._updateCustomer(member, customer);
|
await this._updateCustomer(member, customer);
|
||||||
|
|
||||||
|
debug(`Linking customer:${id} subscriptions`, JSON.stringify(customer.subscriptions));
|
||||||
|
|
||||||
if (customer.subscriptions && customer.subscriptions.data) {
|
if (customer.subscriptions && customer.subscriptions.data) {
|
||||||
for (const subscription of customer.subscriptions.data) {
|
for (const subscription of customer.subscriptions.data) {
|
||||||
await this._updateSubscription(subscription);
|
await this._updateSubscription(subscription);
|
||||||
@ -287,24 +289,29 @@ module.exports = class StripePaymentProcessor {
|
|||||||
});
|
});
|
||||||
return this._updateSubscription(subscriptionWithPayment);
|
return this._updateSubscription(subscriptionWithPayment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mappedSubscription = {
|
||||||
|
customer_id: subscription.customer,
|
||||||
|
|
||||||
|
subscription_id: subscription.id,
|
||||||
|
status: subscription.status,
|
||||||
|
cancel_at_period_end: subscription.cancel_at_period_end,
|
||||||
|
current_period_end: new Date(subscription.current_period_end * 1000),
|
||||||
|
start_date: new Date(subscription.start_date * 1000),
|
||||||
|
default_payment_card_last4: payment && payment.card && payment.card.last4 || null,
|
||||||
|
|
||||||
|
plan_id: subscription.plan.id,
|
||||||
|
plan_nickname: subscription.plan.nickname || '', // NOTE: defaulting to empty string here as migration to nullable field turned to be too much bigger problem
|
||||||
|
plan_interval: subscription.plan.interval,
|
||||||
|
plan_amount: subscription.plan.amount,
|
||||||
|
plan_currency: subscription.plan.currency
|
||||||
|
};
|
||||||
|
|
||||||
debug(`Attaching subscription to customer ${subscription.customer} ${subscription.id}`);
|
debug(`Attaching subscription to customer ${subscription.customer} ${subscription.id}`);
|
||||||
|
debug(`Subscription details`, JSON.stringify(mappedSubscription));
|
||||||
|
|
||||||
await this.storage.set({
|
await this.storage.set({
|
||||||
subscription: {
|
subscription: mappedSubscription
|
||||||
customer_id: subscription.customer,
|
|
||||||
|
|
||||||
subscription_id: subscription.id,
|
|
||||||
status: subscription.status,
|
|
||||||
cancel_at_period_end: subscription.cancel_at_period_end,
|
|
||||||
current_period_end: new Date(subscription.current_period_end * 1000),
|
|
||||||
start_date: new Date(subscription.start_date * 1000),
|
|
||||||
default_payment_card_last4: payment && payment.card && payment.card.last4 || null,
|
|
||||||
|
|
||||||
plan_id: subscription.plan.id,
|
|
||||||
plan_nickname: subscription.plan.nickname,
|
|
||||||
plan_interval: subscription.plan.interval,
|
|
||||||
plan_amount: subscription.plan.amount,
|
|
||||||
plan_currency: subscription.plan.currency
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user