Subscription webhooks
Overview
Subscription webhooks provide real-time notifications about changes to subscriptions. This document outlines the different webhook events you may receive and provides details about the payload structure and handling of each event.
Webhook Events
1. Subscription Created
Event Type: customer.subscription.created
Description: Triggered when a subscription is created but not yet started, meaning the very first payment has not been successfully deducted.
Typical Scenario: A user signs up for a subscription plan, but their initial payment fails.
2. Subscription Started
Event Type: customer.subscription.started
Description: Triggered when a subscription enters into active mode after the first successful payment.
Typical Scenario: A user’s initial payment is successfully processed, and their subscription becomes active.
3. Subscription Unpaid
Event Type: customer.subscription.unpaid
Description: Triggered when the system is unable to charge the user during renewal after multiple retries over a period of 7 days.
Typical Scenario: A user's payment method fails, and all retry attempts to collect the subscription fee are exhausted.
4. Subscription Past Due
Event Type: customer.subscription.past_due
Description: Triggered when the system is unable to charge the user during renewal on the first try, changing the subscription status from
active
topast_due
. If the payment is successfully collected after a retry, the status changes back to active. If all retries fail over 7 days, the status changes frompast_due
tounpaid
.Typical Scenario: A user's payment method fails on the first attempt, but a subsequent retry within 7 days may still succeed.
5. Subscription Canceled
Event Type: customer.subscription.deleted
Description: Triggered when a subscription is canceled at the end of the current period.
Typical Scenario: A user decides to cancel their subscription, and it is set to end at the current period's end.
Sample Webhook Payload
Below is an example payload for the customer.subscription.started
event. The structure of the payload is consistent across different subscription events, with the type
field indicating the specific event type.
Handling Webhooks
When you receive a webhook event, the type
field indicates the specific type of event. The data.object
field contains the latest data about the subscription, including its status, payment method, and relevant timestamps.
Example Workflow for Handling a Subscription Event
Parse the Webhook Payload: Extract the event type and the subscription object.
Identify the Event Type: Use the
type
field to determine the specific subscription event.Update Subscription Status: Update your records based on the latest status provided in the
data.object
.Trigger Appropriate Actions: Depending on the event type, trigger the necessary actions, such as sending a notification to the user or updating user's account status on your application.
No-Code Solution with Zapier
If you prefer a no-code solution, you can use our Zapier application to configure automations or alerts for your team. Zapier allows you to connect Copperx with various other applications and automate workflows without writing any code.
Last updated