bs2_api 0.1.0 → 0.3.2

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: 9c1e001ddc04c41bef41d3e70d36e8855ccbf8c2f798bcf780053d0e832e924b
4
- data.tar.gz: 5eb113c82664566db0fbc4ac9ade7023a55ff7cf7f44820fb7965ec132fc3922
3
+ metadata.gz: 9153997d692126d6fbbc902507f8a62f95feb214c2b6c815507ebbb82981e9aa
4
+ data.tar.gz: 413f69f983087e627979be0e5223688c03452e78aacc2becd913ac1c135ff169
5
5
  SHA512:
6
- metadata.gz: cc1f09dbd72fe994bf3703eb57244cea11ee52cdc83f0b96277af64bb8c385fbf0b1f692d3d513202847fa359c1a336ba17aa1e2df5cb02966e83099718c5442
7
- data.tar.gz: 0ab3b8f4202173d42d3ddcef476489e1378f05df4d4d9c632c7141617385e0592e7f15a1615920c8af5c8fd4d3d87c52f59781c361a340ce83a609c2cd4de25c
6
+ metadata.gz: b667b6c8cf9d321077a6055442bf5fc5632f3a61fcc6cfaf092d42472901450ab3ce079422744a8375591946d54100412ba4002d56b3ef18fff48d74125f5f50
7
+ data.tar.gz: 84092195a3e63e5d99419bf92631361a7abcbbc94f39332d5769990ea331a2569a1bb822a8187f19cc50774101aad26a9077ae1cb4c9f552d02e19753628130b
data/.env.example ADDED
@@ -0,0 +1,3 @@
1
+ BS2_ENVIRONMENT=sandbox
2
+ BS2_CLIENT_ID=123
3
+ BS2_CLIENT_SECRET=123
data/.gitignore CHANGED
@@ -9,3 +9,7 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+
13
+ *.gem
14
+
15
+ .env.test
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,7 +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"
5
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,34 +1,55 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bs2_api (0.1.0)
5
- http (~> 5.0)
4
+ bs2_api (0.3.0)
5
+ activesupport
6
+ builder
7
+ bundler
8
+ httparty (~> 0.18.1)
9
+ rake
6
10
 
7
11
  GEM
8
12
  remote: https://rubygems.org/
9
13
  specs:
14
+ activesupport (6.1.3.2)
15
+ concurrent-ruby (~> 1.0, >= 1.0.2)
16
+ i18n (>= 1.6, < 2)
17
+ minitest (>= 5.1)
18
+ tzinfo (~> 2.0)
19
+ zeitwerk (~> 2.3)
10
20
  addressable (2.7.0)
11
21
  public_suffix (>= 2.0.2, < 5.0)
22
+ builder (3.2.4)
23
+ byebug (11.1.3)
24
+ coderay (1.1.3)
25
+ concurrent-ruby (1.1.9)
26
+ crack (0.4.5)
27
+ rexml
12
28
  diff-lcs (1.4.4)
13
- domain_name (0.5.20190701)
14
- unf (>= 0.0.5, < 1.0.0)
15
- ffi (1.15.1)
16
- ffi-compiler (1.0.1)
17
- ffi (>= 1.0.0)
18
- rake
19
- http (5.0.0)
20
- addressable (~> 2.3)
21
- http-cookie (~> 1.0)
22
- http-form_data (~> 2.2)
23
- llhttp-ffi (~> 0.0.1)
24
- http-cookie (1.0.4)
25
- domain_name (~> 0.5)
26
- http-form_data (2.3.0)
27
- llhttp-ffi (0.0.1)
28
- ffi-compiler (~> 1.0)
29
- rake (~> 13.0)
29
+ dotenv (2.7.6)
30
+ hashdiff (1.0.1)
31
+ httparty (0.18.1)
32
+ mime-types (~> 3.0)
33
+ multi_xml (>= 0.5.2)
34
+ i18n (1.8.10)
35
+ concurrent-ruby (~> 1.0)
36
+ macaddr (1.7.2)
37
+ systemu (~> 2.6.5)
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)
42
+ minitest (5.14.4)
43
+ multi_xml (0.6.0)
44
+ pry (0.13.1)
45
+ coderay (~> 1.1)
46
+ method_source (~> 1.0)
47
+ pry-byebug (3.9.0)
48
+ byebug (~> 11.0)
49
+ pry (~> 0.13.0)
30
50
  public_suffix (4.0.6)
31
51
  rake (13.0.3)
52
+ rexml (3.2.5)
32
53
  rspec (3.10.0)
33
54
  rspec-core (~> 3.10.0)
34
55
  rspec-expectations (~> 3.10.0)
@@ -42,17 +63,30 @@ GEM
42
63
  diff-lcs (>= 1.2.0, < 2.0)
43
64
  rspec-support (~> 3.10.0)
44
65
  rspec-support (3.10.2)
45
- unf (0.1.4)
46
- unf_ext
47
- unf_ext (0.0.7.7)
66
+ systemu (2.6.5)
67
+ tzinfo (2.0.4)
68
+ concurrent-ruby (~> 1.0)
69
+ uuid (2.3.9)
70
+ macaddr (~> 1.0)
71
+ vcr (6.0.0)
72
+ webmock (3.13.0)
73
+ addressable (>= 2.3.6)
74
+ crack (>= 0.3.2)
75
+ hashdiff (>= 0.4.0, < 2.0.0)
76
+ zeitwerk (2.4.2)
48
77
 
49
78
  PLATFORMS
79
+ ruby
50
80
  x86_64-linux
51
81
 
52
82
  DEPENDENCIES
53
83
  bs2_api!
54
- rake (~> 13.0)
84
+ dotenv (~> 2.7, >= 2.7.6)
85
+ pry-byebug (~> 3.9)
55
86
  rspec (~> 3.10)
87
+ uuid (~> 2.3, >= 2.3.9)
88
+ vcr (~> 6.0)
89
+ webmock (~> 3.13)
56
90
 
57
91
  BUNDLED WITH
58
92
  2.2.18
data/Makefile ADDED
@@ -0,0 +1,2 @@
1
+ console:
2
+ ruby bin/console
data/README.md CHANGED
@@ -1,35 +1,142 @@
1
1
  # Bs2Api
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/bs2_api`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Integração com a API do Banco BS2: https://devs.bs2.com/manual/pix-clientes
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
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
6
15
 
7
- ## Installation
8
16
 
9
- Add this line to your application's Gemfile:
17
+ ## Instalação
10
18
 
19
+ Adicionar no seu Gemfile:
11
20
  ```ruby
12
21
  gem 'bs2_api'
13
22
  ```
14
23
 
15
- And then execute:
24
+ E então execute:
25
+ ```bash
26
+ bundle install
27
+ ```
16
28
 
17
- $ bundle install
29
+ Ou instale diretamente via:
30
+ ```bash
31
+ gem install bs2_api
32
+ ```
18
33
 
19
- Or install it yourself as:
34
+ ### Configuração
35
+ Via variável de ambiente:
36
+ ```bash
37
+ BS2_CLIENT_ID
38
+ BS2_CLIENT_SECRET
39
+ BS2_CLIENT_ENVIRONMENT # production or sandbox. Default to sandbox
40
+ ```
20
41
 
21
- $ gem install bs2_api
42
+ ou via initializer:
22
43
 
23
- ## Usage
44
+ ```ruby
45
+ Bs2Api.configure do |config|
46
+ config.client_id = 'you_bs2_client_id'
47
+ config.client_secret = 'you_bs2_client_secret'
48
+ config.env = 'sandbox' # ou production
49
+ end
50
+ ```
24
51
 
25
- TODO: Write usage instructions here
52
+ ### Inicia ordem de Transferência PIX via: Chave
26
53
 
27
- ## Development
54
+ ```ruby
55
+ pix_key = Bs2Api::Entities::PixKey.new(
56
+ key: 'joao@gmail.com',
57
+ type: 'EMAIL'
58
+ )
28
59
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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
30
63
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
64
+ pay_key.payment.id
65
+ => "96f0b3c4-4c76-4a7a-9933-9c9f86df7490" # pagamentoId gerado no BS2
32
66
 
33
- ## Contributing
67
+ pay_key.payment.merchantId
68
+ => "E710278662021061618144401750781P" # endToEndId gerado no BS2
34
69
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/bs2_api.
70
+ ```
71
+
72
+ ### Inicia ordem de Transferência PIX via: Manual
73
+
74
+ ```ruby
75
+ account = Bs2Api::Entities::Account.new(
76
+ bank_code: "218",
77
+ agency: "0993",
78
+ number: "042312",
79
+ type: "ContaCorrente" # ContaCorrente, ContaSalario ou Poupanca
80
+ )
81
+
82
+ customer = Bs2Api::Entities::Customer.new(
83
+ document: "88899988811",
84
+ type: "CPF",
85
+ name: "Rick Sanches",
86
+ business_name: "Nome fantasia" # Utilizar apenas se for type CNPJ
87
+ )
88
+
89
+ receiver_bank = Bs2Api::Entities::Bank.new(
90
+ account: account,
91
+ customer: customer
92
+ )
93
+
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
101
+ ```
102
+
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
117
+
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:
126
+ ```ruby
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/bin/setup CHANGED
@@ -3,6 +3,4 @@ set -euo pipefail
3
3
  IFS=$'\n\t'
4
4
  set -vx
5
5
 
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
6
+ bundle install
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,6 +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_dependency "http", "~> 5.0"
31
- end
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")
34
+
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,7 +1,71 @@
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"
2
5
 
3
- require_relative "bs2_api/version"
6
+ require 'bs2_api/version'
7
+ require 'bs2_api/configuration'
8
+
9
+ require 'bs2_api/initializers/object'
10
+ require 'bs2_api/initializers/hash'
11
+
12
+ require 'bs2_api/errors/base'
13
+ require 'bs2_api/errors/invalid_pix_key'
14
+ require 'bs2_api/errors/invalid_bank'
15
+ require 'bs2_api/errors/invalid_customer'
16
+ require 'bs2_api/errors/missing_configuration'
17
+ require 'bs2_api/errors/unauthorized'
18
+ require 'bs2_api/errors/bad_request'
19
+ require 'bs2_api/errors/server_error'
20
+ require 'bs2_api/errors/confirmation_error'
21
+ require 'bs2_api/errors/missing_bank'
22
+
23
+ require 'bs2_api/entities/account'
24
+ require 'bs2_api/entities/bank'
25
+ require 'bs2_api/entities/customer'
26
+ require 'bs2_api/entities/payment'
27
+ require 'bs2_api/entities/pix_key'
28
+
29
+ require 'bs2_api/payment/base'
30
+ require 'bs2_api/payment/key'
31
+ require 'bs2_api/payment/manual'
32
+ require 'bs2_api/payment/confirmation'
33
+
34
+ require 'bs2_api/request/auth'
35
+
36
+ require 'bs2_api/util/bank_service'
4
37
 
5
38
  module Bs2Api
6
- class Bs2ApiError < StandardError; end
39
+ ENDPOINT = {
40
+ production: 'https://api.bs2.com',
41
+ sandbox: 'https://apihmz.bancobonsucesso.com.br'
42
+ }
43
+
44
+ class << self
45
+ attr_writer :configuration
46
+
47
+ def configuration
48
+ @configuration ||= Configuration.new
49
+ end
50
+
51
+ def configure
52
+ yield(configuration)
53
+ end
54
+
55
+ def endpoint
56
+ ENDPOINT[configuration.env.to_sym]
57
+ end
58
+
59
+ def production?
60
+ env == 'production'
61
+ end
62
+
63
+ def sandbox?
64
+ env == 'sandbox'
65
+ end
66
+
67
+ def env
68
+ configuration.env
69
+ end
70
+ end
7
71
  end