inter_api 0.1.5 → 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: 95c86c38237537b7cff6d601ac6f5a04bec9a1fbf18ea2283226cb02957cba8d
4
- data.tar.gz: aaafdf3f54ef068a0b3389da1915623dce2570cbadb3ac84fbefd592a1ab7e32
3
+ metadata.gz: 50e5c72c21a5a02a2c320b1abd0455a7406f9d713203f30286ecb009c32cdfbc
4
+ data.tar.gz: 5f1fa2b57a8f354da8071275abf502aa817cad3d868058a0a771f5c469be80e8
5
5
  SHA512:
6
- metadata.gz: f27f9a893fead1db9cc001c00f62298af9a04cf8d17ed7be8c71fa8458351a4c6d7889c3494d5a5605398d14aa8d9efdf5b9b9e67169140ac64383a784a21335
7
- data.tar.gz: 7144c8950e292e4df2d5b13e6ffb616528bcab0c6df2be0d04b7b8f25a059c8047f6f4a22affa31feb51d5473125ed0465f18b9a62d0705a3da049b46df8f414
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
 
@@ -70,7 +84,7 @@ module InterApi
70
84
  end
71
85
 
72
86
  def update_payment(payment_id, body)
73
- response = update_payment_request(payment_id, JSON.dump(body)).run
87
+ response = update_payment_request(payment_id, body).run
74
88
  InterApi::Payment.new(response.json, self)
75
89
  end
76
90
 
@@ -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.5"
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.5
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