sicoob_api 1.0.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef77cf8e56978c3dd6504084483aab19593189f89bff0336227beeaf02b866c9
4
- data.tar.gz: 6634e62e1b6b9592172abd71d457b1e0e8e830631b70d77a5cab494fc2d637f9
3
+ metadata.gz: e3e3e5670dd78f93b7f2b89f397e04bcf143e28fd1282088eef522f45f7d94bd
4
+ data.tar.gz: a98857367b8abe24a5a026426904c8f21b35d5c5af4e47b54e92ba496cf982c3
5
5
  SHA512:
6
- metadata.gz: be37bb23833f966b89137ae7f07d1e36fcb479a9195699b010d47c47611ec11fd9ecd449a35672d4672f4c21de90f0aa7227ceff05bedd2f3e8fdd58981bb175
7
- data.tar.gz: 531263f4a6830a239deb21f736c8cbc0d9f1ece2731044dc1079df06b5fc9e2ec91f40599cf9b77d8393f3f022fbd67f127870115139d8e25d083a80cf103df7
6
+ metadata.gz: b2d90d62e9c1a81bc813bc0eabdde0cc12e3f2fda8cf28d0b6c838c33f7faff9f1dbd21b7b960f749336d23c1e58cbd48cba13a7efd751340726be88cec70c2a
7
+ data.tar.gz: 469c4b5d1d14695de9e763191786292f5d9ee849826667f6bec438b41360b149497f6dc4aa5cb47fe4e70f46198073964e51c255668bbb1c81d13d4e4c78cacd
@@ -1,18 +1,19 @@
1
1
  module SicoobApi
2
- class Client < Ac::Base
2
+ class ClientProduction < Ac::Base
3
3
  BASE_URL = "https://api.sicoob.com.br/pix/api/v2"
4
4
  SAVE_RESPONSES = true
5
5
  MAX_RETIES = 2
6
6
 
7
7
  attr_accessor :client_id, :chave_pix, :crt, :key, :token_expires_at, :scopes
8
8
 
9
- def initialize(client_id:, chave_pix:, crt:, key:, access_token: nil, token_expires_at: nil, scopes: "cob.write cob.read cobv.write cobv.read lotecobv.write lotecobv.read pix.write pix.read webhook.read webhook.write payloadlocation.write payloadlocation.read")
9
+ def initialize(client_id:, chave_pix:, crt:, key:, access_token: nil, token_expires_at: nil, scopes: "cob.write cob.read cobv.write cobv.read lotecobv.write lotecobv.read pix.write pix.read webhook.read webhook.write payloadlocation.write payloadlocation.read", test_mode: false)
10
10
  @client_id = client_id
11
11
  @chave_pix = chave_pix
12
12
  @crt = crt
13
13
  @key = key
14
14
  @access_token = access_token
15
15
  @token_expires_at = token_expires_at
16
+ @test_mode = test_mode
16
17
  @scopes = scopes
17
18
  end
18
19
 
@@ -50,26 +51,26 @@ module SicoobApi
50
51
  original: format("%.2f", amount),
51
52
  modalidadeAlteracao: 0
52
53
  },
53
- chave: chave_pix
54
- }
55
- body[:devedor] = devedor(payer_tax_id, payer_name) if payer_tax_id && payer_name
56
- body[:solicitacaoPagador] = solicitacao_pagador if solicitacao_pagador
57
- body[:infoAdicionais] = info_adicionais if info_adicionais.any?
58
- response = post("cob", body:)
59
- SicoobApi::Payment.new(response, self)
54
+ chave: chave_pix,
55
+ devedor: devedor(payer_tax_id, payer_name),
56
+ solicitacaoPagador: solicitacao_pagador,
57
+ infoAdicionais: info_adicionais
58
+ }.compact
59
+ post("cob", body:)
60
60
  end
61
61
 
62
62
  def get_payment txid
63
- response = get("cob/#{txid}")
64
- SicoobApi::Payment.new(response, self)
63
+ get("cob/#{txid}")
65
64
  end
66
65
 
67
- def update_payment(payment_id, body)
68
- response = patch("cob/#{payment_id}", body:)
69
- SicoobApi::Payment.new(response, self)
66
+ def update_payment(payment_id:, status:)
67
+ body = {
68
+ status: status
69
+ }
70
+ patch("cob/#{payment_id}", body:)
70
71
  end
71
72
 
72
- def refund_payment(end_to_end_id, amount, refund_nature, description)
73
+ def refund_payment(end_to_end_id:, amount:, refund_nature:, description: nil)
73
74
  id = SecureRandom.hex(10)
74
75
  body = {
75
76
  valor: format("%.2f", amount),
@@ -79,12 +80,15 @@ module SicoobApi
79
80
  put("pix/#{end_to_end_id}/devolucao/#{id}", body:)
80
81
  end
81
82
 
82
- def get_refund(end_to_end_id, id)
83
- get("pix/#{end_to_end_id}/devolucao/#{id}")
83
+ def get_refund(end_to_end_id:, txid:)
84
+ get("pix/#{end_to_end_id}/devolucao/#{txid}")
84
85
  end
85
86
 
86
87
  def update_webhook url
87
- put("webhook/#{chave_pix}", body: {webhookUrl: url})
88
+ body = {
89
+ webhookUrl: url
90
+ }
91
+ put("webhook/#{chave_pix}", body:)
88
92
  end
89
93
 
90
94
  def get_webhook
@@ -0,0 +1,5 @@
1
+ module SicoobApi
2
+ class ClientSandbox < ClientProduction
3
+ BASE_URL = "https://sandbox.sicoob.com.br/sicoob/sandbox/pix/api/v2"
4
+ end
5
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SicoobApi
4
- VERSION = "1.0.0"
4
+ VERSION = "2.0.0"
5
5
  end
data/lib/sicoob_api.rb CHANGED
@@ -3,11 +3,10 @@
3
3
  require "ac"
4
4
  require "bigdecimal/util"
5
5
  require "securerandom"
6
- require "rqrcode"
7
6
 
8
7
  require_relative "sicoob_api/version"
9
- require_relative "sicoob_api/client"
10
- require_relative "sicoob_api/payment"
8
+ require_relative "sicoob_api/client_production"
9
+ require_relative "sicoob_api/client_sandbox"
11
10
 
12
11
  module SicoobApi
13
12
  Typhoeus::Config.timeout = 10
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sicoob_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - hamilton
@@ -23,20 +23,6 @@ dependencies:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
25
  version: '0'
26
- - !ruby/object:Gem::Dependency
27
- name: rqrcode
28
- requirement: !ruby/object:Gem::Requirement
29
- requirements:
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: '0'
33
- type: :runtime
34
- prerelease: false
35
- version_requirements: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- version: '0'
40
26
  - !ruby/object:Gem::Dependency
41
27
  name: bigdecimal
42
28
  requirement: !ruby/object:Gem::Requirement
@@ -73,8 +59,8 @@ extra_rdoc_files: []
73
59
  files:
74
60
  - README.md
75
61
  - lib/sicoob_api.rb
76
- - lib/sicoob_api/client.rb
77
- - lib/sicoob_api/payment.rb
62
+ - lib/sicoob_api/client_production.rb
63
+ - lib/sicoob_api/client_sandbox.rb
78
64
  - lib/sicoob_api/version.rb
79
65
  homepage: https://github.com/todasessascoisas/sicoob_api
80
66
  licenses: []
@@ -1,111 +0,0 @@
1
- module SicoobApi
2
- class Payment
3
- attr_reader :response, :txid, :end_to_end_id, :devolucoes, :copia_e_cola, :status, :solicitacao, :info_adicionais, :valor_original, :valor_pago, :criacao, :expiracao, :pago_em, :devedor_nome, :devedor_tax_id
4
- def initialize(response, client)
5
- @client = client
6
- @response = response
7
- @txid = response.txid
8
- @end_to_end_id = end_to_end
9
- @devolucoes = devolutions
10
- @copia_e_cola = response.brcode || response.qrCode
11
- @status = response.status
12
- @solicitacao = response["solicitacaoPagador"]
13
- @info_adicionais = response["infoAdicionais"]
14
- @valor_original = response.valor.original
15
- @valor_pago = total_paid
16
- @criacao = creation_date
17
- @expiracao = expiration_date
18
- @pago_em = paid_date
19
- @devedor_nome = debtor_name
20
- @devedor_tax_id = debtor_tax_id
21
- end
22
-
23
- def paid? external_value = nil
24
- external_value = @valor_original if external_value.nil?
25
- @status == "CONCLUIDA" && @valor_original.to_d == @valor_pago.to_d && external_value.to_d == @valor_pago.to_d
26
- end
27
-
28
- def valid?
29
- @status == "ATIVA" && @expiracao > Time.now
30
- end
31
-
32
- def retrieve
33
- @client.get_payment(@txid)
34
- end
35
-
36
- def reload!
37
- new_payment = retrieve
38
- instance_variables.each do |variable|
39
- instance_variable_set(variable, new_payment.instance_variable_get(variable))
40
- end
41
- self
42
- end
43
-
44
- def update(body)
45
- @client.update_payment(@txid, body)
46
- end
47
-
48
- def invalidate!
49
- update({status: "REMOVIDA_PELO_USUARIO_RECEBEDOR"})
50
- reload!
51
- end
52
-
53
- def refund(amount: nil, refund_nature: nil, description: nil)
54
- amount ||= @valor_pago
55
- refund_nature ||= "ORIGINAL"
56
- @client.refund_payment(@end_to_end_id, amount, refund_nature, description)
57
- end
58
-
59
- def qr_code(module_size: 4)
60
- return false unless @copia_e_cola
61
- qr = RQRCode::QRCode.new(@copia_e_cola, size: 10, level: :l)
62
- qr.as_svg(module_size: module_size)
63
- end
64
-
65
- def puts_qrcode
66
- puts RQRCode::QRCode.new(@copia_e_cola).to_s(dark: "██", light: " ")
67
- end
68
-
69
- private
70
-
71
- def creation_date
72
- return nil unless @response.calendario.criacao
73
- Time.new(@response.calendario.criacao)
74
- end
75
-
76
- def expiration_date
77
- return nil unless @response.calendario.criacao
78
- Time.new(@response.calendario.criacao) + @response.calendario.expiracao
79
- end
80
-
81
- def paid_date
82
- return nil unless @response["pix"] && @response.pix.any? && @response.pix[0].horario
83
- Time.new(@response.pix[0].horario)
84
- end
85
-
86
- def end_to_end
87
- return nil unless @response["pix"] && @response.pix.any?
88
- @response.pix[0].endToEndId
89
- end
90
-
91
- def devolutions
92
- return nil unless @response["pix"] && @response.pix.any?
93
- @response.pix[0].devolucoes
94
- end
95
-
96
- def total_paid
97
- return nil unless @response["pix"] && @response.pix.any?
98
- @response.pix[0].valor
99
- end
100
-
101
- def debtor_name
102
- return nil unless @response["devedor"]
103
- @response.devedor.nome
104
- end
105
-
106
- def debtor_tax_id
107
- return nil unless @response["devedor"]
108
- @response.devedor.cpf || @response.devedor.cnpj
109
- end
110
- end
111
- end