आवश्यकताएँ
शुरू करने से पहले, आपके पास ये होना चाहिए:- Dodo Payments merchant account
- Dashboard में Developer → API Keys से API key, जिसे
DODO_PAYMENTS_API_KEYमें संग्रहीत किया गया हो - Developer → Webhooks से webhook secret, जिसे
DODO_PAYMENTS_WEBHOOK_KEYमें संग्रहीत किया गया हो - Products के अंतर्गत बनाया गया कम से कम एक subscription product
API Integration
Checkout Sessions
अपने subscription product के साथ checkout session बनाकर subscription बनाएँ। ग्राहक payment method को authorize करता है और checkout पूरा करने पर subscription सक्रिय हो जाती है।- Node.js SDK
- Python SDK
- REST API
API Response
Response में एकcheckout_url शामिल है:
Webhooks
जब subscription events होते हैं, तो Webhooks आपके server को सूचित करते हैं। Dashboard में Developer → Webhooks के अंतर्गत अपना endpoint सेट अप करें। अपना webhook endpoint सेट अप करने के लिए Webhooks देखें।Subscription Event Types
Subscription lifecycle को manage करने के लिए इन events को track करें:subscription.active— Subscription सक्रिय हो गईsubscription.updated— Subscription का कोई field बदल गयाsubscription.on_hold— Renewal या plan-change charge विफल हो गयाsubscription.failed— Subscription creation विफल हुआ (terminal; ग्राहक को फिर से subscribe करना होगा)subscription.renewed— Recurring charge सफल हुआsubscription.past_due— Renewal विफल हुआ और grace period शुरू हुई; ग्राहक कोpast_due_ends_atतक access मिलता रहेगाsubscription.plan_changed— Plan को upgrade, downgrade या बदला गयाsubscription.cancelled— Subscription cancel कर दी गईsubscription.expired— Subscription अपनी अवधि के अंत तक पहुँच गई
paused, unpaused और update_payment_method शामिल हैं, Subscription Webhooks देखें।
Payment Scenarios
Successful Payment Flow Webhook sequence इस बात पर निर्भर करता है कि subscription में trial है या नहीं। Immediate billing (0 trial days):subscription.active: mandate authorize होती है और subscription सक्रिय हो जाती है।payment.succeeded: पहला charge confirm करता है। Checkout के 2–10 मिनट के भीतर इसकी अपेक्षा करें।
- At trial start (checkout): Payment method authorize होने के बाद
subscription.activefire होता है। अभी कोई recurring charge नहीं लिया जाता। पहला वास्तविक charge trial समाप्त होने तक स्थगित रहता है। - At trial end: Recurring amount charge किया जाता है और आपको
payment.succeededके साथsubscription.renewedप्राप्त होता है।
subscription.renewed: प्रत्येक billing cycle पर fire होता है, जब renewal payment काटा जाता है, और हमेशाpayment.succeededके साथ आता है। इसमें updatednext_billing_dateभी शामिल होता है।
जब भी subscription product के लिए वास्तव में धन काटा जाता है, आपको
subscription.renewed और payment.succeeded प्राप्त होते हैं। अगले cycle के लिए access बढ़ाने के signal के रूप में केवल subscription.renewed का उपयोग करें, payment.succeeded का अकेले नहीं।- Subscription Failure
subscription.failed- Mandate create न हो पाने के कारण subscription creation विफल हुआ।payment.failed- Failed payment दर्शाता है।
- Subscription On Hold
subscription.on_hold- Failed renewal payment या failed plan change charge के कारण subscription को on hold कर दिया गया है। यदि आपके business में grace period है, तो failed renewal पहले subscription कोpast_due(subscription.past_due) में ले जाता है और grace period समाप्त होने पर ही इसेon_hold(या आपकी grace period settings के आधार परcancelled) में ले जाया जाता है। Subscription States देखें।- जब कोई subscription on hold हो जाती है, तो payment method update किए जाने तक वह अपने-आप renew नहीं होगी।
Best Practice: Implementation को सरल बनाने के लिए, subscription lifecycle manage करते समय मुख्य रूप से subscription events को track करने की सलाह दी जाती है।
subscription.failed vs. subscription.on_hold
इन दोनों events को आसानी से भ्रमित किया जा सकता है, लेकिन इनके लिए बिल्कुल अलग handling आवश्यक है:
Handling Subscription On Hold
जब कोई subscriptionon_hold state में जाती है, तो उसे फिर से सक्रिय करने के लिए आपको payment method update करना होगा। यह section बताता है कि subscriptions कब on hold होती हैं और उन्हें कैसे handle करना है।
When Subscriptions Go On Hold
Subscription को on hold किया जाता है जब:- Renewal payment fails: अपर्याप्त funds, expired card या bank decline के कारण automatic renewal charge विफल हो जाता है
- Plan change charge fails: Plan upgrade/downgrade के दौरान immediate charge विफल हो जाता है
- Payment method authorization fails: Payment method को recurring charges के लिए authorize नहीं किया जा सकता
Reactivating Subscriptions from On Hold
Subscription कोon_hold state से फिर से सक्रिय करने के लिए Update Payment Method API का उपयोग करें। यह अपने-आप:
- शेष dues के लिए charge बनाता है
- Charge के लिए invoice generate करता है
- नए payment method का उपयोग करके payment process करता है
- Payment सफल होने पर subscription को
activestate में फिर से सक्रिय करता है
1
Handle subscription.on_hold webhook
जब आपको
subscription.on_hold webhook प्राप्त हो, तो अपने application state को update करें और customer को सूचित करें:2
Update payment method
जब customer अपना payment method update करने के लिए तैयार हो, तो Update Payment Method API call करें:
यदि customer ने payment methods save किए हैं, तो आप मौजूदा payment method ID का भी उपयोग कर सकते हैं:
3
Monitor webhook events
Payment method update करने के बाद, इन webhook events पर नज़र रखें:
payment.succeeded- शेष dues का charge सफल हुआsubscription.active- Subscription फिर से सक्रिय हो गई
Sample Subscription Event Payload
Changing Subscription Plans
आप change plan API endpoint का उपयोग करके subscription plan को upgrade या downgrade कर सकते हैं। इससे आप subscription के product, quantity को संशोधित कर सकते हैं और proration handle कर सकते हैं।Change Plan API Reference
Subscription plans बदलने की विस्तृत जानकारी के लिए हमारी Change Plan API documentation देखें।
Proration Options
Subscription plans बदलते समय immediate charge handle करने के लिए आपके पास चार options होते हैं:1. prorated_immediately
- वर्तमान billing cycle के unused हिस्से का समय शेष रहने के आधार पर prorated credit देता है। Credit base plan, quantity और किसी भी add-ons को cover करता है
- फिर नए plan, quantity और add-ons पर एक full cycle का charge लेता है। Charge स्वयं कभी prorated नहीं होता
- Net immediate charge = (full new cycle) minus (remaining fraction x full old cycle)। यदि credit बड़ा है, तो अंतर future renewals के लिए subscription-scoped credit के रूप में रखा जाता है
- Trial period के दौरान यह user को तुरंत नए plan पर switch कर देता है और customer से तुरंत charge लेता है
2. full_immediately
- Previous cycle के लिए कोई credit दिए बिना नए plan की पूरी subscription amount customer से charge करता है
- Upgrade या downgrade दोनों में customer नए plan की पूरी price शुरू से चुकाता है
- तब उपयोगी है जब पुराने plan में कितना समय बचा है, इसकी परवाह किए बिना पूरी amount charge करनी हो
3. difference_immediately
- Customer पुराने plan की price और नए plan की price के बीच का केवल अंतर चुकाता है
- Amount इस पर निर्भर नहीं करती कि cycle में बदलाव कब किया गया। Day 1 और day 29 पर एक ही upgrade की cost समान रहती है
- Upgrade करते समय customer से अंतर तुरंत charge किया जाता है। उदाहरण के लिए, $30/month → $80/month = तुरंत $50 charge
- Downgrade करते समय price difference subscription-scoped credit के रूप में store होता है और future renewals पर अपने-आप apply होता है। उदाहरण के लिए, $50/month → $20/month = $30 credit के रूप में store
4. do_not_bill
- Plan change तुरंत apply करता है, लेकिन बदलाव के समय कुछ भी charge नहीं करता। नया plan, quantity और add-ons तुरंत उपयोग किए जा सकते हैं
- क्योंकि अभी कोई charge नहीं लिया जाता, इसलिए upgrade customer को वर्तमान cycle के शेष समय के लिए higher plan free देता है। Downgrade तुरंत प्रभावी होता है और पहले से भुगतान किए गए cycle के unused हिस्से के लिए कोई credit नहीं मिलता
do_not_billके माध्यम से दिए गए add-ons को बाद के plan change पर credit नहीं किया जाता, क्योंकि उनका कभी billing नहीं हुआ। अगला change नई add-on quantity को पूरी तरह bill करता है- Updated plan (और quantity/add-ons) को अगले scheduled renewal पर bill किया जाता है और original billing date सुरक्षित रहती है
Behavior
- जब आप इस API को invoke करते हैं, तो Dodo Payments आपके चुने हुए proration option के आधार पर तुरंत charge शुरू करता है
prorated_immediatelyके साथ, current cycle के unused हिस्से का credit हर change पर calculate किया जाता है, चाहे upgrade हो या downgrade। यदि credit नए cycle के charge से अधिक है, तो शेष राशि subscription के credit balance में जोड़ दी जाती है। ये credits उसी subscription के लिए specific होते हैं और केवल उसी subscription के future recurring payments को offset करने के लिए उपयोग किए जाएंगेdifference_immediatelyके साथ net हमेशा exact price difference होता है। Downgrade के लिए excess को subscription-scoped credit के रूप में store किया जाता है, ठीकprorated_immediatelyकी तरहfull_immediatelyoption credit calculations को bypass करता है और नए plan की पूरी amount charge करता हैdo_not_billoption बदलाव को तुरंत apply करता है, लेकिन billing को preserved next renewal date तक स्थगित करता है
Charge Processing
- Plan change पर शुरू किया गया immediate charge आमतौर पर 2 मिनट से कम समय में process हो जाता है
- यदि यह immediate charge किसी भी कारण से विफल होता है, तो issue resolve होने तक subscription को अपने-आप on hold कर दिया जाता है
On-Demand Subscriptions
On-demand subscriptions आपको customers से केवल fixed schedule पर ही नहीं, बल्कि flexible तरीके से charge करने देती हैं। यह feature सभी accounts के लिए उपलब्ध है।
subscription_data.on_demand field शामिल करें। इससे आप बिना immediate charge के payment method authorize कर सकते हैं या custom initial price सेट कर सकते हैं।
On-demand subscription charge करने के लिए:
Subsequent charges के लिए POST /subscriptions//charge endpoint का उपयोग करें और उस transaction के लिए customer से charge की जाने वाली amount specify करें।
पूरी step-by-step guide (request/response examples, safe retry policies और webhook handling सहित) के लिए On-Demand Subscriptions Guide देखें।
Subscription Billing के बारे में जानने योग्य मुख्य बातें
Trials में charge नहीं, बल्कि $0 authorization होती है। जब subscription में trial होता है, तो trial start पर card save करने के लिए $0 mandate authorization बनाई जाती है; पहला वास्तविक charge trial समाप्त होने पर होता है। Payments list में free trial वाली subscription में
total_amount की exactly एक payment दिखाई देती है, जिसकी amount 0 होती है। Paid trial इसके बजाय अपनी trial_amount upfront charge करती है।Subscription lifecycle:
past_due = renewal विफल हुई और grace period चल रही है (customer को access मिलता रहता है)। on_hold = renewal विफल हुई (recoverable: customer को payment method update करने के लिए prompt करें; dunning retries लागू होते हैं)। expired = term बिना renewal के समाप्त हो गई और इसे फिर से सक्रिय नहीं किया जा सकता। Customer को फिर से subscribe करना होगा। cancelled = customer या merchant द्वारा समाप्त की गई। अधिकांश renewal failures issuer-side declines होते हैं (insufficient funds, card declined), Dodo error नहीं।Related API Reference
Create Subscription (Deprecated)
सीधे subscription बनाने के लिए Legacy API। नए integrations के लिए Checkout Sessions का उपयोग करें
Change Subscription Plan
Proration options के साथ subscription plans को upgrade, downgrade या बदलने के लिए API reference
Update Payment Method
Payment methods update करने और on-hold subscriptions को फिर से सक्रिय करने के लिए API reference
Patch Subscription
Subscription details और configuration update करने के लिए API reference