Skip to main content
@dodopayments/convex component आपके Convex backend में Dodo Payments जोड़ता है। यह एक checkout function प्रदान करता है, जो checkout sessions बनाता है; एक customerPortal function, जो signed-in user के लिए Customer Portal खोलता है; और createDodoWebhookHandler, जो Convex HTTP action में webhooks को verify करता है। इसके लिए Convex 1.26 या उसके बाद का संस्करण आवश्यक है।

Checkout Function

Convex actions से checkout sessions बनाएं।

Customer Portal

ग्राहकों को अपनी subscriptions और details manage करने दें।

Webhooks

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

Installation

1

Install the Package

इस command को अपने project root में चलाएं:
2

Add Component to Convex Config

अपने Convex configuration में Dodo Payments component जोड़ें:
convex.config.ts को edit करने के बाद, types generate करने के लिए npx convex dev को एक बार चलाएं।
3

Set Up Environment Variables

अपने Convex dashboard में Settings → Environment Variables के अंतर्गत environment variables सेट करें। Dashboard खोलने के लिए चलाएं:
इन environment variables को जोड़ें:
  • DODO_PAYMENTS_API_KEY: आपकी Dodo Payments API key, जो Dodo Payments dashboard में Developer → API Keys से प्राप्त होती है।
  • DODO_PAYMENTS_ENVIRONMENT: test_mode या live_mode।
  • DODO_PAYMENTS_WEBHOOK_SECRET: आपका webhook secret, जो Developer → Webhooks से प्राप्त होता है। Webhook handling के लिए आवश्यक। Webhook handler इसी exact variable name को पढ़ता है।
Secrets को Convex environment variables के रूप में store करें। Convex backend functions .env files को नहीं पढ़ते। Secrets को कभी भी version control में commit न करें।

Component Setup Examples

1

Create Internal Query

एक internal query बनाएं, जो auth ID के आधार पर आपके database में customer ढूंढे। अगले step में identify function इसका उपयोग signed-in user का Dodo Payments customer ID प्राप्त करने के लिए करता है, ताकि customer portal खोला जा सके।
यह component schema define नहीं करता। इस query का उपयोग करने से पहले, convex/schema.ts में by_auth_id index वाली customers table define करें, या अपने मौजूदा schema के अनुसार query बदलें।
2

Configure DodoPayments Component

Client बनाएं। identify signed-in Convex user को Dodo Payments customer ID से map करता है। यदि कोई user signed in नहीं है या कोई customer match नहीं करता, तो यह null लौटाता है।
अब आवश्यक functions जोड़ें:
अपने Convex app में Dodo Payments checkout जोड़ने के लिए इस function का उपयोग करें। यह component के checkout payload validator द्वारा स्वीकार किए जाने वाले fields से checkout session बनाता है।

Checkout Function

Convex component checkout sessions बनाता है, जो सभी payments के लिए recommended checkout flow है। एक session में product cart, customer details और checkout options होते हैं।

Usage

Convex action से checkout call करें और checkout session fields को payload में पास करें:
checkout, identify को call नहीं करता। किसी मौजूदा customer को attach करने के लिए payload में customer: { customer_id } पास करें। अधिक details और supported fields की पूरी सूची के लिए Checkout Sessions देखें। payment_method_id के साथ बनाया गया session कोई checkout URL नहीं लौटाता, इसलिए checkout इसके लिए error throw करता है।

Response Format

Checkout function checkout URL वाली object लौटाता है:

Customer Portal Function

Customer portal function signed-in user के लिए Customer Portal URL लौटाता है।

Usage

यह portal_url field वाली object लौटाता है।

Parameters

boolean
डिफ़ॉल्ट:"false"
यदि इसे true पर set किया जाता है, तो Dodo Payments customer को portal link email भी करता है।
customerPortal आपके DodoPayments setup में मौजूद identify function से customer प्राप्त करता है, जिसे customer का dodoCustomerId लौटाना आवश्यक है। यदि identify, null लौटाता है, तो customerPortal एक User is not authenticated. error throw करता है।

Webhook Handler

createDodoWebhookHandler आपका code run करने से पहले प्रत्येक request को verify करता है:
  • Method: Route को method: "POST" के साथ register करें। अन्य methods वाली requests handler तक नहीं पहुंचतीं।
  • Signature Verification: DODO_PAYMENTS_WEBHOOK_SECRET environment variable के साथ Standard Webhooks signature verify करता है। Verification विफल होने पर 400 लौटाता है।
  • Payload Validation: Zod के साथ validated। Invalid payloads के लिए 400 लौटाता है।
  • Error Handling:
    • 400: Invalid signature, invalid payload, या आपके किसी handler द्वारा throw किया गया error
    • 200: सभी handlers समाप्त हो गए
    • यदि DODO_PAYMENTS_WEBHOOK_SECRET set नहीं है, तो handler error throw करता है और request विफल हो जाती है।
  • Event Routing: प्रत्येक event के लिए onPayload call करता है, फिर event के type के लिए handler call करता है।

Supported Webhook Event Handlers

प्रत्येक handler को Convex ActionCtx और उसके event type के लिए verified payload प्राप्त होता है:

Frontend Usage

अपने React components से checkout और portal actions को convex/react के useAction hook के साथ call करें।

Prompt for LLM

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