Passer au contenu principal

Événements Webhook d’Abonnement

Les événements webhook suivants sont disponibles pour suivre les changements du cycle de vie des abonnements :
ÉvénementDescription
subscription.activeL’abonnement est activé avec succès
subscription.updatedL’objet d’abonnement a été mis à jour (tout changement de champ déclenche cet événement)
subscription.on_holdL’abonnement est suspendu en raison d’un échec de renouvellement
subscription.renewedL’abonnement est renouvelé pour la prochaine période de facturation
subscription.plan_changedLe plan d’abonnement a été mis à niveau, rétrogradé ou modifié
subscription.cancelledL’abonnement est annulé
subscription.failedLa création de l’abonnement a échoué lors de la création du mandat
subscription.expiredL’abonnement a atteint la fin de sa période

Utilisation de subscription.updated pour la Synchronisation en Temps Réel

Le webhook subscription.updated se déclenche chaque fois qu’un champ d’abonnement change, vous permettant de garder l’état de votre application synchronisé sans interroger :
app.post('/webhooks/dodo', async (req, res) => {
  const event = req.body;
  
  if (event.type === 'subscription.updated') {
    const subscription = event.data;
    
    // Sync subscription changes to your database
    await syncSubscription(subscription.subscription_id, {
      status: subscription.status,
      next_billing_date: subscription.next_billing_date,
      metadata: subscription.metadata,
      // ... other fields you want to track
    });
    
    console.log(`Subscription ${subscription.subscription_id} updated`);
  }
  
  res.json({ received: true });
});
Abonnez-vous à subscription.updated pour recevoir des notifications en temps réel sur tout changement d’abonnement, éliminant ainsi le besoin d’interroger l’API pour des mises à jour.

Schéma de Charge Utile Webhook

Response struct representing subscription details

addons
Addon Cart Response Item · object[]
required

Addons associated with this subscription

billing
object
required

Billing address details for payments

cancel_at_next_billing_date
boolean
required

Indicates if the subscription will cancel at the next billing date

created_at
string<date-time>
required

Timestamp when the subscription was created

currency
enum<string>
required

Currency used for the subscription payments

Options disponibles:
AED,
ALL,
AMD,
ANG,
AOA,
ARS,
AUD,
AWG,
AZN,
BAM,
BBD,
BDT,
BGN,
BHD,
BIF,
BMD,
BND,
BOB,
BRL,
BSD,
BWP,
BYN,
BZD,
CAD,
CHF,
CLP,
CNY,
COP,
CRC,
CUP,
CVE,
CZK,
DJF,
DKK,
DOP,
DZD,
EGP,
ETB,
EUR,
FJD,
FKP,
GBP,
GEL,
GHS,
GIP,
GMD,
GNF,
GTQ,
GYD,
HKD,
HNL,
HRK,
HTG,
HUF,
IDR,
ILS,
INR,
IQD,
JMD,
JOD,
JPY,
KES,
KGS,
KHR,
KMF,
KRW,
KWD,
KYD,
KZT,
LAK,
LBP,
LKR,
LRD,
LSL,
LYD,
MAD,
MDL,
MGA,
MKD,
MMK,
MNT,
MOP,
MRU,
MUR,
MVR,
MWK,
MXN,
MYR,
MZN,
NAD,
NGN,
NIO,
NOK,
NPR,
NZD,
OMR,
PAB,
PEN,
PGK,
PHP,
PKR,
PLN,
PYG,
QAR,
RON,
RSD,
RUB,
RWF,
SAR,
SBD,
SCR,
SEK,
SGD,
SHP,
SLE,
SLL,
SOS,
SRD,
SSP,
STN,
SVC,
SZL,
THB,
TND,
TOP,
TRY,
TTD,
TWD,
TZS,
UAH,
UGX,
USD,
UYU,
UZS,
VES,
VND,
VUV,
WST,
XAF,
XCD,
XOF,
XPF,
YER,
ZAR,
ZMW
customer
object
required

Customer details associated with the subscription

metadata
object
required

Additional custom data associated with the subscription

meters
object[]
required

Meters associated with this subscription (for usage-based billing)

next_billing_date
string<date-time>
required

Timestamp of the next scheduled billing. Indicates the end of current billing period

on_demand
boolean
required

Wether the subscription is on-demand or not

payment_frequency_count
integer<int32>
required

Number of payment frequency intervals

payment_frequency_interval
enum<string>
required

Time interval for payment frequency (e.g. month, year)

Options disponibles:
Day,
Week,
Month,
Year
previous_billing_date
string<date-time>
required

Timestamp of the last payment. Indicates the start of current billing period

product_id
string
required

Identifier of the product associated with this subscription

quantity
integer<int32>
required

Number of units/items included in the subscription

recurring_pre_tax_amount
integer<int32>
required

Amount charged before tax for each recurring payment in smallest currency unit (e.g. cents)

status
enum<string>
required

Current status of the subscription

Options disponibles:
pending,
active,
on_hold,
cancelled,
failed,
expired
subscription_id
string
required

Unique identifier for the subscription

subscription_period_count
integer<int32>
required

Number of subscription period intervals

subscription_period_interval
enum<string>
required

Time interval for the subscription period (e.g. month, year)

Options disponibles:
Day,
Week,
Month,
Year
tax_inclusive
boolean
required

Indicates if the recurring_pre_tax_amount is tax inclusive

trial_period_days
integer<int32>
required

Number of days in the trial period (0 if no trial)

cancelled_at
string<date-time> | null

Cancelled timestamp if the subscription is cancelled

discount_cycles_remaining
integer<int32> | null

Number of remaining discount cycles if discount is applied

discount_id
string | null

The discount id if discount is applied

expires_at
string<date-time> | null

Timestamp when the subscription will expire

payment_method_id
string | null

Saved payment method id used for recurring charges

tax_id
string | null

Tax identifier provided for this subscription (if applicable)