komoju-sdk
The KOMOJU Ruby SDK is a full-featured gem for the KOMOJU Payments API. It works with any Ruby application or framework, including Rails.
For a full reference of all available endpoints and models, see the KOMOJU API Reference.
Installation
Add to your Gemfile:
gem 'komoju-sdk', '~> 1.0.0'
Then run bundle install.
Quick Start
require 'komoju-sdk'
Komoju.configure do |config|
config.api_key = 'YOUR_SECRET_KEY'
# Use a test key during development
end
Get your API keys from the KOMOJU Merchant Settings.
Example: Hosted Page Payment
The following example walks through a basic hosted page payment flow. For a full guide, see the Hosted Page Integration Guide.
1. Creating a Session
When your customer is ready to pay, create a session and redirect them to the returned session_url.
sessions_api = Komoju::SessionsApi.new
session = sessions_api.create_session(
Komoju::CreateSessionRequestWithPaymentMode.new(
mode: 'payment',
amount: 1000,
currency: 'JPY',
return_url: 'https://your-site.com/orders/return'
)
)
redirect_to session.session_url, allow_other_host: true
2. Handling the Return URL
After the customer pays, KOMOJU redirects them back to your return_url with a session_id query param appended:
https://your-site.com/orders/return?session_id=xxxxx
Fetch the session to check the outcome:
sessions_api = Komoju::SessionsApi.new
komoju_session = sessions_api.show_session(params[:session_id])
if komoju_session.status == Komoju::SessionStatus::COMPLETED
# payment.status will be "captured", "authorized", or "pending"
puts "Payment #{komoju_session.payment.status}"
else
puts "Payment was cancelled or failed"
end
3. Set Up Webhooks (Recommended)
It is possible that the redirect in step 2 fails, possibly due to the user closing their browser, network issues, etc. Or, that the capture will only take place later on, such as with Convenience Store payments. To account for this, we recommend setting up a Webhook to listen for payment events such as payment.captured, payment.authorized, and payment.cancelled. Configure your webhook URL in the KOMOJU Merchant Dashboard.
Verifying Webhook Signatures
To ensure a webhook request genuinely came from KOMOJU, set a secret token when creating or updating the webhook. KOMOJU then signs every delivery with a SHA-256 HMAC of the raw request body in the X-Komoju-Signature header, which you can recompute and verify.
See Webhooks → Secret Token for the full explanation and code examples.
Error Handling
All API errors raise Komoju::ApiError:
begin
payment = payments_api.show_payment('pay_xxx')
rescue Komoju::ApiError => e
puts e.code # HTTP status code (e.g. 404, 422)
puts e. # Human-readable error description
end
Documentation
Full API reference is auto-generated in the docs/ folder of this gem.
All URIs are relative to https://komoju.com/api/v1
| Class | Method | HTTP request | Description |
|---|---|---|---|
| Komoju::BarcodesApi | show_barcode | GET /barcodes/payment_id | Barcode: Show |
| Komoju::ChargebacksApi | accept_chargeback_request | POST /chargeback_requests/id/accept | Chargeback: Accept |
| Komoju::ChargebacksApi | defend_chargeback_request | POST /chargeback_requests/id/defend | Chargeback: Defend |
| Komoju::ChargebacksApi | list_chargeback_requests | GET /chargeback_requests | Chargeback: List |
| Komoju::ChargebacksApi | show_chargeback_request | GET /chargeback_requests/id | Chargeback: Show |
| Komoju::DisbursementsApi | cancel_disbursement | POST /disbursements/id/cancel | Disbursement: Cancel |
| Komoju::DisbursementsApi | create_disbursement | POST /disbursements | Disbursement: Create |
| Komoju::DisbursementsApi | disbursement_report | GET /disbursements/report | Disbursement: Report |
| Komoju::DisbursementsApi | list_disbursements | GET /disbursements | Disbursement: List |
| Komoju::DisbursementsApi | show_disbursement | GET /disbursements/id | Disbursement: Show |
| Komoju::EventsApi | list_events | GET /events | Event: List |
| Komoju::EventsApi | show_event | GET /events/id | Event Show |
| Komoju::OneClickApi | delete_external_customer | DELETE /external_customers/id | External Customer: Destroy |
| Komoju::PaymentsApi | cancel_payment | POST /payments/id/cancel | Payment: Cancel |
| Komoju::PaymentsApi | capture_payment | POST /payments/id/capture | Payment: Capture |
| Komoju::PaymentsApi | create_payment | POST /payments | Payment: Create |
| Komoju::PaymentsApi | create_refund_request | POST /payments/id/refund_request | Payment: Refund Request |
| Komoju::PaymentsApi | finalize_payment | POST /payments/id/finalize | Payment: Finalize |
| Komoju::PaymentsApi | list_payment_methods | GET /payment_methods | Payment Method: List |
| Komoju::PaymentsApi | list_payments | GET /payments | Payment: List |
| Komoju::PaymentsApi | refund_payment | POST /payments/id/refund | Payment: Refund |
| Komoju::PaymentsApi | show_payment | GET /payments/id | Payment: Show |
| Komoju::PaymentsApi | update_payment | PATCH /payments/id | Payment: Update |
| Komoju::PlatformModelApi | balance_transfer | POST /balances/currency/transfer | Balance: Transfer |
| Komoju::PlatformModelApi | create_file | POST /merchants/merchant_id/files | File: Create |
| Komoju::PlatformModelApi | create_merchant | POST /merchants | Merchant: Create |
| Komoju::PlatformModelApi | create_merchant_balance_transfer | POST /merchants/merchant_id/balances/currency/transfer | Balance: Transfer |
| Komoju::PlatformModelApi | edit_merchant_balance_settings | PUT /merchants/merchant_id/balances/currency/settings | Balances: Edit Settings |
| Komoju::PlatformModelApi | list_live_application_payment_methods | GET /live_application/merchant_id/payment_methods | Live Application: Payment Methods |
| Komoju::PlatformModelApi | list_merchants | GET /merchants | Merchant: List |
| Komoju::PlatformModelApi | list_submerchant_payments | GET /merchants/merchant_id/payments | Payment: List for Merchant |
| Komoju::PlatformModelApi | list_submerchant_settlements | GET /merchants/merchant_id/settlements | Settlement: List |
| Komoju::PlatformModelApi | merchant_balance_transactions | GET /merchants/merchant_id/balances/currency/transactions | Balance: Transactions |
| Komoju::PlatformModelApi | show_file | GET /merchants/merchant_id/files/id | File: Show |
| Komoju::PlatformModelApi | show_live_application | GET /live_application/merchant_id | Live Application: Show |
| Komoju::PlatformModelApi | show_live_application_payment_method | GET /live_application/merchant_id/payment_methods/payment_method | Live Application: Show Payment Method |
| Komoju::PlatformModelApi | show_merchant | GET /merchants/id | Merchant: Show |
| Komoju::PlatformModelApi | show_merchant_balance | GET /merchants/merchant_id/balances/currency | Balance: Show |
| Komoju::PlatformModelApi | show_merchant_balance_settings | GET /merchants/merchant_id/balances/currency/settings | Balance: Show Settings |
| Komoju::PlatformModelApi | show_merchant_balance_transaction | GET /merchants/merchant_id/balances/currency/transactions/transaction_uuid | Balance: Transaction |
| Komoju::PlatformModelApi | show_submerchant_settlement | GET /merchants/merchant_id/settlements/id | Settlement: Show |
| Komoju::PlatformModelApi | simulate_live_application_payment_method_status | PATCH /live_application/merchant_id/payment_methods/payment_method/simulate_status | Live Application: Simulate Payment Method Status |
| Komoju::PlatformModelApi | simulate_live_application_status | PATCH /live_application/merchant_id/simulate_status | Live Application: Simulate Status |
| Komoju::PlatformModelApi | submerchant_settlement_csv | GET /merchants/merchant_id/settlements/id/csv | Settlement: CSV |
| Komoju::PlatformModelApi | submerchant_settlement_pdf | GET /merchants/merchant_id/settlements/id/pdf | Settlement: PDF |
| Komoju::PlatformModelApi | submerchant_settlement_xls | GET /merchants/merchant_id/settlements/id/xls | Settlement: XLS |
| Komoju::PlatformModelApi | update_live_application | PATCH /live_application/merchant_id | Live Application: Update |
| Komoju::PlatformModelApi | update_live_application_payment_method | PATCH /live_application/merchant_id/payment_methods/payment_method | Live Application: Update Payment Method |
| Komoju::PlatformModelApi | update_merchant | PATCH /merchants/id | Merchant: Update |
| Komoju::SecureTokensApi | create_secure_token | POST /secure_tokens | SecureToken: Create |
| Komoju::SecureTokensApi | show_secure_token | GET /secure_tokens/id | SecureToken: Show |
| Komoju::SessionsApi | cancel_session | POST /sessions/id/cancel | Session: Cancel |
| Komoju::SessionsApi | create_session | POST /sessions | Session: Create |
| Komoju::SessionsApi | pay_session | POST /sessions/id/pay | Session: Pay |
| Komoju::SessionsApi | show_session | GET /sessions/id | Session: Show |
| Komoju::SettlementsApi | balance_transactions | GET /balances/currency/transactions | Balance: Transactions |
| Komoju::SettlementsApi | list_settlements | GET /settlements | Settlement: Index |
| Komoju::SettlementsApi | show_balance | GET /balances/currency | Balance: Show |
| Komoju::SettlementsApi | show_settlement | GET /settlements/id | Settlement: Show |
| Komoju::SettlementsApi | show_settlement_csv | GET /settlements/id/csv | Settlement: CSV |
| Komoju::SettlementsApi | show_settlement_pdf | GET /settlements/id/pdf | Settlement: PDF |
| Komoju::SettlementsApi | show_settlement_xls | GET /settlements/id/xls | Settlement: XLS |
| Komoju::SettlementsApi | show_transaction | GET /balances/currency/transactions/transaction_uuid | Balance: Transaction |
| Komoju::SubscriptionsApi | create_customer | POST /customers | Customer: Create |
| Komoju::SubscriptionsApi | create_subscription | POST /subscriptions | Subscription: Create |
| Komoju::SubscriptionsApi | delete_customer | DELETE /customers/id | Customer: Destroy |
| Komoju::SubscriptionsApi | delete_subscription | DELETE /subscriptions/id | Subscription: Destroy |
| Komoju::SubscriptionsApi | list_customers | GET /customers | Customer: List |
| Komoju::SubscriptionsApi | list_subscriptions | GET /subscriptions | Subscription: List |
| Komoju::SubscriptionsApi | show_customer | GET /customers/id | Customer: Show |
| Komoju::SubscriptionsApi | show_subscription | GET /subscriptions/id | Subscription: Show |
| Komoju::SubscriptionsApi | update_customer | PATCH /customers/id | Customer: Update |
| Komoju::TokensApi | create_token | POST /tokens | Token: Create |
Models
- Komoju::APIError
- Komoju::APIErrorBody
- Komoju::Address
- Komoju::Auto
- Komoju::AvailablePaymentMethod
- Komoju::Balance
- Komoju::BalanceSettings
- Komoju::BalanceShow
- Komoju::BalanceTransactionList
- Komoju::BalanceTransferRequest
- Komoju::BalanceTransferServiceRecord
- Komoju::BarcodePendingResponse
- Komoju::BarcodeReadyResponse
- Komoju::CancelDisbursementRequest
- Komoju::CapturePaymentRequest
- Komoju::ChargebackCustomer
- Komoju::ChargebackDefense
- Komoju::ChargebackDefenseDocument
- Komoju::ChargebackDefenseRecipientInfo
- Komoju::ChargebackDefenseShippingInfo
- Komoju::ChargebackPayment
- Komoju::ChargebackPaymentMethod
- Komoju::ChargebackRequestDetail
- Komoju::ChargebackRequestList
- Komoju::ChargebackRequestListItem
- Komoju::ChargebackStatus
- Komoju::ChargebackTimelineEntry
- Komoju::CountryCode
- Komoju::CreateCustomerRequest
- Komoju::CreateDisbursementRequest
- Komoju::CreateFileRequest
- Komoju::CreateMerchantBalanceTransferRequest
- Komoju::CreateMerchantRequest
- Komoju::CreatePaymentRequest
- Komoju::CreatePaymentRequestWithCustomer
- Komoju::CreatePaymentRequestWithPaymentDetails
- Komoju::CreatePaymentRequestWithPaymentDetailsTax
- Komoju::CreateRefundRequestRequest
- Komoju::CreateSecureTokenRequest
- Komoju::CreateSecureTokenRequestWithCustomer
- Komoju::CreateSecureTokenRequestWithPaymentDetails
- Komoju::CreateSessionRequest
- Komoju::CreateSessionRequestWithCustomerMode
- Komoju::CreateSessionRequestWithCustomerPaymentMode
- Komoju::CreateSessionRequestWithPaymentMode
- Komoju::CreateSubscriptionRequest
- Komoju::CreateTokenRequest
- Komoju::Currency
- Komoju::Customer
- Komoju::CustomerList
- Komoju::CustomerSource
- Komoju::DefendChargebackDocument
- Komoju::DefendChargebackRecipientInfo
- Komoju::DefendChargebackRequestBody
- Komoju::DefendChargebackShippingInfo
- Komoju::DeleteExternalCustomer200Response
- Komoju::Disbursement
- Komoju::DisbursementList
- Komoju::DisbursementStatus
- Komoju::EditMerchantBalanceSettingsRequest
- Komoju::ErroredField
- Komoju::Event
- Komoju::EventList
- Komoju::Field
- Komoju::FieldFieldProperties
- Komoju::FinalizePaymentRequest
- Komoju::FraudDetails
- Komoju::IndustryType
- Komoju::Installments
- Komoju::Intent
- Komoju::LineItem
- Komoju::LiveApplication
- Komoju::LiveApplicationRequest
- Komoju::LiveApplicationStatus
- Komoju::LiveApplicationWithSubmittedFields
- Komoju::Locale
- Komoju::MerchantBalance
- Komoju::MerchantData
- Komoju::MerchantFile
- Komoju::MerchantRole
- Komoju::MerchantSubmissionStatus
- Komoju::PaySessionRequest
- Komoju::PaySessionResponse
- Komoju::Payment
- Komoju::PaymentData
- Komoju::PaymentDataRequest
- Komoju::PaymentDetailsAU
- Komoju::PaymentDetailsAlipay
- Komoju::PaymentDetailsAlipayHK
- Komoju::PaymentDetailsAll
- Komoju::PaymentDetailsAupay
- Komoju::PaymentDetailsBancontact
- Komoju::PaymentDetailsBankTransfer
- Komoju::PaymentDetailsBitCash
- Komoju::PaymentDetailsBlik
- Komoju::PaymentDetailsCVS
- Komoju::PaymentDetailsCreditCard
- Komoju::PaymentDetailsCreditCardBrazil
- Komoju::PaymentDetailsCreditCardKorea
- Komoju::PaymentDetailsCreditCardKoreaSocialId
- Komoju::PaymentDetailsCreditCardTerminal
- Komoju::PaymentDetailsCultureVoucher
- Komoju::PaymentDetailsDana
- Komoju::PaymentDetailsDocomo
- Komoju::PaymentDetailsDokuWallet
- Komoju::PaymentDetailsDospara
- Komoju::PaymentDetailsDragonpay
- Komoju::PaymentDetailsEnets
- Komoju::PaymentDetailsEpospay
- Komoju::PaymentDetailsEps
- Komoju::PaymentDetailsFpx
- Komoju::PaymentDetailsGCash
- Komoju::PaymentDetailsGiropay
- Komoju::PaymentDetailsHappyMoney
- Komoju::PaymentDetailsIdeal
- Komoju::PaymentDetailsKakaopay
- Komoju::PaymentDetailsKonbini
- Komoju::PaymentDetailsMerpay
- Komoju::PaymentDetailsMobile
- Komoju::PaymentDetailsMobileJapan
- Komoju::PaymentDetailsMultibanco
- Komoju::PaymentDetailsMybank
- Komoju::PaymentDetailsNarvesen
- Komoju::PaymentDetailsNaverpay
- Komoju::PaymentDetailsNetCash
- Komoju::PaymentDetailsOnlyCreditCards
- Komoju::PaymentDetailsOvo
- Komoju::PaymentDetailsPaidy
- Komoju::PaymentDetailsPayEasy
- Komoju::PaymentDetailsPayPay
- Komoju::PaymentDetailsPayco
- Komoju::PaymentDetailsPaypost
- Komoju::PaymentDetailsPaysafeCard
- Komoju::PaymentDetailsPaysafeCash
- Komoju::PaymentDetailsPaysera
- Komoju::PaymentDetailsPayu
- Komoju::PaymentDetailsPerlas
- Komoju::PaymentDetailsPix
- Komoju::PaymentDetailsPoli
- Komoju::PaymentDetailsPrzelewy24
- Komoju::PaymentDetailsRakutenpay
- Komoju::PaymentDetailsSepaTransfer
- Komoju::PaymentDetailsSofortbanking
- Komoju::PaymentDetailsSoftbank
- Komoju::PaymentDetailsTNG
- Komoju::PaymentDetailsToss
- Komoju::PaymentDetailsTruemoney
- Komoju::PaymentDetailsUnionpay
- Komoju::PaymentDetailsWebMoney
- Komoju::PaymentDetailsWechatpay
- Komoju::PaymentList
- Komoju::PaymentMethod
- Komoju::PaymentMethodApplication
- Komoju::PaymentMethodApplicationStatus
- Komoju::PaymentMethodApplicationWithSubmittedFields
- Komoju::PaymentMethodBrands
- Komoju::PaymentMethodInstallmentsInner
- Komoju::PaymentMethodStatus
- Komoju::PaymentMethodsList
- Komoju::PaymentStatus
- Komoju::PaymentType
- Komoju::PlatformDetails
- Komoju::PlatformMerchantPaymentList
- Komoju::PlatformPayment
- Komoju::PrepaidCards
- Komoju::ProcessingMerchant
- Komoju::Refund
- Komoju::RefundPaymentRequest
- Komoju::RefundRequest
- Komoju::RefundRequestStatus
- Komoju::ResponsePaymentDetailsAU
- Komoju::ResponsePaymentDetailsAlipay
- Komoju::ResponsePaymentDetailsAlipayHK
- Komoju::ResponsePaymentDetailsAll
- Komoju::ResponsePaymentDetailsAupay
- Komoju::ResponsePaymentDetailsBancontact
- Komoju::ResponsePaymentDetailsBankTransfer
- Komoju::ResponsePaymentDetailsBitCash
- Komoju::ResponsePaymentDetailsBlik
- Komoju::ResponsePaymentDetailsCVS
- Komoju::ResponsePaymentDetailsCreditCard
- Komoju::ResponsePaymentDetailsCreditCardBrazil
- Komoju::ResponsePaymentDetailsCreditCardKorea
- Komoju::ResponsePaymentDetailsCreditCardTerminal
- Komoju::ResponsePaymentDetailsCultureVoucher
- Komoju::ResponsePaymentDetailsDana
- Komoju::ResponsePaymentDetailsDocomo
- Komoju::ResponsePaymentDetailsDokuWallet
- Komoju::ResponsePaymentDetailsDospara
- Komoju::ResponsePaymentDetailsDragonpay
- Komoju::ResponsePaymentDetailsEnets
- Komoju::ResponsePaymentDetailsEpospay
- Komoju::ResponsePaymentDetailsEps
- Komoju::ResponsePaymentDetailsFpx
- Komoju::ResponsePaymentDetailsGCash
- Komoju::ResponsePaymentDetailsGiropay
- Komoju::ResponsePaymentDetailsHappyMoney
- Komoju::ResponsePaymentDetailsIdeal
- Komoju::ResponsePaymentDetailsKakaopay
- Komoju::ResponsePaymentDetailsKonbini
- Komoju::ResponsePaymentDetailsMerpay
- Komoju::ResponsePaymentDetailsMobile
- Komoju::ResponsePaymentDetailsMobileJapan
- Komoju::ResponsePaymentDetailsMultibanco
- Komoju::ResponsePaymentDetailsMybank
- Komoju::ResponsePaymentDetailsNarvesen
- Komoju::ResponsePaymentDetailsNaverpay
- Komoju::ResponsePaymentDetailsNetCash
- Komoju::ResponsePaymentDetailsOvo
- Komoju::ResponsePaymentDetailsPaidy
- Komoju::ResponsePaymentDetailsPayEasy
- Komoju::ResponsePaymentDetailsPayPay
- Komoju::ResponsePaymentDetailsPayco
- Komoju::ResponsePaymentDetailsPaypost
- Komoju::ResponsePaymentDetailsPaysafeCard
- Komoju::ResponsePaymentDetailsPaysafeCash
- Komoju::ResponsePaymentDetailsPaysera
- Komoju::ResponsePaymentDetailsPayu
- Komoju::ResponsePaymentDetailsPerlas
- Komoju::ResponsePaymentDetailsPix
- Komoju::ResponsePaymentDetailsPoli
- Komoju::ResponsePaymentDetailsPrzelewy24
- Komoju::ResponsePaymentDetailsRakutenpay
- Komoju::ResponsePaymentDetailsSepaTransfer
- Komoju::ResponsePaymentDetailsSofortbanking
- Komoju::ResponsePaymentDetailsSoftbank
- Komoju::ResponsePaymentDetailsTNG
- Komoju::ResponsePaymentDetailsToss
- Komoju::ResponsePaymentDetailsTruemoney
- Komoju::ResponsePaymentDetailsUnionpay
- Komoju::ResponsePaymentDetailsWebMoney
- Komoju::ResponsePaymentDetailsWechatpay
- Komoju::SecureToken
- Komoju::SecureTokenThreeDSecureAccount
- Komoju::SerializedSubmerchant
- Komoju::SerializedSubmerchantActivePaymentMethodsInner
- Komoju::SerializedSubmerchantExpirySettingsInner
- Komoju::Session
- Komoju::SessionMode
- Komoju::SessionStatus
- Komoju::Settlement
- Komoju::SettlementDownload
- Komoju::SettlementFrequency
- Komoju::SettlementList
- Komoju::SettlementShow
- Komoju::SharedDetails
- Komoju::SharedDetailsCorrections
- Komoju::SharedDetailsDisbursements
- Komoju::SharedDetailsMisc
- Komoju::SharedDetailsPayments
- Komoju::SharedDetailsPlatformModel
- Komoju::SharedDetailsRefunds
- Komoju::ShowBalance200Response
- Komoju::ShowBarcodeResponse
- Komoju::SimulateLiveApplicationPaymentMethodStatusRequest
- Komoju::StatementDescriptor
- Komoju::Status
- Komoju::Submerchant
- Komoju::SubmerchantListItem
- Komoju::SubmerchantsList
- Komoju::SubmittedField
- Komoju::SubmittedFieldAllOfValue
- Komoju::Subscription
- Komoju::SubscriptionCustomer
- Komoju::SubscriptionList
- Komoju::SubscriptionPaymentDetails
- Komoju::SubscriptionPeriod
- Komoju::TerminalError
- Komoju::TerminalErrorBody
- Komoju::ThreeDsAuthResult
- Komoju::Token
- Komoju::TokenPaymentDetails
- Komoju::Transaction
- Komoju::Transfer
- Komoju::UpdateCustomerRequest
- Komoju::UpdateMerchantRequest
- Komoju::UpdateMerchantRequestExpirySettingsInner
- Komoju::UpdatePaymentMethodRequest
- Komoju::UpdatePaymentRequest
Authorization
Authentication schemes defined for the API:
api_key
- Type: HTTP basic authentication (API key as username, blank password)
Support
- KOMOJU Developer Documentation
- KOMOJU Merchant Dashboard
- For SDK issues, open an issue on GitHub