@dodopayments/hono adaptor आपके Hono ऐप को तीन route handlers देता है: Checkout checkout URLs लौटाता है, CustomerPortal ग्राहक को Customer Portal पर भेजता है, और Webhooks webhook requests की पुष्टि करके आपके event handlers को कॉल करता है।
Checkout Handler
अपने Hono ऐप से payment links और checkout sessions बनाएँ।
Customer Portal
ग्राहकों को अपनी subscriptions और विवरण प्रबंधित करने दें।
Webhooks
Dodo Payments webhook events की पुष्टि और processing करें।
Installation
1
Install the Package
अपने project root में निम्न command चलाएँ:इस package के लिए Hono 4.8.9 या बाद का संस्करण आवश्यक है।
2
Set Up Environment Variables
अपने project root में एक API key Developer → API Keys के अंतर्गत बनाएँ। अपना webhook endpoint Developer → Webhooks के अंतर्गत जोड़ें और उसके signing secret को
.env file बनाएँ:DODO_PAYMENTS_WEBHOOK_KEY में कॉपी करें। Build करते समय DODO_PAYMENTS_ENVIRONMENT=test_mode वाली test mode API key का उपयोग करें, क्योंकि test mode key केवल test mode के साथ काम करती है। DODO_PAYMENTS_RETURN_URL वैकल्पिक है।Route Handler Examples
उदाहरण
new Hono() से बनाए गए Hono ऐप पर routes register करते हैं। Handlers request body को स्वयं पढ़ते हैं, इसलिए उन्हें body-parsing middleware की आवश्यकता नहीं होती।- Checkout Handler
- Customer Portal Handler
- Webhook Handler
अपने Hono ऐप में Dodo Payments checkout integrate करने के लिए इस handler का उपयोग करें। यह static (GET), dynamic (POST) और session (POST) flows को support करता है। प्रत्येक POST flow को उसके अपने path पर register करें, क्योंकि किसी request के लिए चलने वाले पहले handler पर Hono रुक जाता है।
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 लेता है:
जब
type, static हो, तब handler को GET के लिए register करें; और जब type, dynamic या session हो, तब POST के लिए register करें। Handler हर उस request को static checkout request मानता है जो POST नहीं है।
Static Checkout (GET)
Static Checkout (GET)
Supported Query Parameters
string
आवश्यक
Product identifier, उदाहरण के लिए
?productId=pdt_nZuwz45WAs64n3l07zpQR।integer
डिफ़ॉल्ट:"1"
Product की quantity।
string
Customer का पूरा नाम। यदि
firstName या lastName दिया गया हो, तो इसे अनदेखा किया जाता है।string
Customer का पहला नाम।
string
Customer का अंतिम नाम।
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 में charge की गई राशि तय करता है, उदाहरण के लिए $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।true हो और matching field में कोई value हो, उदाहरण के लिए disableEmail के साथ email। Handler इन parameters को static payment link को भेजता है।Response Format
Static checkout checkout URL के साथ JSON response लौटाता है:Dynamic Checkout (POST)
Dynamic Checkout (POST)
- POST request में parameters को JSON body के रूप में भेजें।
- One-time और recurring दोनों payments को support करता है। Handler product प्राप्त करता है, फिर 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(या deprecateddiscount_code),return_url,show_saved_payment_methodsऔरtax_idको भी forward करता है। Subscriptions के लिए यहaddons,on_demandऔरtrial_period_daysको भी forward करता है। अन्य fields को अनदेखा करता है। - Field details के लिए देखें:
Response Format
Dynamic checkout payment link को checkout URL के रूप में JSON response लौटाता है:Checkout Sessions (POST)
Checkout Sessions (POST)
JSON body के रूप में checkout session payload भेजें। Handler एक checkout session बनाता है, जो one-time purchases और subscriptions के लिए complete payment flow संभालता है, और उसका
checkout_url लौटाता है। product_cart आवश्यक है और इसमें कम से कम एक product होना चाहिए।प्रत्येक checkout_url एक बार काम करता है और 24 घंटे बाद expire हो जाता है, या confirm: true पास करने पर 15 मिनट बाद। payment_method_id से बनाया गया session कोई checkout_url नहीं लौटाता, इसलिए handler 400 response देता है।अधिक विवरण और supported fields की पूरी सूची के लिए Checkout Sessions Integration Guide देखें।Response Format
Checkout sessions checkout URL के साथ JSON response लौटाते हैं:Customer Portal Route Handler
Customer Portal Route Handlercustomer_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 पर सेट है, तो customer को portal link वाला email भेजता है।Webhook Route Handler
Webhook handler प्रत्येक request की पुष्टि आपके webhook secret से करता है, जिसेwebhookKey के रूप में pass किया जाता है, और फिर आपके event handlers को call करता है। यह raw request body को स्वयं पढ़ता है, इसलिए route को body-parsing middleware की आवश्यकता नहीं होती।
- Method: केवल POST requests supported हैं। अन्य methods 405 लौटाते हैं।
- Signature Verification:
webhook-id,webhook-timestampऔरwebhook-signatureheaders की पुष्टिwebhookKeyके साथ Standard Webhooks specification के अनुसार करता है। 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, फिर event के type के handler को call करता है और उनके समाप्त होने पर 200 लौटाता है। Handler आपके event handlers द्वारा throw की गई errors को catch नहीं करता।