Handled storing of trial start/end info for subscription (#15161)

refs https://github.com/TryGhost/Team/issues/1724

With free trials, members can start subscriptions with a trial period. This change stores the information about trial start and end date for every subscription so it can be shown on Admin/Portal for member.

- adds new `trial_start_at` column for storing trial start date on Stripe subscription. Will in most cases match the start of subscription date.
- adds new `trial_end_at` column for storing trial end date on Stripe subscription.
- wires storing trial start and end values on stripe subscription
This commit is contained in:
Rishabh Garg 2022-08-05 17:50:40 +05:30 committed by GitHub
parent b03ec721a2
commit 5704ac061e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 2 deletions

View File

@ -0,0 +1,6 @@
const {createAddColumnMigration} = require('../../utils');
module.exports = createAddColumnMigration('members_stripe_customers_subscriptions', 'trial_start_at', {
type: 'dateTime',
nullable: true
});

View File

@ -0,0 +1,6 @@
const {createAddColumnMigration} = require('../../utils');
module.exports = createAddColumnMigration('members_stripe_customers_subscriptions', 'trial_end_at', {
type: 'dateTime',
nullable: true
});

View File

@ -585,6 +585,8 @@ module.exports = {
updated_by: {type: 'string', maxlength: 24, nullable: true}, updated_by: {type: 'string', maxlength: 24, nullable: true},
mrr: {type: 'integer', unsigned: true, nullable: false, defaultTo: 0}, mrr: {type: 'integer', unsigned: true, nullable: false, defaultTo: 0},
offer_id: {type: 'string', maxlength: 24, nullable: true, unique: false, references: 'offers.id'}, offer_id: {type: 'string', maxlength: 24, nullable: true, unique: false, references: 'offers.id'},
trial_start_at: {type: 'dateTime', nullable: true},
trial_end_at: {type: 'dateTime', nullable: true},
/* Below fields are now redundant as we link prie_id to stripe_prices table */ /* Below fields are now redundant as we link prie_id to stripe_prices table */
plan_id: {type: 'string', maxlength: 255, nullable: false, unique: false}, plan_id: {type: 'string', maxlength: 255, nullable: false, unique: false},
plan_nickname: {type: 'string', maxlength: 50, nullable: false}, plan_nickname: {type: 'string', maxlength: 50, nullable: false},

View File

@ -35,7 +35,7 @@ const validateRouteSettings = require('../../../../../core/server/services/route
*/ */
describe('DB version integrity', function () { describe('DB version integrity', function () {
// Only these variables should need updating // Only these variables should need updating
const currentSchemaHash = '01156d65accecd6a056a6a8341e8b81f'; const currentSchemaHash = '45337ae85129a98e4c1b551cc91790da';
const currentFixturesHash = 'a75211a41f515202280be7cb287e101f'; const currentFixturesHash = 'a75211a41f515202280be7cb287e101f';
const currentSettingsHash = 'd54210758b7054e2174fd34aa2320ad7'; const currentSettingsHash = 'd54210758b7054e2174fd34aa2320ad7';
const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01'; const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';

View File

@ -803,6 +803,9 @@ module.exports = class MemberRepository {
default_payment_card_last4: paymentMethod && paymentMethod.card && paymentMethod.card.last4 || null, default_payment_card_last4: paymentMethod && paymentMethod.card && paymentMethod.card.last4 || null,
stripe_price_id: subscriptionPriceData.id, stripe_price_id: subscriptionPriceData.id,
plan_id: subscriptionPriceData.id, plan_id: subscriptionPriceData.id,
// trial start and end are returned as Stripe timestamps and need coversion
trial_start_at: subscription.trial_start ? new Date(subscription.trial_start * 1000) : null,
trial_end_at: subscription.trial_end ? new Date(subscription.trial_end * 1000) : null,
// NOTE: Defaulting to interval as migration to nullable field // NOTE: Defaulting to interval as migration to nullable field
// turned out to be much bigger problem. // turned out to be much bigger problem.
// Ideally, would need nickname field to be nullable on the DB level // Ideally, would need nickname field to be nullable on the DB level
@ -1371,4 +1374,3 @@ module.exports = class MemberRepository {
return true; return true;
} }
}; };