bs2_api 0.2.0 → 0.3.3

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: b46010721b6fd642ba8db84aff501d9a29ecf78faacf023c4dc844ff50d58b41
4
- data.tar.gz: '0982876fca9f7c65f23c58286d9f60bcb01217d934287b38505fd21d2000f9c2'
3
+ metadata.gz: b2b8b144d4d8f5045e87461029c823e9b5f5a7c3d5a9191f1e39a542ac5d7400
4
+ data.tar.gz: c9bcf3bb230b56e8a0ac0d0e2d4373ec37a49869bc1918597b36dd57d1ff5bab
5
5
  SHA512:
6
- metadata.gz: 6fcee38ab1c4c3c3ada7eb9e2ada3f8090223ad0d28e0797a7494bd8c00bd11a9d828e2ccc545f9ad23278d9ac86b124116f6b604e7cc476ad5aab08cc5c074a
7
- data.tar.gz: 98e9b97e08e256ee31145a404758702dbd40c6a62f12d018fcf1e0f2de9456efb3604d25fe8361b43d004104003d96ba237020b7afa690d1bf11088c8646c7cf
6
+ metadata.gz: d4a1c8e8823be43d5c6f8a69b4817552e58e3e1a82d81780ed3a181ecae7449d6da2f0235bda18d36b2632dc7e58d06346624690efc9ed6f1b46ef526167572f
7
+ data.tar.gz: 242287b0695c77833428867361fb1a469eb912ffa0b387c8443f8fbba3db23a2bdd4aa1dbc6e9e172084166fb087ff8fbe9ff19a0cdc6260a12449963ecc7e86
data/CHANGELOG.md CHANGED
@@ -1,4 +1,15 @@
1
- ## [Unreleased]
1
+ ## [0.3.1] - 2021-06-16
2
+
3
+ - Method Hash#to_query conflicting with Rails
4
+
5
+ ## [0.3.0] - 2021-06-16
6
+
7
+ - Confirmation, Adjust README.md
8
+
9
+ ## [0.2.0] - 2021-06-15
10
+
11
+ - Entities, Auth, Create Pix Key Payment
12
+
2
13
 
3
14
  ## [0.1.0] - 2021-06-11
4
15
 
data/Gemfile CHANGED
@@ -2,12 +2,4 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- # Specify your gem's dependencies in bs2_api.gemspec
6
- gemspec
7
-
8
- gem "rake", "~> 13.0"
9
-
10
- group :test do
11
- gem "pry-byebug", "~> 3.9"
12
- gem 'uuid', '~> 2.3', '>= 2.3.9'
13
- end
5
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,9 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bs2_api (0.2.0)
5
- activesupport (~> 6.1, >= 6.1.3.2)
6
- http (~> 4.4)
4
+ bs2_api (0.3.2)
5
+ activesupport
6
+ builder
7
+ bundler
8
+ httparty (~> 0.18.1)
9
+ rake
7
10
 
8
11
  GEM
9
12
  remote: https://rubygems.org/
@@ -16,36 +19,28 @@ GEM
16
19
  zeitwerk (~> 2.3)
17
20
  addressable (2.7.0)
18
21
  public_suffix (>= 2.0.2, < 5.0)
22
+ builder (3.2.4)
19
23
  byebug (11.1.3)
20
24
  coderay (1.1.3)
21
25
  concurrent-ruby (1.1.9)
22
26
  crack (0.4.5)
23
27
  rexml
24
28
  diff-lcs (1.4.4)
25
- domain_name (0.5.20190701)
26
- unf (>= 0.0.5, < 1.0.0)
27
29
  dotenv (2.7.6)
28
- ffi (1.15.1)
29
- ffi-compiler (1.0.1)
30
- ffi (>= 1.0.0)
31
- rake
32
30
  hashdiff (1.0.1)
33
- http (4.4.1)
34
- addressable (~> 2.3)
35
- http-cookie (~> 1.0)
36
- http-form_data (~> 2.2)
37
- http-parser (~> 1.2.0)
38
- http-cookie (1.0.4)
39
- domain_name (~> 0.5)
40
- http-form_data (2.3.0)
41
- http-parser (1.2.3)
42
- ffi-compiler (>= 1.0, < 2.0)
31
+ httparty (0.18.1)
32
+ mime-types (~> 3.0)
33
+ multi_xml (>= 0.5.2)
43
34
  i18n (1.8.10)
44
35
  concurrent-ruby (~> 1.0)
45
36
  macaddr (1.7.2)
46
37
  systemu (~> 2.6.5)
47
38
  method_source (1.0.0)
39
+ mime-types (3.3.1)
40
+ mime-types-data (~> 3.2015)
41
+ mime-types-data (3.2021.0225)
48
42
  minitest (5.14.4)
43
+ multi_xml (0.6.0)
49
44
  pry (0.13.1)
50
45
  coderay (~> 1.1)
51
46
  method_source (~> 1.0)
@@ -71,9 +66,6 @@ GEM
71
66
  systemu (2.6.5)
72
67
  tzinfo (2.0.4)
73
68
  concurrent-ruby (~> 1.0)
74
- unf (0.1.4)
75
- unf_ext
76
- unf_ext (0.0.7.7)
77
69
  uuid (2.3.9)
78
70
  macaddr (~> 1.0)
79
71
  vcr (6.0.0)
@@ -84,13 +76,13 @@ GEM
84
76
  zeitwerk (2.4.2)
85
77
 
86
78
  PLATFORMS
79
+ ruby
87
80
  x86_64-linux
88
81
 
89
82
  DEPENDENCIES
90
83
  bs2_api!
91
84
  dotenv (~> 2.7, >= 2.7.6)
92
85
  pry-byebug (~> 3.9)
93
- rake (~> 13.0)
94
86
  rspec (~> 3.10)
95
87
  uuid (~> 2.3, >= 2.3.9)
96
88
  vcr (~> 6.0)
data/README.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  Integração com a API do Banco BS2: https://devs.bs2.com/manual/pix-clientes
4
4
 
5
+ TO-DO:
6
+ - Pagamentos (**Transfere** dinheiro para alguém)
7
+ - [x] Criar pagamento por Chave
8
+ - [x] Criar pagamento Manual
9
+ - [x] Confirmar pagamento
10
+ - [ ] Consultar pagamento
11
+ - Recebimentos (**Recebe** dinheiro de alguém)
12
+ - [ ] Cobrança estático
13
+ - [ ] Cobrança dinâmico
14
+ - [ ] Consultar cobrança
15
+
16
+
5
17
  ## Instalação
6
18
 
7
19
  Adicionar no seu Gemfile:
@@ -31,13 +43,13 @@ ou via initializer:
31
43
 
32
44
  ```ruby
33
45
  Bs2Api.configure do |config|
34
- config.client_id = 'you_bs2_client_id'
35
- config.client_secret = 'you_bs2_client_secret'
36
- config.pix_environment = 'pix_enviroment'
46
+ config.client_id = 'you_bs2_client_id'
47
+ config.client_secret = 'you_bs2_client_secret'
48
+ config.env = 'sandbox' # ou production
37
49
  end
38
50
  ```
39
51
 
40
- ### Iniciar pagamento por Chave
52
+ ### Inicia ordem de Transferência PIX via: Chave
41
53
 
42
54
  ```ruby
43
55
  pix_key = Bs2Api::Entities::PixKey.new(
@@ -45,100 +57,86 @@ pix_key = Bs2Api::Entities::PixKey.new(
45
57
  type: 'EMAIL'
46
58
  )
47
59
 
48
- payment = Bs2Api::Payment::Key.new(pix_key).call
49
- ```
60
+ # Caso ocorra algum problema na criação, um erro será lançado
61
+ # Veja abaixo (Classes de errors) quais erros que podem ser lançados
62
+ pay_key = Bs2Api::Payment::Key.new(pix_key).call
50
63
 
51
- Tipos:
52
- ```bash
53
- CPF
54
- CNPJ
55
- PHONE
56
- EMAIL
57
- EVP (Chave aleatória)
58
- ```
64
+ pay_key.payment.id
65
+ => "96f0b3c4-4c76-4a7a-9933-9c9f86df7490" # pagamentoId gerado no BS2
59
66
 
67
+ pay_key.payment.merchantId
68
+ => "E710278662021061618144401750781P" # endToEndId gerado no BS2
60
69
 
61
- ### Iniciar pagamento Manual
70
+ ```
71
+
72
+ ### Inicia ordem de Transferência PIX via: Manual
62
73
 
63
74
  ```ruby
64
75
  account = Bs2Api::Entities::Account.new(
65
- bank_code: '341',
66
- bank_name: 'Itaú',
67
- agency: '0944',
68
- number: '09442-1',
69
- type: 'ContaCorrente'
76
+ bank_code: "218",
77
+ agency: "0993",
78
+ number: "042312",
79
+ type: "ContaCorrente" # ContaCorrente, ContaSalario ou Poupanca
70
80
  )
71
81
 
72
82
  customer = Bs2Api::Entities::Customer.new(
73
- document: '88899988811',
74
- type: 'CPF',
75
- name: 'João Silva'
83
+ document: "88899988811",
84
+ type: "CPF",
85
+ name: "Rick Sanches",
86
+ business_name: "Nome fantasia" # Utilizar apenas se for type CNPJ
76
87
  )
77
88
 
78
- receiver = Bs2Api::Entities::Bank.new(
79
- account: account,
89
+ receiver_bank = Bs2Api::Entities::Bank.new(
90
+ account: account,
80
91
  customer: customer
81
92
  )
82
93
 
83
- payment = Bs2Api::Payment::Manual.new(receiver).call
94
+ pay_manual = Bs2Api::Payment::Manual.new(receiver_bank).call
95
+
96
+ pay_manual.payment.id
97
+ => "96f0b3c4-4c76-4a7a-9933-9c9f86df7490" # UUID gerado no BS2
98
+
99
+ pay_manual.payment.merchantId
100
+ => "E710278662021061618144401750781P" # endToEndId gerado no BS2
84
101
  ```
85
102
 
86
- ### Objetos
103
+ ### Confirmar ordem de transferência
104
+ ```ruby
105
+ # Após criar um Payment é necessário confirmar
106
+ # Nessa etapa o dinheiro é de fato transferido
107
+
108
+ # Tanto a ordem de transferência via chave ou manual tem o mesmo payment.
109
+ # Caso tenha criado via chave no passo anterior:
110
+ payment = pay_key.payment
111
+
112
+ # Ou caso tenha criado a ordem via Manual no passo anterior:
113
+ payment = pay_manual.payment
114
+
115
+ amount = 10.50
116
+ confirmation = Bs2Api::Payment::Confirmation.new(payment, value: amount).call
87
117
 
88
- ##### Payment
118
+ # Caso a confirmação de problema, um erro será lançado.
119
+ raise Bs2Api::Errors::ConfirmationError
120
+
121
+ # Caso nenhum erro seja lançado (já é sucesso) porém, você pode ter certeza com
122
+ confirmation.success?
123
+ ```
124
+ ---
125
+ ### Classes de erros:
89
126
  ```ruby
90
- payment.id # pagamentoId
91
- payment.merchant_id # endToEndId
92
- payment.receiver # recebedor
93
- payment.payer # pagador
94
-
95
- payment.receiver.class
96
- => Bs2Api::Entities::Bank
97
-
98
- payment.payer.class
99
- => Bs2Api::Entities::Bank
100
-
101
- payment.payer.account # conta
102
- => Bs2Api::Entities::Account
103
-
104
- payment.payer.customer # pessoa
105
- => Bs2Api::Entities::Customer
106
-
107
- payment.to_hash
108
- {
109
- "pagamentoId"=>"123",
110
- "endToEndId"=>"456",
111
- "recebedor"=>{
112
- "ispb"=>"71027866",
113
- "conta"=>{
114
- "banco"=>"218",
115
- "bancoNome"=>"BCO BS2 S.A.",
116
- "agencia"=>"0001",
117
- "numero"=>"3134806",
118
- "tipo"=>"ContaCorrente"
119
- },
120
- "pessoa"=>{
121
- "documento"=>"25215188000116",
122
- "tipoDocumento"=>"CNPJ",
123
- "nome"=>"Teste Automatizado",
124
- "nomeFantasia"=>nil
125
- }
126
- },
127
- "pagador"=>{
128
- "ispb"=>"71027866",
129
- "conta"=>{
130
- "banco"=>"218",
131
- "bancoNome"=>"BCO BS2 S.A.",
132
- "agencia"=>"0001",
133
- "numero"=>"3134806",
134
- "tipo"=>"ContaCorrente"
135
- },
136
- "pessoa"=>{
137
- "documento"=>"25215188000116",
138
- "tipoDocumento"=>"CNPJ",
139
- "nome"=>"Teste Automatizado",
140
- "nomeFantasia"=>nil
141
- }
142
- }
143
- }
144
- ```
127
+ # Todos erros herdam de:
128
+ Bs2Api::Errors::Base
129
+
130
+ Bs2Api::Errors::BadRequest
131
+ Bs2Api::Errors::ConfirmationError
132
+ Bs2Api::Errors::InvalidCustomer
133
+ Bs2Api::Errors::InvalidPixKey
134
+ Bs2Api::Errors::MissingConfiguration
135
+ Bs2Api::Errors::ServerError
136
+ Bs2Api::Errors::Unauthorized
137
+
138
+ # Caso não queira tratar um erro em específico basta fazer rescue do Base
139
+ rescue Bs2Api::Errors::Base => e
140
+ puts "Erro: #{e.message}"
141
+ end
142
+ ```
data/bs2_api.gemspec CHANGED
@@ -9,13 +9,13 @@ Gem::Specification.new do |spec|
9
9
  spec.email = ["kimpastro@gmail.com"]
10
10
 
11
11
  spec.summary = "Integração com a API do BS2"
12
- spec.description = "Criar pagamentos PIX"
13
- spec.homepage = "https://github.com/kimpastro/bs2_api"
14
- spec.required_ruby_version = ">= 2.7.2"
12
+ spec.description = "Fazer transferências via PIX"
13
+ spec.homepage = "https://github.com/latamgateway/bs2_api"
14
+ spec.required_ruby_version = "~> 2.7", "< 3"
15
15
 
16
16
  spec.metadata["homepage_uri"] = spec.homepage
17
- spec.metadata["source_code_uri"] = "https://github.com/kimpastro/bs2_api"
18
- spec.metadata["changelog_uri"] = "https://github.com/kimpastro/bs2_api/blob/main/CHANGELOG.md"
17
+ spec.metadata["source_code_uri"] = "https://github.com/latamgateway/bs2_api"
18
+ spec.metadata["changelog_uri"] = "https://github.com/latamgateway/bs2_api/blob/main/CHANGELOG.md"
19
19
 
20
20
  # Specify which files should be added to the gem when it is released.
21
21
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -26,11 +26,16 @@ Gem::Specification.new do |spec|
26
26
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
27
  spec.require_paths = ["lib"]
28
28
 
29
- spec.add_development_dependency "rspec", "~> 3.10"
30
- spec.add_development_dependency "webmock", "~> 3.13"
31
- spec.add_development_dependency "vcr", "~> 6.0"
32
- spec.add_development_dependency "dotenv", "~> 2.7", ">= 2.7.6"
29
+ spec.add_dependency("builder")
30
+ spec.add_dependency("bundler")
31
+ spec.add_dependency("rake")
32
+ spec.add_dependency("activesupport")
33
+ spec.add_dependency("httparty", "~> 0.18.1")
33
34
 
34
- spec.add_dependency "http", "~> 4.4"
35
- spec.add_dependency "activesupport", "~> 6.1", ">= 6.1.3.2"
36
- end
35
+ spec.add_development_dependency("pry-byebug", "~> 3.9")
36
+ spec.add_development_dependency("uuid", "~> 2.3", ">= 2.3.9")
37
+ spec.add_development_dependency("rspec", "~> 3.10")
38
+ spec.add_development_dependency("webmock", "~> 3.13")
39
+ spec.add_development_dependency("vcr", "~> 6.0")
40
+ spec.add_development_dependency("dotenv", "~> 2.7", ">= 2.7.6")
41
+ end
data/lib/bs2_api.rb CHANGED
@@ -1,17 +1,23 @@
1
1
  # frozen_string_literal: true
2
+ require "httparty"
3
+ require "active_support/core_ext/hash/indifferent_access"
4
+ require "active_support/core_ext/hash/except"
5
+ require "active_support/core_ext/object/to_query"
6
+ require "active_support/core_ext/object/blank"
2
7
 
3
8
  require 'bs2_api/version'
4
9
  require 'bs2_api/configuration'
5
10
 
6
- require 'bs2_api/initializers/object'
7
- require 'bs2_api/initializers/hash'
8
-
9
11
  require 'bs2_api/errors/base'
10
12
  require 'bs2_api/errors/invalid_pix_key'
13
+ require 'bs2_api/errors/invalid_bank'
14
+ require 'bs2_api/errors/invalid_customer'
11
15
  require 'bs2_api/errors/missing_configuration'
12
16
  require 'bs2_api/errors/unauthorized'
13
17
  require 'bs2_api/errors/bad_request'
14
18
  require 'bs2_api/errors/server_error'
19
+ require 'bs2_api/errors/confirmation_error'
20
+ require 'bs2_api/errors/missing_bank'
15
21
 
16
22
  require 'bs2_api/entities/account'
17
23
  require 'bs2_api/entities/bank'
@@ -22,16 +28,15 @@ require 'bs2_api/entities/pix_key'
22
28
  require 'bs2_api/payment/base'
23
29
  require 'bs2_api/payment/key'
24
30
  require 'bs2_api/payment/manual'
31
+ require 'bs2_api/payment/confirmation'
25
32
 
26
33
  require 'bs2_api/request/auth'
27
34
 
28
35
  require 'bs2_api/util/bank_service'
29
36
 
30
- require "active_support/core_ext/hash/indifferent_access"
31
-
32
37
  module Bs2Api
33
38
  ENDPOINT = {
34
- production: 'https://api.bs2.com:8443',
39
+ production: 'https://api.bs2.com',
35
40
  sandbox: 'https://apihmz.bancobonsucesso.com.br'
36
41
  }
37
42
 
@@ -41,7 +46,7 @@ module Bs2Api
41
46
  def configuration
42
47
  @configuration ||= Configuration.new
43
48
  end
44
-
49
+
45
50
  def configure
46
51
  yield(configuration)
47
52
  end
@@ -53,7 +58,7 @@ module Bs2Api
53
58
  def production?
54
59
  env == 'production'
55
60
  end
56
-
61
+
57
62
  def sandbox?
58
63
  env == 'sandbox'
59
64
  end
@@ -62,4 +67,4 @@ module Bs2Api
62
67
  configuration.env
63
68
  end
64
69
  end
65
- end
70
+ end
@@ -13,17 +13,17 @@ module Bs2Api
13
13
 
14
14
  def initialize(args = {})
15
15
  @bank_code = args.fetch(:bank_code, nil)
16
- @bank_name = args.fetch(:bank_name, nil)
17
16
  @agency = args.fetch(:agency, nil)
18
17
  @number = args.fetch(:number, nil)
19
18
  @type = args.fetch(:type, nil)
19
+ @bank_name = get_bank_name
20
20
  end
21
21
 
22
22
  def to_hash
23
23
  ActiveSupport::HashWithIndifferentAccess.new(
24
24
  {
25
25
  "banco": @bank_code,
26
- "bancoNome": bank_name,
26
+ "bancoNome": get_bank_name,
27
27
  "agencia": @agency,
28
28
  "numero": @number,
29
29
  "tipo": @type
@@ -54,6 +54,11 @@ module Bs2Api
54
54
  def saving?
55
55
  @type == TYPES[:saving]
56
56
  end
57
+
58
+ private
59
+ def get_bank_name
60
+ Bs2Api::Util::BankService.find_by_code(@bank_code)["name"]
61
+ end
57
62
  end
58
63
  end
59
64
  end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bs2Api
4
+ module Errors
5
+ class ConfirmationError < Base; end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bs2Api
4
+ module Errors
5
+ class InvalidBank < Base; end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bs2Api
4
+ module Errors
5
+ class MissingBank < Base; end
6
+ end
7
+ end
@@ -1,27 +1,30 @@
1
- # frozen_string_literal: true
2
-
3
1
  module Bs2Api
4
2
  module Payment
5
3
  class Base
4
+ attr_reader :payment
5
+
6
+ def initialize
7
+ raise NoMethodError, "Missing #{__method__} to #{self.class}"
8
+ end
9
+
6
10
  def call
7
- response = HTTP.auth("Bearer #{bearer_token}")
8
- .headers(headers)
9
- .post(
10
- url,
11
- json: payload
12
- )
13
-
14
- raise Bs2Api::Errors::BadRequest, response.body.to_s if !response.status.created?
11
+ response = post_request
12
+ raise Bs2Api::Errors::BadRequest, parse_error(response) unless response.created?
15
13
 
16
- Bs2Api::Entities::Payment.from_response(response.parse)
14
+ @payment = Bs2Api::Entities::Payment.from_response(response)
15
+ self
17
16
  end
18
17
 
19
18
  private
19
+ def post_request
20
+ HTTParty.post(url, headers: headers, body: payload.to_json)
21
+ end
22
+
20
23
  def headers
21
24
  {
22
25
  "Content-Type": "application/json",
23
26
  "Accept": "application/json",
24
- "Accept-Encoding": "gzip,deflate"
27
+ "Authorization": "Bearer #{bearer_token}"
25
28
  }
26
29
  end
27
30
 
@@ -29,15 +32,26 @@ module Bs2Api
29
32
  Bs2Api::Request::Auth.token
30
33
  end
31
34
 
35
+ def parse_error(response)
36
+ hash = JSON.parse(response.body)
37
+ message = "#{response.code}: "
38
+
39
+ if hash.is_a?(Array)
40
+ message << hash[0]["descricao"]
41
+ elsif hash.key?("error_description")
42
+ message << hash["error_description"]
43
+ else
44
+ message << hash.to_s
45
+ end
46
+
47
+ message
48
+ end
49
+
32
50
  def payload
33
- no_method_error
51
+ raise NoMethodError, "Missing #{__method__} to #{self.class}"
34
52
  end
35
53
 
36
54
  def url
37
- no_method_error
38
- end
39
-
40
- def no_method_error
41
55
  raise NoMethodError, "Missing #{__method__} to #{self.class}"
42
56
  end
43
57
  end
@@ -0,0 +1,38 @@
1
+ module Bs2Api
2
+ module Payment
3
+ class Confirmation < Base
4
+ attr_reader :success
5
+
6
+ def initialize payment, value: nil
7
+ raise Bs2Api::Errors::ConfirmationError, 'invalid payment' unless payment.present? && payment.is_a?(Bs2Api::Entities::Payment)
8
+ raise Bs2Api::Errors::ConfirmationError, 'invalid value' unless value.to_f.positive?
9
+ @payment = payment
10
+
11
+ @value = value.to_f
12
+ end
13
+
14
+ def call
15
+ response = post_request
16
+ raise Bs2Api::Errors::ConfirmationError, parse_error(response) unless response.accepted?
17
+
18
+ @success = true
19
+ self
20
+ end
21
+
22
+ private
23
+ def payload
24
+ @payment.to_hash
25
+ .except!("pagamentoId", "endToEndId")
26
+ .merge("valor": @value)
27
+ end
28
+
29
+ def url
30
+ "#{Bs2Api.endpoint}/pix/direto/forintegration/v1/pagamentos/#{@payment.id}/confirmacao"
31
+ end
32
+
33
+ def success?
34
+ !!@success
35
+ end
36
+ end
37
+ end
38
+ end
@@ -4,6 +4,7 @@ module Bs2Api
4
4
  module Payment
5
5
  class Manual < Base
6
6
  def initialize bank
7
+ raise Bs2Api::Errors::InvalidBank, 'Invalid Bank' unless bank.is_a?(Bs2Api::Entities::Bank)
7
8
  @bank = bank
8
9
  end
9
10
 
@@ -9,22 +9,23 @@ module Bs2Api
9
9
 
10
10
  response = create_session
11
11
 
12
- raise Bs2Api::Errors::Unauthorized, response.parse["error_description"] if response.status.unauthorized?
13
- raise Bs2Api::Errors::BadRequest, response.parse["error_description"] if response.status.bad_request?
14
- raise Bs2Api::Errors::ServerError, response.body.to_s if !response.status.success?
12
+ raise Bs2Api::Errors::Unauthorized, response["error_description"] if response.unauthorized?
13
+ raise Bs2Api::Errors::BadRequest, response["error_description"] if response.bad_request?
14
+ raise Bs2Api::Errors::ServerError, response.body if !response.success?
15
15
 
16
- response.parse["access_token"]
16
+ response["access_token"]
17
17
  end
18
18
 
19
19
  private
20
20
  def create_session
21
- HTTP.basic_auth(
22
- user: Bs2Api.configuration.client_id,
23
- pass: Bs2Api.configuration.client_secret
24
- ).post(
21
+ HTTParty.post(
25
22
  auth_url,
26
- body: body,
27
- headers: headers
23
+ headers: headers,
24
+ body: body,
25
+ basic_auth: {
26
+ username: Bs2Api.configuration.client_id,
27
+ password: Bs2Api.configuration.client_secret
28
+ }
28
29
  )
29
30
  end
30
31
 
@@ -48,4 +49,4 @@ module Bs2Api
48
49
  end
49
50
  end
50
51
  end
51
- end
52
+ end
@@ -7,7 +7,9 @@ module Bs2Api
7
7
  class BankService
8
8
  class << self
9
9
  def find_by_code code
10
- bank_list.find {|b| b["code"] == code }
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?
12
+ bank
11
13
  end
12
14
 
13
15
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bs2Api
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.3"
5
5
  end
metadata CHANGED
@@ -1,112 +1,182 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bs2_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.3
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-06-15 00:00:00.000000000 Z
11
+ date: 2021-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rspec
14
+ name: builder
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.10'
20
- type: :development
19
+ version: '0'
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '3.10'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: webmock
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: httparty
29
71
  requirement: !ruby/object:Gem::Requirement
30
72
  requirements:
31
73
  - - "~>"
32
74
  - !ruby/object:Gem::Version
33
- version: '3.13'
34
- type: :development
75
+ version: 0.18.1
76
+ type: :runtime
35
77
  prerelease: false
36
78
  version_requirements: !ruby/object:Gem::Requirement
37
79
  requirements:
38
80
  - - "~>"
39
81
  - !ruby/object:Gem::Version
40
- version: '3.13'
82
+ version: 0.18.1
41
83
  - !ruby/object:Gem::Dependency
42
- name: vcr
84
+ name: pry-byebug
43
85
  requirement: !ruby/object:Gem::Requirement
44
86
  requirements:
45
87
  - - "~>"
46
88
  - !ruby/object:Gem::Version
47
- version: '6.0'
89
+ version: '3.9'
48
90
  type: :development
49
91
  prerelease: false
50
92
  version_requirements: !ruby/object:Gem::Requirement
51
93
  requirements:
52
94
  - - "~>"
53
95
  - !ruby/object:Gem::Version
54
- version: '6.0'
96
+ version: '3.9'
55
97
  - !ruby/object:Gem::Dependency
56
- name: dotenv
98
+ name: uuid
57
99
  requirement: !ruby/object:Gem::Requirement
58
100
  requirements:
59
101
  - - "~>"
60
102
  - !ruby/object:Gem::Version
61
- version: '2.7'
103
+ version: '2.3'
62
104
  - - ">="
63
105
  - !ruby/object:Gem::Version
64
- version: 2.7.6
106
+ version: 2.3.9
65
107
  type: :development
66
108
  prerelease: false
67
109
  version_requirements: !ruby/object:Gem::Requirement
68
110
  requirements:
69
111
  - - "~>"
70
112
  - !ruby/object:Gem::Version
71
- version: '2.7'
113
+ version: '2.3'
72
114
  - - ">="
73
115
  - !ruby/object:Gem::Version
74
- version: 2.7.6
116
+ version: 2.3.9
75
117
  - !ruby/object:Gem::Dependency
76
- name: http
118
+ name: rspec
77
119
  requirement: !ruby/object:Gem::Requirement
78
120
  requirements:
79
121
  - - "~>"
80
122
  - !ruby/object:Gem::Version
81
- version: '4.4'
82
- type: :runtime
123
+ version: '3.10'
124
+ type: :development
83
125
  prerelease: false
84
126
  version_requirements: !ruby/object:Gem::Requirement
85
127
  requirements:
86
128
  - - "~>"
87
129
  - !ruby/object:Gem::Version
88
- version: '4.4'
130
+ version: '3.10'
89
131
  - !ruby/object:Gem::Dependency
90
- name: activesupport
132
+ name: webmock
91
133
  requirement: !ruby/object:Gem::Requirement
92
134
  requirements:
93
135
  - - "~>"
94
136
  - !ruby/object:Gem::Version
95
- version: '6.1'
137
+ version: '3.13'
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: '3.13'
145
+ - !ruby/object:Gem::Dependency
146
+ name: vcr
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: '6.0'
152
+ type: :development
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - "~>"
157
+ - !ruby/object:Gem::Version
158
+ version: '6.0'
159
+ - !ruby/object:Gem::Dependency
160
+ name: dotenv
161
+ requirement: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - "~>"
164
+ - !ruby/object:Gem::Version
165
+ version: '2.7'
96
166
  - - ">="
97
167
  - !ruby/object:Gem::Version
98
- version: 6.1.3.2
99
- type: :runtime
168
+ version: 2.7.6
169
+ type: :development
100
170
  prerelease: false
101
171
  version_requirements: !ruby/object:Gem::Requirement
102
172
  requirements:
103
173
  - - "~>"
104
174
  - !ruby/object:Gem::Version
105
- version: '6.1'
175
+ version: '2.7'
106
176
  - - ">="
107
177
  - !ruby/object:Gem::Version
108
- version: 6.1.3.2
109
- description: Criar pagamentos PIX
178
+ version: 2.7.6
179
+ description: Fazer transferências via PIX
110
180
  email:
111
181
  - kimpastro@gmail.com
112
182
  executables: []
@@ -136,35 +206,40 @@ files:
136
206
  - lib/bs2_api/entities/pix_key.rb
137
207
  - lib/bs2_api/errors/bad_request.rb
138
208
  - lib/bs2_api/errors/base.rb
209
+ - lib/bs2_api/errors/confirmation_error.rb
210
+ - lib/bs2_api/errors/invalid_bank.rb
139
211
  - lib/bs2_api/errors/invalid_customer.rb
140
212
  - lib/bs2_api/errors/invalid_pix_key.rb
213
+ - lib/bs2_api/errors/missing_bank.rb
141
214
  - lib/bs2_api/errors/missing_configuration.rb
142
215
  - lib/bs2_api/errors/server_error.rb
143
216
  - lib/bs2_api/errors/unauthorized.rb
144
- - lib/bs2_api/initializers/hash.rb
145
- - lib/bs2_api/initializers/object.rb
146
217
  - lib/bs2_api/payment/base.rb
218
+ - lib/bs2_api/payment/confirmation.rb
147
219
  - lib/bs2_api/payment/key.rb
148
220
  - lib/bs2_api/payment/manual.rb
149
221
  - lib/bs2_api/request/auth.rb
150
222
  - lib/bs2_api/util/bank_service.rb
151
223
  - lib/bs2_api/util/banks.yml
152
224
  - lib/bs2_api/version.rb
153
- homepage: https://github.com/kimpastro/bs2_api
225
+ homepage: https://github.com/latamgateway/bs2_api
154
226
  licenses: []
155
227
  metadata:
156
- homepage_uri: https://github.com/kimpastro/bs2_api
157
- source_code_uri: https://github.com/kimpastro/bs2_api
158
- changelog_uri: https://github.com/kimpastro/bs2_api/blob/main/CHANGELOG.md
228
+ homepage_uri: https://github.com/latamgateway/bs2_api
229
+ source_code_uri: https://github.com/latamgateway/bs2_api
230
+ changelog_uri: https://github.com/latamgateway/bs2_api/blob/main/CHANGELOG.md
159
231
  post_install_message:
160
232
  rdoc_options: []
161
233
  require_paths:
162
234
  - lib
163
235
  required_ruby_version: !ruby/object:Gem::Requirement
164
236
  requirements:
165
- - - ">="
237
+ - - "~>"
238
+ - !ruby/object:Gem::Version
239
+ version: '2.7'
240
+ - - "<"
166
241
  - !ruby/object:Gem::Version
167
- version: 2.7.2
242
+ version: '3'
168
243
  required_rubygems_version: !ruby/object:Gem::Requirement
169
244
  requirements:
170
245
  - - ">="
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Hash
4
- def to_query
5
- keys.map do |key|
6
- "#{key}=#{self[key]}"
7
- end.join("&")
8
- end
9
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Object
4
- def blank?
5
- respond_to?(:empty?) ? !!empty? : !self
6
- end
7
-
8
- def present?
9
- !blank?
10
- end
11
- end