-
Notifications
You must be signed in to change notification settings - Fork 399
chore(backend): Add extend trial endpoint #6714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@clerk/backend': minor | ||
--- | ||
|
||
Extend the trial of a subscription item via the BillingAPI. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,14 @@ type CancelSubscriptionItemParams = { | |
endNow?: boolean; | ||
}; | ||
|
||
type ExtendSubscriptionItemFreeTrialParams = { | ||
/** | ||
* RFC3339 timestamp to extend the free trial to. | ||
* Must be in the future and not more than 365 days from the current trial end. | ||
*/ | ||
extendTo: Date; | ||
}; | ||
|
||
export class BillingAPI extends AbstractAPI { | ||
/** | ||
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. | ||
|
@@ -49,6 +57,22 @@ export class BillingAPI extends AbstractAPI { | |
}); | ||
} | ||
|
||
/** | ||
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. | ||
* It is advised to pin the SDK version to avoid breaking changes. | ||
*/ | ||
public async extendSubscriptionItemFreeTrial( | ||
subscriptionItemId: string, | ||
params: ExtendSubscriptionItemFreeTrialParams, | ||
) { | ||
this.requireId(subscriptionItemId); | ||
return this.request<CommerceSubscriptionItem>({ | ||
method: 'POST', | ||
path: joinPaths('/billing', 'subscription_items', subscriptionItemId, 'extend_free_trial'), | ||
bodyParams: params, | ||
}); | ||
} | ||
|
||
Comment on lines
+64
to
+75
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainAdd explicit return type; ensure RFC3339 serialization; avoid hardcoded '/billing'
Apply this diff within the shown lines: - public async extendSubscriptionItemFreeTrial(
+ public async extendSubscriptionItemFreeTrial(
subscriptionItemId: string,
params: ExtendSubscriptionItemFreeTrialParams,
- ) {
+ ): Promise<CommerceSubscriptionItem> {
this.requireId(subscriptionItemId);
return this.request<CommerceSubscriptionItem>({
method: 'POST',
- path: joinPaths('/billing', 'subscription_items', subscriptionItemId, 'extend_free_trial'),
- bodyParams: params,
+ path: joinPaths(billingBasePath, 'subscription_items', subscriptionItemId, 'extend_free_trial'),
+ bodyParams: {
+ // Ensure RFC3339 payload
+ extendTo: params.extendTo.toISOString(),
+ },
});
} And add this near the other base path constants: const billingBasePath = '/billing'; Verification script to confirm serializer expectations and path correctness: 🏁 Script executed: #!/bin/bash
# Inspect request serialization to confirm Date handling and key-casing.
fd 'AbstractApi.ts' -t f
if [[ -f packages/backend/src/api/endpoints/AbstractApi.ts ]]; then
sed -n '1,220p' packages/backend/src/api/endpoints/AbstractApi.ts | sed -n '1,220p'
fi
rg -nP -C3 --type=ts 'bodyParams:\s*{[^}]*toISOString\('
rg -nP -C3 --type=ts "joinPaths\('/billing'|billingBasePath" packages/backend
# Check if there is a params key transform (camelCase -> snake_case)
rg -nP -C2 --type=ts 'snake|camel.*case|serialize.*params|toSnake' packages Length of output: 12970 Declare explicit return type, billingBasePath constant, and enable deepSnakecaseBodyParamKeys
🤖 Prompt for AI Agents
|
||
/** | ||
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. | ||
* It is advised to pin the SDK version to avoid breaking changes. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Export the public params type
This type appears in a public method signature; make it exported to avoid d.ts naming issues and to enable reuse.
Apply this diff:
📝 Committable suggestion
🤖 Prompt for AI Agents