/checkout-sdk-ruby

Checkout.com SDK for Ruby

Primary LanguageRubyMIT LicenseMIT

GitHub license GitHub release

Checkout.com Ruby SDK

🚀 Install

Add this line to your application's Gemfile:

gem 'checkout_sdk'

And then execute:

$ bundle

Or install it yourself as:

$ gem install checkout_sdk

🔧 Configure

API keys must be configured in the gem setup. You can do this anywhere in your application before you make API calls using the gem.

CheckoutSdk.configure do |config|
  config.secret_key = ENV['SECRET_KEY']
  config.public_key = ENV['PUBLIC_KEY']
  config.base_url   = ENV['BASE_URL']
  config.persistent = true|false # default: true
end

📖 Documentation

You can see the SDK documentation here.

💨 Quickstart

Source Type: token

A card token can be obtained using one of Checkout.com's JavaScript frontend solutions such as Frames or any of the mobile SDKs

payment_request_source = CheckoutSdk::PaymentRequestSource.new
payment_request_source.type = "token"
payment_request_source.token = "tok_..."
payment_request_source.amount = 2022
payment_request_source.currency = "GBP"

api_resource = CheckoutSdk::ApiResource.new

# Send API call
response = api_resource.request_payment(payment_request_source)

# response parsing
response.data           # => {...}
response.body           # => "..."
response.headers        # => {...}
response.remote_ip      # => "..."
response.status         # => 200
response.remote_ip      # => "..."
response.local_port     # => 51601
response.local_address  # => "..."

Source Type: id

payment_request_source = CheckoutSdk::PaymentRequestSource.new
payment_request_source.type = "id"
payment_request_source.token = "src_..."
payment_request_source.amount = 2022
payment_request_source.currency = "GBP"

api_resource = CheckoutSdk::ApiResource.new

# Send API call
response = api_resource.request_payment(payment_request_source)

# response parsing
response.data           # => {...}
response.body           # => "..."
response.headers        # => {...}
response.remote_ip      # => "..."
response.status         # => 200
response.remote_ip      # => "..."
response.local_port     # => 51601
response.local_address  # => "..."

Source Type: card

Fully PCI Compliant merchants only

payment_request_source = CheckoutSdk::PaymentRequestSource.new
payment_request_source.type = "card"
payment_request_source.card_number = "4242424242424242"
payment_request_source.card_expiry_month = 6
payment_request_source.card_expiry_year = 2025
payment_request_source.card_name = "Bruce Wayne"
payment_request_source.card_cvv = "100"
payment_request_source.amount = 2022
payment_request_source.currency = "GBP"

api_resource = CheckoutSdk::ApiResource.new

# Send API call
response = api_resource.request_payment(payment_request_source)

# response parsing
response.data           # => {...}
response.body           # => "..."
response.headers        # => {...}
response.remote_ip      # => "..."
response.status         # => 200
response.remote_ip      # => "..."
response.local_port     # => 51601
response.local_address  # => "..."

⚠️ Boolean/falsy values

"nil" or empty strings will be stripped from API calls

# ignored
payment_request_source.capture = nil
payment_request_source.capture = ""

but "false" or 0 are retained and sent in the request

# sent
payment_request_source.capture = false
payment_request_source.capture = 0

See api_resource_spec for details.

🚨 Tests

$ rspec