getnet_api 1.0.2 → 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 +5 -5
- data/.github/workflows/ruby.yml +40 -0
- data/.gitignore +2 -0
- data/.rspec +1 -0
- data/Gemfile +11 -1
- data/Gemfile.lock +63 -10
- data/README.md +31 -6
- data/lib/getnet_api/base.rb +14 -18
- data/lib/getnet_api/boleto.rb +0 -1
- data/lib/getnet_api/configure.rb +1 -1
- data/lib/getnet_api/customer.rb +5 -5
- data/lib/getnet_api/payment.rb +23 -29
- data/lib/getnet_api/payment_cancel.rb +1 -1
- data/lib/getnet_api/pix.rb +35 -0
- data/lib/getnet_api/version.rb +2 -2
- data/lib/getnet_api.rb +5 -5
- data/spec/lib/getnet_api/address_spec.rb +77 -0
- data/spec/lib/getnet_api/base_spec.rb +63 -0
- 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_token_spec.rb +15 -0
- data/spec/lib/getnet_api/card_verification_spec.rb +30 -0
- data/spec/lib/getnet_api/configure_spec.rb +70 -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 +121 -0
- data/spec/vcr_cassettes/GetnetApi_Base/_build_request/builds_and_executes_request_based_on.yml +113 -0
- 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 +58 -0
- data/spec/vcr_cassettes/getnet_api/cardtoken/get.yml +55 -0
- data/spec/vcr_cassettes/getnet_api/payment_cancel/create.yml +62 -0
- metadata +58 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
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
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ master ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ master ]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
runs-on: ubuntu-latest
|
19
|
+
steps:
|
20
|
+
- uses: actions/checkout@v2
|
21
|
+
|
22
|
+
- uses: actions/setup-ruby@v1
|
23
|
+
with:
|
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
|
+
|
34
|
+
- name: Install dependencies
|
35
|
+
run: |
|
36
|
+
bundle config path vendor/bundle
|
37
|
+
bundle install --jobs 4 --retry 3
|
38
|
+
|
39
|
+
- name: Run tests
|
40
|
+
run: bundle exec rspec
|
data/.gitignore
CHANGED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,33 +1,86 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
getnet_api (
|
4
|
+
getnet_api (1.1.0)
|
5
5
|
rest-client (>= 1.7.3)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
|
10
|
+
activemodel (6.1.3.1)
|
11
|
+
activesupport (= 6.1.3.1)
|
12
|
+
activesupport (6.1.3.1)
|
13
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
+
i18n (>= 1.6, < 2)
|
15
|
+
minitest (>= 5.1)
|
16
|
+
tzinfo (~> 2.0)
|
17
|
+
zeitwerk (~> 2.3)
|
18
|
+
addressable (2.8.0)
|
19
|
+
public_suffix (>= 2.0.2, < 5.0)
|
20
|
+
coderay (1.1.3)
|
21
|
+
concurrent-ruby (1.1.8)
|
22
|
+
crack (0.4.3)
|
23
|
+
safe_yaml (~> 1.0.0)
|
24
|
+
diff-lcs (1.4.4)
|
25
|
+
domain_name (0.5.20190701)
|
11
26
|
unf (>= 0.0.5, < 1.0.0)
|
12
|
-
|
27
|
+
hashdiff (1.0.0)
|
28
|
+
http-accept (1.7.0)
|
29
|
+
http-cookie (1.0.8)
|
13
30
|
domain_name (~> 0.5)
|
14
|
-
|
31
|
+
i18n (1.8.10)
|
32
|
+
concurrent-ruby (~> 1.0)
|
33
|
+
logger (1.6.5)
|
34
|
+
method_source (1.0.0)
|
35
|
+
mime-types (3.6.0)
|
36
|
+
logger
|
15
37
|
mime-types-data (~> 3.2015)
|
16
|
-
mime-types-data (3.
|
38
|
+
mime-types-data (3.2025.0107)
|
39
|
+
minitest (5.14.4)
|
17
40
|
netrc (0.11.0)
|
18
|
-
|
41
|
+
pry (0.13.1)
|
42
|
+
coderay (~> 1.1)
|
43
|
+
method_source (~> 1.0)
|
44
|
+
public_suffix (4.0.6)
|
45
|
+
rest-client (2.1.0)
|
46
|
+
http-accept (>= 1.7.0, < 2.0)
|
19
47
|
http-cookie (>= 1.0.2, < 2.0)
|
20
48
|
mime-types (>= 1.16, < 4.0)
|
21
49
|
netrc (~> 0.8)
|
22
|
-
|
23
|
-
|
24
|
-
|
50
|
+
rspec (3.10.0)
|
51
|
+
rspec-core (~> 3.10.0)
|
52
|
+
rspec-expectations (~> 3.10.0)
|
53
|
+
rspec-mocks (~> 3.10.0)
|
54
|
+
rspec-core (3.10.1)
|
55
|
+
rspec-support (~> 3.10.0)
|
56
|
+
rspec-expectations (3.10.1)
|
57
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
58
|
+
rspec-support (~> 3.10.0)
|
59
|
+
rspec-mocks (3.10.2)
|
60
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
61
|
+
rspec-support (~> 3.10.0)
|
62
|
+
rspec-support (3.10.2)
|
63
|
+
safe_yaml (1.0.5)
|
64
|
+
tzinfo (2.0.4)
|
65
|
+
concurrent-ruby (~> 1.0)
|
66
|
+
unf (0.2.0)
|
67
|
+
vcr (6.0.0)
|
68
|
+
webmock (3.7.1)
|
69
|
+
addressable (>= 2.3.6)
|
70
|
+
crack (>= 0.3.2)
|
71
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
72
|
+
zeitwerk (2.4.2)
|
25
73
|
|
26
74
|
PLATFORMS
|
27
75
|
ruby
|
28
76
|
|
29
77
|
DEPENDENCIES
|
78
|
+
activemodel
|
30
79
|
getnet_api!
|
80
|
+
pry (~> 0.13.1)
|
81
|
+
rspec
|
82
|
+
vcr
|
83
|
+
webmock
|
31
84
|
|
32
85
|
BUNDLED WITH
|
33
|
-
1.
|
86
|
+
1.17.3
|
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)
|
@@ -177,18 +198,22 @@ cancelamento = GetnetApi::PaymentCancel.create obj_cancelamento
|
|
177
198
|
|
178
199
|
- [QW3 Software & Marketing](http://qw3.com.br)
|
179
200
|
- [Leandro dos Santos Falcão](https://www.linkedin.com/in/lsfalcao)
|
201
|
+
|
202
|
+
## Contributors
|
203
|
+
|
180
204
|
- [Victor Barreiros](www.linkedin.com/in/victor-barreiros)
|
181
205
|
- [Daniel B. Brumazzi](https://www.linkedin.com/in/daniel-brumazzi-2153707b/)
|
206
|
+
- [eduardosleite](https://github.com/eduardosleite)
|
182
207
|
|
183
208
|
## Copyright
|
184
209
|
|
185
|
-
[
|
210
|
+
[Falcão Tecnologias Digitais](http://qw3.com.br)
|
186
211
|
|
187
|
-

|
188
213
|
|
189
214
|
MIT License
|
190
215
|
|
191
|
-
Copyright (c)
|
216
|
+
Copyright (c) 2025 FalcãoTD - Software, Marketing e Consultoria
|
192
217
|
|
193
218
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
194
219
|
of this software and associated documentation files (the "Software"), to deal
|
@@ -206,4 +231,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
206
231
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
207
232
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
208
233
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
209
|
-
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/configure.rb
CHANGED
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,6 +1,7 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "rubygems"
|
2
|
+
require "active_model"
|
3
|
+
require "active_support/time"
|
4
|
+
require "json"
|
4
5
|
|
5
6
|
require "getnet_api/version"
|
6
7
|
require "getnet_api/configure"
|
@@ -15,10 +16,9 @@ require "getnet_api/boleto"
|
|
15
16
|
require "getnet_api/credit"
|
16
17
|
require "getnet_api/payment"
|
17
18
|
require "getnet_api/payment_cancel"
|
18
|
-
|
19
|
+
require "getnet_api/pix"
|
19
20
|
|
20
21
|
# -*- encoding : utf-8 -*-
|
21
22
|
module GetnetApi
|
22
23
|
extend GetnetApi::Configure
|
23
|
-
|
24
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
|