Use this file to discover all available pages before exploring further.
Das Ruby SDK bietet eine einfache und intuitive Möglichkeit, Dodo Payments in Ihre Ruby-Anwendungen zu integrieren. Es folgt den Ruby-Konventionen und Best Practices und bietet umfassende Fehlerbehandlung, Paginierung und Middleware-Unterstützung.
Verwenden Sie immer die neueste SDK-Version, um auf die neuesten Dodo Payments-Funktionen zuzugreifen. Führen Sie bundle update dodopayments regelmäßig aus, um auf dem neuesten Stand zu bleiben.
Führen Sie dann aus:
bundle install
Das SDK unterstützt Ruby 3.2.0 und spätere Versionen mit umfassenden Typen, Fehlerbehandlung und Retry-Mechanismen.
Initialisieren Sie den Client und erstellen Sie eine Checkout-Sitzung:
require "bundler/setup"require "dodopayments"dodo_payments = Dodopayments::Client.new( bearer_token: ENV["DODO_PAYMENTS_API_KEY"], # This is the default and can be omitted environment: "test_mode" # defaults to "live_mode")checkout_session_response = dodo_payments.checkout_sessions.create( product_cart: [{product_id: "product_id", quantity: 1}])puts(checkout_session_response.session_id)
Speichern Sie Ihre API-Schlüssel sicher mithilfe von Umgebungsvariablen. Committen Sie sie niemals in die Versionskontrolle oder legen Sie sie offen in Ihrem Code ab.
Erstellen und verwalten Sie wiederkehrende Abonnements:
# Create a subscriptionsubscription = dodo_payments.subscriptions.create( billing: { country: "US", city: "San Francisco", state: "CA", street: "1 Market St", zipcode: "94105" }, customer: { customer_id: "cus_123" }, # or { email: "...", name: "..." } for a new customer product_id: "pdt_456", quantity: 1)# Charge an on-demand subscription# product_price is in the lowest currency denomination (e.g., 2500 = $25.00 USD)charge = dodo_payments.subscriptions.charge( subscription.subscription_id, product_price: 2500)# Update subscription metadataupdated = dodo_payments.subscriptions.update( subscription.subscription_id, metadata: { plan_type: "premium" })
billing erfordert mindestens den zweibuchstabigen ISO country Code. customer akzeptiert entweder { customer_id: "..." }, um einen bestehenden Kunden anzuhängen, oder { email: "...", name: "..." }, um einen neuen zu erstellen. product_price ist in der kleinsten Währungsdenomination.
page = dodo_payments.payments.list# Fetch single item from pagepayment = page.items[0]puts(payment.brand_id)# Automatically fetches more pages as neededpage.auto_paging_each do |payment| puts(payment.brand_id)end
begin checkout_session = dodo_payments.checkout_sessions.create(product_cart: [{product_id: "product_id", quantity: 1}] )rescue Dodopayments::Errors::APIConnectionError => e puts("The server could not be reached") puts(e.cause) # an underlying Exception, likely raised within `net/http`rescue Dodopayments::Errors::RateLimitError => e puts("A 429 status code was received; we should back off a bit.")rescue Dodopayments::Errors::APIStatusError => e puts("Another non-200-range status code was received") puts(e.status)end
Retry-Logik mit exponentiellen Backoff für Rate-Limit-Fehler implementieren, um sicherzustellen, dass Ihre Anwendung Hochvolumen-Szenarien elegant verarbeitet.
# Type-safe using Sorbet RBI definitionsdodo_payments.checkout_sessions.create( product_cart: [ Dodopayments::ProductItemReq.new( product_id: "product_id", quantity: 1 ) ])# Hashes work, but are not typesafedodo_payments.checkout_sessions.create( product_cart: [{product_id: "product_id", quantity: 1}])# You can also splat a full Params classparams = Dodopayments::CheckoutSessionCreateParams.new( product_cart: [ Dodopayments::ProductItemReq.new( product_id: "product_id", quantity: 1 ) ])dodo_payments.checkout_sessions.create(**params)