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 +4 -4
- data/CHANGELOG.md +12 -1
- data/Gemfile +1 -9
- data/Gemfile.lock +15 -23
- data/README.md +81 -83
- data/bs2_api.gemspec +17 -12
- data/lib/bs2_api.rb +14 -9
- data/lib/bs2_api/entities/account.rb +7 -2
- 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/missing_bank.rb +7 -0
- data/lib/bs2_api/payment/base.rb +31 -17
- data/lib/bs2_api/payment/confirmation.rb +38 -0
- data/lib/bs2_api/payment/manual.rb +1 -0
- data/lib/bs2_api/request/auth.rb +12 -11
- data/lib/bs2_api/util/bank_service.rb +3 -1
- data/lib/bs2_api/version.rb +1 -1
- metadata +114 -39
- data/lib/bs2_api/initializers/hash.rb +0 -9
- data/lib/bs2_api/initializers/object.rb +0 -11
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b2b8b144d4d8f5045e87461029c823e9b5f5a7c3d5a9191f1e39a542ac5d7400
|
|
4
|
+
data.tar.gz: c9bcf3bb230b56e8a0ac0d0e2d4373ec37a49869bc1918597b36dd57d1ff5bab
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d4a1c8e8823be43d5c6f8a69b4817552e58e3e1a82d81780ed3a181ecae7449d6da2f0235bda18d36b2632dc7e58d06346624690efc9ed6f1b46ef526167572f
|
|
7
|
+
data.tar.gz: 242287b0695c77833428867361fb1a469eb912ffa0b387c8443f8fbba3db23a2bdd4aa1dbc6e9e172084166fb087ff8fbe9ff19a0cdc6260a12449963ecc7e86
|
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,9 +1,12 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
bs2_api (0.2
|
|
5
|
-
activesupport
|
|
6
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
|
35
|
-
config.client_secret
|
|
36
|
-
config.
|
|
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
|
-
###
|
|
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
|
-
|
|
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
|
-
|
|
52
|
-
|
|
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
|
-
|
|
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:
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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:
|
|
74
|
-
type:
|
|
75
|
-
name:
|
|
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
|
-
|
|
79
|
-
account: account,
|
|
89
|
+
receiver_bank = Bs2Api::Entities::Bank.new(
|
|
90
|
+
account: account,
|
|
80
91
|
customer: customer
|
|
81
92
|
)
|
|
82
93
|
|
|
83
|
-
|
|
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
|
-
###
|
|
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
|
-
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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 = "
|
|
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,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.
|
|
30
|
-
spec.
|
|
31
|
-
spec.
|
|
32
|
-
spec.
|
|
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.
|
|
35
|
-
spec.
|
|
36
|
-
|
|
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
|
|
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":
|
|
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
|
data/lib/bs2_api/payment/base.rb
CHANGED
|
@@ -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 =
|
|
8
|
-
|
|
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
|
|
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
|
-
"
|
|
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
|
-
|
|
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
|
data/lib/bs2_api/request/auth.rb
CHANGED
|
@@ -9,22 +9,23 @@ module Bs2Api
|
|
|
9
9
|
|
|
10
10
|
response = create_session
|
|
11
11
|
|
|
12
|
-
raise Bs2Api::Errors::Unauthorized, response
|
|
13
|
-
raise Bs2Api::Errors::BadRequest, response
|
|
14
|
-
raise Bs2Api::Errors::ServerError, response.body
|
|
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
|
|
16
|
+
response["access_token"]
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
private
|
|
20
20
|
def create_session
|
|
21
|
-
|
|
22
|
-
user: Bs2Api.configuration.client_id,
|
|
23
|
-
pass: Bs2Api.configuration.client_secret
|
|
24
|
-
).post(
|
|
21
|
+
HTTParty.post(
|
|
25
22
|
auth_url,
|
|
26
|
-
|
|
27
|
-
|
|
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
|
data/lib/bs2_api/version.rb
CHANGED
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.
|
|
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-
|
|
11
|
+
date: 2021-06-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
14
|
+
name: builder
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - "
|
|
17
|
+
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
20
|
-
type: :
|
|
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: '
|
|
26
|
+
version: '0'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
|
-
name:
|
|
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:
|
|
34
|
-
type: :
|
|
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:
|
|
82
|
+
version: 0.18.1
|
|
41
83
|
- !ruby/object:Gem::Dependency
|
|
42
|
-
name:
|
|
84
|
+
name: pry-byebug
|
|
43
85
|
requirement: !ruby/object:Gem::Requirement
|
|
44
86
|
requirements:
|
|
45
87
|
- - "~>"
|
|
46
88
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: '
|
|
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: '
|
|
96
|
+
version: '3.9'
|
|
55
97
|
- !ruby/object:Gem::Dependency
|
|
56
|
-
name:
|
|
98
|
+
name: uuid
|
|
57
99
|
requirement: !ruby/object:Gem::Requirement
|
|
58
100
|
requirements:
|
|
59
101
|
- - "~>"
|
|
60
102
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '2.
|
|
103
|
+
version: '2.3'
|
|
62
104
|
- - ">="
|
|
63
105
|
- !ruby/object:Gem::Version
|
|
64
|
-
version: 2.
|
|
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.
|
|
113
|
+
version: '2.3'
|
|
72
114
|
- - ">="
|
|
73
115
|
- !ruby/object:Gem::Version
|
|
74
|
-
version: 2.
|
|
116
|
+
version: 2.3.9
|
|
75
117
|
- !ruby/object:Gem::Dependency
|
|
76
|
-
name:
|
|
118
|
+
name: rspec
|
|
77
119
|
requirement: !ruby/object:Gem::Requirement
|
|
78
120
|
requirements:
|
|
79
121
|
- - "~>"
|
|
80
122
|
- !ruby/object:Gem::Version
|
|
81
|
-
version: '
|
|
82
|
-
type: :
|
|
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: '
|
|
130
|
+
version: '3.10'
|
|
89
131
|
- !ruby/object:Gem::Dependency
|
|
90
|
-
name:
|
|
132
|
+
name: webmock
|
|
91
133
|
requirement: !ruby/object:Gem::Requirement
|
|
92
134
|
requirements:
|
|
93
135
|
- - "~>"
|
|
94
136
|
- !ruby/object:Gem::Version
|
|
95
|
-
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'
|
|
96
166
|
- - ">="
|
|
97
167
|
- !ruby/object:Gem::Version
|
|
98
|
-
version:
|
|
99
|
-
type: :
|
|
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: '
|
|
175
|
+
version: '2.7'
|
|
106
176
|
- - ">="
|
|
107
177
|
- !ruby/object:Gem::Version
|
|
108
|
-
version:
|
|
109
|
-
description:
|
|
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/
|
|
225
|
+
homepage: https://github.com/latamgateway/bs2_api
|
|
154
226
|
licenses: []
|
|
155
227
|
metadata:
|
|
156
|
-
homepage_uri: https://github.com/
|
|
157
|
-
source_code_uri: https://github.com/
|
|
158
|
-
changelog_uri: https://github.com/
|
|
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:
|
|
242
|
+
version: '3'
|
|
168
243
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
244
|
requirements:
|
|
170
245
|
- - ">="
|