보류 상태에서 구독을 재활성화하려면 결제 방법 업데이트 API를 사용하세요. 이 과정은 자동으로:
남은 요금에 대한 청구를 생성합니다.
청구에 대한 송장을 생성합니다.
새 결제 방법을 사용하여 결제를 처리합니다.
성공적인 결제 후 구독을 active 상태로 재활성화합니다.
1
subscription.on_hold 웹훅 처리
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
결제 방법 업데이트
고객이 결제 방법을 업데이트할 준비가 되면 결제 방법 업데이트 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 엔드포인트를 사용하고 해당 거래에 대해 고객에게 청구할 금액을 지정하세요.
완전한 단계별 가이드를 보려면—요청/응답 예제, 안전한 재시도 정책 및 웹훅 처리 포함—주문형 구독 가이드를 참조하세요.