getnet_api 1.0.3 → 1.1.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/.github/workflows/ruby.yml +14 -2
- data/.gitignore +2 -0
- data/Gemfile.lock +8 -8
- data/README.md +27 -6
- data/lib/getnet_api/base.rb +14 -18
- data/lib/getnet_api/boleto.rb +0 -1
- data/lib/getnet_api/customer.rb +5 -5
- data/lib/getnet_api/payment.rb +23 -29
- data/lib/getnet_api/pix.rb +35 -0
- data/lib/getnet_api/version.rb +2 -2
- data/lib/getnet_api.rb +5 -7
- data/spec/lib/getnet_api/address_spec.rb +77 -0
- data/spec/lib/getnet_api/base_spec.rb +6 -8
- data/spec/lib/getnet_api/boleto_spec.rb +49 -0
- data/spec/lib/getnet_api/card_spec.rb +69 -0
- data/spec/lib/getnet_api/card_verification_spec.rb +30 -0
- data/spec/lib/getnet_api/configure_spec.rb +9 -0
- data/spec/lib/getnet_api/credit_spec.rb +68 -0
- data/spec/lib/getnet_api/customer_spec.rb +130 -0
- data/spec/lib/getnet_api/order_spec.rb +30 -0
- data/spec/lib/getnet_api/payment_cancel_spec.rb +121 -0
- data/spec/lib/getnet_api/payment_spec.rb +163 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/vcr_cassettes/{getnet_api/base/build_request.yml → GetnetApi_Base/_build_request/builds_and_executes_request_based_on.yml} +12 -12
- data/spec/vcr_cassettes/GetnetApi_CardVerification/_verify/performs_the_request_and_returns_the_verification_result.yml +110 -0
- data/spec/vcr_cassettes/GetnetApi_Customer/_create/performs_the_request.yml +64 -0
- data/spec/vcr_cassettes/GetnetApi_Customer/_create/performs_the_request_and_returns_the_number_token.yml +112 -0
- data/spec/vcr_cassettes/GetnetApi_Payment/_create/test/correctly_requests_for_cancelling.yml +67 -0
- data/spec/vcr_cassettes/GetnetApi_Payment/_create/when_cancelling_a_payment/correctly_execute_the_request.yml +118 -0
- data/spec/vcr_cassettes/GetnetApi_Payment/_create/when_paying_by_boleto/correctly_requests_for_boleto_payment.yml +60 -0
- data/spec/vcr_cassettes/GetnetApi_Payment/_create/when_paying_by_credit/correctly_requests_for_credit_payment.yml +63 -0
- data/spec/vcr_cassettes/getnet_api/base/valid_bearer.yml +5 -5
- data/spec/vcr_cassettes/getnet_api/cardtoken/get.yml +8 -63
- data/spec/vcr_cassettes/getnet_api/payment_cancel/create.yml +62 -0
- metadata +43 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe142d6c121ad9f8648364f3e45fafd1acd9ebfe369a87bad034db9cf0223a55
|
4
|
+
data.tar.gz: 3ef9013855d1149c71d5c21f542b25e441e2f6f40d61266e32e301633e7ac8af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d80a89c714e683e9437ae27a5839738cca9f54c9e6950a6bb3f096476d0b7ad895bef4c6a910bb4e971a6d322473c1e3f56f2be0edbd11837f863347aa4f1f55
|
7
|
+
data.tar.gz: f898d223eb7ec5629ca087e488ef3b4cede019ba5ca472fcbf0ad9394bada97ce8782ec9201188aebe25f900d8e3cbea469c2066ce4b3adec989b043d92a769b
|
data/.github/workflows/ruby.yml
CHANGED
@@ -18,11 +18,23 @@ jobs:
|
|
18
18
|
runs-on: ubuntu-latest
|
19
19
|
steps:
|
20
20
|
- uses: actions/checkout@v2
|
21
|
+
|
21
22
|
- uses: actions/setup-ruby@v1
|
22
23
|
with:
|
23
24
|
ruby-version: '2.6'
|
25
|
+
|
26
|
+
- uses: actions/cache@v2
|
27
|
+
name: Fetching cache for bundle
|
28
|
+
with:
|
29
|
+
path: vendor/bundle
|
30
|
+
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
|
31
|
+
restore-keys: |
|
32
|
+
${{ runner.os }}-gems-
|
33
|
+
|
24
34
|
- name: Install dependencies
|
25
|
-
run:
|
35
|
+
run: |
|
36
|
+
bundle config path vendor/bundle
|
37
|
+
bundle install --jobs 4 --retry 3
|
38
|
+
|
26
39
|
- name: Run tests
|
27
40
|
run: bundle exec rspec
|
28
|
-
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
getnet_api (1.0
|
4
|
+
getnet_api (1.1.0)
|
5
5
|
rest-client (>= 1.7.3)
|
6
6
|
|
7
7
|
GEM
|
@@ -15,7 +15,7 @@ GEM
|
|
15
15
|
minitest (>= 5.1)
|
16
16
|
tzinfo (~> 2.0)
|
17
17
|
zeitwerk (~> 2.3)
|
18
|
-
addressable (2.
|
18
|
+
addressable (2.8.0)
|
19
19
|
public_suffix (>= 2.0.2, < 5.0)
|
20
20
|
coderay (1.1.3)
|
21
21
|
concurrent-ruby (1.1.8)
|
@@ -26,14 +26,16 @@ GEM
|
|
26
26
|
unf (>= 0.0.5, < 1.0.0)
|
27
27
|
hashdiff (1.0.0)
|
28
28
|
http-accept (1.7.0)
|
29
|
-
http-cookie (1.0.
|
29
|
+
http-cookie (1.0.8)
|
30
30
|
domain_name (~> 0.5)
|
31
31
|
i18n (1.8.10)
|
32
32
|
concurrent-ruby (~> 1.0)
|
33
|
+
logger (1.6.5)
|
33
34
|
method_source (1.0.0)
|
34
|
-
mime-types (3.
|
35
|
+
mime-types (3.6.0)
|
36
|
+
logger
|
35
37
|
mime-types-data (~> 3.2015)
|
36
|
-
mime-types-data (3.
|
38
|
+
mime-types-data (3.2025.0107)
|
37
39
|
minitest (5.14.4)
|
38
40
|
netrc (0.11.0)
|
39
41
|
pry (0.13.1)
|
@@ -61,9 +63,7 @@ GEM
|
|
61
63
|
safe_yaml (1.0.5)
|
62
64
|
tzinfo (2.0.4)
|
63
65
|
concurrent-ruby (~> 1.0)
|
64
|
-
unf (0.
|
65
|
-
unf_ext
|
66
|
-
unf_ext (0.0.7.7)
|
66
|
+
unf (0.2.0)
|
67
67
|
vcr (6.0.0)
|
68
68
|
webmock (3.7.1)
|
69
69
|
addressable (>= 2.3.6)
|
data/README.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
# Gem Getnet API - Meios de Pagamento
|
2
|
+
[](https://github.com/minestore/getnet_api/actions)
|
3
|
+
<a href="https://codeclimate.com/github/minestore/getnet_api/maintainability"><img src="https://api.codeclimate.com/v1/badges/779e36dcfce7e558f24b/maintainability" /></a>
|
2
4
|
|
3
5
|
## Versão Beta
|
4
6
|
|
@@ -39,7 +41,7 @@ GetnetApi.configure do |config|
|
|
39
41
|
#
|
40
42
|
# Código que identifica o seller_id dentro da Getnet
|
41
43
|
# Enviado pela Getnet
|
42
|
-
config.seller_id = '5c89ec4a-db89-45a6-8c96-5b0b72907ef5'
|
44
|
+
config.seller_id = '5c89ec4a-db89-45a6-8c96-5b0b72907ef5'
|
43
45
|
|
44
46
|
#
|
45
47
|
# Código que identifica o client_id dentro da Getnet
|
@@ -109,7 +111,6 @@ obj_pagamento = GetnetApi::Payment.new ({
|
|
109
111
|
amount: 100, # Quantidade em centavos
|
110
112
|
order: obj_pedido, # Objeto da classe GetnetApi::Order
|
111
113
|
customer: obj_cliente, # Objeto da classe GetnetApi::Customer
|
112
|
-
billing_address: obj_endereco, # Objeto da classe GetnetApi::Address
|
113
114
|
})
|
114
115
|
```
|
115
116
|
## Criando um pagamento na GetNet do tipo Credit
|
@@ -157,6 +158,26 @@ obj_boleto = GetnetApi::Boleto.new ({
|
|
157
158
|
novo_pagamento = GetnetApi::Payment.create obj_pagamento, obj_boleto, :boleto
|
158
159
|
```
|
159
160
|
|
161
|
+
---
|
162
|
+
|
163
|
+
## Criando um pagamento na GetNet do tipo Pix
|
164
|
+
|
165
|
+
### Montar [Pix](https://www.rubydoc.info/gems/getnet_api/GetnetApi/Pix)
|
166
|
+
https://developers.getnet.com.br/api#tag/PIX%2Fpaths%2F~1v1~1payments~1qrcode~1pix%2Fpost
|
167
|
+
|
168
|
+
```ruby
|
169
|
+
obj_pix = GetnetApi::Pix.new ({
|
170
|
+
order_id: "6598",
|
171
|
+
customer_id: "1234"
|
172
|
+
})
|
173
|
+
```
|
174
|
+
|
175
|
+
```ruby
|
176
|
+
# No Caso de pagamento de Pix
|
177
|
+
# GetnetApi::Payment.create(GetnetApi::Payment, GetnetApi::Pix, tipo)
|
178
|
+
novo_pagamento = GetnetApi::Payment.create obj_pagamento, obj_pix, :pix
|
179
|
+
```
|
180
|
+
|
160
181
|
## Criando um cancelamento de cartão de crédito
|
161
182
|
|
162
183
|
### Montar [Cancelamento](https://www.rubydoc.info/gems/getnet_api/GetnetApi/PaymentCancel)
|
@@ -186,13 +207,13 @@ cancelamento = GetnetApi::PaymentCancel.create obj_cancelamento
|
|
186
207
|
|
187
208
|
## Copyright
|
188
209
|
|
189
|
-
[
|
210
|
+
[Falcão Tecnologias Digitais](http://qw3.com.br)
|
190
211
|
|
191
|
-

|
192
213
|
|
193
214
|
MIT License
|
194
215
|
|
195
|
-
Copyright (c)
|
216
|
+
Copyright (c) 2025 FalcãoTD - Software, Marketing e Consultoria
|
196
217
|
|
197
218
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
198
219
|
of this software and associated documentation files (the "Software"), to deal
|
@@ -210,4 +231,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
210
231
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
211
232
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
212
233
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
213
|
-
SOFTWARE.
|
234
|
+
SOFTWARE.
|
data/lib/getnet_api/base.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
module GetnetApi
|
2
2
|
class Base
|
3
|
-
require
|
4
|
-
require
|
5
|
-
|
6
|
-
def self.build_request endpoint, metodo, body=nil
|
3
|
+
require "uri"
|
4
|
+
require "net/http"
|
7
5
|
|
6
|
+
def self.build_request endpoint, metodo, body = nil
|
8
7
|
url = URI("#{GetnetApi.base_uri}/#{endpoint}")
|
9
8
|
|
10
9
|
http = Net::HTTP.new(url.host, url.port)
|
@@ -23,14 +22,14 @@ module GetnetApi
|
|
23
22
|
request = GetnetApi::Base.default_headers request
|
24
23
|
|
25
24
|
request.body = body.to_json
|
26
|
-
|
25
|
+
http.request(request)
|
27
26
|
end
|
28
27
|
|
29
28
|
def self.default_headers request
|
30
29
|
request["authorization"] = "Bearer #{GetnetApi::Base.valid_bearer}"
|
31
30
|
request["Content-Type"] = "application/json"
|
32
|
-
request["seller_id"] =
|
33
|
-
|
31
|
+
request["seller_id"] = GetnetApi.seller_id.to_s
|
32
|
+
request
|
34
33
|
end
|
35
34
|
|
36
35
|
def self.get_token_de_bearer
|
@@ -38,27 +37,24 @@ module GetnetApi
|
|
38
37
|
http = Net::HTTP.new(url.host, url.port)
|
39
38
|
http.use_ssl = true
|
40
39
|
request = Net::HTTP::Post.new(url)
|
41
|
-
request.basic_auth
|
40
|
+
request.basic_auth GetnetApi.client_id.to_s, GetnetApi.client_secret.to_s
|
42
41
|
request["Content-Type"] = "application/x-www-form-urlencoded"
|
43
|
-
hash =
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
hash = {
|
43
|
+
"scope" => "oob",
|
44
|
+
"grant_type" => "client_credentials"
|
45
|
+
}
|
47
46
|
request.body = hash.to_query
|
48
|
-
response =
|
47
|
+
response = http.request(request)
|
49
48
|
result = JSON.parse(response.read_body)
|
50
49
|
GetnetApi.access_token = result["access_token"]
|
51
50
|
GetnetApi.expires_in = DateTime.now + result["expires_in"].to_i.seconds - 60.seconds
|
52
51
|
end
|
53
52
|
|
54
53
|
def self.valid_bearer
|
55
|
-
|
56
|
-
return GetnetApi.access_token
|
57
|
-
else
|
54
|
+
unless GetnetApi.expires_in > DateTime.now
|
58
55
|
GetnetApi::Base.get_token_de_bearer
|
59
|
-
return GetnetApi.access_token
|
60
56
|
end
|
57
|
+
GetnetApi.access_token
|
61
58
|
end
|
62
|
-
|
63
59
|
end
|
64
60
|
end
|
data/lib/getnet_api/boleto.rb
CHANGED
@@ -29,7 +29,6 @@ module GetnetApi
|
|
29
29
|
|
30
30
|
# validates :valor_total, length: { maximum: }
|
31
31
|
# validates :expiration_date, length: { maximum: }
|
32
|
-
validates :moeda, length: { maximum: 3 }
|
33
32
|
validates :our_number , length: { maximum: 12 }
|
34
33
|
validates :document_number, length: { maximum: 15 }
|
35
34
|
validates :instructions, length: { maximum: 1000 }
|
data/lib/getnet_api/customer.rb
CHANGED
@@ -9,7 +9,7 @@ module GetnetApi
|
|
9
9
|
}
|
10
10
|
|
11
11
|
# Código que identifica o cliente no estabelecimento.
|
12
|
-
# Alfa Numérico - Até
|
12
|
+
# Alfa Numérico - Até 100 caracteres
|
13
13
|
attr_accessor :customer_id
|
14
14
|
|
15
15
|
# Nome do comprador
|
@@ -106,10 +106,10 @@ module GetnetApi
|
|
106
106
|
}
|
107
107
|
|
108
108
|
if tipo == :customer
|
109
|
-
customer.merge!({
|
109
|
+
customer.merge!({address: address.to_request})
|
110
110
|
elsif tipo == :payment
|
111
|
-
customer.merge!({
|
112
|
-
customer.merge!({
|
111
|
+
customer.merge!({name: self.name.to_s})
|
112
|
+
customer.merge!({billing_address: address.to_request})
|
113
113
|
end
|
114
114
|
|
115
115
|
return customer
|
@@ -128,7 +128,7 @@ module GetnetApi
|
|
128
128
|
private
|
129
129
|
|
130
130
|
def self.endpoint
|
131
|
-
return "
|
131
|
+
return "customers"
|
132
132
|
end
|
133
133
|
|
134
134
|
end
|
data/lib/getnet_api/payment.rb
CHANGED
@@ -23,7 +23,6 @@ module GetnetApi
|
|
23
23
|
# Validações do Rails 3
|
24
24
|
include ActiveModel::Validations
|
25
25
|
|
26
|
-
validates :amount, length: { maximum: 3 }
|
27
26
|
validates :currency, length: { maximum: 3 }
|
28
27
|
|
29
28
|
validates_each [:order] do |record, attr, value|
|
@@ -36,16 +35,6 @@ module GetnetApi
|
|
36
35
|
end
|
37
36
|
end
|
38
37
|
|
39
|
-
validates_each [:boleto] do |record, attr, value|
|
40
|
-
if value.is_a? GetnetApi::Boleto
|
41
|
-
if value.invalid?
|
42
|
-
value.errors.full_messages.each { |msg| record.errors.add(attr, msg) }
|
43
|
-
end
|
44
|
-
else
|
45
|
-
record.errors.add(attr, 'deve ser um objeto GetnetApi::Boleto.')
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
38
|
validates_each [:customer] do |record, attr, value|
|
50
39
|
if value.is_a? GetnetApi::Customer
|
51
40
|
if value.invalid?
|
@@ -74,41 +63,46 @@ module GetnetApi
|
|
74
63
|
# Montar o Hash de dados do usuario no padrão utilizado pela Getnet
|
75
64
|
def to_request obj, type
|
76
65
|
payment = {
|
77
|
-
seller_id:
|
78
|
-
amount:
|
79
|
-
currency:
|
80
|
-
order:
|
81
|
-
customer:
|
66
|
+
seller_id: GetnetApi.seller_id.to_s,
|
67
|
+
amount: amount.to_i,
|
68
|
+
currency: currency.to_s,
|
69
|
+
order: order.to_request,
|
70
|
+
customer: customer.to_request(:payment)
|
82
71
|
}
|
83
72
|
|
73
|
+
if type == :boleto || type == :credit
|
74
|
+
payment[:order] = order.to_request
|
75
|
+
payment[:customer] = customer.to_request(:payment)
|
76
|
+
end
|
77
|
+
|
84
78
|
if type == :boleto
|
85
|
-
|
86
|
-
elsif :credit
|
87
|
-
|
79
|
+
payment[:boleto] = obj.to_request
|
80
|
+
elsif type == :credit
|
81
|
+
payment[:credit] = obj.to_request
|
82
|
+
elsif type == :pix
|
83
|
+
payment.merge!(obj.to_request)
|
88
84
|
end
|
89
85
|
|
90
|
-
|
86
|
+
payment
|
91
87
|
end
|
92
88
|
|
93
89
|
# a = GetnetApi::Payment.create pagamento, boleto, :boleto
|
94
90
|
def self.create(payment, obj, type)
|
95
|
-
|
96
91
|
hash = payment.to_request(obj, type)
|
97
92
|
|
98
|
-
response =
|
93
|
+
response = build_request(endpoint(type), "post", hash)
|
99
94
|
|
100
|
-
|
95
|
+
JSON.parse(response.read_body)
|
101
96
|
end
|
102
97
|
|
103
|
-
private
|
104
|
-
|
105
98
|
def self.endpoint type
|
106
99
|
if type == :boleto
|
107
|
-
|
108
|
-
elsif :credit
|
109
|
-
|
100
|
+
"payments/boleto"
|
101
|
+
elsif type == :credit
|
102
|
+
"payments/credit"
|
103
|
+
elsif type == :pix
|
104
|
+
"payments/qrcode/pix"
|
110
105
|
end
|
111
106
|
end
|
112
|
-
|
113
107
|
end
|
114
108
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module GetnetApi
|
2
|
+
class Pix
|
3
|
+
# string 200 characters
|
4
|
+
# Código de identificação da compra utilizado pelo e-commerce. Caso seja informado ele será repassado na Notificação de Pagamento PIX.
|
5
|
+
attr_accessor :order_id
|
6
|
+
|
7
|
+
# string 36 characters
|
8
|
+
# Identificador do comprador utilizado pelo e-commerce. Caso seja informado ele será repassado na Notificação de Pagamento PIX.
|
9
|
+
attr_accessor :customer_id
|
10
|
+
|
11
|
+
# Validações do Rails 3
|
12
|
+
include ActiveModel::Validations
|
13
|
+
|
14
|
+
validates :order_id, length: {maximum: 200}
|
15
|
+
validates :customer_id, length: {maximum: 36}
|
16
|
+
|
17
|
+
# Nova instancia da classe Pix
|
18
|
+
# @param [Hash] campos
|
19
|
+
def initialize(campos = {})
|
20
|
+
campos.each do |campo, valor|
|
21
|
+
if GetnetApi::Pix.public_instance_methods.include? "#{campo}=".to_sym
|
22
|
+
send "#{campo}=", valor
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Montar o Hash de dados do pagamento no padrão utilizado pela Getnet
|
28
|
+
def to_request
|
29
|
+
{
|
30
|
+
order_id: order_id,
|
31
|
+
customer_id: customer_id
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/getnet_api/version.rb
CHANGED
data/lib/getnet_api.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require 'json'
|
1
|
+
require "rubygems"
|
2
|
+
require "active_model"
|
3
|
+
require "active_support/time"
|
4
|
+
require "json"
|
6
5
|
|
7
6
|
require "getnet_api/version"
|
8
7
|
require "getnet_api/configure"
|
@@ -17,10 +16,9 @@ require "getnet_api/boleto"
|
|
17
16
|
require "getnet_api/credit"
|
18
17
|
require "getnet_api/payment"
|
19
18
|
require "getnet_api/payment_cancel"
|
20
|
-
|
19
|
+
require "getnet_api/pix"
|
21
20
|
|
22
21
|
# -*- encoding : utf-8 -*-
|
23
22
|
module GetnetApi
|
24
23
|
extend GetnetApi::Configure
|
25
|
-
|
26
24
|
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe GetnetApi::Address do
|
4
|
+
let(:address) do
|
5
|
+
GetnetApi::Address.new(
|
6
|
+
street: 'Nome da Rua',
|
7
|
+
number: '123',
|
8
|
+
complement: 'Complemento',
|
9
|
+
district: 'Nome do Bairro',
|
10
|
+
city: 'São Paulo',
|
11
|
+
state: 'SP',
|
12
|
+
country: 'Brasil',
|
13
|
+
postal_code: '01010010'
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'is valid with valid attributes' do
|
18
|
+
expect(address).to be_valid
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'is not valid with street length > 60' do
|
22
|
+
address.street = 'A' * 61
|
23
|
+
expect(address).not_to be_valid
|
24
|
+
expect(address.errors.messages[:street]).to be_present
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'is not valid with number length > 10' do
|
28
|
+
address.number = '1' * 11
|
29
|
+
expect(address).not_to be_valid
|
30
|
+
expect(address.errors.messages[:number]).to be_present
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'is not valid with complement length > 60' do
|
34
|
+
address.complement = 'A' * 61
|
35
|
+
expect(address).not_to be_valid
|
36
|
+
expect(address.errors.messages[:complement]).to be_present
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'is not valid with district length > 40' do
|
40
|
+
address.district = 'A' * 41
|
41
|
+
expect(address).not_to be_valid
|
42
|
+
expect(address.errors.messages[:district]).to be_present
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'is not valid with city length > 40' do
|
46
|
+
address.city = 'A' * 41
|
47
|
+
expect(address).not_to be_valid
|
48
|
+
expect(address.errors.messages[:city]).to be_present
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'is not valid with state length > 20' do
|
52
|
+
address.state = 'A' * 21
|
53
|
+
expect(address).not_to be_valid
|
54
|
+
expect(address.errors.messages[:state]).to be_present
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'is not valid with country length > 20' do
|
58
|
+
address.country = 'A' * 21
|
59
|
+
expect(address).not_to be_valid
|
60
|
+
expect(address.errors.messages[:country]).to be_present
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'is not valid with postal code length > 8' do
|
64
|
+
address.postal_code = '1' * 9
|
65
|
+
expect(address).not_to be_valid
|
66
|
+
expect(address.errors.messages[:postal_code]).to be_present
|
67
|
+
end
|
68
|
+
|
69
|
+
context '#to_request' do
|
70
|
+
it 'returns address object as a hash' do
|
71
|
+
address_hash = address.to_request
|
72
|
+
address_hash.keys.each do |key|
|
73
|
+
expect(address_hash[key]).to eq address.send(key)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -1,15 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
describe GetnetApi::Base do
|
4
|
-
describe '.build_request' do
|
4
|
+
describe '.build_request', :vcr do
|
5
5
|
it 'builds and executes request based on' do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
expect(WebMock).to have_requested(:get, expected_uri)
|
12
|
-
end
|
6
|
+
GetnetApi.ambiente = :sandbox
|
7
|
+
response = GetnetApi::Base.build_request 'some_endpoint', 'get'
|
8
|
+
expect(response).to be_a Net::HTTPNotFound
|
9
|
+
expected_uri = 'https://api-sandbox.getnet.com.br/v1/some_endpoint'
|
10
|
+
expect(WebMock).to have_requested(:get, expected_uri)
|
13
11
|
end
|
14
12
|
end
|
15
13
|
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe GetnetApi::Boleto do
|
4
|
+
let(:boleto) do
|
5
|
+
GetnetApi::Boleto.new(
|
6
|
+
our_number: '123321123',
|
7
|
+
document_number: '12345678',
|
8
|
+
instructions: 'Não receber após o vencimento',
|
9
|
+
provider: 'santander'
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'is valid with valid attributes' do
|
14
|
+
expect(boleto).to be_valid
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'is not valid with our number length > 12' do
|
18
|
+
boleto.our_number = '1' * 13
|
19
|
+
expect(boleto).not_to be_valid
|
20
|
+
expect(boleto.errors.messages[:our_number]).to be_present
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'is not valid with document number length > 15' do
|
24
|
+
boleto.document_number = '1' * 16
|
25
|
+
expect(boleto).not_to be_valid
|
26
|
+
expect(boleto.errors.messages[:document_number]).to be_present
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'is not valid with instructions length > 1000' do
|
30
|
+
boleto.instructions = 'A' * 1001
|
31
|
+
expect(boleto).not_to be_valid
|
32
|
+
expect(boleto.errors.messages[:instructions]).to be_present
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'is not valid with provider length > 40' do
|
36
|
+
boleto.provider = 'A' * 41
|
37
|
+
expect(boleto).not_to be_valid
|
38
|
+
expect(boleto.errors.messages[:provider]).to be_present
|
39
|
+
end
|
40
|
+
|
41
|
+
context '#to_request' do
|
42
|
+
it 'returns boleto object as a hash' do
|
43
|
+
boleto_hash = boleto.to_request
|
44
|
+
boleto_hash.keys.each do |key|
|
45
|
+
expect(boleto_hash[key]).to eq boleto.send(key)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe GetnetApi::Card do
|
4
|
+
let(:card) do
|
5
|
+
GetnetApi::Card.new(
|
6
|
+
number_token: 'dfe05208b105578c070f806c80abd3af09e246827d29b866cf4ce16c205849977c9496cbf0d0234f42339937f327747075f68763537b90b31389e01231d4d13c',
|
7
|
+
cardholder_name: 'JOAO DA SILVA',
|
8
|
+
security_code: '123',
|
9
|
+
brand: 'Mastercard',
|
10
|
+
expiration_month: '12',
|
11
|
+
expiration_year: '20'
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'is valid with valid attributes' do
|
16
|
+
expect(card).to be_valid
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'is not valid with number token length > 128' do
|
20
|
+
card.number_token = '1' * 129
|
21
|
+
expect(card).not_to be_valid
|
22
|
+
expect(card.errors.messages[:number_token]).to be_present
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'is not valid with cardholder name length > 26' do
|
26
|
+
card.cardholder_name = '1' * 27
|
27
|
+
expect(card).not_to be_valid
|
28
|
+
expect(card.errors.messages[:cardholder_name]).to be_present
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'is not valid with security_code length > 4' do
|
32
|
+
card.security_code = 'A' * 5
|
33
|
+
expect(card).not_to be_valid
|
34
|
+
expect(card.errors.messages[:security_code]).to be_present
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'is not valid with security_code length < 3' do
|
38
|
+
card.security_code = 'AA'
|
39
|
+
expect(card).not_to be_valid
|
40
|
+
expect(card.errors.messages[:security_code]).to be_present
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'is not valid with brand length > 50' do
|
44
|
+
card.brand = 'A' * 51
|
45
|
+
expect(card).not_to be_valid
|
46
|
+
expect(card.errors.messages[:brand]).to be_present
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'is not valid with expiration month length > 2' do
|
50
|
+
card.expiration_month = '123'
|
51
|
+
expect(card).not_to be_valid
|
52
|
+
expect(card.errors.messages[:expiration_month]).to be_present
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'is not valid with expiration year length > 2' do
|
56
|
+
card.expiration_year = '123'
|
57
|
+
expect(card).not_to be_valid
|
58
|
+
expect(card.errors.messages[:expiration_year]).to be_present
|
59
|
+
end
|
60
|
+
|
61
|
+
context '#to_request' do
|
62
|
+
it 'returns card object as a hash' do
|
63
|
+
card_hash = card.to_request
|
64
|
+
card_hash.keys.each do |key|
|
65
|
+
expect(card_hash[key]).to eq card.send(key)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|