inter_api 0.1.7 → 0.1.9

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: db16129e231c0aa017089bb5a701e95dcf06a407402efa0ca12bc2d3ec0110f0
4
+ data.tar.gz: aca55c9bd8fd7e37a1e13e85c81c5d81929eaeb3412bce2a663aceba1a3b269a
5
5
  SHA512:
6
- metadata.gz: 876363b28280c3872131a75ee2babe00ab0e09603325e1183afd1a0876d97ea5117e277df760beda2ac80421dc120be76daa939acea66c7104f04e28023441a6
7
- data.tar.gz: 2219528db956bed1e098fcd23f0d27450f4facc5e68cfcb123921fa371d1f41707b74fff54f4e368ad2c52b7a804035a7b657598df80991ebe32f651b5b7fde8
6
+ metadata.gz: 913351127cd258e3fa8d6708af0e5e24e8fa11b49a22277dd8abe76d48581b3f2518cefb148cb1cc3858527174a7c96a44392453fb28aa644868c1c66ed404b1
7
+ data.tar.gz: c8bf3ef2db3a681db0502608bcf8535e3a88d093a74d13af76a680a7f76c83fd0a273428db1b7618939500b9a652c59358be42687bbe651964629a4c3fae4c83
@@ -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.9"
5
5
  end
data/lib/inter_api.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  require "bigdecimal/util"
4
4
  require "securerandom"
5
5
  require "rqrcode"
6
- require "debug"
6
+ # require "debug"
7
7
  require "ac"
8
8
 
9
9
  require_relative "inter_api/version"
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.9
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