net/http और connection pool के साथ requests भेजता है, विफल requests को retry करता है, आपके लिए paginated lists पर iterate करता है और RBI तथा RBS type definitions प्रदान करता है।
स्थापना
अपने Gemfile में जेम जोड़ें:Gemfile
SDK के लिए Ruby 3.2.0 या बाद का version आवश्यक है।
त्वरित प्रारंभ
एक client बनाएं, फिर checkout session बनाएं:bearer_token छोड़ देते हैं, तो client DODO_PAYMENTS_API_KEY environment variable को पढ़ता है। यदि आप environment छोड़ देते हैं, तो client live mode से connect करता है। Test mode API key केवल environment: "test_mode" के साथ काम करती है।
मुख्य सुविधाएं
Ruby Conventions
Snake_case methods और keyword arguments, nested parameters के लिए plain hashes स्वीकार किए जाते हैं।
Elegant Syntax
Responses attribute readers वाले objects होते हैं और
obj[:prop] उन fields को भी पढ़ता है जिन्हें SDK define नहीं करता।Auto-Pagination
auto_paging_each हर item पर iterate करता है और आवश्यकता होने पर अगला page fetch करता है।Type Safety
Sorbet के लिए RBI definitions,
sorbet-runtime पर निर्भरता के बिना।Configuration
Dodopayments::Client.new, bearer_token, webhook_key, environment, base_url, max_retries, timeout, initial_retry_delay और max_retry_delay स्वीकार करता है। इन्हें छोड़ने पर यह environment से DODO_PAYMENTS_API_KEY, DODO_PAYMENTS_WEBHOOK_KEY (आपका webhook signing secret) और DODO_PAYMENTS_BASE_URL पढ़ता है। Client thread-safe है और अपना connection pool बनाए रखता है, इसलिए अपने application के लिए एक client बनाएं और उसका पुनः उपयोग करें।
Webhook verify करने के लिए raw request body और headers को dodo_payments.webhooks.unwrap(payload, headers: headers) में pass करें। यह आपकी webhook key से signature check करता है और parsed event लौटाता है। dodo_payments.webhooks.unsafe_unwrap(payload) body को verify किए बिना parse करता है, इसलिए इसका उपयोग केवल testing के लिए करें। Webhooks देखें।
Timeout Configuration
By default, requests 60 seconds के बाद timeout हो जाती हैं। Client या किसी single request पर, seconds में,timeout सेट करें:
Dodopayments::Errors::APITimeoutError raise करता है। Timed-out requests को default रूप से retry किया जाता है।
Retry Configuration
SDK connection errors, timeouts और 408, 409, 429 या 500 और उससे अधिक status वाली responses को retry करता है। यह default रूप से short exponential backoff के साथ दो बार retry करता है। Client या किसी single request परmax_retries सेट करें:
सामान्य Operations
इस section में दिए गए examples Quick Start सेdodo_payments client का उपयोग करते हैं।
Checkout Session बनाना
Checkout session बनाएं, फिर customer को लौटाए गएcheckout_url पर redirect करें:
Customers को Manage करना
Email address और name के साथ customer बनाएं, फिर उसे ID से retrieve करें:Subscriptions को Handle करना
Subscription बनाएं, on-demand subscription charge करें और subscription का metadata update करें।billing के लिए केवल country, यानी two-letter ISO country code, आवश्यक है। customer मौजूदा customer जोड़ने के लिए { customer_id: "..." } या नया customer बनाने के लिए { email: "...", name: "..." } स्वीकार करता है। charge on-demand subscriptions के लिए है और product_price currency की smallest unit में है।Pagination
Auto-Pagination
List methods एक page लौटाते हैं। मौजूदा page के लिएitems पढ़ें या हर item पर iterate करने के लिए auto_paging_each call करें। आवश्यकता होने पर यह अगला page fetch करता है:
Manual Pagination
एक बार में एक page आगे बढ़ने के लिएnext_page? और next_page call करें:
Error Handling
जब SDK API से connect नहीं कर पाता या API 4xx या 5xx status लौटाती है, तो SDKDodopayments::Errors::APIError की subclass raise करता है:
status, headers और body attributes होते हैं:
Sorbet के साथ Type Safety
SDK RBI definitions के साथ आता है औरsorbet-runtime पर निर्भर नहीं करता। Type-checked request parameters पाने के लिए hashes के बजाय model classes pass करें:
Advanced Usage
Undocumented Endpoints
ऐसे endpoint को call करने के लिए जिसका कोई SDK method नहीं है,request का उपयोग करें। यह SDK methods जैसी ही authentication और retries लागू करता है:
Undocumented Parameters
ऐसे parameters भेजने के लिए जिन्हें SDK define नहीं करता, उन्हेंrequest_options में pass करें। Documented parameter के समान name वाला extra_* parameter उसे override करता है:
Rails Integration
Initializer बनाना
Rails शुरू होने परconfig/initializers/dodo_payments.rb में एक client बनाएं:
Service Object Pattern
Client को service object में wrap करें:Controller Integration
Controller से service call करें और checkout page पर redirect करें:Sinatra Integration
एकconfigure block में client को एक बार बनाएं और अपनी routes में उसका उपयोग करें:
Resources
GitHub Repository
Source code, releases और पूरी method list।
API Reference
हर endpoint, parameter और response।
Discord Community
प्रश्न पूछें और अन्य developers से बातचीत करें।
Report Issues
Bugs report करें या features का अनुरोध करें।
Support
Ruby SDK के लिए सहायता पाने हेतु:- Discord: Real-time सहायता के लिए community server से जुड़ें।
- Email: support@dodopayments.com पर संपर्क करें।
- GitHub: repository पर issue खोलें।