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)
API 키를 환경 변수를 사용하여 안전하게 저장하세요. 버전 관리에 커밋하거나 코드에 노출하지 마세요.
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: 0}] )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
비율 제한 오류에 대해 지수 백오프를 사용하여 재시도 로직을 구현하여 애플리케이션이 고부하 시나리오를 원활하게 처리하도록 하세요.
# Type-safe using Sorbet RBI definitionsdodo_payments.checkout_sessions.create( product_cart: [ Dodopayments::CheckoutSessionRequest::ProductCart.new( product_id: "product_id", quantity: 0 ) ])# Hashes work, but are not typesafedodo_payments.checkout_sessions.create( product_cart: [{product_id: "product_id", quantity: 0}])# You can also splat a full Params classparams = Dodopayments::CheckoutSessionCreateParams.new( product_cart: [ Dodopayments::CheckoutSessionRequest::ProductCart.new( product_id: "product_id", quantity: 0 ) ])dodo_payments.checkout_sessions.create(**params)