Skip to content
espago.com api wrapper
Ruby HTML
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
app
lib
spec
.gitignore
.travis.yml
Gemfile
Gemfile.lock
Guardfile
LICENSE.txt
README.md
Rakefile
espago.gemspec

README.md

Espago gem

Build Status Gem Version Code Climate Test Coverage

Installing Espago gem

gem install espago

or just add it to your Gemfile if you are running a Rails project

Configuration

After registering at http://espago.com configure your app with the security credentials. More information about configuration of merchant account you can find in our documentation https://developers.espago.com/en

The most standard way of configuring Espago is to do it globally on the Espago class.

Espago.app_id = 'your-espago-app-id'
Espago.app_password = 'your-espago-secret'
Espago.public_key = 'your-espago-key'
Espago.production = false #sets Espago enviroment to sandbox
Espago.api_version = 3

Sending request

There are two possible ways of sending requests by using Espago gem. The first possibility is to call everytime send_request() function with proper path, HTTP method and parameters.

Espago.send_request path, request_type, [parameters]

Here it is an example of using this way to create new client (read how to created token_id at https://github.com/espago/espago-1.2.js-demo) :

Espago.send_request :clients, :post, {description: "Jan Kowalski", email: "kowalski@example.com", card: 'token_id'}

The second possible way to sending requests by Espago gem is to call the proper path on Espago object, using specific HTTP method and setting chosen parameteres.

Espago.path request_type, [parameters]

Below, it is an example of using this possibility to create new client:

Espago.clients :post, {description: "Jan Kowalski", email: "kowalski@example.com", card: 'token_id'}

Getting response

Every returned object includes informations about header and body of response.

For example for request:

client = Espago.clients :post, {description: "Jan Kowalski", email: "kowalski@example.com", card: 'token_id'}

Espago returns an special response object:

#<Espago::Response:0x000001038dba40
  @body=
   {"email"=>"kowalski@example.com",
    "id"=>"cli_N2NNf85cFB1xWs",
    "created_at"=>1381834598,
    "description"=>"Jan Kowalski",
    "card"=>
     {"company"=>"VI",
      "last4"=>"4242",
      "year"=>2019,
      "month"=>3,
      "first_name"=>"Jan",
      "last_name"=>"Kowalski",
      "authorized"=>nil,
      "created_at"=>1381834598},
    "deleted"=>false},
  @status=201>

To get response status code you should use "status" method. For example

client.status

returns "201" code.

To get body of response you should use "body" method. For example

client.body

can return hash with client details:

{
  "email"=>"kowalski@example.com",
  "id"=>"cli_N2NNf85cFB1xWs",
  "created_at"=>1381834598,
  "description"=>"Jan Kowalski",
  "card"=>
   {"company"=>"VI",
    "last4"=>"4242",
    "year"=>2019,
    "month"=>3,
    "first_name"=>"Jan",
    "last_name"=>"Kowalski",
    "authorized"=>nil,
    "created_at"=>1381834598},
  "deleted"=>false
}

Now if you want get customer's e-mail(or anoher field in 1st level of response) this short code should execute operation:

client.email
=> "kowalski@example.com"

client.card
=> {"company"=>"VI", "last4"=>"4242", "year"=>2019, "month"=>3, "first_name"=>"Jan", "last_name"=>"Kowalski", "authorized"=>nil, "created_at"=>1381834598}

All possible paths (resources)

ParameterDescriptionDocumentation link
tokensspecial id for credit cardhttps://developers.espago.com/en/v3#244-card-tokens
clientsclients datahttps://developers.espago.com/en/v3#255-customers
chargescredit paymentshttps://developers.espago.com/en/v3#209-card-payments
plansplans for recurring paymentshttps://developers.espago.com/en/v3#222-plans
subscriptionsrecurring payments for client according to the created planhttps://developers.espago.com/en/v3#228-subscriptions
invoicessingle recurring paymenthttps://developers.espago.com/en/v3#234-invoices
line_itemselement of every invoicehttps://developers.espago.com/en/v3#241-getting-informations-about-line-items-of-invoice
You can’t perform that action at this time.