Omise Ruby Library
Clone or download

README.md

Omise Ruby Client

CodeClimate CircleCI Gem Join the chat at https://gitter.im/omise/omise-ruby

Installation

Installing via rubygems:

gem 'omise'

Or use the cutting-edge version by installing via github:

gem 'omise', github: 'omise/omise-ruby'

Requirements

Requires ruby 1.9.2 or above, the rest-client and json gems.

Configuration

First configure your secret key:

Omise.api_key = "skey_test_xxxxxxxxxxxxxxxxxxx"

If you need to use the Token API you also need to set your public key:

Omise.public_api_key = "pkey_test_xxxxxxxxxxxxxxxxxxx"

With this set you'll be able to retrieve tokens or create new ones.

However we recommend using Omise.js to collect cards. When creating a token server side you'll need card data transiting to and from your server and this requires that your organization be PCI compliant.

API version

In case you want to enforce API version the application use, you can specify it by setting the api_version. The version specified by this settings will override the version setting in your account. This is useful if you have multiple environments with different API versions (e.g. development on the latest but production on the older version).

require "omise"
Omise.api_version = "2014-07-27"

It is highly recommended to set this version to the current version you're using.

Logging

To enable log you can set Omise.logger with a Ruby logger. All HTTP requests and responses will be logged.

To disable log, just configure Omise.logger to nil. Default is disabled.

An example configuring Rails logger:

Omise.logger = Rails.logger

Quick Start

After you have implemented Omise.js on your frontend you can charge the card by passing the token into the card attribute.

# Charge 1000.00 THB
charge = Omise::Charge.create({
  amount: 1_000_00,
  currency: "thb",
  card: params[:omise_token]
})

if charge.paid
  # handle success
  puts "thanks"
else
  # handle failure
  raise charge.failure_code
end

You can check the complete documentation at omise.co/docs.

Development

The test suite can be run with bundle exec rake test.