ateliware / bcash-ruby

Ruby wrapper for the BCash API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

#Bcash Ruby

Gem Version Build Status Code Climate Coverage Status

Ruby wrapper for the Bcash API. This gem provides wrapper for account and transaction methods.

Installation

gem install bcash-ruby

Resources

Configuration

Bcash.configure do |b|
  b.email = Rails.application.secrets.bcash["email"]
  b.token = Rails.application.secrets.bcash["token"]
end

Usage Examples

Search accounts by CPF

  client = Bcash::Client.new
  response = client.search_account_by_cpf('07411111111')
  response.code # 1
  response.cpf # 074111111111
  response.message # Foi encontrado 1 registro para o CPF ou email informado!
  response.accounts.size # 1
  response.accounts.first # { "mail" => 'pessoa@hotmail.com', "token" => 'kx4F3mkZDlGUejQNKWdnP5Ttmk', "idClient" => '205' }

Create account

  data = {
    owner: {
      email: "jose@vendedor.net",
      gender: "M",
      name: "José o Vendedor",
      cpf: "43677708699",
      birth_date: "12/12/1912"
    },
    address: {
      address: "Rua Agostinho",
      zip_code: "81560-040",
      number: "1000",
      neighborhood: "Centro",
      complement: "Casa",
      city: "Curitiba",
      state: "PR"
    },
    contact: {
      phone_number: "41-3333-3333"
    }
  }

  client = Bcash::Client.new
  response = client.create_account(data)
  response.success? # true
  response.message # Conta criada com sucesso

Find Transaction

  client = Bcash::Client.new

  # Find by order id
  response = client.find_by_order_id('1001')
  response.success? # true
  response.transaction
    # { "id_transacao"=>"123456",
    # "data_transacao"=>"07/10/2014",
    # "data_credito"=>"22/10/2014",
    # "valor_original"=>"5.00", ...}

  # Find by transaction_id
  response = client.find_by_transaction_id('2343856')
  response.success? # false
  response.message # Pedido não localizado

Verify Bcash return

  data = {
    transacao: '2833',
    status: 'Transação em Andamento',
    cod_status: '0',
    valor_original: '2145.23',
    valor_loja: '2083.23',
    token:  '1211CF51917E074BC3784592C71FC'
  }

  client = Bcash::Client.new
  response = client.verify_return(data)
  response.verified? #true

Supported Ruby Versions

This library aims to support and is [tested against][travis] the following Ruby implementations:

  • Ruby 1.9.3
  • Ruby 2.0.0
  • Ruby 2.1.0
  • Rubinius

If something doesn't work on one of these interpreters, it's a bug.

This library may inadvertently work (or seem to work) on other Ruby implementations, however support will only be provided for the versions listed above.

If you would like this library to support another Ruby version, you may volunteer to be a maintainer. Being a maintainer entails making sure all tests run and pass on that implementation. When something breaks on your implementation, you will be responsible for providing patches in a timely fashion. If critical issues for a particular implementation exist at the time of a major release, support for that Ruby version may be dropped.

License

Copyright (c) 2014 Raphael Costa and minestore, Inc. See LICENSE for details.

About

Ruby wrapper for the BCash API

License:GNU General Public License v2.0


Languages

Language:Ruby 100.0%