Skip to content

Commit

Permalink
Handles customer.subscription.paused webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
joshnuss committed May 13, 2024
1 parent a1c6df7 commit ec49979
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/sveltekit/src/lib/server/webhooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export async function handleWebhook(billing, body, signature) {
case 'customer.subscription.updated':
case 'customer.subscription.deleted':
case 'customer.subscription.trial_will_end':
case 'customer.subscription.paused':
await billing.syncSubscription(object.id)
console.log(`Synced subscription ${object.id}`)
break
Expand Down
15 changes: 15 additions & 0 deletions packages/sveltekit/src/lib/server/webhooks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,19 @@ describe('handleWebhook', () => {

expect(billing.syncSubscription).toHaveBeenCalledWith('sub_1234')
})

test('when subscription.paused event, syncs subscription', async () => {
stripe.webhooks.constructEvent.mockReturnValue({
type: 'customer.subscription.paused',
data: {
object: {
id: 'sub_1234'
}
}
})

await handleWebhook(billing, 'fake-body', 'fake-sig')

expect(billing.syncSubscription).toHaveBeenCalledWith('sub_1234')
})
})

0 comments on commit ec49979

Please sign in to comment.