Installing via rubgems:
gem 'omise'
Or use the cutting-edge version by installing via github:
gem 'omise', github: 'omise/omise-ruby'
Requires ruby 1.9.2 or above, the rest-client and json gem.
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.vault_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 create tokens. 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.
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.
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 docs.omise.co.
The test suite can be run with bundle exec rake test
.