bs2_api 0.2.1 → 0.3.4

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: 86300aea3210ea0f4a86d34cc062b75ec68e1315520b240c907b2ec0cf79cd62
4
- data.tar.gz: 3515768ebac73fec3704b59f332b4c2ddd09b71a33866682ea692409653e577f
3
+ metadata.gz: 83d1974407ed876b13a3c90b79f4ea2ac0d10f018671176974d0546c8cf37c16
4
+ data.tar.gz: 11ae325cfb8f34158df8cffc73bb97b44371b5c1092a3c45784fb9a947672d7c
5
5
  SHA512:
6
- metadata.gz: b6ff81648836152febb2a1faa2bf1e592c5e8f3a962e25d29782a6dc99dceddb74d906a83bdfe194c95f32c27b8b1ea1c92bde3d8917d4afeda07d23c1043a4e
7
- data.tar.gz: 4f195c7cc92db0bbddb6680e2cb54113c65350deeedce4c936a9a244b91b233dd703bcc36d86c8b22b574d214ac32732e94ca2f88573ab619a83405e66d42da6
6
+ metadata.gz: afa20659aead1ad39f6a5d8123d7d34a880b3379888c4a1f4357fea96805ba3aa5da8ad95da622dd06fa656b63f2e9c05082d75136dcfd30ac9d49f8914f97da
7
+ data.tar.gz: fc45ca9142c72de060b098e716c578a6a636ebab90bdd67627be66ec8fa00d9c2603c1e5efb8b5c6be0bba500f9dff68bdf89a85b0e11a580972fe0996e507c1
@@ -0,0 +1,34 @@
1
+ name: bs2_api test
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ types: [ opened, synchronize, reopened ]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ env:
13
+ BS2_ENVIRONMENT: 'sandbox'
14
+ BS2_CLIENT_ID: '123'
15
+ BS2_CLIENT_SECRET: '123'
16
+ BS2_EVP_TEST_KEY: '123'
17
+
18
+ strategy:
19
+ matrix:
20
+ ruby-version: ["2.7.2"]
21
+
22
+ steps:
23
+ - uses: actions/checkout@v2
24
+
25
+ - name: Set up Ruby
26
+ uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
27
+ with:
28
+ ruby-version: ${{ matrix.ruby-version }}
29
+
30
+ - name: Install dependencies
31
+ run: bundle install
32
+
33
+ - name: Run tests
34
+ run: bundle exec rspec spec/
data/CHANGELOG.md CHANGED
@@ -1,4 +1,10 @@
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
2
8
 
3
9
  ## [0.2.0] - 2021-06-15
4
10
 
data/Gemfile CHANGED
@@ -2,17 +2,4 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gemspec
6
-
7
- gem "rake", "~> 13.0"
8
- gem "httparty", "~> 0.18.1"
9
- gem "activesupport", "~> 6.1", ">= 6.1.3.2"
10
-
11
- group :test do
12
- gem "pry-byebug", "~> 3.9"
13
- gem "uuid", "~> 2.3", ">= 2.3.9"
14
- gem "rspec", "~> 3.10"
15
- gem "webmock", "~> 3.13"
16
- gem "vcr", "~> 6.0"
17
- gem "dotenv", "~> 2.7", ">= 2.7.6"
18
- end
5
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,8 +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)
4
+ bs2_api (0.3.4)
5
+ activesupport
6
+ builder
7
+ bundler
8
+ httparty (~> 0.18.1)
9
+ rake
6
10
 
7
11
  GEM
8
12
  remote: https://rubygems.org/
@@ -15,6 +19,7 @@ GEM
15
19
  zeitwerk (~> 2.3)
16
20
  addressable (2.7.0)
17
21
  public_suffix (>= 2.0.2, < 5.0)
22
+ builder (3.2.4)
18
23
  byebug (11.1.3)
19
24
  coderay (1.1.3)
20
25
  concurrent-ruby (1.1.9)
@@ -71,15 +76,13 @@ GEM
71
76
  zeitwerk (2.4.2)
72
77
 
73
78
  PLATFORMS
79
+ ruby
74
80
  x86_64-linux
75
81
 
76
82
  DEPENDENCIES
77
- activesupport (~> 6.1, >= 6.1.3.2)
78
83
  bs2_api!
79
84
  dotenv (~> 2.7, >= 2.7.6)
80
- httparty (~> 0.18.1)
81
85
  pry-byebug (~> 3.9)
82
- rake (~> 13.0)
83
86
  rspec (~> 3.10)
84
87
  uuid (~> 2.3, >= 2.3.9)
85
88
  vcr (~> 6.0)
data/README.md CHANGED
@@ -1,7 +1,24 @@
1
+ [![CI status](https://github.com/latamgateway/bs2_api/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/latamgateway/bs2_api/actions/workflows/test.yml)
2
+ [![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/latamgateway/bs2_api.svg?style=flat-square)](http://github.com/latamgateway/bs2_api/releases)
3
+ [![Version](https://img.shields.io/gem/v/bs2_api.svg?style=flat-square)](https://rubygems.org/gems/bs2_api)
4
+ [![GitHub](https://img.shields.io/github/license/latamgateway/bs2_api?style=flat-square)](https://github.com/latamgateway/bs2_api/blob/main/LICENSE)
5
+
1
6
  # Bs2Api
2
7
 
3
8
  Integração com a API do Banco BS2: https://devs.bs2.com/manual/pix-clientes
4
9
 
10
+ TO-DO:
11
+ - Pagamentos (**Transfere** dinheiro para alguém)
12
+ - [x] Criar pagamento por Chave
13
+ - [x] Criar pagamento Manual
14
+ - [x] Confirmar pagamento
15
+ - [ ] Consultar pagamento
16
+ - Recebimentos (**Recebe** dinheiro de alguém)
17
+ - [ ] Cobrança estático
18
+ - [ ] Cobrança dinâmico
19
+ - [ ] Consultar cobrança
20
+
21
+
5
22
  ## Instalação
6
23
 
7
24
  Adicionar no seu Gemfile:
@@ -31,13 +48,13 @@ ou via initializer:
31
48
 
32
49
  ```ruby
33
50
  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'
51
+ config.client_id = 'you_bs2_client_id'
52
+ config.client_secret = 'you_bs2_client_secret'
53
+ config.env = 'sandbox' # ou production
37
54
  end
38
55
  ```
39
56
 
40
- ### Iniciar pagamento por Chave
57
+ ### Inicia ordem de Transferência PIX via: Chave
41
58
 
42
59
  ```ruby
43
60
  pix_key = Bs2Api::Entities::PixKey.new(
@@ -45,100 +62,88 @@ pix_key = Bs2Api::Entities::PixKey.new(
45
62
  type: 'EMAIL'
46
63
  )
47
64
 
48
- payment = Bs2Api::Payment::Key.new(pix_key).call
49
- ```
65
+ # Caso ocorra algum problema na criação, um erro será lançado
66
+ # Veja abaixo (Classes de errors) quais erros que podem ser lançados
67
+ pay_key = Bs2Api::Payment::Key.new(pix_key).call
50
68
 
51
- Tipos:
52
- ```bash
53
- CPF
54
- CNPJ
55
- PHONE
56
- EMAIL
57
- EVP (Chave aleatória)
58
- ```
69
+ pay_key.payment.id
70
+ => "96f0b3c4-4c76-4a7a-9933-9c9f86df7490" # pagamentoId gerado no BS2
59
71
 
72
+ pay_key.payment.merchant_id
73
+ => "E710278662021061618144401750781P" # endToEndId gerado no BS2
60
74
 
61
- ### Iniciar pagamento Manual
75
+ ```
76
+
77
+ ### Inicia ordem de Transferência PIX via: Manual
62
78
 
63
79
  ```ruby
64
80
  account = Bs2Api::Entities::Account.new(
65
- bank_code: '341',
66
- bank_name: 'Itaú',
67
- agency: '0944',
68
- number: '09442-1',
69
- type: 'ContaCorrente'
81
+ bank_code: "218",
82
+ agency: "0993",
83
+ number: "042312",
84
+ type: "ContaCorrente" # ContaCorrente, ContaSalario ou Poupanca
70
85
  )
71
86
 
72
87
  customer = Bs2Api::Entities::Customer.new(
73
- document: '88899988811',
74
- type: 'CPF',
75
- name: 'João Silva'
88
+ document: "88899988811",
89
+ type: "CPF",
90
+ name: "Rick Sanches",
91
+ business_name: "Nome fantasia" # Utilizar apenas se for type CNPJ
76
92
  )
77
93
 
78
- receiver = Bs2Api::Entities::Bank.new(
79
- account: account,
94
+ receiver_bank = Bs2Api::Entities::Bank.new(
95
+ account: account,
80
96
  customer: customer
81
97
  )
82
98
 
83
- payment = Bs2Api::Payment::Manual.new(receiver).call
99
+ pay_manual = Bs2Api::Payment::Manual.new(receiver_bank).call
100
+
101
+ pay_manual.payment.id
102
+ => "96f0b3c4-4c76-4a7a-9933-9c9f86df7490" # UUID gerado no BS2
103
+
104
+ pay_manual.payment.merchantId
105
+ => "E710278662021061618144401750781P" # endToEndId gerado no BS2
84
106
  ```
85
107
 
86
- ### Objetos
108
+ ### Confirmar ordem de transferência
109
+ Após criar um Payment é necessário confirmar, nessa etapa o dinheiro é de fato transferido.
110
+ Nessa etapa é necessário **informar o valor** que deseja ser transferido.
87
111
 
88
- ##### Payment
89
112
  ```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
- ```
113
+
114
+ # Ambos modelos de criação da ordem de pagamento possuem o mesmo objeto payment
115
+ # podendo ser utilizado da mesma forma nos dois casos:
116
+ # pay_key.payment ou pay_manual.payment
117
+
118
+ payment = pay_key.payment
119
+ amount = 10.50
120
+
121
+ confirmation = Bs2Api::Payment::Confirmation.new(payment, value: amount).call
122
+
123
+ # Caso a confirmação dê problema, um erro será lançado.
124
+ raise Bs2Api::Errors::ConfirmationError
125
+
126
+ # Caso nenhum erro seja lançado significa que foi sucesso. Você pode ter certeza com
127
+ confirmation.success?
128
+ ```
129
+
130
+ ### Classes de erros:
131
+ ```ruby
132
+ # Todos erros herdam de:
133
+ Bs2Api::Errors::Base
134
+
135
+ # Errors possíveis de serem lançados
136
+ Bs2Api::Errors::BadRequest
137
+ Bs2Api::Errors::ConfirmationError
138
+ Bs2Api::Errors::InvalidCustomer
139
+ Bs2Api::Errors::InvalidPixKey
140
+ Bs2Api::Errors::MissingConfiguration
141
+ Bs2Api::Errors::ServerError
142
+ Bs2Api::Errors::Unauthorized
143
+ ```
144
+
145
+ ---
146
+
147
+ ### Observações
148
+ - Método `call` retorna o próprio objeto
149
+ - Em caso de retorno diferente de sucesso na comunicação com a API do Bs2, um erro sempre será lançado.
data/bs2_api.gemspec CHANGED
@@ -9,13 +9,15 @@ 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
+
16
+ spec.license = "MIT"
15
17
 
16
18
  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"
19
+ spec.metadata["source_code_uri"] = "https://github.com/latamgateway/bs2_api"
20
+ spec.metadata["changelog_uri"] = "https://github.com/latamgateway/bs2_api/blob/main/CHANGELOG.md"
19
21
 
20
22
  # Specify which files should be added to the gem when it is released.
21
23
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -26,5 +28,16 @@ Gem::Specification.new do |spec|
26
28
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
29
  spec.require_paths = ["lib"]
28
30
 
29
- spec.add_dependency "activesupport", "~> 6.1", ">= 6.1.3.2"
30
- end
31
+ spec.add_dependency("builder")
32
+ spec.add_dependency("bundler")
33
+ spec.add_dependency("rake")
34
+ spec.add_dependency("activesupport")
35
+ spec.add_dependency("httparty", "~> 0.18.1")
36
+
37
+ spec.add_development_dependency("pry-byebug", "~> 3.9")
38
+ spec.add_development_dependency("uuid", "~> 2.3", ">= 2.3.9")
39
+ spec.add_development_dependency("rspec", "~> 3.10")
40
+ spec.add_development_dependency("webmock", "~> 3.13")
41
+ spec.add_development_dependency("vcr", "~> 6.0")
42
+ spec.add_development_dependency("dotenv", "~> 2.7", ">= 2.7.6")
43
+ end
data/lib/bs2_api.rb CHANGED
@@ -1,19 +1,26 @@
1
1
  # frozen_string_literal: true
2
- require 'httparty'
2
+ require "httparty"
3
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"
4
7
 
5
8
  require 'bs2_api/version'
6
9
  require 'bs2_api/configuration'
7
10
 
8
- require 'bs2_api/initializers/object'
9
- require 'bs2_api/initializers/hash'
11
+ require 'bs2_api/util/bank_service'
12
+ require 'bs2_api/util/response'
10
13
 
11
14
  require 'bs2_api/errors/base'
12
15
  require 'bs2_api/errors/invalid_pix_key'
16
+ require 'bs2_api/errors/invalid_bank'
17
+ require 'bs2_api/errors/invalid_customer'
13
18
  require 'bs2_api/errors/missing_configuration'
14
19
  require 'bs2_api/errors/unauthorized'
15
20
  require 'bs2_api/errors/bad_request'
16
21
  require 'bs2_api/errors/server_error'
22
+ require 'bs2_api/errors/confirmation_error'
23
+ require 'bs2_api/errors/missing_bank'
17
24
 
18
25
  require 'bs2_api/entities/account'
19
26
  require 'bs2_api/entities/bank'
@@ -24,14 +31,13 @@ require 'bs2_api/entities/pix_key'
24
31
  require 'bs2_api/payment/base'
25
32
  require 'bs2_api/payment/key'
26
33
  require 'bs2_api/payment/manual'
34
+ require 'bs2_api/payment/confirmation'
27
35
 
28
36
  require 'bs2_api/request/auth'
29
37
 
30
- require 'bs2_api/util/bank_service'
31
-
32
38
  module Bs2Api
33
39
  ENDPOINT = {
34
- production: 'https://api.bs2.com:8443',
40
+ production: 'https://api.bs2.com',
35
41
  sandbox: 'https://apihmz.bancobonsucesso.com.br'
36
42
  }
37
43
 
@@ -41,7 +47,7 @@ module Bs2Api
41
47
  def configuration
42
48
  @configuration ||= Configuration.new
43
49
  end
44
-
50
+
45
51
  def configure
46
52
  yield(configuration)
47
53
  end
@@ -53,7 +59,7 @@ module Bs2Api
53
59
  def production?
54
60
  env == 'production'
55
61
  end
56
-
62
+
57
63
  def sandbox?
58
64
  env == 'sandbox'
59
65
  end
@@ -62,4 +68,4 @@ module Bs2Api
62
68
  configuration.env
63
69
  end
64
70
  end
65
- end
71
+ end
@@ -11,5 +11,7 @@ class Configuration
11
11
 
12
12
  def valid?
13
13
  raise Bs2Api::Errors::MissingConfiguration, 'Missing configuration credentials' if @client_id.blank? || @client_secret.blank?
14
+
15
+ true
14
16
  end
15
17
  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,11 +1,18 @@
1
1
  module Bs2Api
2
2
  module Payment
3
3
  class Base
4
+ attr_reader :payment
5
+
6
+ def initialize
7
+ raise NoMethodError, "Missing #{__method__} to #{self.class}"
8
+ end
9
+
4
10
  def call
5
11
  response = post_request
6
-
7
- raise Bs2Api::Errors::BadRequest, parse_error(response) if !response.created?
8
- Bs2Api::Entities::Payment.from_response(response)
12
+ raise Bs2Api::Errors::BadRequest, ::Util::Response.parse_error(response) unless response.created?
13
+
14
+ @payment = Bs2Api::Entities::Payment.from_response(response)
15
+ self
9
16
  end
10
17
 
11
18
  private
@@ -25,21 +32,6 @@ module Bs2Api
25
32
  Bs2Api::Request::Auth.token
26
33
  end
27
34
 
28
- def parse_error(response)
29
- hash = JSON.parse(response.body)
30
- message = "#{response.code}: "
31
-
32
- if hash.is_a?(Array)
33
- message << hash[0]["descricao"]
34
- elsif hash.key?("error_description")
35
- message << hash["error_description"]
36
- else
37
- message << hash.to_s
38
- end
39
-
40
- message
41
- end
42
-
43
35
  def payload
44
36
  raise NoMethodError, "Missing #{__method__} to #{self.class}"
45
37
  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, ::Util::Response.parse_error(response) unless response.accepted?
17
+
18
+ @success = true
19
+ self
20
+ end
21
+
22
+ def success?
23
+ !!@success
24
+ end
25
+
26
+ private
27
+ def payload
28
+ @payment.to_hash
29
+ .except!("pagamentoId", "endToEndId")
30
+ .merge("valor": @value)
31
+ end
32
+
33
+ def url
34
+ "#{Bs2Api.endpoint}/pix/direto/forintegration/v1/pagamentos/#{@payment.id}/confirmacao"
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
 
@@ -39,7 +39,7 @@ module Bs2Api
39
39
  def body
40
40
  {
41
41
  grant_type: "client_credentials",
42
- scope: "pix.write%20pix.read"
42
+ scope: "pix.write pix.read"
43
43
  }.to_query
44
44
  end
45
45
 
@@ -49,4 +49,4 @@ module Bs2Api
49
49
  end
50
50
  end
51
51
  end
52
- 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
@@ -0,0 +1,20 @@
1
+ module Util
2
+ class Response
3
+ class << self
4
+ def parse_error res
5
+ hash = JSON.parse(res.body)
6
+ message = "#{res.code}: "
7
+
8
+ if hash.is_a?(Array)
9
+ message << hash[0]["descricao"]
10
+ elsif hash.key?("error_description")
11
+ message << hash["error_description"]
12
+ else
13
+ message << hash.to_s
14
+ end
15
+
16
+ message
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bs2Api
4
- VERSION = "0.2.1"
4
+ VERSION = "0.3.4"
5
5
  end
metadata CHANGED
@@ -1,36 +1,182 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bs2_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.4
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-16 00:00:00.000000000 Z
11
+ date: 2021-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: builder
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
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'
13
55
  - !ruby/object:Gem::Dependency
14
56
  name: activesupport
15
57
  requirement: !ruby/object:Gem::Requirement
16
58
  requirements:
17
- - - "~>"
59
+ - - ">="
18
60
  - !ruby/object:Gem::Version
19
- version: '6.1'
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
20
66
  - - ">="
21
67
  - !ruby/object:Gem::Version
22
- version: 6.1.3.2
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: httparty
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.18.1
23
76
  type: :runtime
24
77
  prerelease: false
25
78
  version_requirements: !ruby/object:Gem::Requirement
26
79
  requirements:
27
80
  - - "~>"
28
81
  - !ruby/object:Gem::Version
29
- version: '6.1'
82
+ version: 0.18.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.9'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.9'
97
+ - !ruby/object:Gem::Dependency
98
+ name: uuid
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.3'
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: 2.3.9
107
+ type: :development
108
+ prerelease: false
109
+ version_requirements: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - "~>"
112
+ - !ruby/object:Gem::Version
113
+ version: '2.3'
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: 2.3.9
117
+ - !ruby/object:Gem::Dependency
118
+ name: rspec
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '3.10'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '3.10'
131
+ - !ruby/object:Gem::Dependency
132
+ name: webmock
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
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'
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: 2.7.6
169
+ type: :development
170
+ prerelease: false
171
+ version_requirements: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - "~>"
174
+ - !ruby/object:Gem::Version
175
+ version: '2.7'
30
176
  - - ">="
31
177
  - !ruby/object:Gem::Version
32
- version: 6.1.3.2
33
- description: Criar pagamentos PIX
178
+ version: 2.7.6
179
+ description: Fazer transferências via PIX
34
180
  email:
35
181
  - kimpastro@gmail.com
36
182
  executables: []
@@ -38,6 +184,7 @@ extensions: []
38
184
  extra_rdoc_files: []
39
185
  files:
40
186
  - ".env.example"
187
+ - ".github/workflows/test.yml"
41
188
  - ".gitignore"
42
189
  - ".rspec"
43
190
  - ".ruby-version"
@@ -60,35 +207,42 @@ files:
60
207
  - lib/bs2_api/entities/pix_key.rb
61
208
  - lib/bs2_api/errors/bad_request.rb
62
209
  - lib/bs2_api/errors/base.rb
210
+ - lib/bs2_api/errors/confirmation_error.rb
211
+ - lib/bs2_api/errors/invalid_bank.rb
63
212
  - lib/bs2_api/errors/invalid_customer.rb
64
213
  - lib/bs2_api/errors/invalid_pix_key.rb
214
+ - lib/bs2_api/errors/missing_bank.rb
65
215
  - lib/bs2_api/errors/missing_configuration.rb
66
216
  - lib/bs2_api/errors/server_error.rb
67
217
  - lib/bs2_api/errors/unauthorized.rb
68
- - lib/bs2_api/initializers/hash.rb
69
- - lib/bs2_api/initializers/object.rb
70
218
  - lib/bs2_api/payment/base.rb
219
+ - lib/bs2_api/payment/confirmation.rb
71
220
  - lib/bs2_api/payment/key.rb
72
221
  - lib/bs2_api/payment/manual.rb
73
222
  - lib/bs2_api/request/auth.rb
74
223
  - lib/bs2_api/util/bank_service.rb
75
224
  - lib/bs2_api/util/banks.yml
225
+ - lib/bs2_api/util/response.rb
76
226
  - lib/bs2_api/version.rb
77
- homepage: https://github.com/kimpastro/bs2_api
78
- licenses: []
227
+ homepage: https://github.com/latamgateway/bs2_api
228
+ licenses:
229
+ - MIT
79
230
  metadata:
80
- homepage_uri: https://github.com/kimpastro/bs2_api
81
- source_code_uri: https://github.com/kimpastro/bs2_api
82
- changelog_uri: https://github.com/kimpastro/bs2_api/blob/main/CHANGELOG.md
231
+ homepage_uri: https://github.com/latamgateway/bs2_api
232
+ source_code_uri: https://github.com/latamgateway/bs2_api
233
+ changelog_uri: https://github.com/latamgateway/bs2_api/blob/main/CHANGELOG.md
83
234
  post_install_message:
84
235
  rdoc_options: []
85
236
  require_paths:
86
237
  - lib
87
238
  required_ruby_version: !ruby/object:Gem::Requirement
88
239
  requirements:
89
- - - ">="
240
+ - - "~>"
241
+ - !ruby/object:Gem::Version
242
+ version: '2.7'
243
+ - - "<"
90
244
  - !ruby/object:Gem::Version
91
- version: 2.7.2
245
+ version: '3'
92
246
  required_rubygems_version: !ruby/object:Gem::Requirement
93
247
  requirements:
94
248
  - - ">="
@@ -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