@dodopayments/astro पैकेज आपके Astro प्रोजेक्ट को तीन endpoint handlers देता है। Checkout checkout URLs लौटाता है, CustomerPortal किसी customer को Customer Portal पर भेजता है, और Webhooks webhook events को verify करके आपके code तक पहुंचाता है।
Checkout Handler
static, dynamic और checkout session flows के साथ checkout URLs बनाएं।
Customer Portal
ग्राहकों को अपनी subscriptions और विवरण प्रबंधित करने दें।
Webhooks
Dodo Payments webhook events प्राप्त और process करें।
Installation
1
Install the Package
यह command अपने project root में चलाएं:यह पैकेज Astro 4 या 5 और
zod 3.25 या उसके बाद के versions को peer dependencies के रूप में सूचीबद्ध करता है।2
Set Up Environment Variables
अपने project root में एक checkout के बाद ग्राहक जिस स्थान पर पहुंचते हैं, वह
.env file बनाएं। API key Developer → API Keys के अंतर्गत बनाएं। अपना webhook endpoint Developer → Webhooks के अंतर्गत जोड़ें और उसका Signing secret DODO_PAYMENTS_WEBHOOK_KEY में copy करें:DODO_PAYMENTS_RETURN_URL है। यदि आप environment pass नहीं करते हैं, तो handlers live_mode का उपयोग करते हैं। Test mode API key केवल test_mode के साथ काम करती है।Route Handler Examples
उदाहरण
src/pages/api/ में Astro server endpoints हैं। Dodo Payments को call करने वाले endpoints को on demand render करना आवश्यक है, इसलिए अपने Astro प्रोजेक्ट में server adapter जोड़ें। Astro के default static output mode में endpoints build time पर render होते हैं, इसलिए प्रत्येक उदाहरण endpoint को हर request पर render करने के लिए इसके बजाय prerender = false export करता है।- Checkout Handler
- Customer Portal Handler
- Webhook Handler
अपने app में Dodo Payments checkout जोड़ने के लिए इस handler का उपयोग करें।
GET handler static checkout serve करता है। POST handler checkout sessions serve करता है, या जब आप type: "dynamic" set करते हैं, तब dynamic checkout serve करता है। एक endpoint file केवल एक POST handler export कर सकती है, इसलिए dynamic checkout उदाहरण मानता है कि आपने type: "dynamic" set किया है।Checkout Route Handler
checkout handler Dodo Payments के साथ payments लेने के तीनों तरीकों का समर्थन करता है:- Static Payment Links: साझा किए जा सकने वाले URLs, जो code के बिना payments collect करते हैं।
- Dynamic Payment Links: custom details के साथ बनाए गए payment links। ये deprecated endpoints का उपयोग करते हैं।
- Checkout Sessions: product cart, customer details और customization options के साथ hosted checkout। यह recommended flow है।
Checkout ये options लेता है:
handler
GET requests के लिए static checkout serve करता है। POST requests के लिए, जब type, dynamic हो, तब यह dynamic payment link बनाता है और अन्यथा checkout session बनाता है।
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 का 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 का ZIP या postal code।
boolean
Full name field को disable करने के लिए
true पर set करें।boolean
First name field को disable करने के लिए
true पर set करें।boolean
Last name field को disable करने के लिए
true पर set करें।boolean
Email field को disable करने के लिए
true पर set करें।boolean
Country field को disable करने के लिए
true पर set करें।boolean
Address line field को disable करने के लिए
true पर set करें।boolean
City field को disable करने के लिए
true पर set करें।boolean
State field को disable करने के लिए
true पर set करें।boolean
ZIP code field को disable करने के लिए
true पर set करें।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 के रूप में pass किया जाता है, उदाहरण के लिए metadata_orderId=123।disableEmail=true के साथ email। Handler अपने config से returnUrl को link में redirect_url के रूप में जोड़ता है।Response Format
Static checkout checkout URL के साथ JSON response लौटाता है। Test mode में URLtest.checkout.dodopayments.com का उपयोग करता है:Dynamic Checkout (POST)
Dynamic Checkout (POST)
- Parameters को POST request में JSON body के रूप में भेजें।
- One-time और recurring payments दोनों का समर्थन करता है। Handler product retrieve करता है, फिर product recurring होने पर subscription और अन्यथा one-time payment बनाता है।
- Body में
billing(साथ मेंstreet,city,state,countryऔरzipcode) तथाcustomer, और साथ मेंproduct_idयाproduct_cartआवश्यक हैं। Subscriptions के लिएproduct_idआवश्यक है। - प्रत्येक supported body field के लिए देखें:
Response Format
Dynamic checkout payment link को checkout URL के रूप में JSON response में लौटाता है:Checkout Sessions (POST)
Checkout Sessions (POST)
Checkout sessions one-time purchases और subscriptions के लिए hosted checkout बनाते हैं, जिसमें customization पर पूरा control होता है।
product_cart एकमात्र required field है और इसमें कम से कम एक product होना चाहिए। यदि body में return_url नहीं है, तो handler अपने config से returnUrl का उपयोग करता है।प्रत्येक checkout_url एक बार काम करता है और 24 घंटे बाद expire हो जाता है, या जब आप confirm: true pass करते हैं, तब 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 handler आपके द्वारा pass किए गए customer के लिए Customer Portal session बनाता है और browser को उस पर redirect करता है।CustomerPortal, Checkout के समान bearerToken और environment options लेता है।
Query Parameters
string
आवश्यक
Portal session के लिए customer ID, उदाहरण के लिए
?customer_id=cus_123।boolean
यदि इसे
true पर set किया जाता है, तो Dodo Payments customer को portal link email भी करता है।customer_id missing है, तो handler 400 लौटाता है, और यदि portal session create नहीं की जा सकती, तो 500 लौटाता है।
Webhook Route Handler
Webhook route handler आपका code चलाने से पहले,webhookKey के रूप में pass किए गए webhook secret से प्रत्येक request verify करता है:
- Method: केवल POST requests supported हैं। अन्य methods 405 लौटाते हैं।
- Signature Verification:
webhookKeyके साथwebhook-id,webhook-timestampऔरwebhook-signatureheaders को Standard Webhooks specification का पालन करते हुए verify करता है। Verification विफल होने पर 401 लौटाता है। - Payload Validation: Payload को Zod से validate करता है। Invalid payload के लिए 400 लौटाता है।
- Error Handling:
- 401: Invalid signature
- 400: Invalid payload
- 500: Verification के दौरान internal error
- Event Routing: प्रत्येक event के लिए
onPayloadको call करता है, फिर event के type के handler को call करके 200 लौटाता है।