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 키를 안전하게 저장하세요. 절대 버전 관리에 커밋하거나 코드에 노출하지 마세요.
# 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 최소한 ISO 2자리 country 코드가 필요합니다. customer 기존 고객을 연결하기 위한 { customer_id: "..." } 또는 새 고객을 생성하기 위한 { email: "...", name: "..." } 중 하나를 허용합니다. product_price는 가장 낮은 통화 단위에 있습니다.
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
고용량 시나리오를 우아하게 처리할 수 있도록 속도 제한 오류에 대한 지수 백오프를 사용한 재시도 로직을 구현하세요.
# 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)