@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 में एक Developer → API Keys के अंतर्गत API key बनाएं। अपना webhook endpoint Developer → Webhooks के अंतर्गत जोड़ें और उसका signing secret
.env file बनाएं:DODO_PAYMENTS_WEBHOOK_KEY में copy करें। DODO_PAYMENTS_RETURN_URL वह स्थान है जहां checkout के बाद customers पहुंचते हैं। यदि आप environment पास नहीं करते हैं, तो handlers live_mode का उपयोग करते हैं।Route Handler Examples
Examples
+server.ts के अंतर्गत SvelteKit src/routes/api/ endpoints हैं। वे आपकी credentials $env/static/private से import करते हैं, जिसे SvelteKit client-side code से बाहर रखता है।- Checkout Handler
- Customer Portal Handler
- Webhook Handler
अपने 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 लौटाता है।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 लेता है:
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 का पहला नाम।
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 के रूप में पास किया जाता है।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 दोनों का समर्थन करता है।
billingऔरcustomerआवश्यक हैं।- प्रत्येक 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 बनाता है और 302 response के साथ browser को उस पर redirect करता है।Query Parameters
string
आवश्यक
Portal session के लिए customer ID, उदाहरण के लिए
?customer_id=cus_123।boolean
यदि
true पर सेट है, तो Dodo Payments customer को portal link email भी करता है।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के साथ 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 लौटाता है।