Git Product home page Git Product logo

Espago gem

Build Status Gem Version

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: "[email protected]", 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: "[email protected]", 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: "[email protected]", card: 'token_id'}

Espago returns an special response object:

#<Espago::Response:0x000001038dba40
  @body=
   {"email"=>"[email protected]",
    "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"=>"[email protected]",
  "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
=> "[email protected]"

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

Espago's Projects

gus_bir1 icon gus_bir1

Simple, ruby wrapper for Polish GUS REGON database BIR1 (Baza Internetowa Regon 1)

issuer_response_codes icon issuer_response_codes

A simple Ruby gem which provides Issuer Response Code descriptions and suggestions for cardholders and merchants

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.