Skip to main content
@dodopayments/fastify adaptor आपके Fastify ऐप को तीन route handlers देता है: Checkout checkout URLs लौटाता है, CustomerPortal ग्राहक को Customer Portal पर भेजता है, और Webhooks webhook requests को सत्यापित करके आपके event handlers को कॉल करता है।

Checkout Handler

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

Customer Portal

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

Webhooks

Dodo Payments webhook events को सत्यापित और process करें।

Installation

1

Install the Package

अपने project root में निम्न command चलाएँ:
इस package के लिए Fastify 5.4.0 या बाद का version आवश्यक है।
2

Set Up Environment Variables

अपने project root में एक .env file बनाएँ:
Developer → API Keys के अंतर्गत API key बनाएँ। Developer → Webhooks के अंतर्गत अपना webhook endpoint जोड़ें और उसका 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 file या secrets को version control में कभी commit न करें।

Route Handler Examples

इन examples में Fastify() से बनाए गए Fastify instance पर routes register किए गए हैं। Webhook route को raw request body चाहिए, इसलिए इसके example में केवल webhook route वाले plugin के अंदर string body parser जोड़ा गया है।
Dodo Payments checkout को अपने Fastify ऐप में integrate करने के लिए इस handler का उपयोग करें। यह static (GET), dynamic (POST) और session (POST) payment flows को support करता है। Checkout() static flow के लिए एक getHandler और dynamic तथा session flows के लिए एक postHandler लौटाता है। प्रत्येक POST flow को अपने अलग path पर register करें।

Checkout Route Handler

Adaptor सभी तीन Dodo Payments checkout flows को support करता है। Route द्वारा serve किए जाने वाले flow को चुनने के लिए 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 का उपयोग करें।
Checkout ये options लेता है: Checkout दो handlers वाला object लौटाता है। जब type, static हो, तब GET के लिए getHandler register करें; और जब type, dynamic या session हो, तब POST के लिए postHandler register करें।

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 का देश, 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 हो, उदाहरण के लिए disableEmail के साथ email। Handler इन parameters को static payment link में पास करता है।
यदि productId मौजूद नहीं है, तो handler 400 response लौटाता है। Invalid query parameters या आपके account में मौजूद न होने वाला product भी 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 पास करने पर 15 मिनट बाद। payment_method_id के साथ बनाए गए session में कोई checkout_url नहीं होता, इसलिए handler 400 लौटाता है।अधिक विवरण और supported fields की पूरी सूची के लिए 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, Checkout की तरह ही bearerToken और environment options लेता है। यदि Dodo Payments session नहीं बना पाता, तो handler 500 लौटाता है।

Query Parameters

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

Webhook Route Handler

Webhook handler आपके webhook secret से प्रत्येक request को verify करता है, जिसे webhookKey के रूप में pass किया जाता है, फिर आपके event handlers को call करता है।
Webhook handler को raw request body string के रूप में चाहिए, इसलिए application/json के लिए parseAs: 'string' के साथ content type parser जोड़ें। Fastify उस scope के प्रत्येक route पर parser लागू करता है जहाँ आप उसे जोड़ते हैं। इसे ऐसे plugin के अंदर जोड़ें जो केवल webhook route register करता हो, जैसा example में है। Root instance पर ऐसा करने से POST checkout handlers को भी string मिलेगी और वे 400 लौटाएँगे।
  • 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 से validated। 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 वैकल्पिक और async है। प्रत्येक event के payload के लिए Webhook Event Guide देखें।

LLM के लिए Prompt

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