@dodopayments/remix package आपके Remix app को तीन request handlers देता है। Checkout checkout URLs लौटाता है, CustomerPortal ग्राहक को Customer Portal पर भेजता है, और Webhooks webhook events को verify करके आपके code तक पहुंचाता है। प्रत्येक handler एक Request लेता है और एक Response लौटाता है, इसलिए आप इसे किसी route के loader या action से call करते हैं।
Checkout Handler
अपने Remix app से checkout URLs बनाएं।
Customer Portal
ग्राहकों को अपनी subscriptions और details manage करने दें।
Webhooks
Dodo Payments webhook events प्राप्त और verify करें।
Installation
1
Install the Package
यह command अपने project root में चलाएं:यह package Remix 2 (
remix 2.16.8 या बाद का) और zod 3.25 या बाद के versions को peer dependencies के रूप में सूचीबद्ध करता है।2
Set Up Environment Variables
अपने project root में एक Developer → API Keys के अंतर्गत API key बनाएं। Developer → Webhooks के अंतर्गत अपना webhook endpoint जोड़ें और उसका signing secret
.env file बनाएं:DODO_PAYMENTS_WEBHOOK_KEY में copy करें। DODO_PAYMENTS_RETURN_URL वह स्थान है जहां ग्राहक checkout के बाद पहुंचते हैं। यदि आप environment pass नहीं करते हैं, तो handlers live_mode का उपयोग करते हैं।Route Handler Examples
ये examples Remix resource routes हैं, जो GET requests के लिए एक
loader या POST requests के लिए एक action export करते हैं और इनमें कोई component नहीं होता। Flat file routes के साथ, app/routes/api.checkout.tsx, /api/checkout को serve करता है।- Checkout Handler
- Customer Portal Handler
- Webhook Handler
अपने Remix app में Dodo Payments checkout जोड़ने के लिए इस handler का उपयोग करें।
loader static checkout serve करता है। action यहां dynamic checkout serve करता है। Checkout sessions serve करने के लिए, जो recommended flow है, इसके बजाय action से checkoutSessionHandler(request) return करें।action, checkoutSessionHandler(request) return करता है।Checkout Route Handler
Checkout handler, Dodo Payments के साथ payments लेने के तीनों तरीकों का समर्थन करता है:- Static Payment Links: Share करने योग्य 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 है।
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 का 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 को fix करता है, उदाहरण के लिए $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 का समर्थन करता है।
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 बनाता है और 307 response के साथ 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 को run करने से पहले प्रत्येक 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 लौटाता है।