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 +4 -4
- data/.env.example +3 -0
- data/.gitignore +4 -0
- data/CHANGELOG.md +12 -1
- data/Gemfile +1 -4
- data/Gemfile.lock +57 -23
- data/Makefile +2 -0
- data/README.md +122 -15
- data/bin/setup +1 -3
- data/bs2_api.gemspec +18 -8
- data/lib/bs2_api.rb +66 -2
- data/lib/bs2_api/configuration.rb +15 -0
- data/lib/bs2_api/entities/account.rb +64 -0
- data/lib/bs2_api/entities/bank.rb +40 -0
- data/lib/bs2_api/entities/customer.rb +51 -0
- data/lib/bs2_api/entities/payment.rb +38 -0
- data/lib/bs2_api/entities/pix_key.rb +40 -0
- data/lib/bs2_api/errors/bad_request.rb +7 -0
- data/lib/bs2_api/errors/base.rb +7 -0
- data/lib/bs2_api/errors/confirmation_error.rb +7 -0
- data/lib/bs2_api/errors/invalid_bank.rb +7 -0
- data/lib/bs2_api/errors/invalid_customer.rb +7 -0
- data/lib/bs2_api/errors/invalid_pix_key.rb +7 -0
- data/lib/bs2_api/errors/missing_bank.rb +7 -0
- data/lib/bs2_api/errors/missing_configuration.rb +7 -0
- data/lib/bs2_api/errors/server_error.rb +7 -0
- data/lib/bs2_api/errors/unauthorized.rb +7 -0
- data/lib/bs2_api/initializers/hash.rb +9 -0
- data/lib/bs2_api/initializers/object.rb +11 -0
- data/lib/bs2_api/payment/base.rb +59 -0
- data/lib/bs2_api/payment/confirmation.rb +38 -0
- data/lib/bs2_api/payment/key.rb +22 -0
- data/lib/bs2_api/payment/manual.rb +23 -0
- data/lib/bs2_api/request/auth.rb +52 -0
- data/lib/bs2_api/util/bank_service.rb +22 -0
- data/lib/bs2_api/util/banks.yml +393 -0
- data/lib/bs2_api/version.rb +1 -1
- metadata +181 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9153997d692126d6fbbc902507f8a62f95feb214c2b6c815507ebbb82981e9aa
|
4
|
+
data.tar.gz: 413f69f983087e627979be0e5223688c03452e78aacc2becd913ac1c135ff169
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b667b6c8cf9d321077a6055442bf5fc5632f3a61fcc6cfaf092d42472901450ab3ce079422744a8375591946d54100412ba4002d56b3ef18fff48d74125f5f50
|
7
|
+
data.tar.gz: 84092195a3e63e5d99419bf92631361a7abcbbc94f39332d5769990ea331a2569a1bb822a8187f19cc50774101aad26a9077ae1cb4c9f552d02e19753628130b
|
data/.env.example
ADDED
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,15 @@
|
|
1
|
-
## [
|
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
data/Gemfile.lock
CHANGED
@@ -1,34 +1,55 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
bs2_api (0.
|
5
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
46
|
-
|
47
|
-
|
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
|
-
|
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
data/README.md
CHANGED
@@ -1,35 +1,142 @@
|
|
1
1
|
# Bs2Api
|
2
2
|
|
3
|
-
|
3
|
+
Integração com a API do Banco BS2: https://devs.bs2.com/manual/pix-clientes
|
4
4
|
|
5
|
-
|
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
|
-
|
17
|
+
## Instalação
|
10
18
|
|
19
|
+
Adicionar no seu Gemfile:
|
11
20
|
```ruby
|
12
21
|
gem 'bs2_api'
|
13
22
|
```
|
14
23
|
|
15
|
-
|
24
|
+
E então execute:
|
25
|
+
```bash
|
26
|
+
bundle install
|
27
|
+
```
|
16
28
|
|
17
|
-
|
29
|
+
Ou instale diretamente via:
|
30
|
+
```bash
|
31
|
+
gem install bs2_api
|
32
|
+
```
|
18
33
|
|
19
|
-
|
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
|
-
|
42
|
+
ou via initializer:
|
22
43
|
|
23
|
-
|
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
|
-
|
52
|
+
### Inicia ordem de Transferência PIX via: Chave
|
26
53
|
|
27
|
-
|
54
|
+
```ruby
|
55
|
+
pix_key = Bs2Api::Entities::PixKey.new(
|
56
|
+
key: 'joao@gmail.com',
|
57
|
+
type: 'EMAIL'
|
58
|
+
)
|
28
59
|
|
29
|
-
|
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
|
-
|
64
|
+
pay_key.payment.id
|
65
|
+
=> "96f0b3c4-4c76-4a7a-9933-9c9f86df7490" # pagamentoId gerado no BS2
|
32
66
|
|
33
|
-
|
67
|
+
pay_key.payment.merchantId
|
68
|
+
=> "E710278662021061618144401750781P" # endToEndId gerado no BS2
|
34
69
|
|
35
|
-
|
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
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 = "
|
13
|
-
spec.homepage = "https://github.com/
|
14
|
-
spec.required_ruby_version = "
|
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/
|
18
|
-
spec.metadata["changelog_uri"] = "https://github.com/
|
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.
|
30
|
-
spec.add_dependency
|
31
|
-
|
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
|
-
|
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
|
-
|
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
|