bs2_api 1.0.0 → 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/CHANGELOG.md +9 -0
- data/Gemfile.lock +4 -4
- data/README.md +23 -3
- data/lib/bs2_api/entities/bank.rb +1 -0
- data/lib/bs2_api/entities/customer.rb +14 -0
- data/lib/bs2_api/entities/payment.rb +9 -9
- data/lib/bs2_api/payment/base.rb +4 -4
- data/lib/bs2_api/payment/detail.rb +27 -0
- data/lib/bs2_api/util/bank_service.rb +4 -5
- data/lib/bs2_api/version.rb +1 -1
- data/lib/bs2_api.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68ed1e77534b0eaefc776507d8251749815a45e958ab03860bb3680f587d966b
|
4
|
+
data.tar.gz: 462fc6a165a14fd8d8c1065d7bae3dab8795b5bf0bb67e368766b1c694960766
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a73e88ab91779a2e9f771001eb17b08e6c4e5056cbe50d4308251e27f6368ed713b571651f32fc0844d9e225fd9e8247c41a0edd6b2a88a113bcb36affcaaa1
|
7
|
+
data.tar.gz: '04098a0800c1bf9324ef44494a2c2800def7fd71b14fda526c89996cd5b9016166725112d18428fd204ea18adb386bc491fac8bfb0b6573c7df95a589ac8c2dc'
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## [1.1.0] - 2021-09-13
|
2
|
+
- Get payment detail
|
3
|
+
|
4
|
+
## [1.0.3] - 2021-07-23
|
5
|
+
- First and Last name methods to customer
|
6
|
+
|
7
|
+
## [1.0.1] - 2021-06-25
|
8
|
+
- Adjust HTTP response code when create payments into BS2
|
9
|
+
|
1
10
|
## [1.0.0] - 2021-06-18
|
2
11
|
- Changed payment.id to payment.payment_id
|
3
12
|
- Changed payment.merchant_id to payment.end_to_end_id
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
bs2_api (1.0.
|
4
|
+
bs2_api (1.0.3)
|
5
5
|
activesupport
|
6
6
|
builder
|
7
7
|
bundler
|
@@ -11,7 +11,7 @@ PATH
|
|
11
11
|
GEM
|
12
12
|
remote: https://rubygems.org/
|
13
13
|
specs:
|
14
|
-
activesupport (6.1.
|
14
|
+
activesupport (6.1.4.1)
|
15
15
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
16
16
|
i18n (>= 1.6, < 2)
|
17
17
|
minitest (>= 5.1)
|
@@ -38,7 +38,7 @@ GEM
|
|
38
38
|
method_source (1.0.0)
|
39
39
|
mime-types (3.3.1)
|
40
40
|
mime-types-data (~> 3.2015)
|
41
|
-
mime-types-data (3.2021.
|
41
|
+
mime-types-data (3.2021.0704)
|
42
42
|
minitest (5.14.4)
|
43
43
|
multi_xml (0.6.0)
|
44
44
|
pry (0.13.1)
|
@@ -48,7 +48,7 @@ GEM
|
|
48
48
|
byebug (~> 11.0)
|
49
49
|
pry (~> 0.13.0)
|
50
50
|
public_suffix (4.0.6)
|
51
|
-
rake (13.0.
|
51
|
+
rake (13.0.6)
|
52
52
|
rexml (3.2.5)
|
53
53
|
rspec (3.10.0)
|
54
54
|
rspec-core (~> 3.10.0)
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@ TO-DO:
|
|
12
12
|
- [x] Criar pagamento por Chave
|
13
13
|
- [x] Criar pagamento Manual
|
14
14
|
- [x] Confirmar pagamento
|
15
|
-
- [
|
15
|
+
- [x] Consultar pagamento
|
16
16
|
- Recebimentos (**Recebe** dinheiro de alguém)
|
17
17
|
- [ ] Cobrança estático
|
18
18
|
- [ ] Cobrança dinâmico
|
@@ -66,12 +66,14 @@ pix_key = Bs2Api::Entities::PixKey.new(
|
|
66
66
|
# Veja abaixo (Classes de errors) quais erros que podem ser lançados
|
67
67
|
pay_key = Bs2Api::Payment::Key.new(pix_key).call
|
68
68
|
|
69
|
-
pay_key.payment.
|
69
|
+
pay_key.payment.payment_id
|
70
70
|
=> "96f0b3c4-4c76-4a7a-9933-9c9f86df7490" # pagamentoId gerado no BS2
|
71
71
|
|
72
72
|
pay_key.payment.end_to_end_id
|
73
73
|
=> "E710278662021061618144401750781P" # endToEndId gerado no BS2
|
74
74
|
|
75
|
+
pay_key.payment.class
|
76
|
+
=> Bs2Api::Entities::Payment
|
75
77
|
```
|
76
78
|
|
77
79
|
### Inicia ordem de Transferência PIX via: Manual
|
@@ -99,10 +101,13 @@ receiver_bank = Bs2Api::Entities::Bank.new(
|
|
99
101
|
pay_manual = Bs2Api::Payment::Manual.new(receiver_bank).call
|
100
102
|
|
101
103
|
pay_manual.payment.payment_id
|
102
|
-
=> "96f0b3c4-4c76-4a7a-9933-9c9f86df7490" #
|
104
|
+
=> "96f0b3c4-4c76-4a7a-9933-9c9f86df7490" # Payment id no BS2
|
103
105
|
|
104
106
|
pay_manual.payment.end_to_end_id
|
105
107
|
=> "E710278662021061618144401750781P" # endToEndId gerado no BS2
|
108
|
+
|
109
|
+
pay_manual.payment.class
|
110
|
+
=> Bs2Api::Entities::Payment
|
106
111
|
```
|
107
112
|
|
108
113
|
### Confirmar ordem de transferência
|
@@ -127,6 +132,21 @@ raise Bs2Api::Errors::ConfirmationError
|
|
127
132
|
confirmation.success?
|
128
133
|
```
|
129
134
|
|
135
|
+
### Busca informações do pagamento
|
136
|
+
```ruby
|
137
|
+
payment_id = "96f0b3c4-4c76-4a7a-9933-9c9f86df7490"
|
138
|
+
|
139
|
+
payment = Bs2Api::Payment::Detail.new(payment_id).call # Payment id no BS2
|
140
|
+
payment.id
|
141
|
+
=> "96f0b3c4-4c76-4a7a-9933-9c9f86df7490"
|
142
|
+
|
143
|
+
payment.end_to_end_id
|
144
|
+
=> "E710278662021061618144401750781P" # endToEndId gerado no BS2
|
145
|
+
|
146
|
+
payment.class
|
147
|
+
=> Bs2Api::Entities::Payment
|
148
|
+
```
|
149
|
+
|
130
150
|
### Classes de erros:
|
131
151
|
```ruby
|
132
152
|
# Todos erros herdam de:
|
@@ -46,6 +46,20 @@ module Bs2Api
|
|
46
46
|
def business?
|
47
47
|
@type == TYPES[:business]
|
48
48
|
end
|
49
|
+
|
50
|
+
def first_name
|
51
|
+
split_name.first
|
52
|
+
end
|
53
|
+
|
54
|
+
def last_name
|
55
|
+
return '' if split_name.size <= 1
|
56
|
+
split_name.last
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
def split_name
|
61
|
+
@split_name ||= @name.split(' ')
|
62
|
+
end
|
49
63
|
end
|
50
64
|
end
|
51
65
|
end
|
@@ -13,21 +13,21 @@ module Bs2Api
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def to_hash
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
)
|
16
|
+
hash_data = {
|
17
|
+
"pagamentoId": @payment_id,
|
18
|
+
"endToEndId": @end_to_end_id
|
19
|
+
}
|
20
|
+
|
21
|
+
hash_data.merge!({ "recebedor": @receiver.to_hash } ) if @receiver.present?
|
22
|
+
hash_data.merge!({ "pagador": @payer.to_hash } ) if @payer.present?
|
23
|
+
ActiveSupport::HashWithIndifferentAccess.new(hash_data)
|
24
24
|
end
|
25
25
|
|
26
26
|
def self.from_response(hash_payload)
|
27
27
|
hash = ActiveSupport::HashWithIndifferentAccess.new(hash_payload)
|
28
28
|
|
29
29
|
Bs2Api::Entities::Payment.new(
|
30
|
-
payment_id: hash["pagamentoId"],
|
30
|
+
payment_id: hash["pagamentoId"] || hash["cobranca"]["id"],
|
31
31
|
end_to_end_id: hash["endToEndId"],
|
32
32
|
receiver: Bs2Api::Entities::Bank.from_response(hash["recebedor"]),
|
33
33
|
payer: Bs2Api::Entities::Bank.from_response(hash["pagador"])
|
data/lib/bs2_api/payment/base.rb
CHANGED
@@ -9,8 +9,8 @@ module Bs2Api
|
|
9
9
|
|
10
10
|
def call
|
11
11
|
response = post_request
|
12
|
-
raise Bs2Api::Errors::BadRequest, ::Util::Response.parse_error(response) unless response.
|
13
|
-
|
12
|
+
raise Bs2Api::Errors::BadRequest, ::Util::Response.parse_error(response) unless response.ok?
|
13
|
+
|
14
14
|
@payment = Bs2Api::Entities::Payment.from_response(response)
|
15
15
|
self
|
16
16
|
end
|
@@ -35,10 +35,10 @@ module Bs2Api
|
|
35
35
|
def payload
|
36
36
|
raise NoMethodError, "Missing #{__method__} to #{self.class}"
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def url
|
40
40
|
raise NoMethodError, "Missing #{__method__} to #{self.class}"
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
44
|
-
end
|
44
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Bs2Api
|
2
|
+
module Payment
|
3
|
+
class Detail < Base
|
4
|
+
attr_reader :success
|
5
|
+
|
6
|
+
def initialize payment_id
|
7
|
+
@payment_id = payment_id
|
8
|
+
end
|
9
|
+
|
10
|
+
def call
|
11
|
+
response = detail_request
|
12
|
+
raise Bs2Api::Errors::BadRequest, ::Util::Response.parse_error(response) unless response.ok?
|
13
|
+
|
14
|
+
Bs2Api::Entities::Payment.from_response(response)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
def url
|
19
|
+
"#{Bs2Api.endpoint}/pix/direto/forintegration/v1/pagamentos/#{@payment_id}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def detail_request
|
23
|
+
HTTParty.get(url, headers: headers)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -8,14 +8,13 @@ module Bs2Api
|
|
8
8
|
class << self
|
9
9
|
def find_by_code code
|
10
10
|
bank = bank_list.find {|b| b["code"] == code }
|
11
|
-
raise Bs2Api::Errors::MissingBank,
|
11
|
+
raise Bs2Api::Errors::MissingBank, "Bank with code #{code} not registered into util/banks.yml file" if bank.blank?
|
12
12
|
bank
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
15
|
+
def bank_list
|
16
|
+
@bank_list ||= YAML.load_file(File.join(__dir__, 'banks.yml'))
|
17
|
+
end
|
19
18
|
end
|
20
19
|
end
|
21
20
|
end
|
data/lib/bs2_api/version.rb
CHANGED
data/lib/bs2_api.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bs2_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kim Pastro
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: builder
|
@@ -217,6 +217,7 @@ files:
|
|
217
217
|
- lib/bs2_api/errors/unauthorized.rb
|
218
218
|
- lib/bs2_api/payment/base.rb
|
219
219
|
- lib/bs2_api/payment/confirmation.rb
|
220
|
+
- lib/bs2_api/payment/detail.rb
|
220
221
|
- lib/bs2_api/payment/key.rb
|
221
222
|
- lib/bs2_api/payment/manual.rb
|
222
223
|
- lib/bs2_api/request/auth.rb
|