bs2_api 1.0.2 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fedfacb857654251513141faee3fe9594e888c3d10f6de512016d4902f532e17
4
- data.tar.gz: 5d424e8fd30eeeeb261470ac5aef0e4bc09cf511aafe9f221f8f684a684477b6
3
+ metadata.gz: 2b3224179dc0824ec6bd97ad39ea0069086ed63c83438add32914a6f5336b8e4
4
+ data.tar.gz: 543ed7441a126e649ba442b1ff3144bfa6967fc8136ab58ccc6775537e1477fc
5
5
  SHA512:
6
- metadata.gz: ac0eb6711af976b5354a2f4a8b61e1aa63f7818df87601f7234390788b88621176dde42e1c34d6c175ba2a4801c783750bb47b2372a3e6d62f93112480d2864d
7
- data.tar.gz: 0ecd2596091a8a4c664307e4f9d40e7c0a95fb113466d97bb3ac59c8e45e9914630e4a590bbba0813bce72a53d08e921af61f036152a02f711a9f78dcfd5ddd1
6
+ metadata.gz: 76d95274953486d82a83b863bd37f5a7dc47b86a35732ade87b3e2c27bd79a330d10ae7b6cc2895665cf4b96ff1cfa05910bc94d7b84d84ec6576192c08b39e1
7
+ data.tar.gz: 6f5013bf0e2b1f9f3bf771f74cf4d4265d78627ccc0c934301a29e8e6f2fe5d4898300acb0211f99037a97eff26110ee943d2ddfe70fad6bb8ff3addd40a94cc
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
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
+
1
7
  ## [1.0.1] - 2021-06-25
2
8
  - Adjust HTTP response code when create payments into BS2
3
9
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bs2_api (1.0.1)
4
+ bs2_api (1.1.1)
5
5
  activesupport
6
6
  builder
7
7
  bundler
@@ -11,12 +11,11 @@ PATH
11
11
  GEM
12
12
  remote: https://rubygems.org/
13
13
  specs:
14
- activesupport (6.1.4)
14
+ activesupport (7.0.0)
15
15
  concurrent-ruby (~> 1.0, >= 1.0.2)
16
16
  i18n (>= 1.6, < 2)
17
17
  minitest (>= 5.1)
18
18
  tzinfo (~> 2.0)
19
- zeitwerk (~> 2.3)
20
19
  addressable (2.7.0)
21
20
  public_suffix (>= 2.0.2, < 5.0)
22
21
  builder (3.2.4)
@@ -31,15 +30,15 @@ GEM
31
30
  httparty (0.18.1)
32
31
  mime-types (~> 3.0)
33
32
  multi_xml (>= 0.5.2)
34
- i18n (1.8.10)
33
+ i18n (1.8.11)
35
34
  concurrent-ruby (~> 1.0)
36
35
  macaddr (1.7.2)
37
36
  systemu (~> 2.6.5)
38
37
  method_source (1.0.0)
39
- mime-types (3.3.1)
38
+ mime-types (3.4.1)
40
39
  mime-types-data (~> 3.2015)
41
- mime-types-data (3.2021.0225)
42
- minitest (5.14.4)
40
+ mime-types-data (3.2021.1115)
41
+ minitest (5.15.0)
43
42
  multi_xml (0.6.0)
44
43
  pry (0.13.1)
45
44
  coderay (~> 1.1)
@@ -48,7 +47,7 @@ GEM
48
47
  byebug (~> 11.0)
49
48
  pry (~> 0.13.0)
50
49
  public_suffix (4.0.6)
51
- rake (13.0.3)
50
+ rake (13.0.6)
52
51
  rexml (3.2.5)
53
52
  rspec (3.10.0)
54
53
  rspec-core (~> 3.10.0)
@@ -73,7 +72,6 @@ GEM
73
72
  addressable (>= 2.3.6)
74
73
  crack (>= 0.3.2)
75
74
  hashdiff (>= 0.4.0, < 2.0.0)
76
- zeitwerk (2.4.2)
77
75
 
78
76
  PLATFORMS
79
77
  ruby
@@ -89,4 +87,4 @@ DEPENDENCIES
89
87
  webmock (~> 3.13)
90
88
 
91
89
  BUNDLED WITH
92
- 2.2.18
90
+ 2.2.31
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
- - [ ] Consultar pagamento
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.payment_idid
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" # UUID gerado no BS2
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:
@@ -22,6 +22,7 @@ module Bs2Api
22
22
  end
23
23
 
24
24
  def self.from_response(hash_payload)
25
+ return if hash_payload.blank?
25
26
  hash = ActiveSupport::HashWithIndifferentAccess.new(hash_payload)
26
27
 
27
28
  Bs2Api::Entities::Bank.new(
@@ -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
- ActiveSupport::HashWithIndifferentAccess.new(
17
- {
18
- "pagamentoId": @payment_id,
19
- "endToEndId": @end_to_end_id,
20
- "recebedor": @receiver.to_hash,
21
- "pagador": @payer.to_hash
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"])
@@ -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
@@ -7,15 +7,16 @@ module Bs2Api
7
7
  class BankService
8
8
  class << self
9
9
  def find_by_code code
10
+ code = code.to_s.strip
10
11
  bank = bank_list.find {|b| b["code"] == code }
11
- raise Bs2Api::Errors::MissingBank, 'Bank not registered into util/banks.yml file' if bank.blank?
12
+ raise Bs2Api::Errors::MissingBank, "Bank with code '#{code}' not registered into util/banks.yml file" if bank.blank?
12
13
  bank
13
14
  end
14
15
 
15
16
  def bank_list
16
- @bank_list ||= YAML.load_file(File.join(__dir__, 'banks.yml'))
17
+ YAML.load_file(File.join(__dir__, 'banks.yml'))
17
18
  end
18
19
  end
19
20
  end
20
21
  end
21
- end
22
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bs2Api
4
- VERSION = "1.0.2"
4
+ VERSION = "1.1.2"
5
5
  end
data/lib/bs2_api.rb CHANGED
@@ -32,6 +32,7 @@ require 'bs2_api/payment/base'
32
32
  require 'bs2_api/payment/key'
33
33
  require 'bs2_api/payment/manual'
34
34
  require 'bs2_api/payment/confirmation'
35
+ require 'bs2_api/payment/detail'
35
36
 
36
37
  require 'bs2_api/request/auth'
37
38
 
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.0.2
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kim Pastro
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-06 00:00:00.000000000 Z
11
+ date: 2021-12-22 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
@@ -231,7 +232,7 @@ metadata:
231
232
  homepage_uri: https://github.com/latamgateway/bs2_api
232
233
  source_code_uri: https://github.com/latamgateway/bs2_api
233
234
  changelog_uri: https://github.com/latamgateway/bs2_api/blob/main/CHANGELOG.md
234
- post_install_message:
235
+ post_install_message:
235
236
  rdoc_options: []
236
237
  require_paths:
237
238
  - lib
@@ -250,7 +251,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
250
251
  version: '0'
251
252
  requirements: []
252
253
  rubygems_version: 3.1.4
253
- signing_key:
254
+ signing_key:
254
255
  specification_version: 4
255
256
  summary: Integração com a API do BS2
256
257
  test_files: []