@dodopayments/nextjs पैकेज आपके Next.js App Router प्रोजेक्ट को तीन route handlers देता है। Checkout checkout URLs लौटाता है, CustomerPortal ग्राहक को Customer Portal पर भेजता है, और Webhooks webhook events को सत्यापित करके आपके code तक पहुंचाता है। यह पैकेज Next.js 14, 15 और 16 को support करता है।
Checkout Handler
static, dynamic और checkout session flows के साथ checkout URLs बनाएं।
Customer Portal
ग्राहकों को अपनी subscriptions और details प्रबंधित करने दें।
Webhooks
Dodo Payments webhook events प्राप्त और process करें।
Installation
1
Install the Package
यह command अपने project root में चलाएं:इस पैकेज को peer dependency के रूप में Zod 3.25 या Zod 4 की भी आवश्यकता होती है।
2
Set Up Environment Variables
अपने project root में एक
.env file बनाएं। Dashboard में Developer → API Keys के अंतर्गत API key और Developer → Webhooks के अंतर्गत webhook secret बनाएं:DODO_PAYMENTS_RETURN_URL वह स्थान है जहां checkout के बाद ग्राहक पहुंचते हैं। यदि आप environment pass नहीं करते हैं, तो handlers live_mode का उपयोग करते हैं।Route Handler Examples
सभी examples में माना गया है कि आप Next.js App Router का उपयोग करते हैं।
- Checkout Handler
- Customer Portal Handler
- Webhook Handler
अपने app में Dodo Payments checkout जोड़ने के लिए इस handler का उपयोग करें। एक
GET handler static checkout serve करता है। एक POST handler checkout sessions serve करता है, या जब आप type: "dynamic" सेट करते हैं तो dynamic checkout serve करता है।Checkout Route Handler
Dodo Payments के साथ payments लेने के तीनों तरीकों को checkout handler support करता है:- Static Payment Links: ऐसे shareable URLs जो बिना code के payments collect करते हैं।
- Dynamic Payment Links: custom details के साथ आपके द्वारा generate किए गए payment links। ये deprecated endpoints का उपयोग करते हैं।
- Checkout Sessions: product cart, customer details और customization options के साथ hosted checkout। यह recommended flow है।
Static Checkout (GET)
Static Checkout (GET)
Supported Query Parameters
string
आवश्यक
Product identifier, उदाहरण के लिए
?productId=pdt_123।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 की 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 में charged amount तय करता है, उदाहरण के लिए $12.50 के लिए
12.5। केवल Pay What You Want products के साथ काम करता है और यदि यह product की minimum price से कम है तो इसे अनदेखा किया जाता है।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 भी करता है।customer_id मौजूद नहीं है, तो handler 400 लौटाता है, और यदि portal session नहीं बनाई जा सकती, तो 500 लौटाता है।
Webhook Route Handler
Webhook route handler आपके code को चलाने से पहले प्रत्येक request को verify करता है:- Method: केवल POST requests supported हैं। अन्य methods 405 लौटाते हैं।
- Signature Verification: Raw request body को
webhook-id,webhook-timestampऔरwebhook-signatureheaders के विरुद्धwebhookKeyसे verify करता है। Verification विफल होने पर 401 लौटाता है। - Payload Validation: Verified body को JSON के रूप में parse करता है और Zod से validate करता है। Parsed payload webhook schema से match न होने पर 400 लौटाता है।
- Error Handling:
- 401: Invalid signature
- 400: Invalid payload
- 500: Unexpected verification errors, malformed JSON या आपके callbacks द्वारा throw की गई errors
- Event Routing: प्रत्येक event के लिए
onPayloadको call करता है, फिर event के type के handler को call करता है और 200 लौटाता है।