inter_api 0.1.7 → 0.1.8

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: 4c305373c21fb67bae2babd2a584dec0da485c1e7e08723dab7cc80f769cc77c
4
- data.tar.gz: 8e14a26390eec3f29a2aff59a3cabe58d32f3d3f582aa6c7b0d86a8490cf476c
3
+ metadata.gz: 50e5c72c21a5a02a2c320b1abd0455a7406f9d713203f30286ecb009c32cdfbc
4
+ data.tar.gz: 5f1fa2b57a8f354da8071275abf502aa817cad3d868058a0a771f5c469be80e8
5
5
  SHA512:
6
- metadata.gz: 876363b28280c3872131a75ee2babe00ab0e09603325e1183afd1a0876d97ea5117e277df760beda2ac80421dc120be76daa939acea66c7104f04e28023441a6
7
- data.tar.gz: 2219528db956bed1e098fcd23f0d27450f4facc5e68cfcb123921fa371d1f41707b74fff54f4e368ad2c52b7a804035a7b657598df80991ebe32f651b5b7fde8
6
+ metadata.gz: 1bc26a87ed361e9c4643d6897907a3e9f4e5aef1946060f8a8fd6ba0dffb0445a42ba7cba5c58a9ab90294a45b827444ca348d74775b5f8fc3e6aaa73988b715
7
+ data.tar.gz: e2d6dbb63754bad7ad47cf719b95ef75c5c4af1fb99f5221303eb5b19ec207612383525e8f46025d9372180679ec077daa4027503b9fbaacbd2f8c1f5c95a98b
@@ -1,6 +1,7 @@
1
1
  module InterApi
2
2
  class Client < Ac::Base
3
3
  BASE_URL = "https://cdpj.partners.bancointer.com.br/"
4
+ MAX_RETIES = 2
4
5
 
5
6
  attr_reader :crt, :key, :client_id, :client_secret, :chave_pix, :conta_corrente, :scopes
6
7
  attr_accessor :token, :token_expires_at
@@ -39,7 +40,7 @@ module InterApi
39
40
  end
40
41
 
41
42
  def get_payment(payment_id)
42
- response = get_payment_request(payment_id).run
43
+ response = get("/pix/v2/cob/#{payment_id}", headers: build_headers, sslcert: @crt, sslkey: @key) { |response| validate_response(response, "txid") }
43
44
  InterApi::Payment.new(response.json, self)
44
45
  end
45
46
 
@@ -61,7 +62,20 @@ module InterApi
61
62
  end
62
63
 
63
64
  def create_payment(amount:, payer_tax_id:, payer_name:, expiration: 3600, solicitacao_pagador: nil, info_adicionais: [])
64
- response = create_payment_request(amount: amount, payer_tax_id: payer_tax_id, payer_name: payer_name, expiration: expiration, solicitacao_pagador: solicitacao_pagador, info_adicionais: info_adicionais).run
65
+ body = {
66
+ calendario: {
67
+ expiracao: expiration
68
+ },
69
+ devedor: build_devedor(payer_tax_id, payer_name),
70
+ valor: {
71
+ original: format("%.2f", amount),
72
+ modalidadeAlteracao: 0
73
+ },
74
+ chave: @chave_pix,
75
+ solicitacaoPagador: solicitacao_pagador,
76
+ infoAdicionais: info_adicionais
77
+ }
78
+ response = post("/pix/v2/cob", headers: build_headers, sslcert: @crt, sslkey: @key, body: JSON.dump(body)) { |response| validate_response(response, "txid") }
65
79
  InterApi::Payment.new(response.json, self)
66
80
  end
67
81
 
@@ -108,5 +122,10 @@ module InterApi
108
122
  "Content-Type" => "application/json"
109
123
  }
110
124
  end
125
+
126
+ def validate_response(response, required_response_key)
127
+ puts response.json unless response.success?
128
+ ![500, 429].include?(response.code) || response.json.dig(*required_response_key)
129
+ end
111
130
  end
112
131
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InterApi
4
- VERSION = "0.1.7"
4
+ VERSION = "0.1.8"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inter_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - ulysses
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-29 00:00:00.000000000 Z
11
+ date: 2024-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ac