ebanx 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +8 -0
- data/CONTRIBUTORS +1 -0
- data/README.md +43 -10
- data/Rakefile +9 -1
- data/VERSION +1 -1
- data/ebanx.gemspec +4 -2
- data/lib/ebanx.rb +17 -6
- data/lib/ebanx/command/command.rb +12 -1
- data/lib/ebanx/command/direct.rb +19 -0
- data/lib/ebanx/command/{print_html.rb → print.rb} +2 -2
- data/lib/ebanx/command/token.rb +21 -0
- data/lib/ebanx/command/zipcode.rb +16 -0
- data/lib/ebanx/response.rb +13 -0
- data/lib/ebanx/version.rb +1 -1
- data/test/ebanx/cancel_command_test.rb +7 -0
- data/test/ebanx/direct_command_test.rb +38 -0
- data/test/ebanx/request_command_test.rb +24 -0
- data/test/ebanx/zipcode_command_test.rb +20 -0
- data/test/test_helper.rb +18 -0
- metadata +59 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 457ce2e7ec65501d6a9cc5aa6751220dd02e8525
|
4
|
+
data.tar.gz: a3133d9e22217d01ef0bc35071dbc2cf309b366d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46e1c94cd33109f050d628bca2b9deaba68852016cc2c13b8612022d335d116f853241753eb5817d4c000384b67e85259105300bdc9c90219117394294389548
|
7
|
+
data.tar.gz: d3cc2e19b0427d1291fe327229313b760da40416d62df5365acdff0ee35007862ed42f45aafb408b71175475e81dd8f4aeae2cf33b922664262d0bd49cf990b5
|
data/.travis.yml
ADDED
data/CONTRIBUTORS
CHANGED
data/README.md
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
#
|
1
|
+
# EBANX Ruby gem [](https://travis-ci.org/ebanx-integration/ebanx-ruby) [](https://codeclimate.com/github/ebanx-integration/ebanx-ruby) [](https://codeclimate.com/github/ebanx-integration/ebanx-ruby/coverage)
|
2
|
+
Gem to communicate with EBANX.
|
2
3
|
|
3
|
-
|
4
|
+
Documentation: https://developers.ebanx.com/
|
4
5
|
|
5
6
|
## Installation
|
6
7
|
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
+
Add this line to your application's Gemfile, and bundle it:
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
$ bundle
|
10
|
+
```
|
11
|
+
gem 'ebanx'
|
12
|
+
$ bundle
|
13
|
+
```
|
14
14
|
|
15
15
|
Or install it yourself as:
|
16
16
|
|
@@ -18,7 +18,40 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
#### Create a new Boleto using Direct API
|
22
|
+
```ruby
|
23
|
+
response = ebanx.do_direct {
|
24
|
+
operation: 'request',
|
25
|
+
mode: 'full',
|
26
|
+
payment: {
|
27
|
+
name: 'João da Silva',
|
28
|
+
email: 'joao@mailinator.com',
|
29
|
+
currency_code: 'USD',
|
30
|
+
amount_total: 100.50,
|
31
|
+
merchant_payment_code: Random.rand(10000000000),
|
32
|
+
payment_type_code: 'boleto',
|
33
|
+
person_type: 'personal',
|
34
|
+
document: '13326724691',
|
35
|
+
birth_date: '01/01/1980',
|
36
|
+
zipcode: '70000-000',
|
37
|
+
address: 'Rua Brasil',
|
38
|
+
street_number: '1',
|
39
|
+
city: 'Brasília',
|
40
|
+
state: 'DF',
|
41
|
+
country: 'br',
|
42
|
+
phone_number: '6130001111',
|
43
|
+
due_date: (Time.now + 86400).strftime('%d/%m/%Y')
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
```
|
48
|
+
|
49
|
+
## Automated Tests
|
50
|
+
We use minitest for testing this Gem.
|
51
|
+
|
52
|
+
```
|
53
|
+
rake test
|
54
|
+
```
|
22
55
|
|
23
56
|
## Contributing
|
24
57
|
|
@@ -26,4 +59,4 @@ TODO: Write usage instructions here
|
|
26
59
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
60
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
61
|
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
-
5. Create new Pull Request
|
62
|
+
5. Create new Pull Request
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
1.0.0
|
data/ebanx.gemspec
CHANGED
@@ -20,6 +20,8 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
22
|
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "codeclimate-test-reporter"
|
23
24
|
|
24
|
-
spec.add_dependency
|
25
|
-
|
25
|
+
spec.add_dependency 'rest-client', '~> 1.7.3'
|
26
|
+
spec.add_dependency 'json'
|
27
|
+
end
|
data/lib/ebanx.rb
CHANGED
@@ -2,35 +2,41 @@ require 'rest-client'
|
|
2
2
|
require 'json'
|
3
3
|
|
4
4
|
require_relative 'ebanx/version'
|
5
|
+
require_relative 'ebanx/response'
|
5
6
|
require_relative 'ebanx/command/command'
|
6
7
|
require_relative 'ebanx/command/cancel'
|
7
8
|
require_relative 'ebanx/command/capture'
|
9
|
+
require_relative 'ebanx/command/direct'
|
8
10
|
require_relative 'ebanx/command/exchange'
|
9
|
-
require_relative 'ebanx/command/
|
11
|
+
require_relative 'ebanx/command/print'
|
10
12
|
require_relative 'ebanx/command/query'
|
11
13
|
require_relative 'ebanx/command/refund'
|
12
14
|
require_relative 'ebanx/command/refund_or_cancel'
|
13
15
|
require_relative 'ebanx/command/request'
|
14
|
-
|
16
|
+
require_relative 'ebanx/command/token'
|
17
|
+
require_relative 'ebanx/command/zipcode'
|
15
18
|
|
16
19
|
module Ebanx
|
17
20
|
@test_mode = false
|
18
21
|
|
19
22
|
class << self
|
20
|
-
attr_accessor :integration_key, :test_mode
|
23
|
+
attr_accessor :integration_key, :test_mode, :parse_response
|
21
24
|
end
|
22
25
|
|
23
26
|
def self.base_uri
|
24
27
|
if @test_mode
|
25
|
-
'https://
|
28
|
+
'https://sandbox.ebanx.com/ws/'
|
26
29
|
else
|
27
30
|
'https://www.ebanx.com/pay/ws/'
|
28
31
|
end
|
29
32
|
end
|
30
33
|
|
34
|
+
protected
|
31
35
|
def self.run_command(method, params)
|
32
36
|
klass = get_command_class method
|
33
37
|
|
38
|
+
raise ArgumentError if !params[0] || params[0].length == 0
|
39
|
+
|
34
40
|
params = params[0].merge! integration_key: @integration_key
|
35
41
|
command = klass.new params
|
36
42
|
|
@@ -41,8 +47,13 @@ module Ebanx
|
|
41
47
|
|
42
48
|
def self.request(command)
|
43
49
|
uri = Ebanx::base_uri + command.request_action
|
44
|
-
|
45
|
-
|
50
|
+
|
51
|
+
case command.request_method
|
52
|
+
when :post then response = RestClient.post uri, command.params, content_type: command.response_type
|
53
|
+
when :get then response = RestClient.get uri, params: command.params
|
54
|
+
end
|
55
|
+
|
56
|
+
Ebanx::Response.new response, command.response_type
|
46
57
|
end
|
47
58
|
|
48
59
|
def self.method_missing(method, *args, &block)
|
@@ -1,12 +1,23 @@
|
|
1
1
|
module Ebanx
|
2
2
|
module Command
|
3
3
|
class Command
|
4
|
-
|
4
|
+
@request_body = false
|
5
|
+
|
6
|
+
attr_accessor :params, :request_method, :request_action, :response_type, :request_body
|
5
7
|
|
6
8
|
def valid?
|
7
9
|
validate
|
8
10
|
end
|
9
11
|
|
12
|
+
def params
|
13
|
+
# Wraps parameters into request_body
|
14
|
+
if @request_body
|
15
|
+
{ request_body: @params.to_json }
|
16
|
+
else
|
17
|
+
@params
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
10
21
|
protected
|
11
22
|
def validate
|
12
23
|
raise NotImplementedError
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Ebanx
|
2
|
+
module Command
|
3
|
+
class Direct < Command
|
4
|
+
def initialize(params)
|
5
|
+
@params = params
|
6
|
+
@request_method = :post
|
7
|
+
@request_action = 'direct'
|
8
|
+
@response_type = :json
|
9
|
+
@request_body = true
|
10
|
+
end
|
11
|
+
|
12
|
+
def validate
|
13
|
+
validate_presence :operation
|
14
|
+
validate_presence :mode
|
15
|
+
validate_presence :payment
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module Ebanx
|
2
2
|
module Command
|
3
|
-
class
|
3
|
+
class Print < Command
|
4
4
|
def initialize(params)
|
5
5
|
@params = params
|
6
6
|
@request_method = :get
|
7
|
-
@request_action = '
|
7
|
+
@request_action = 'print'
|
8
8
|
@response_type = 'text/html'
|
9
9
|
end
|
10
10
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Ebanx
|
2
|
+
module Command
|
3
|
+
class Zipcode < Command
|
4
|
+
def initialize(params)
|
5
|
+
@params = params
|
6
|
+
@request_method = :post
|
7
|
+
@request_action = 'token'
|
8
|
+
@response_type = :json
|
9
|
+
end
|
10
|
+
|
11
|
+
def validate
|
12
|
+
validate_presence :currency_code
|
13
|
+
validate_presence :amount
|
14
|
+
validate_presence :merchant_payment_code
|
15
|
+
validate_presence :name
|
16
|
+
validate_presence :email
|
17
|
+
validate_presence :payment_type_code
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Ebanx
|
2
|
+
module Command
|
3
|
+
class Zipcode < Command
|
4
|
+
def initialize(params)
|
5
|
+
@params = params
|
6
|
+
@request_method = :get
|
7
|
+
@request_action = 'zipcode'
|
8
|
+
@response_type = :json
|
9
|
+
end
|
10
|
+
|
11
|
+
def validate
|
12
|
+
validate_presence :zipcode
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Ebanx
|
2
|
+
class Response
|
3
|
+
attr_accessor :http_code, :raw_response, :response
|
4
|
+
|
5
|
+
def initialize(response, response_type)
|
6
|
+
@http_code = response.code
|
7
|
+
@raw_response = response.to_str
|
8
|
+
@response = response.to_str
|
9
|
+
|
10
|
+
@response = JSON.parse @response if response_type == :json
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/ebanx/version.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
describe Ebanx::Command::Direct do
|
4
|
+
before do
|
5
|
+
@params = {
|
6
|
+
operation: 'request',
|
7
|
+
mode: 'full',
|
8
|
+
payment: {
|
9
|
+
name: 'João da Silva',
|
10
|
+
email: 'joao@mailinator.com',
|
11
|
+
currency_code: 'BRL',
|
12
|
+
amount_total: 100.50,
|
13
|
+
merchant_payment_code: Random.rand(10000000000),
|
14
|
+
payment_type_code: 'boleto',
|
15
|
+
document: '13326724691',
|
16
|
+
birth_date: '01/01/1980',
|
17
|
+
zipcode: '70000-000',
|
18
|
+
address: 'Rua Brasil',
|
19
|
+
street_number: '1',
|
20
|
+
city: 'Brasília',
|
21
|
+
state: 'DF',
|
22
|
+
country: 'br',
|
23
|
+
phone_number: '6130001111',
|
24
|
+
due_date: (Time.now + 86400).strftime('%d/%m/%Y')
|
25
|
+
}
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
it "can't run without arguments" do
|
30
|
+
lambda { ebanx.do_direct }.must_raise ArgumentError
|
31
|
+
end
|
32
|
+
|
33
|
+
it "performs a successful request" do
|
34
|
+
response = ebanx.do_direct @params
|
35
|
+
response.http_code.must_equal 200
|
36
|
+
response.response['status'].must_equal 'SUCCESS'
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
describe Ebanx::Command::Request do
|
4
|
+
before do
|
5
|
+
@params = {
|
6
|
+
name: 'João da Silva',
|
7
|
+
email: 'joao@mailinator.com',
|
8
|
+
currency_code: 'BRL',
|
9
|
+
amount: 100.00,
|
10
|
+
merchant_payment_code: Random.rand(10000000000),
|
11
|
+
payment_type_code: 'boleto',
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
it "can't run without arguments" do
|
16
|
+
lambda { ebanx.do_request }.must_raise ArgumentError
|
17
|
+
end
|
18
|
+
|
19
|
+
it "performs a successful request" do
|
20
|
+
response = ebanx.do_request @params
|
21
|
+
response.http_code.must_equal 200
|
22
|
+
response.response['status'].must_equal 'SUCCESS'
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
describe Ebanx::Command::Zipcode do
|
4
|
+
before do
|
5
|
+
@params = {
|
6
|
+
zipcode: '80230010'
|
7
|
+
}
|
8
|
+
end
|
9
|
+
|
10
|
+
it "can't run without arguments" do
|
11
|
+
lambda { ebanx.do_zipcode }.must_raise ArgumentError
|
12
|
+
end
|
13
|
+
|
14
|
+
# Evil integration test
|
15
|
+
it "performs a successful request" do
|
16
|
+
response = ebanx.do_zipcode @params
|
17
|
+
response.http_code.must_equal 200
|
18
|
+
response.response['status'].must_equal 'SUCCESS'
|
19
|
+
end
|
20
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
if ENV['CODECLIMATE_REPO_TOKEN']
|
2
|
+
require 'codeclimate-test-reporter'
|
3
|
+
CodeClimate::TestReporter.start
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'ebanx'
|
7
|
+
require 'minitest/autorun'
|
8
|
+
require 'minitest/spec'
|
9
|
+
require 'minitest/pride'
|
10
|
+
|
11
|
+
class MiniTest::Spec
|
12
|
+
def ebanx
|
13
|
+
Ebanx.tap do |e|
|
14
|
+
e.integration_key = ENV.fetch('INTEGRATION_KEY')
|
15
|
+
e.test_mode = true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,57 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ebanx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gustavo Henrique Mascarenhas Machado
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.3'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: codeclimate-test-reporter
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rest-client
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- - ~>
|
59
|
+
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
61
|
+
version: 1.7.3
|
48
62
|
type: :runtime
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
|
-
- - ~>
|
66
|
+
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
68
|
+
version: 1.7.3
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: json
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
55
83
|
description: EBANX is the market leader in e-commerce payment solutions for International
|
56
84
|
Merchants selling online to Brazil
|
57
85
|
email:
|
@@ -60,7 +88,8 @@ executables: []
|
|
60
88
|
extensions: []
|
61
89
|
extra_rdoc_files: []
|
62
90
|
files:
|
63
|
-
- .gitignore
|
91
|
+
- ".gitignore"
|
92
|
+
- ".travis.yml"
|
64
93
|
- CONTRIBUTORS
|
65
94
|
- Gemfile
|
66
95
|
- LICENSE.txt
|
@@ -72,13 +101,22 @@ files:
|
|
72
101
|
- lib/ebanx/command/cancel.rb
|
73
102
|
- lib/ebanx/command/capture.rb
|
74
103
|
- lib/ebanx/command/command.rb
|
104
|
+
- lib/ebanx/command/direct.rb
|
75
105
|
- lib/ebanx/command/exchange.rb
|
76
|
-
- lib/ebanx/command/
|
106
|
+
- lib/ebanx/command/print.rb
|
77
107
|
- lib/ebanx/command/query.rb
|
78
108
|
- lib/ebanx/command/refund.rb
|
79
109
|
- lib/ebanx/command/refund_or_cancel.rb
|
80
110
|
- lib/ebanx/command/request.rb
|
111
|
+
- lib/ebanx/command/token.rb
|
112
|
+
- lib/ebanx/command/zipcode.rb
|
113
|
+
- lib/ebanx/response.rb
|
81
114
|
- lib/ebanx/version.rb
|
115
|
+
- test/ebanx/cancel_command_test.rb
|
116
|
+
- test/ebanx/direct_command_test.rb
|
117
|
+
- test/ebanx/request_command_test.rb
|
118
|
+
- test/ebanx/zipcode_command_test.rb
|
119
|
+
- test/test_helper.rb
|
82
120
|
homepage: https://www.ebanx.com
|
83
121
|
licenses:
|
84
122
|
- BSD
|
@@ -89,18 +127,23 @@ require_paths:
|
|
89
127
|
- lib
|
90
128
|
required_ruby_version: !ruby/object:Gem::Requirement
|
91
129
|
requirements:
|
92
|
-
- -
|
130
|
+
- - ">="
|
93
131
|
- !ruby/object:Gem::Version
|
94
132
|
version: '0'
|
95
133
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
134
|
requirements:
|
97
|
-
- -
|
135
|
+
- - ">="
|
98
136
|
- !ruby/object:Gem::Version
|
99
137
|
version: '0'
|
100
138
|
requirements: []
|
101
139
|
rubyforge_project:
|
102
|
-
rubygems_version: 2.
|
140
|
+
rubygems_version: 2.4.6
|
103
141
|
signing_key:
|
104
142
|
specification_version: 4
|
105
143
|
summary: Ruby bindings for the EBANX API
|
106
|
-
test_files:
|
144
|
+
test_files:
|
145
|
+
- test/ebanx/cancel_command_test.rb
|
146
|
+
- test/ebanx/direct_command_test.rb
|
147
|
+
- test/ebanx/request_command_test.rb
|
148
|
+
- test/ebanx/zipcode_command_test.rb
|
149
|
+
- test/test_helper.rb
|