Period fields not populated after stripe subscription

Hello, period_start and period_end fields in the subscription object are not populated after a user subscribes via subscription.upgrade. Stripe : 17.7.0 Better-auth : 1.2.7
5 Replies
Duki
Dukiβ€’17h ago
Heya, I experience the same issue. But I see an update error on prisma, saying:
Invalid `prisma.subscription.update()` invocation:

{
where: {
id: "SiGKftVY9a591QLakFP0IUkWPDNaygQK"
},
data: {
plan: "basic",
stripeSubscriptionId: "sub_1RGEcnPL1qjk3NmrqLLPgRDK",
status: "active",
periodStart: new Date("Invalid Date"),
~~~~~~~~~~~~~~~~~~~~~~~~
periodEnd: new Date("Invalid Date"),
seats: 1
}
}
Invalid `prisma.subscription.update()` invocation:

{
where: {
id: "SiGKftVY9a591QLakFP0IUkWPDNaygQK"
},
data: {
plan: "basic",
stripeSubscriptionId: "sub_1RGEcnPL1qjk3NmrqLLPgRDK",
status: "active",
periodStart: new Date("Invalid Date"),
~~~~~~~~~~~~~~~~~~~~~~~~
periodEnd: new Date("Invalid Date"),
seats: 1
}
}
Do you also see an error from your ORM or something? I also checked BA's code where they populate these fields (in packages/stripe/src/hooks.ts line 44):
periodStart: new Date(subscription.current_period_start * 1000),
periodEnd: new Date(subscription.current_period_end * 1000),
periodStart: new Date(subscription.current_period_start * 1000),
periodEnd: new Date(subscription.current_period_end * 1000),
There they reference the fields current_period_end and current_period_start, but when I retrieve the subscription myself I cannot find these fields in the subscription object. In my stripe plugin I added an event hook to check the subscription myself like this:
onEvent: async (event) => {
switch (event.type) {
case 'checkout.session.completed': {
const subscriptionId = event.data.object.subscription
const subscription = await stripeBackendClient.subscriptions.retrieve(subscriptionId as string);
console.log('subscription', subscription);
break;
}
}
},
onEvent: async (event) => {
switch (event.type) {
case 'checkout.session.completed': {
const subscriptionId = event.data.object.subscription
const subscription = await stripeBackendClient.subscriptions.retrieve(subscriptionId as string);
console.log('subscription', subscription);
break;
}
}
},
And it logs this subscription object:
{
id: 'sub_1RGEcnPL1qjk3NmrqLLPgRDK',
object: 'subscription',
application: null,
application_fee_percent: null,
automatic_tax: { ... },
billing_cycle_anchor: 1745219919,
billing_cycle_anchor_config: null,
cancel_at: null,
cancel_at_period_end: false,
canceled_at: null,
cancellation_details: { ... },
collection_method: 'charge_automatically',
created: 1745219919,
currency: 'chf',
customer: 'cus_SALpY9cI1moQS7',
days_until_due: null,
default_payment_method: 'pm_1RGEclPL1qjk3NmrfKoROdnv',
default_source: null,
default_tax_rates: [],
description: null,
discounts: [],
ended_at: null,
invoice_settings: { ... },
items: { ... },
latest_invoice: 'in_1RGEcnPL1qjk3NmrfugfoyZJ',
livemode: false,
metadata: {},
next_pending_invoice_item_invoice: null,
on_behalf_of: null,
pause_collection: null,
payment_settings: {
payment_method_options: { ... },
payment_method_types: null,
save_default_payment_method: 'off'
},
pending_invoice_item_interval: null,
pending_setup_intent: null,
pending_update: null,
plan: {
id: 'price_1RFVZWPL1qjk3NmrTduzFHok',
object: 'plan',
active: true,
amount: 1500,
amount_decimal: '1500',
billing_scheme: 'per_unit',
created: 1745046738,
currency: 'chf',
interval: 'month',
interval_count: 1,
livemode: false,
metadata: {},
meter: null,
nickname: 'Basic Monthly',
product: 'prod_S9pDoekuN3KnzH',
tiers_mode: null,
transform_usage: null,
trial_period_days: null,
usage_type: 'licensed'
},
quantity: 1,
schedule: null,
start_date: 1745219919,
status: 'active',
test_clock: null,
transfer_data: null,
trial_end: null,
trial_settings: { end_behavior: { missing_payment_method: 'create_invoice' } },
trial_start: null
}
{
id: 'sub_1RGEcnPL1qjk3NmrqLLPgRDK',
object: 'subscription',
application: null,
application_fee_percent: null,
automatic_tax: { ... },
billing_cycle_anchor: 1745219919,
billing_cycle_anchor_config: null,
cancel_at: null,
cancel_at_period_end: false,
canceled_at: null,
cancellation_details: { ... },
collection_method: 'charge_automatically',
created: 1745219919,
currency: 'chf',
customer: 'cus_SALpY9cI1moQS7',
days_until_due: null,
default_payment_method: 'pm_1RGEclPL1qjk3NmrfKoROdnv',
default_source: null,
default_tax_rates: [],
description: null,
discounts: [],
ended_at: null,
invoice_settings: { ... },
items: { ... },
latest_invoice: 'in_1RGEcnPL1qjk3NmrfugfoyZJ',
livemode: false,
metadata: {},
next_pending_invoice_item_invoice: null,
on_behalf_of: null,
pause_collection: null,
payment_settings: {
payment_method_options: { ... },
payment_method_types: null,
save_default_payment_method: 'off'
},
pending_invoice_item_interval: null,
pending_setup_intent: null,
pending_update: null,
plan: {
id: 'price_1RFVZWPL1qjk3NmrTduzFHok',
object: 'plan',
active: true,
amount: 1500,
amount_decimal: '1500',
billing_scheme: 'per_unit',
created: 1745046738,
currency: 'chf',
interval: 'month',
interval_count: 1,
livemode: false,
metadata: {},
meter: null,
nickname: 'Basic Monthly',
product: 'prod_S9pDoekuN3KnzH',
tiers_mode: null,
transform_usage: null,
trial_period_days: null,
usage_type: 'licensed'
},
quantity: 1,
schedule: null,
start_date: 1745219919,
status: 'active',
test_clock: null,
transfer_data: null,
trial_end: null,
trial_settings: { end_behavior: { missing_payment_method: 'create_invoice' } },
trial_start: null
}
(shortened some things, because the message would have been too long and I dont have discord nitro) Do we have to populate any metadata or something? πŸ€” @Ping Sorry for the ping, but its breaking the subscription flow a bit πŸ™ˆ Can you confirm whether this is a bug or if we r missing any configurations? If it's a bug I can create an issue in github when necessary
Ping
Pingβ€’16h ago
what version is your stripe?
Duki
Dukiβ€’14h ago
18.0.0 Ooh i see it now. They have breaking changes in v18 πŸ™ˆ That explains a lot
Ping
Pingβ€’14h ago
It will be fixed soon, but for now, yeah just downgrade to 17.7.0
Duki
Dukiβ€’13h ago
Perfect, thanks a lot for checking in!

Did you find this page helpful?