@dodopayments/nuxt मॉड्यूल आपके Nuxt ऐप को तीन server route handlers देता है। checkoutHandler checkout URLs लौटाता है, customerPortalHandler ग्राहक को Customer Portal पर भेजता है, और Webhooks webhook events की पुष्टि करके उन्हें आपके code तक पहुँचाता है।
Checkout API Route
Nuxt server route से checkout URLs बनाएँ।
Customer Portal API Route
ग्राहकों को Nuxt server route से अपनी subscriptions और विवरण प्रबंधित करने दें।
Webhooks API Route
Nuxt में Dodo Payments webhook events प्राप्त करें और verify करें।
अवलोकन
मॉड्यूल अपने handlers को Nuxt server auto-imports के रूप में register करता है, इसलिए आपके server routes बिना import statements के
checkoutHandler, customerPortalHandler और Webhooks को call कर सकते हैं। प्रत्येक route अपने credentials runtimeConfig से पढ़ता है। Nuxt browser के लिए केवल runtimeConfig.public expose करता है, इसलिए API key और webhook secret server पर ही रहते हैं।Installation
1
Install the Nuxt Module
यह command अपने project root में चलाएँ:मॉड्यूल peer dependencies के रूप में Nuxt 3 (3.13.1 या बाद का) और
zod 3.25 या बाद के version को सूचीबद्ध करता है।2
Register the Module in nuxt.config.ts
अपने इन environment variables को set करें, उदाहरण के लिए project root की
modules array में @dodopayments/nuxt जोड़ें और अपने credentials को runtimeConfig में map करें:nuxt.config.ts
.env file में:Built Nuxt server आपकी
.env file को नहीं पढ़ता। Runtime में Nuxt, runtimeConfig value को केवल उस variable से override करता है जो उसके path से match करता है, जैसे private.returnUrl के लिए NUXT_PRIVATE_RETURN_URL। इसलिए इन variables को अपने hosting environment में भी set करें।API Route Handler के उदाहरण
उदाहरण
server/routes/api/ directory में server routes बनाते हैं। Nuxt प्रत्येक file को उसके name और method suffix के आधार पर route करता है, इसलिए checkout.get.ts, GET /api/checkout को handle करता है।- Checkout API Route
- Customer Portal API Route
- Webhook API Route
अपने Nuxt ऐप में Dodo Payments checkout जोड़ने के लिए इस handler का उपयोग करें। GET route static checkout serve करता है। POST route checkout sessions serve करता है, या जब आप
type: "dynamic" set करते हैं, तो dynamic checkout serve करता है।checkout.post.ts एक POST flow serve करता है। Dynamic checkout उदाहरण या checkout session उदाहरण में से किसी एक का उपयोग करें:Checkout Route Handler
Checkout handler Dodo Payments से payments लेने के तीनों तरीकों को support करता है:- Static Payment Links: Share किए जा सकने वाले 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 है।
checkoutHandler ये options लेता है:
Static Checkout (GET)
Static Checkout (GET)
Supported Query Parameters
string
आवश्यक
Product identifier, उदाहरण के लिए
?productId=pdt_nZuwz45WAs64n3l07zpQR।integer
डिफ़ॉल्ट:"1"
Product की quantity।
string
Customer का पूरा नाम। यदि
firstName या lastName दिया गया है, तो इसे ignore किया जाता है।string
Customer का पहला नाम।
string
Customer का last name।
string
Customer का email address।
string
Customer का country, ISO 3166-1 alpha-2 code के रूप में।
string
Customer का address line।
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 की जाने वाली amount को fix करता है, उदाहरण के लिए $12.50 के लिए
12.5। केवल Pay What You Want products के साथ काम करता है और product की minimum price से कम होने पर ignore किया जाता है।boolean
डिफ़ॉल्ट:"true"
Discounts section दिखाएँ या छिपाएँ।
string
metadata_ से शुरू होने वाला कोई भी query parameter metadata के रूप में pass किया जाता है।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 को support करता है।
billingऔरcustomerrequired हैं।- प्रत्येक supported body field के लिए देखें:
Response Format
Dynamic checkout checkout URL के साथ JSON response लौटाता है:Checkout Sessions (POST)
Checkout Sessions (POST)
Checkout sessions one-time purchases और subscriptions के लिए hosted checkout बनाते हैं, जिसमें customization पर पूरा control होता है।
product_cart एकमात्र required field है। यदि body में return_url नहीं है, तो handler अपने config से returnUrl का उपयोग करता है।अधिक details और सभी supported fields के लिए Checkout Sessions Integration Guide देखें।payment_method_id के साथ बनाया गया session कोई checkout URL नहीं लौटाता, इसलिए handler 400 response देता है। Saved payment method को charge करने के लिए SDK से session बनाएँ।Response Format
Checkout sessions checkout URL के साथ JSON response लौटाते हैं:Customer Portal Route Handler
Customer Portal route handler आपके द्वारा दिए गए customer के लिए Customer Portal session बनाता है और browser को उस पर redirect करता है।Query Parameters
string
आवश्यक
Portal session के लिए customer ID, उदाहरण के लिए
?customer_id=cus_123।boolean
यदि इसे
true पर set किया जाता है, तो Dodo Payments customer को portal link email भी करता है।Webhook Route Handler
Webhook route handler आपके code को चलाने से पहले प्रत्येक request की पुष्टि करता है:- Method: केवल POST requests supported हैं। अन्य methods 405 लौटाते हैं।
- Signature Verification: Raw request body और
webhook-id,webhook-timestampतथाwebhook-signatureheaders कीwebhookKeyके साथ, Standard Webhooks specification का पालन करते हुए पुष्टि करता है। 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 लौटाता है।