Skip to main content
@dodopayments/sveltekit package आपके SvelteKit app को तीन route handlers देता है। Checkout checkout URLs लौटाता है, CustomerPortal किसी customer को Customer Portal पर भेजता है, और Webhooks webhook events को verify करके आपके code तक पहुंचाता है।

Checkout Handler

अपने SvelteKit app से checkout URLs बनाएं।

Customer Portal

Customers को अपनी subscriptions और details manage करने दें।

Webhooks

Dodo Payments webhook events प्राप्त और verify करें।

Installation

1

Install the Package

यह command अपने project root में चलाएं:
Package peer dependencies के रूप में SvelteKit 2 (@sveltejs/kit 2.20.3 या बाद का) और zod 3.25 या बाद का सूचीबद्ध करता है।
2

Set Up Environment Variables

अपने project root में एक .env file बनाएं:
Developer → API Keys के अंतर्गत API key बनाएं। अपना webhook endpoint Developer → Webhooks के अंतर्गत जोड़ें और उसका signing secret DODO_PAYMENTS_WEBHOOK_KEY में copy करें। DODO_PAYMENTS_RETURN_URL वह स्थान है जहां checkout के बाद customers पहुंचते हैं। यदि आप environment पास नहीं करते हैं, तो handlers live_mode का उपयोग करते हैं।
अपने .env file या secrets को version control में कभी commit न करें।

Route Handler Examples

Examples +server.ts के अंतर्गत SvelteKit src/routes/api/ endpoints हैं। वे आपकी credentials $env/static/private से import करते हैं, जिसे SvelteKit client-side code से बाहर रखता है।
अपने SvelteKit app में Dodo Payments checkout जोड़ने के लिए इस handler का उपयोग करें। Checkout static checkout के लिए एक GET handler और checkout sessions के लिए, या type: "dynamic" सेट करने पर dynamic checkout के लिए, एक POST handler लौटाता है। GET को type: "static" से बनाए गए handler से export करें या type न दें, क्योंकि session या dynamic handler का GET handler 400 लौटाता है।
Dynamic checkout request तब काम करता है जब POST, type: "dynamic" से बनाए गए handler से आता है। type: "session" के साथ, जैसा कि example route में है, checkout session request भेजें।

Checkout Route Handler

Checkout handler Dodo Payments के साथ payments लेने के तीनों तरीकों का समर्थन करता है:
  • Static Payment Links: ऐसे shareable 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 लेता है:

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 का address line।
string
Customer का city।
string
Customer का state या province।
string
Customer का ZIP या postal 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 metadata के रूप में पास किया जाता है।
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 बनाता है और 302 response के साथ browser को उस पर redirect करता है।
Handler यह check नहीं करता कि इसे कौन call कर रहा है। Customer ID के साथ request करने वाला कोई भी व्यक्ति उस customer का portal प्राप्त कर सकता है। Route को अपनी authentication से protect करें और केवल signed-in user की customer ID पास करें।

Query Parameters

string
आवश्यक
Portal session के लिए customer ID, उदाहरण के लिए ?customer_id=cus_123।
boolean
यदि true पर सेट है, तो Dodo Payments customer को portal link email भी करता है।
यदि customer_id मौजूद नहीं है, तो 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 के साथ 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 लौटाता है।
Adaptor आपके handlers में thrown errors को catch नहीं करता। वे SvelteKit तक propagate होते हैं और request विफल हो जाती है।

Supported Webhook Event Handlers

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

Prompt for LLM

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