on_hold 상태의 구독을 다시 활성화하려면 Update Payment Method API를 사용하세요. 이 API는 자동으로 다음을 수행합니다:
남은 금액에 대한 청구를 생성합니다
해당 청구에 대한 인보이스를 생성합니다
새 결제 수단으로 결제를 처리합니다
결제가 성공하면 구독을 active 상태로 다시 활성화합니다
1
Handle subscription.on_hold webhook
subscription.on_hold 웹훅을 수신하면 애플리케이션 상태를 업데이트하고 고객에게 알려주세요:
복사
// Webhook handlerapp.post('/webhooks/dodo', async (req, res) => { const event = req.body; if (event.type === 'subscription.on_hold') { const subscription = event.data; // Update subscription status in your database await updateSubscriptionStatus(subscription.subscription_id, 'on_hold'); // Notify customer to update payment method await sendEmailToCustomer(subscription.customer_id, { subject: 'Payment Required - Subscription On Hold', message: 'Your subscription is on hold. Please update your payment method to continue service.' }); } res.json({ received: true });});
2
Update payment method
고객이 결제 수단을 업데이트할 준비가 되면 Update Payment Method API를 호출하세요:
복사
// Update with new payment methodconst response = await client.subscriptions.updatePaymentMethod(subscriptionId, { type: 'new', return_url: 'https://example.com/return'});// For on_hold subscriptions, a charge is automatically createdif (response.payment_id) { console.log('Charge created for remaining dues:', response.payment_id); // Redirect customer to response.payment_link to complete payment}
if (event.type === 'payment.succeeded') { const payment = event.data; // Check if this payment is for an on_hold subscription if (payment.subscription_id) { // Wait for subscription.active webhook to confirm reactivation }}if (event.type === 'subscription.active') { const subscription = event.data; // Update subscription status in your database await updateSubscriptionStatus(subscription.subscription_id, 'active'); // Restore customer access await restoreCustomerAccess(subscription.customer_id); // Notify customer of successful reactivation await sendEmailToCustomer(subscription.customer_id, { subject: 'Subscription Reactivated', message: 'Your subscription has been reactivated successfully.' });}
주문형 구독을 사용하면 고정 일정에 얽매이지 않고 고객에게 유연하게 요금을 청구할 수 있습니다. 이 기능은 모든 계정에서 사용할 수 있습니다.
주문형 구독을 생성하려면:주문형 구독을 생성하려면 POST /subscriptions API 엔드포인트를 사용하고 요청 본문에 on_demand 필드를 포함하세요. 이렇게 하면 즉시 청구 없이 결제 수단을 승인하거나 사용자 정의 초기 가격을 설정할 수 있습니다.주문형 구독에 요금을 청구하려면:후속 요금 청구를 위해 POST /subscriptions/charge 엔드포인트를 사용하고 해당 거래에 대해 고객에게 청구할 금액을 지정하세요.