Heads up: trial_end was being silently dropped on subscription creation
Heads up: trial_end was being silently dropped on subscription creation
Release: v1.0.110
What happened
When creating a subscription via the Calmony Pay SDK and passing a trial_end Unix timestamp, the value was never actually saved.
Here is the sequence that caused it:
CreateSubscriptionParamscorrectly declaredtrial_end?: number— so TypeScript was happy and no compile-time error was raised.- Inside
subscriptions.create(), parameters were spread into arestobject and forwarded to the REST API. - The REST layer validated the incoming body with
createSubscriptionSchema(a Zod schema). Becausetrial_endwas not listed in that schema, Zod's default strip behaviour silently removed the field before the data was written. - The subscription was created without a trial end date, with no error or warning returned to the caller.
Who is affected
Any integration that calls subscriptions.create() with a trial_end value. If you set a trial period on new subscriptions you should audit whether those records were saved correctly.
What changed in v1.0.110
trial_end has been added to createSubscriptionSchema in src/lib/calmony-pay/client.ts. The field is now accepted by the REST layer and persisted as expected.
What you need to do
- Upgrade to v1.0.110 to ensure all new subscriptions respect the
trial_endvalue you pass. - Review any subscriptions created before this release where a trial period was expected. Those records will not have a
trial_enddate set and may need to be updated manually.
Example — creating a subscription with a trial period
import { calmonyPay } from '@/lib/calmony-pay';
const subscription = await calmonyPay.subscriptions.create({
customer_id: 'cust_abc123',
plan_id: 'plan_monthly_pro',
trial_end: Math.floor(Date.now() / 1000) + 60 * 60 * 24 * 14, // 14 days from now
});
console.log(subscription.trial_end); // Now correctly populated
Before v1.0.110, subscription.trial_end would have been null or absent despite being passed in.
Technical detail
Zod schemas strip unknown keys by default. This means any field not explicitly declared in a schema is removed without throwing an error — a safe default for most cases, but one that can cause silent data loss when a schema and its callers fall out of sync. The fix is straightforward: trial_end is now a first-class field in createSubscriptionSchema, aligning the schema with both the pinned SDK spec and the TypeScript interface.