solidus_inter 2.0.0 → 3.0.0
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/README.md +143 -7
- data/app/models/solidus_inter/inter_client.rb +56 -0
- data/app/models/solidus_inter/inter_pix.rb +114 -67
- data/app/models/solidus_inter/pix_payment_source.rb +5 -22
- data/lib/solidus_inter/version.rb +1 -1
- data/lib/solidus_inter.rb +1 -0
- metadata +20 -5
- data/app/models/solidus_inter/account.rb +0 -5
- data/app/models/solidus_inter/gateway.rb +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb69e01d4ea7ac6966c62d12bfc5f344271ebf3530aeb945e51b4c58a68e2f20
|
4
|
+
data.tar.gz: 5e8782241005478d0ffd5f18d11deeb569e403f8af2a50977067efcb788e0e2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afbb51c72beef7e6e65469ea80008847d4374bc542defccb666f9e281049f7eaa394ac1730312e8f21224312a9fe0c66a6113fdef2da22482ec00c682e2dc686
|
7
|
+
data.tar.gz: d2ef37846e2c3930ff777d275369a9cbf568b2a25ed038d14013ddf82f7a3cffcb5c672f5e7f4d5df5f8df4d4ad7b6aaf27d700219c1fb85a8f326bf8fa4cf99
|
data/README.md
CHANGED
@@ -1,16 +1,152 @@
|
|
1
|
-
#
|
2
|
-
<!-- Explain what your extension does. -->
|
1
|
+
# SolidusInter
|
3
2
|
|
4
|
-
|
3
|
+
Integração do Banco Inter com o Solidus para pagamentos via PIX.
|
5
4
|
|
6
|
-
|
5
|
+
## Sobre
|
6
|
+
|
7
|
+
SolidusInter é uma extensão para o Solidus que permite integração com a API do Banco Inter para processamento de pagamentos via PIX. A gem oferece uma solução completa para gerar códigos PIX, QR codes e processar pagamentos em tempo real.
|
8
|
+
|
9
|
+
## Funcionalidades
|
10
|
+
|
11
|
+
- ✅ Geração automática de códigos PIX
|
12
|
+
- ✅ Criação de QR codes para pagamento
|
13
|
+
- ✅ Validação de pagamentos em tempo real
|
14
|
+
- ✅ Integração completa com o admin do Solidus
|
15
|
+
- ✅ Suporte para diferentes chaves PIX
|
16
|
+
- ✅ Interface responsiva para mobile e desktop
|
17
|
+
- ✅ Webhooks para confirmação automática de pagamentos
|
18
|
+
|
19
|
+
## Instalação
|
20
|
+
|
21
|
+
Adicione esta linha ao Gemfile da sua aplicação:
|
7
22
|
|
8
23
|
```ruby
|
9
24
|
gem 'solidus_inter'
|
10
25
|
```
|
11
26
|
|
12
|
-
|
27
|
+
Execute:
|
13
28
|
|
14
|
-
```
|
15
|
-
|
29
|
+
```bash
|
30
|
+
$ bundle install
|
16
31
|
```
|
32
|
+
|
33
|
+
Execute o gerador de instalação:
|
34
|
+
|
35
|
+
```bash
|
36
|
+
$ rails generate solidus_inter:install
|
37
|
+
```
|
38
|
+
|
39
|
+
Isso irá:
|
40
|
+
- Copiar as migrações necessárias
|
41
|
+
- Executar as migrações (se você confirmar)
|
42
|
+
|
43
|
+
## Configuração
|
44
|
+
|
45
|
+
### 1. Credenciais do Banco Inter
|
46
|
+
|
47
|
+
Você precisará das seguintes credenciais do Banco Inter:
|
48
|
+
|
49
|
+
- **Client ID**: ID do cliente fornecido pelo Banco Inter
|
50
|
+
- **Client Secret**: Chave secreta fornecida pelo Banco Inter
|
51
|
+
- **Chave PIX**: Sua chave PIX cadastrada no Banco Inter
|
52
|
+
- **Conta Corrente**: Número da conta corrente
|
53
|
+
- **Certificados**: Certificado (.crt) e chave privada (.key) fornecidos pelo Banco Inter
|
54
|
+
|
55
|
+
### 2. Configuração do Payment Method
|
56
|
+
|
57
|
+
No admin do Solidus, vá para:
|
58
|
+
|
59
|
+
1. `Settings` → `Payment Methods`
|
60
|
+
2. Clique em `New Payment Method`
|
61
|
+
3. Selecione `SolidusInter::InterPix` como tipo
|
62
|
+
4. Configure as preferências:
|
63
|
+
- **Client ID**: Seu client ID do Banco Inter
|
64
|
+
- **Client Secret**: Seu client secret do Banco Inter
|
65
|
+
- **Chave PIX**: Sua chave PIX
|
66
|
+
- **Conta Corrente**: Número da sua conta corrente
|
67
|
+
- **CRT**: Conteúdo do certificado (.crt)
|
68
|
+
- **Key**: Conteúdo da chave privada (.key)
|
69
|
+
|
70
|
+
## Uso
|
71
|
+
|
72
|
+
### Fluxo de Pagamento
|
73
|
+
|
74
|
+
1. **Checkout**: O cliente seleciona PIX como método de pagamento
|
75
|
+
2. **Geração**: A gem gera automaticamente o código PIX e QR code
|
76
|
+
3. **Pagamento**: O cliente usa o app do banco para pagar
|
77
|
+
4. **Confirmação**: O pagamento é confirmado via webhook ou polling
|
78
|
+
5. **Finalização**: O pedido é processado automaticamente
|
79
|
+
|
80
|
+
### Códigos de Estado
|
81
|
+
|
82
|
+
A gem controla automaticamente os seguintes estados de pagamento:
|
83
|
+
|
84
|
+
- `pending`: Pagamento aguardando confirmação
|
85
|
+
- `paid`: Pagamento confirmado
|
86
|
+
- `expired`: Pagamento expirado
|
87
|
+
- `cancelled`: Pagamento cancelado
|
88
|
+
|
89
|
+
## API
|
90
|
+
|
91
|
+
### Principais Classes
|
92
|
+
|
93
|
+
#### `SolidusInter::InterPix`
|
94
|
+
|
95
|
+
Classe principal do método de pagamento que herda de `Spree::PaymentMethod`:
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
payment_method = SolidusInter::InterPix.new
|
99
|
+
payment_method.create_payment(order) # Cria pagamento PIX
|
100
|
+
payment_method.find_payment(txid) # Busca pagamento por txid
|
101
|
+
```
|
102
|
+
|
103
|
+
#### `SolidusInter::PixPaymentSource`
|
104
|
+
|
105
|
+
Representa a fonte de pagamento PIX:
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
source = SolidusInter::PixPaymentSource.new
|
109
|
+
source.paid? # Verifica se foi pago
|
110
|
+
source.expired? # Verifica se expirou
|
111
|
+
source.active? # Verifica se está ativo
|
112
|
+
```
|
113
|
+
|
114
|
+
#### `SolidusInter::InterClient`
|
115
|
+
|
116
|
+
Cliente para comunicação com a API do Banco Inter:
|
117
|
+
|
118
|
+
```ruby
|
119
|
+
client = SolidusInter::InterClient.new(payment_method)
|
120
|
+
client.get_payment(txid) # Busca pagamento
|
121
|
+
client.create_payment(data) # Cria novo pagamento
|
122
|
+
```
|
123
|
+
|
124
|
+
## Personalização
|
125
|
+
|
126
|
+
### Views
|
127
|
+
|
128
|
+
As views podem ser customizadas copiando-as para sua aplicação:
|
129
|
+
|
130
|
+
```
|
131
|
+
app/views/spree/admin/payments/source_forms/_inter_pix.html.erb
|
132
|
+
app/views/spree/admin/payments/source_views/_inter_pix.html.erb
|
133
|
+
app/views/spree/api/payments/source_views/_inter_pix.jbuilder
|
134
|
+
```
|
135
|
+
|
136
|
+
## Desenvolvimento
|
137
|
+
|
138
|
+
### Configuração do Ambiente
|
139
|
+
|
140
|
+
```bash
|
141
|
+
git clone https://github.com/todasessascoisas/solidus_inter.git
|
142
|
+
cd solidus_inter
|
143
|
+
bundle install
|
144
|
+
```
|
145
|
+
|
146
|
+
## Dependências
|
147
|
+
|
148
|
+
- **Ruby**: >= 2.5, < 4
|
149
|
+
- **Solidus**: Compatível com versões atuais
|
150
|
+
- **[inter_api](https://github.com/todasessascoisas/inter_api)**: API client para o Banco Inter
|
151
|
+
- **[solidus_brazilian_adaptations](https://github.com/todasessascoisas/solidus_brazilian_adaptations)**: Adaptações brasileiras para Solidus
|
152
|
+
- **rqrcode**: Geração de QR codes
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module SolidusInter
|
2
|
+
class InterClient
|
3
|
+
def self.for_payment_method(payment_method)
|
4
|
+
client_class = payment_method.preferred_test_mode ? InterClientSandbox : InterClientProduction
|
5
|
+
client_class.new(payment_method)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module PaymentMethodSyncable
|
10
|
+
attr_accessor :payment_method
|
11
|
+
|
12
|
+
def initialize(payment_method)
|
13
|
+
@payment_method = payment_method
|
14
|
+
super(
|
15
|
+
client_id: payment_method.preferred_client_id,
|
16
|
+
client_secret: payment_method.preferred_client_secret,
|
17
|
+
chave_pix: payment_method.preferred_chave_pix,
|
18
|
+
conta_corrente: payment_method.preferred_conta_corrente,
|
19
|
+
crt: temp_file(payment_method.preferred_crt).path,
|
20
|
+
key: temp_file(payment_method.preferred_key).path,
|
21
|
+
access_token: payment_method.preferred_access_token,
|
22
|
+
token_expires_at: payment_method.preferred_token_expires_at.to_datetime,
|
23
|
+
test_mode: payment_method.preferred_test_mode
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def refresh_token
|
28
|
+
super
|
29
|
+
sync_payment_method_tokens
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def sync_payment_method_tokens
|
35
|
+
payment_method.update!(
|
36
|
+
preferred_access_token: access_token,
|
37
|
+
preferred_token_expires_at: token_expires_at
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
def temp_file(content)
|
42
|
+
t = Tempfile.new
|
43
|
+
t << content
|
44
|
+
t.close
|
45
|
+
t
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class InterClientSandbox < ::InterApi::ClientSandbox
|
50
|
+
include PaymentMethodSyncable
|
51
|
+
end
|
52
|
+
|
53
|
+
class InterClientProduction < ::InterApi::ClientProduction
|
54
|
+
include PaymentMethodSyncable
|
55
|
+
end
|
56
|
+
end
|
@@ -6,15 +6,13 @@ module SolidusInter
|
|
6
6
|
preference :conta_corrente, :string
|
7
7
|
preference :crt, :text
|
8
8
|
preference :key, :text
|
9
|
+
preference :access_token, :string
|
10
|
+
preference :token_expires_at, :string
|
9
11
|
|
10
12
|
def payment_source_class
|
11
13
|
PixPaymentSource
|
12
14
|
end
|
13
15
|
|
14
|
-
def gateway_class
|
15
|
-
Gateway
|
16
|
-
end
|
17
|
-
|
18
16
|
def supports?(source)
|
19
17
|
source.is_a?(payment_source_class)
|
20
18
|
end
|
@@ -28,13 +26,13 @@ module SolidusInter
|
|
28
26
|
end
|
29
27
|
|
30
28
|
def find_payment(txid)
|
31
|
-
|
32
|
-
client.get_payment(txid)
|
29
|
+
inter_client.get_payment(txid)
|
33
30
|
end
|
34
31
|
|
35
32
|
def create_payment(order)
|
36
33
|
existing_payment = find_existing_payment(order)
|
37
34
|
return existing_payment if payment_is_usable?(existing_payment, order)
|
35
|
+
invalidate_valid_payments(order, existing_payment&.id)
|
38
36
|
|
39
37
|
payment = order.payments.new(amount: order.total, payment_method: self)
|
40
38
|
payment.source = init_source(order)
|
@@ -45,38 +43,61 @@ module SolidusInter
|
|
45
43
|
payment
|
46
44
|
end
|
47
45
|
|
48
|
-
def invalidate_payment(
|
49
|
-
|
46
|
+
def invalidate_payment(payment)
|
47
|
+
txid = payment.source&.txid
|
48
|
+
return false if txid.nil?
|
49
|
+
inter_payment = find_payment(payment.source.txid)
|
50
|
+
sync(payment, inter_payment)
|
51
|
+
return false unless payment.checkout?
|
50
52
|
|
51
|
-
inter_payment =
|
52
|
-
|
53
|
-
|
54
|
-
inter_payment.invalidate!
|
55
|
-
payment_source.payments[0].log_entries.create!(parsed_payment_response_details_with_fallback: failure_response("Pagamento cancelado"))
|
56
|
-
true
|
53
|
+
inter_payment = inter_client.update_payment(payment_id: txid, status: "REMOVIDA_PELO_USUARIO_RECEBEDOR")
|
54
|
+
sync(payment, inter_payment)
|
57
55
|
end
|
58
56
|
|
59
|
-
def pay_test_payment(
|
60
|
-
return false unless
|
57
|
+
def pay_test_payment(payment, amount: nil)
|
58
|
+
return false unless inter_client.class == InterClientSandbox
|
61
59
|
|
62
|
-
|
63
|
-
|
60
|
+
amount ||= payment.amount
|
61
|
+
txid = payment.source&.txid
|
62
|
+
return false if txid.nil?
|
63
|
+
inter_payment = find_payment(payment.source.txid)
|
64
|
+
sync(payment, inter_payment)
|
65
|
+
return false unless payment.checkout?
|
64
66
|
|
65
|
-
|
66
|
-
|
67
|
+
inter_client.pay_pix(payment_id: payment.source.txid, amount: amount)
|
68
|
+
sync(payment, inter_payment)
|
69
|
+
end
|
70
|
+
|
71
|
+
def purchase(money, source, _options = {})
|
72
|
+
inter_payment = source.retrieve_from_api
|
73
|
+
sync(source.payments.sole, inter_payment)
|
74
|
+
if inter_payment.status == "CONCLUIDA"
|
75
|
+
successful_response("Pagamento realizado", status: source.status, internal_detail: "")
|
76
|
+
else
|
77
|
+
failure_response("Pagamento não realizado", status: source.status, internal_detail: "")
|
78
|
+
end
|
67
79
|
end
|
68
80
|
|
69
|
-
|
70
|
-
|
81
|
+
# Não da pra chamar o sync aqui pq ele da payment.complete e isso faz nao chamar o purchase
|
82
|
+
def pix_paid? payment
|
83
|
+
return false unless payment.source&.txid
|
84
|
+
inter_payment = find_payment(payment.source.txid)
|
85
|
+
paid_amount = total_paid(inter_payment)
|
86
|
+
inter_payment.status == "CONCLUIDA" && paid_amount >= payment.amount
|
71
87
|
end
|
72
88
|
|
73
|
-
def
|
74
|
-
|
75
|
-
|
89
|
+
def payment_valid? payment
|
90
|
+
return false unless payment.source&.txid
|
91
|
+
purchase(payment)
|
92
|
+
payment.checkout?
|
76
93
|
end
|
77
94
|
|
78
95
|
private
|
79
96
|
|
97
|
+
def inter_client
|
98
|
+
InterClient.for_payment_method(self)
|
99
|
+
end
|
100
|
+
|
80
101
|
def init_source(order)
|
81
102
|
PixPaymentSource.new(
|
82
103
|
amount: order.total,
|
@@ -87,8 +108,7 @@ module SolidusInter
|
|
87
108
|
end
|
88
109
|
|
89
110
|
def create_inter_payment(payment_source)
|
90
|
-
|
91
|
-
client.create_payment(
|
111
|
+
inter_client.create_payment(
|
92
112
|
amount: payment_source.amount,
|
93
113
|
payer_tax_id: payment_source.payer_tax_id,
|
94
114
|
payer_name: payment_source.payer_name,
|
@@ -110,66 +130,93 @@ module SolidusInter
|
|
110
130
|
end
|
111
131
|
|
112
132
|
def process_payment_response(payment, inter_payment)
|
113
|
-
payment.update(response_code: inter_payment.txid)
|
114
133
|
payment.source.update(
|
115
134
|
txid: inter_payment.txid,
|
116
|
-
pix_code: inter_payment.
|
117
|
-
qr_code_svg: inter_payment
|
135
|
+
pix_code: inter_payment.pixCopiaECola,
|
136
|
+
qr_code_svg: qr_code(inter_payment),
|
118
137
|
status: inter_payment.status,
|
119
|
-
expiration: inter_payment
|
138
|
+
expiration: expiration_date(inter_payment)
|
120
139
|
)
|
140
|
+
payment.update(response_code: inter_payment.txid)
|
141
|
+
sync(payment, inter_payment)
|
142
|
+
end
|
143
|
+
|
144
|
+
def sync(payment, inter_payment)
|
145
|
+
paid_amount = total_paid(inter_payment)
|
146
|
+
payment.source.update!(status: inter_payment.status, paid_amount: paid_amount, e2e_id: end_to_end(inter_payment))
|
147
|
+
if inter_payment.status == "CONCLUIDA" && paid_amount >= payment.amount
|
148
|
+
approve_payment(payment)
|
149
|
+
elsif inter_payment.status == "CONCLUIDA"
|
150
|
+
raise "Payment paid with value less than the created - #{inter_payment.txid}"
|
151
|
+
elsif inter_payment.status != "ATIVA" || payment.source.expired?
|
152
|
+
invalid_payment(payment)
|
153
|
+
end
|
154
|
+
end
|
121
155
|
|
122
|
-
|
156
|
+
def approve_payment(payment)
|
157
|
+
payment.complete
|
158
|
+
payment_source = payment.source
|
159
|
+
payment_source.update! status: payment.state
|
160
|
+
response = successful_response("Pagamento realizado", status: payment_source.status, internal_detail: "")
|
161
|
+
payment.log_entries.create(parsed_payment_response_details_with_fallback: response)
|
123
162
|
end
|
124
163
|
|
125
|
-
def
|
126
|
-
|
127
|
-
|
164
|
+
def invalid_payment payment
|
165
|
+
return false unless payment.checkout?
|
166
|
+
if payment.checkout?
|
167
|
+
payment.invalidate!
|
168
|
+
else
|
169
|
+
payment.failure!
|
128
170
|
end
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
client = ::InterApi::Client.new(
|
135
|
-
client_id: preferences[:client_id],
|
136
|
-
client_secret: preferences[:client_secret],
|
137
|
-
chave_pix: preferences[:chave_pix],
|
138
|
-
conta_corrente: preferences[:conta_corrente],
|
139
|
-
crt: temp_file(preferences[:crt]).path,
|
140
|
-
key: temp_file(preferences[:key]).path,
|
141
|
-
access_token: account&.token,
|
142
|
-
token_expires_at: account&.expires_at,
|
143
|
-
test_mode: preferences[:test_mode]
|
144
|
-
)
|
145
|
-
SolidusInter::Account.upsert(
|
146
|
-
{token: client.access_token, expires_at: client.token_expires_at, chave_pix: client.chave_pix,
|
147
|
-
spree_payment_method_id: id}, unique_by: :chave_pix
|
148
|
-
)
|
149
|
-
client
|
171
|
+
|
172
|
+
payment_source = payment.source
|
173
|
+
payment_source.update!(status: payment.state)
|
174
|
+
response = failure_response("Pagamento invalidado", status: payment_source.status, internal_detail: "")
|
175
|
+
payment.log_entries.create(parsed_payment_response_details_with_fallback: response)
|
150
176
|
end
|
151
177
|
|
152
|
-
def
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
178
|
+
def invalidate_valid_payments order, existing_payment_id
|
179
|
+
available_payments = order.payments.where(state: ["checkout", "pending"])
|
180
|
+
available_payments.where.not(id: existing_payment_id).each do |payment|
|
181
|
+
payment.source.void!
|
182
|
+
end
|
157
183
|
end
|
158
184
|
|
159
|
-
def successful_response
|
185
|
+
def successful_response message, status:, internal_detail:
|
186
|
+
full_message = message + " - " + status + ": " + internal_detail
|
160
187
|
ActiveMerchant::Billing::Response.new(
|
161
188
|
true,
|
162
|
-
|
163
|
-
{},
|
164
|
-
authorization: transaction_id
|
189
|
+
full_message
|
165
190
|
)
|
166
191
|
end
|
167
192
|
|
168
|
-
def failure_response
|
193
|
+
def failure_response message, status:, internal_detail:
|
194
|
+
full_message = message + " - " + status + ": " + internal_detail
|
169
195
|
ActiveMerchant::Billing::Response.new(
|
170
196
|
false,
|
171
|
-
|
197
|
+
full_message
|
172
198
|
)
|
173
199
|
end
|
200
|
+
|
201
|
+
def qr_code(inter_payment, module_size: 4)
|
202
|
+
return unless inter_payment.pixCopiaECola
|
203
|
+
qr = RQRCode::QRCode.new(inter_payment.pixCopiaECola, size: 10, level: :l)
|
204
|
+
qr.as_svg(module_size: module_size)
|
205
|
+
end
|
206
|
+
|
207
|
+
def expiration_date(inter_payment)
|
208
|
+
return unless inter_payment.calendario.criacao
|
209
|
+
Time.new(inter_payment.calendario.criacao) + inter_payment.calendario.expiracao
|
210
|
+
end
|
211
|
+
|
212
|
+
def total_paid(inter_payment)
|
213
|
+
return unless inter_payment["pix"] && inter_payment.pix.any?
|
214
|
+
Float(inter_payment.pix[0].valor)
|
215
|
+
end
|
216
|
+
|
217
|
+
def end_to_end(inter_payment)
|
218
|
+
return unless inter_payment["pix"] && inter_payment.pix.any?
|
219
|
+
inter_payment.pix[0].endToEndId
|
220
|
+
end
|
174
221
|
end
|
175
222
|
end
|
@@ -1,27 +1,11 @@
|
|
1
1
|
module SolidusInter
|
2
2
|
class PixPaymentSource < Spree::PaymentSource
|
3
|
-
def actions
|
4
|
-
%w[]
|
5
|
-
end
|
6
|
-
|
7
|
-
def can_capture?(payment)
|
8
|
-
payment.pending? || payment.checkout?
|
9
|
-
end
|
10
|
-
|
11
|
-
def can_void?(payment)
|
12
|
-
payment.can_void?
|
13
|
-
end
|
14
|
-
|
15
|
-
def can_credit?(payment)
|
16
|
-
payment.completed? && payment.credit_allowed > 0
|
17
|
-
end
|
18
|
-
|
19
3
|
def expired?
|
20
|
-
expiration.past?
|
4
|
+
expiration.nil? || expiration.past?
|
21
5
|
end
|
22
6
|
|
23
7
|
def active?
|
24
|
-
expiration.future?
|
8
|
+
expiration.present? && expiration.future?
|
25
9
|
end
|
26
10
|
|
27
11
|
def retrieve_from_api
|
@@ -29,12 +13,11 @@ module SolidusInter
|
|
29
13
|
end
|
30
14
|
|
31
15
|
def paid?
|
32
|
-
|
33
|
-
inter_payment.paid?
|
16
|
+
payment_method.pix_paid?(payments.sole)
|
34
17
|
end
|
35
18
|
|
36
|
-
def
|
37
|
-
payment_method.invalidate_payment(
|
19
|
+
def void!
|
20
|
+
payment_method.invalidate_payment(payments.sole)
|
38
21
|
end
|
39
22
|
end
|
40
23
|
end
|
data/lib/solidus_inter.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solidus_inter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ulysses
|
@@ -37,15 +37,30 @@ dependencies:
|
|
37
37
|
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '0'
|
40
|
-
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: rqrcode
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
type: :runtime
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
description: Extensão para o Solidus que permite integração completa com a API do
|
55
|
+
Banco Inter para processamento de pagamentos via PIX, incluindo geração de QR codes
|
56
|
+
e validação automática de pagamentos.
|
41
57
|
email: ulyssesh.20@gmail.com
|
42
58
|
executables: []
|
43
59
|
extensions: []
|
44
60
|
extra_rdoc_files: []
|
45
61
|
files:
|
46
62
|
- README.md
|
47
|
-
- app/models/solidus_inter/
|
48
|
-
- app/models/solidus_inter/gateway.rb
|
63
|
+
- app/models/solidus_inter/inter_client.rb
|
49
64
|
- app/models/solidus_inter/inter_pix.rb
|
50
65
|
- app/models/solidus_inter/pix_payment_source.rb
|
51
66
|
- app/views/spree/admin/payments/source_forms/_inter_pix.html.erb
|
@@ -81,5 +96,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
96
|
requirements: []
|
82
97
|
rubygems_version: 3.6.9
|
83
98
|
specification_version: 4
|
84
|
-
summary:
|
99
|
+
summary: Integração do Banco Inter com Solidus para pagamentos via PIX
|
85
100
|
test_files: []
|
@@ -1,37 +0,0 @@
|
|
1
|
-
module SolidusInter
|
2
|
-
class Gateway
|
3
|
-
def initialize(options)
|
4
|
-
end
|
5
|
-
|
6
|
-
def purchase(_money, source, _options = {})
|
7
|
-
inter_payment = source.retrieve_from_api
|
8
|
-
if inter_payment.paid?
|
9
|
-
source.update(status: "approved", paid_amount: inter_payment.valor_pago, e2e_id: inter_payment.end_to_end_id)
|
10
|
-
successful_response("Pagamento realizado", inter_payment.txid)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def void(transaction_id, _options = {})
|
15
|
-
# Respondendo sempre com successful_response para funcionar o botão de "Cancelar" do pedido. Reembolso deve ser feito por fora.
|
16
|
-
successful_response("Pagamento cancelado. Se necessário, realize o reembolso.", transaction_id)
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def successful_response(message, transaction_id)
|
22
|
-
ActiveMerchant::Billing::Response.new(
|
23
|
-
true,
|
24
|
-
message,
|
25
|
-
{},
|
26
|
-
authorization: transaction_id
|
27
|
-
)
|
28
|
-
end
|
29
|
-
|
30
|
-
def failure_response(message)
|
31
|
-
ActiveMerchant::Billing::Response.new(
|
32
|
-
false,
|
33
|
-
message
|
34
|
-
)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|