-
Notifications
You must be signed in to change notification settings - Fork 370
chore(backend): Add webhook event types for Commerce related events #6338
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
Merged
mauricioabreu
merged 5 commits into
main
from
mauricio-antunes/com-1039-export-billing-webhook-types-from-clerkbackend
Jul 24, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
503fcca
chore(backend): Add webhook event types for Commerce related events
mauricioabreu 50a1a29
fix: statuses field can be stricter
mauricioabreu f3d9b2a
chore: changeset
mauricioabreu f0b00a4
fix: period_start is always defined
mauricioabreu c5b082b
chore: remove is_prorated
mauricioabreu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@clerk/backend': minor | ||
--- | ||
|
||
Add types for Commerce webhooks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,10 @@ export const ObjectType = { | |
TestingToken: 'testing_token', | ||
Role: 'role', | ||
Permission: 'permission', | ||
CommercePayer: 'commerce_payer', | ||
CommercePaymentAttempt: 'commerce_payment_attempt', | ||
CommerceSubscription: 'commerce_subscription', | ||
CommerceSubscriptionItem: 'commerce_subscription_item', | ||
} as const; | ||
|
||
export type ObjectType = (typeof ObjectType)[keyof typeof ObjectType]; | ||
|
@@ -757,6 +761,136 @@ export interface IdPOAuthAccessTokenJSON extends ClerkResourceJSON { | |
updated_at: number; | ||
} | ||
|
||
export interface CommercePayerJSON extends ClerkResourceJSON { | ||
object: typeof ObjectType.CommercePayer; | ||
instance_id: string; | ||
user_id?: string; | ||
first_name?: string; | ||
last_name?: string; | ||
email: string; | ||
organization_id?: string; | ||
organization_name?: string; | ||
image_url: string; | ||
created_at: number; | ||
updated_at: number; | ||
} | ||
|
||
export interface CommercePayeeJSON { | ||
id: string; | ||
gateway_type: string; | ||
gateway_external_id: string; | ||
gateway_status: 'active' | 'pending' | 'restricted' | 'disconnected'; | ||
} | ||
|
||
export interface CommerceAmountJSON { | ||
amount: number; | ||
amount_formatted: string; | ||
currency: string; | ||
currency_symbol: string; | ||
} | ||
|
||
export interface CommerceTotalsJSON { | ||
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. For FAPI we also have |
||
subtotal: CommerceAmountJSON; | ||
tax_total: CommerceAmountJSON; | ||
grand_total: CommerceAmountJSON; | ||
} | ||
|
||
export interface CommercePaymentSourceJSON { | ||
id: string; | ||
gateway: string; | ||
gateway_external_id: string; | ||
gateway_external_account_id?: string; | ||
payment_method: string; | ||
status: 'active' | 'disconnected'; | ||
card_type?: string; | ||
last4?: string; | ||
panteliselef marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
export interface CommercePaymentFailedReasonJSON { | ||
code: string; | ||
decline_code: string; | ||
} | ||
|
||
export interface CommerceSubscriptionCreditJSON { | ||
amount: CommerceAmountJSON; | ||
cycle_days_remaining: number; | ||
cycle_days_total: number; | ||
cycle_remaining_percent: number; | ||
} | ||
|
||
export interface CommercePlanJSON { | ||
id: string; | ||
instance_id: string; | ||
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. are we keeping |
||
product_id: string; | ||
name: string; | ||
slug: string; | ||
description?: string; | ||
is_default: boolean; | ||
is_recurring: boolean; | ||
amount: number; | ||
period: 'month' | 'annual'; | ||
interval: number; | ||
has_base_fee: boolean; | ||
currency: string; | ||
annual_monthly_amount: number; | ||
publicly_visible: boolean; | ||
} | ||
|
||
export interface CommerceSubscriptionItemJSON extends ClerkResourceJSON { | ||
object: typeof ObjectType.CommerceSubscriptionItem; | ||
status: 'abandoned' | 'active' | 'canceled' | 'ended' | 'expired' | 'incomplete' | 'past_due' | 'upcoming'; | ||
credit: CommerceSubscriptionCreditJSON; | ||
proration_date: string; | ||
mauricioabreu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
plan_period: 'month' | 'annual'; | ||
period_start: number; | ||
period_end?: number; | ||
canceled_at?: number; | ||
past_due_at?: number; | ||
lifetime_paid: number; | ||
next_payment_amount: number; | ||
next_payment_date: number; | ||
amount: CommerceAmountJSON; | ||
plan: CommercePlanJSON; | ||
plan_id: string; | ||
} | ||
|
||
export interface CommercePaymentAttemptJSON extends ClerkResourceJSON { | ||
object: typeof ObjectType.CommercePaymentAttempt; | ||
instance_id: string; | ||
payment_id: string; | ||
statement_id: string; | ||
gateway_external_id: string; | ||
status: 'pending' | 'paid' | 'failed'; | ||
created_at: number; | ||
updated_at: number; | ||
paid_at?: number; | ||
failed_at?: number; | ||
failed_reason?: CommercePaymentFailedReasonJSON; | ||
billing_date: number; | ||
charge_type: 'checkout' | 'recurring'; | ||
payee: CommercePayeeJSON; | ||
payer: CommercePayerJSON; | ||
totals: CommerceTotalsJSON; | ||
payment_source: CommercePaymentSourceJSON; | ||
subscription_items: CommerceSubscriptionItemJSON[]; | ||
} | ||
|
||
export interface CommerceSubscriptionJSON extends ClerkResourceJSON { | ||
object: typeof ObjectType.CommerceSubscription; | ||
status: 'abandoned' | 'active' | 'canceled' | 'ended' | 'expired' | 'incomplete' | 'past_due' | 'upcoming'; | ||
active_at?: number; | ||
canceled_at?: number; | ||
created_at: number; | ||
ended_at?: number; | ||
past_due_at?: number; | ||
updated_at: number; | ||
latest_payment_id: string; | ||
payer_id: string; | ||
payer: CommercePayerJSON; | ||
payment_source_id: string; | ||
items: CommerceSubscriptionItemJSON[]; | ||
} | ||
|
||
export interface WebhooksSvixJSON { | ||
svix_url: string; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
are we keeping
instance_id
?