bs2_api 1.0.3 → 1.1.0

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: 1121a339962d5ccf01e2e82d2cac9c26326b0cb5f07bb58af18cd2aaf8502009
4
- data.tar.gz: 5ca659be8a6422c8c620b4304769822bd78d64835a6ed6f8e2b4612f0e3cea07
3
+ metadata.gz: 68ed1e77534b0eaefc776507d8251749815a45e958ab03860bb3680f587d966b
4
+ data.tar.gz: 462fc6a165a14fd8d8c1065d7bae3dab8795b5bf0bb67e368766b1c694960766
5
5
  SHA512:
6
- metadata.gz: 2ba02bb1b9d40ea4e78d087a4cf3e89fa698adce23b1c7d50eedc4fe05808a548f7cbcb15ea98a321515b0b7faeabaf10cdccb5a80b35295cc9926758c3b26a8
7
- data.tar.gz: 864734c20782307fe3d2ba4cb86dd78ee1de72f84681a3019b9a6c48b504eae9aef08aecbb66541515b80791d9abcbb39a594d0aefb6427d5c71cdd5916376bd
6
+ metadata.gz: 9a73e88ab91779a2e9f771001eb17b08e6c4e5056cbe50d4308251e27f6368ed713b571651f32fc0844d9e225fd9e8247c41a0edd6b2a88a113bcb36affcaaa1
7
+ data.tar.gz: '04098a0800c1bf9324ef44494a2c2800def7fd71b14fda526c89996cd5b9016166725112d18428fd204ea18adb386bc491fac8bfb0b6573c7df95a589ac8c2dc'
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## [1.1.0] - 2021-09-13
2
+ - Get payment detail
3
+
1
4
  ## [1.0.3] - 2021-07-23
2
5
  - First and Last name methods to customer
3
6
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bs2_api (1.0.2)
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.4)
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)
@@ -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.4)
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
- - [ ] 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(
@@ -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
@@ -8,7 +8,7 @@ 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, 'Bank not registered into util/banks.yml file' if bank.blank?
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bs2Api
4
- VERSION = "1.0.3"
4
+ VERSION = "1.1.0"
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.3
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-07-23 00:00:00.000000000 Z
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