Skip to main content
@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 का उपयोग करते हैं।
अपने .env file या secrets को version control में कभी commit न करें।

Route Handler Examples

सभी examples में माना गया है कि आप Next.js App Router का उपयोग करते हैं।
अपने 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 है।

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 किया जाता है।
Handler अपने config से returnUrl को link में redirect_url के रूप में जोड़ता है।
यदि productId मौजूद नहीं है, तो handler 400 response लौटाता है। Invalid query parameters और मौजूद न रहने वाले product IDs भी 400 लौटाते हैं।

Response Format

Static checkout checkout URL के साथ JSON response लौटाता है। Test mode में URL test.checkout.dodopayments.com का उपयोग करता है।
Dynamic checkout deprecated POST /payments और POST /subscriptions endpoints को proxy करता है। यह existing integrations के लिए काम करता रहेगा, लेकिन नए integrations को checkout sessions का उपयोग करना चाहिए।

Response Format

Dynamic checkout checkout URL के साथ JSON response लौटाता है:
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 करता है।
Handler यह check नहीं करता कि उसे कौन call कर रहा है। Customer ID के साथ request करने वाला कोई भी व्यक्ति उस customer के portal तक पहुंच जाता है। Route को अपनी authentication से protect करें और केवल signed-in user की customer ID pass करें।

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-signature headers के विरुद्ध 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 लौटाता है।
Adaptor आपके handlers में throw की गई errors को catch नहीं करता। वे Next.js तक propagate होती हैं और request विफल हो जाती है।

Supported Webhook Event Handlers

प्रत्येक handler को अपने event type के लिए verified payload मिलता है:
प्रत्येक event का अर्थ जानने के लिए Webhook Event Guide देखें।

Prompt for LLM

इस prompt को अपने AI coding assistant में copy करके उससे अपने project में adaptor जोड़ने को कहें। अपने agent को Dodo Payments docs और skills भी देने के लिए Agent Plugin install करें।
अंतिम संशोधन 26 सितंबर 2026