Skip to main content

Ruby

Learn how to install and configure our Ruby SDK to use Efí's APIs

Attention!

Requests made to Efí's APIs using the Ruby SDK require the certificate generated in your Efí account in the .pem format.

Check here the step-by-step guide to convert your P12 certificate to PEM format.


Installation via RubyGems

Add this line to your application's Gemfile:

gem 'sdk_ruby_apis_efi'

And then run:

$ bundle

Or install it as:

$ gem install sdk_ruby_apis_efi

Installation via Git

Our SDK is also available in our Efí Github repository.

$ git clone https://github.com/efipay/sdk-ruby-apis-efi.git

Tested with

  • Ruby 2.1.0
  • Ruby 2.7.0
  • Ruby 3.0.4

Basic Usage

require 'sdk_ruby_apis_efi'
require_relative "../../credentials"

options = {
client_id: CREDENTIALS::CLIENT_ID,
client_secret: CREDENTIALS::CLIENT_SECRET,
sandbox: CREDENTIALS::SANDBOX
}

body = {
items: [{
name: "Product 1",
value: 1000,
amount: 2
}],
shippings: [{
name: "Default Shipping Cost",
value: 100
}]
}

efipay = SdkRubyApisEfi.new(options)
puts efipay.create_charge(body: body)

Examples

You can run the examples inside the examples directory with:

$ ruby ​​examples/create_charge.rb

Remember to set the correct credentials within examples/credentials.rb before running.


Tests

To run the tests, simply run rspec:

$rspec

Or use guard to monitor files and automatically run rspec:

$ guard -n false -c