Please do NOT use Omise Ruby library versions less than 0.8.0, as they are outdated and have security vulnerabilities.
Add the following to your Gemfile
and run bundle install
to install via RubyGems:
gem 'omise'
Or use the cutting-edge version by installing via GitHub:
gem 'omise', github: 'omise/omise-ruby'
Tested on Ruby 2.5 and above
First configure your secret key:
require "omise"
Omise.api_key = "skey_test_xxxxxxxxxxxxxxxxxxx"
After you have implemented Omise.js on your frontend, you can charge the card by passing the token generated by Omise.js 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.
To enforce the API version that the application must use, specify it
by setting 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).
Omise.api_version = "2019-05-29"
It is highly recommended to set this version to the current version that you are using.
To enable logging, you can set Omise.logger
with a Ruby logger. All HTTP requests and responses will be logged.
To disable logging, configure Omise.logger
to nil
. Default is disabled.
An example configuring Rails logger:
Omise.logger = Rails.logger
The test suite can be run with bundle exec rake test
.