Chuyển đến nội dung chính

Sự kiện Webhook Đăng Ký

Các sự kiện webhook sau đây có sẵn để theo dõi các thay đổi trong vòng đời đăng ký:
EventDescription
subscription.activeĐăng ký được kích hoạt thành công
subscription.updatedĐối tượng đăng ký đã được cập nhật (mọi thay đổi trường đều kích hoạt sự kiện này)
subscription.on_holdĐăng ký bị tạm ngưng do gia hạn thất bại
subscription.renewedĐăng ký được gia hạn cho kỳ thanh toán tiếp theo
subscription.plan_changedKế hoạch đăng ký đã được nâng cấp, giảm cấp hoặc chỉnh sửa
subscription.cancelledĐăng ký bị hủy
subscription.failedTạo đăng ký thất bại trong quá trình tạo ủy quyền
subscription.expiredĐăng ký đã hết hạn

Sử dụng subscription.updated để đồng bộ thời gian thực

Webhook subscription.updated được kích hoạt mỗi khi bất kỳ trường đăng ký nào thay đổi, cho phép bạn giữ trạng thái ứng dụng đồng bộ mà không cần dò hỏi:
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 });
});
Đăng ký subscription.updated để nhận thông báo thời gian thực về bất kỳ thay đổi đăng ký nào, loại bỏ việc phải truy vấn API để cập nhật.

Lược Đồ Payload Webhook

Response struct representing subscription details

addons
Addon Cart Response Item · object[]
bắt buộc

Addons associated with this subscription

billing
object
bắt buộc

Billing address details for payments

cancel_at_next_billing_date
boolean
bắt buộc

Indicates if the subscription will cancel at the next billing date

created_at
string<date-time>
bắt buộc

Timestamp when the subscription was created

credit_entitlement_cart
object[]
bắt buộc

Credit entitlement cart settings for this subscription

currency
enum<string>
bắt buộc

Currency used for the subscription payments

Tùy chọn có sẵn:
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
bắt buộc

Customer details associated with the subscription

metadata
object
bắt buộc

Additional custom data associated with the subscription

meter_credit_entitlement_cart
object[]
bắt buộc

Meter credit entitlement cart settings for this subscription

meters
object[]
bắt buộc

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

next_billing_date
string<date-time>
bắt buộc

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

on_demand
boolean
bắt buộc

Wether the subscription is on-demand or not

payment_frequency_count
integer<int32>
bắt buộc

Number of payment frequency intervals

payment_frequency_interval
enum<string>
bắt buộc

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

Tùy chọn có sẵn:
Day,
Week,
Month,
Year
previous_billing_date
string<date-time>
bắt buộc

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

product_id
string
bắt buộc

Identifier of the product associated with this subscription

quantity
integer<int32>
bắt buộc

Number of units/items included in the subscription

recurring_pre_tax_amount
integer<int32>
bắt buộc

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

status
enum<string>
bắt buộc

Current status of the subscription

Tùy chọn có sẵn:
pending,
active,
on_hold,
cancelled,
failed,
expired
subscription_id
string
bắt buộc

Unique identifier for the subscription

subscription_period_count
integer<int32>
bắt buộc

Number of subscription period intervals

subscription_period_interval
enum<string>
bắt buộc

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

Tùy chọn có sẵn:
Day,
Week,
Month,
Year
tax_inclusive
boolean
bắt buộc

Indicates if the recurring_pre_tax_amount is tax inclusive

trial_period_days
integer<int32>
bắt buộc

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

cancelled_at
string<date-time> | null

Cancelled timestamp if the subscription is cancelled

custom_field_responses
object[] | null

Customer's responses to custom fields collected during checkout

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)