DodoPayments, और एक asynchronous client, AsyncDodoPayments है, जो दोनों httpx पर बनाए गए हैं। Nested request parameters typed dictionaries होते हैं और responses Pydantic models होते हैं।
स्थापना
SDK को pip से install करें:aiohttp extra install करें:
client.webhooks.unwrap() से webhook signatures verify करने के लिए, webhooks extra भी install करें: pip install "dodopayments[webhooks]"।
SDK के लिए Python 3.9 या बाद का version आवश्यक है। Security updates पाने के लिए नवीनतम stable Python release का उपयोग करें।
त्वरित शुरुआत
Synchronous Client
एक client बनाएं, फिर checkout session बनाएं:bearer_token को छोड़ देते हैं, तो client DODO_PAYMENTS_API_KEY environment variable को पढ़ता है। यदि आप environment को छोड़ देते हैं, तो client live mode से connect होता है। Test mode API key केवल environment="test_mode" के साथ काम करती है।
Asynchronous Client
AsyncDodoPayments में DodoPayments जैसी ही methods हैं। प्रत्येक call को await करें:
मुख्य सुविधाएं
Pythonic Interface
Parameters के लिए keyword arguments, nested objects के लिए
TypedDict types, और responses के लिए Pydantic models।Async/Await
asyncio के लिए
AsyncDodoPayments, जिसमें aiohttp एक optional HTTP backend है।Type Hints
प्रत्येक method पर type hints, editor autocomplete और mypy के साथ type checking के लिए।
Auto-Pagination
List methods ऐसे iterators लौटाती हैं जो loop करते समय अगला page fetch करते हैं।
Configuration
Environment Variables
अपनी API key को environment variable में रखें:.env
यदि
DODO_PAYMENTS_BASE_URL set है और आप environment भी pass करते हैं, तो constructor “Ambiguous URL” error उत्पन्न करता है। उस स्थिति में environment का उपयोग करने के लिए base_url=None pass करें।
Webhook verify करने के लिए raw request body और headers को client.webhooks.unwrap(payload, headers=headers) में pass करें। यह आपकी webhook key से signature check करता है और parsed event लौटाता है। client.webhooks.unsafe_unwrap(payload) body को verify किए बिना parse करता है, इसलिए इसका उपयोग केवल testing के लिए करें। Webhooks देखें।
Timeouts
Requests default रूप से 1 minute बाद timeout हो जाती हैं और connection timeout 5 seconds होता है। Seconds मेंtimeout pass करें, या अलग-अलग read, write और connect limits के लिए एक httpx.Timeout pass करें:
APITimeoutError उत्पन्न करता है। Timed-out requests को retry किया जाता है, इसलिए fail होने से पहले कोई call timeout से अधिक समय ले सकती है।
Retries
Client परmax_retries set करें, या किसी एक request पर with_options() के साथ set करें:
dodopayments.APIError की subclass उत्पन्न करता है:
Status exceptions
dodopayments.APIStatusError से inherit करती हैं, जिसमें status_code और response attributes होते हैं। APITimeoutError, APIConnectionError की subclass है।
सामान्य Operations
इस section में दिए गए examples Quick Start केclient का उपयोग करते हैं।
Checkout Session बनाएं
एक checkout session बनाएं, फिर customer को लौटाए गएcheckout_url पर redirect करें:
checkout_url केवल एक बार काम करता है और 24 hours बाद expire हो जाता है। प्रत्येक session option के लिए Checkout Sessions देखें।
Customers Manage करें
Email address और name के साथ customer बनाएं, फिर उसे ID से retrieve करें:Subscriptions Handle करें
एक subscription बनाएं, on-demand subscription को charge करें और subscription का usage history पढ़ें।billing के लिए केवल country आवश्यक है, जो दो-अक्षरों वाला ISO country code है। customer किसी existing customer को attach करने के लिए {"customer_id": ...} या नया customer बनाने के लिए {"email": ..., "name": ...} लेता है। charge on-demand subscriptions के लिए है और product_price currency की smallest unit में होता है। retrieve_usage_history paginated list लौटाता है, जिसे आप Pagination में दिखाए अनुसार iterate कर सकते हैं।Usage-Based Billing
Usage Events Ingest करें
किसी customer के लिए usage events भेजें:event_id idempotency key है, इसलिए प्रत्येक event को unique value दें। यदि एक ही request में वही event_id दो बार दिखाई देता है, तो पूरी request reject कर दी जाती है। यदि कोई event_id पहले ही ingest किया जा चुका है, तो नया event ignore कर दिया जाता है। एक request में अधिकतम 1,000 events स्वीकार किए जाते हैं। timestamp default रूप से current time पर set होता है और यदि वह past में 1 hour से अधिक या future में 5 minutes से अधिक हो, तो reject कर दिया जाता है।Events List और Retrieve करें
किसी event को उसकेevent_id से retrieve करें, या customer और event name से filtered events की list बनाएं:
usage_events.list, meter_id, start और end filters भी स्वीकार करता है।
Pagination
Auto-Pagination
List methods ऐसा iterator लौटाती हैं जो loop करते समय अगला page fetch करता है:Async Pagination
Async client के साथasync for का उपयोग करके loop करें:
Manual Pagination
एक समय में एक page के साथ काम करने के लिएitems पढ़ें और has_next_page() तथा get_next_page() call करें। next_page_info() अगली request के parameters लौटाता है:
HTTP Client Configuration
Proxy, custom transport या अन्यhttpx settings जोड़ने के लिए अपना http_client pass करें। DefaultHttpxClient SDK की default connection limits, timeout और redirect settings बनाए रखता है:
client.with_options(http_client=...) call करें।
AIOHTTP के साथ Async
Default रूप से async clienthttpx के साथ requests भेजता है। बेहतर concurrency के लिए aiohttp extra install करें और DefaultAioHttpClient() को http_client के रूप में pass करें:
Logging
SDK standard library केlogging module के साथ logs करता है। Logging चालू करने के लिए DODO_PAYMENTS_LOG को info पर set करें:
debug पर set करें:
Framework Integration
ये examples किसी web endpoint से checkout session बनाते हैं और उसका URL लौटाते हैं।FastAPI
यह endpoint async client का उपयोग करता है:Django
यह view sync client का उपयोग करता है:Resources
GitHub Repository
Source code, releases और methods की पूरी list।
API Reference
प्रत्येक endpoint, parameter और response।
Discord Community
प्रश्न पूछें और अन्य developers से बातचीत करें।
Report Issues
Bugs report करें या features का अनुरोध करें।
Support
Python SDK के लिए सहायता पाने हेतु:- Discord: Real-time सहायता के लिए community server से जुड़ें।
- Email: support@dodopayments.com पर संपर्क करें।
- GitHub: repository पर issue खोलें।