Skip to main content
@dodopayments/express adaptor आपके Express ऐप को तीन route handlers देता है: checkoutHandler checkout URLs लौटाता है, CustomerPortal ग्राहक को Customer Portal पर भेजता है, और Webhooks webhook requests को verify करके आपके event handlers को call करता है।

Checkout Handler

अपने Express ऐप से payment links और checkout sessions बनाएं।

Customer Portal

ग्राहकों को अपनी subscriptions और details प्रबंधित करने दें।

Webhooks

Dodo Payments webhook events को verify और process करें।

इंस्टॉलेशन

1

Install the Package

अपने project root में निम्न command चलाएं:
2

Set Up Environment Variables

अपने project root में एक .env फ़ाइल बनाएं:
Developer → API Keys के अंतर्गत API key बनाएं। अपना webhook endpoint Developer → Webhooks के अंतर्गत जोड़ें और उसका signing secret DODO_PAYMENTS_WEBHOOK_KEY में copy करें। Build करते समय, DODO_PAYMENTS_ENVIRONMENT=test_mode के साथ test mode API key का उपयोग करें, क्योंकि test mode key केवल test mode के विरुद्ध काम करती है। DODO_PAYMENTS_RETURN_URL वैकल्पिक है।
अपनी .env फ़ाइल या secrets को version control में कभी commit न करें।

Route Handler उदाहरण

उदाहरण express() से बनाए गए Express ऐप पर routes register करते हैं। POST checkout handlers और webhook handler req.body पढ़ते हैं, इसलिए प्रत्येक उदाहरण अपने routes से पहले express.json() register करता है।
Dodo Payments checkout को अपने Express ऐप में integrate करने के लिए इस handler का उपयोग करें। यह static (GET), dynamic (POST) और session (POST) payment flows को support करता है। प्रत्येक POST flow को अपने path पर register करें, क्योंकि किसी path के लिए register किया गया पहला handler उस path के हर request का उत्तर देता है।

Checkout Route Handler

Adaptor सभी तीन Dodo Payments checkout flows को support करता है। कोई route कौन-सा flow serve करे, यह चुनने के लिए handler config में type सेट करें। हर flow JSON response देता है जिसमें ग्राहक के खोलने के लिए एक checkout_url होता है।
  • Static Payment Links: type: "static", GET। Query parameters से एक product के लिए payment link बनाता है, पहले यह जांचने के बाद कि product मौजूद है।
  • Dynamic Payment Links: type: "dynamic", POST। Product recurring है या नहीं, इसके आधार पर payment link के साथ one-time payment या subscription बनाता है।
  • Checkout Sessions: type: "session", POST। Product cart और customer details से checkout session बनाता है। नए integrations के लिए इस flow का उपयोग करें।
checkoutHandler ये options लेता है: जब type, static हो, तब handler को GET के लिए register करें; और जब यह dynamic या session हो, तब POST के लिए register करें। अन्य methods के लिए handler 405 लौटाता है।

Supported Query Parameters

string
आवश्यक
Product identifier, उदाहरण के लिए ?productId=pdt_nZuwz45WAs64n3l07zpQR।
integer
डिफ़ॉल्ट:"1"
Product की quantity।
string
Customer का पूरा नाम। यदि firstName या lastName दिया गया हो, तो इसे अनदेखा किया जाता है।
string
Customer का first name।
string
Customer का last name।
string
Customer का email address।
string
Customer का country, ISO 3166-1 alpha-2 code के रूप में।
string
Customer का street address।
string
Customer का city।
string
Customer का state या province।
string
Customer का postal या ZIP code।
boolean
Full name field को disable करने के लिए इसे true पर सेट करें।
boolean
First name field को disable करने के लिए इसे true पर सेट करें।
boolean
Last name field को disable करने के लिए इसे true पर सेट करें।
boolean
Email field को disable करने के लिए इसे true पर सेट करें।
boolean
Country field को disable करने के लिए इसे true पर सेट करें।
boolean
Address line field को disable करने के लिए इसे true पर सेट करें।
boolean
City field को disable करने के लिए इसे true पर सेट करें।
boolean
State field को disable करने के लिए इसे true पर सेट करें।
boolean
ZIP code field को disable करने के लिए इसे true पर सेट करें।
string
Payment currency, उदाहरण के लिए USD।
boolean
डिफ़ॉल्ट:"true"
Currency selector दिखाएं या छिपाएं।
number
Major currency units में charged amount को निश्चित करता है, उदाहरण के लिए $12.50 के लिए 12.5। यह केवल Pay What You Want products के साथ काम करता है और product की minimum price से कम होने पर अनदेखा किया जाता है।
boolean
डिफ़ॉल्ट:"true"
Discounts section दिखाएं या छिपाएं।
string
metadata_ से शुरू होने वाला कोई भी query parameter checkout को metadata के रूप में भेजा जाता है, उदाहरण के लिए metadata_orderId=123।
Disable flag तभी प्रभावी होता है जब वह true हो और matching field में कोई value हो, उदाहरण के लिए email के साथ disableEmail। Handler इन parameters को static payment link में भेजता है।
यदि productId मौजूद नहीं है, तो handler 400 response लौटाता है। Invalid query parameters या ऐसा product जो आपके account में मौजूद नहीं है, भी 400 response का कारण बनते हैं।

Response Format

Static checkout checkout URL के साथ JSON response लौटाता है:
  • Parameters को POST request में JSON body के रूप में भेजें।
  • One-time और recurring payments दोनों को support करता है। Handler product retrieve करता है, फिर product recurring होने पर subscription और अन्यथा one-time payment बनाता है।
  • Body में billing (साथ में street, city, state, country और zipcode), customer, और product_id (वैकल्पिक quantity के साथ) या product_cart होना चाहिए। Subscriptions के लिए product_id आवश्यक है।
  • Handler metadata, allowed_payment_method_types, billing_currency, discount_codes (या deprecated discount_code), return_url, show_saved_payment_methods और tax_id भी forward करता है। Subscriptions के लिए यह addons, on_demand और trial_period_days भी forward करता है। अन्य fields को अनदेखा किया जाता है।
  • Field details के लिए देखें:
Dynamic Checkout deprecated POST /payments और POST /subscriptions endpoints को call करता है। नए integrations के लिए Checkout Sessions का उपयोग करें।

Response Format

Dynamic checkout payment link को checkout URL के रूप में JSON response में लौटाता है:
Checkout session payload को JSON body के रूप में भेजें। Handler एक checkout session बनाता है, जो one-time purchases और subscriptions के लिए पूरी payment flow को संभालता है, और उसका checkout_url लौटाता है। product_cart आवश्यक है और इसमें कम से कम एक product होना चाहिए।प्रत्येक checkout_url एक बार काम करता है और 24 घंटे बाद expire हो जाता है, या जब आप confirm: true pass करते हैं तो 15 मिनट बाद। payment_method_id के साथ बनाया गया session कोई checkout_url नहीं लौटाता, इसलिए handler 400 response देता है।अधिक details और supported fields की पूरी list के लिए Checkout Sessions Integration Guide देखें।

Response Format

Checkout sessions checkout URL के साथ JSON response लौटाते हैं:

Customer Portal Route Handler

Customer Portal Route Handler customer_id में customer के लिए Customer Portal session बनाता है और request को portal link पर redirect करता है। CustomerPortal, checkoutHandler की तरह ही bearerToken और environment options लेता है। यदि Dodo Payments session नहीं बना पाता, तो handler 500 लौटाता है।

Query Parameters

string
आवश्यक
Portal session के लिए customer ID, उदाहरण के लिए ?customer_id=cus_123।
boolean
यदि इसे true पर सेट किया गया है, तो customer को portal link वाला email भेजता है।
यदि customer_id मौजूद नहीं है, तो 400 लौटाता है। Handler request को authenticate नहीं करता और उसे मिलने वाले किसी भी customer_id के लिए portal खोल देता है, इसलिए route को अपनी authentication के पीछे रखें और केवल signed-in user की customer ID pass करें।

Webhook Route Handler

Webhook handler प्रत्येक request को webhookKey के रूप में दिए गए webhook secret से verify करता है, फिर आपके event handlers को call करता है।
Webhook route से पहले express.json() register करें। Handler signature को req.body के विरुद्ध verify करता है, इसलिए body को parsed JSON के रूप में न पढ़े जाने पर हर request reject कर देता है। इस route के लिए express.raw() का उपयोग न करें।
  • Method: केवल POST requests supported हैं। अन्य methods 405 लौटाते हैं।
  • Signature Verification: Standard Webhooks specification का पालन करते हुए webhookKey से webhook-id, webhook-timestamp और webhook-signature headers को verify करता है। Verification विफल होने पर 401 लौटाता है।
  • Payload Validation: Zod से validate किया जाता है। Invalid payloads के लिए 400 लौटाता है।
  • Error Handling:
    • 401: Invalid signature
    • 400: Invalid payload
    • 500: Verification के दौरान internal error
  • Event Routing: प्रत्येक event के लिए onPayload को call करता है, फिर event के type के handler को call करता है और उनके पूरा होने पर 200 लौटाता है। Handler आपके event handlers द्वारा throw की गई errors को catch नहीं करता।

Supported Webhook Event Handlers

हर handler optional और async है। प्रत्येक event के payload के लिए Webhook Event Guide देखें।

LLM के लिए Prompt

अंतिम संशोधन 28 सितंबर 2026