solidus_inter 3.0.0 → 3.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb69e01d4ea7ac6966c62d12bfc5f344271ebf3530aeb945e51b4c58a68e2f20
4
- data.tar.gz: 5e8782241005478d0ffd5f18d11deeb569e403f8af2a50977067efcb788e0e2a
3
+ metadata.gz: fb213ef73a6677b7b49dcc1912667b3f45540d76f8cb80fb2120a261f18dff6f
4
+ data.tar.gz: c3a0928c11a41c3169aaae2698c601b18ef86a136f6fa027766161caa466457d
5
5
  SHA512:
6
- metadata.gz: afbb51c72beef7e6e65469ea80008847d4374bc542defccb666f9e281049f7eaa394ac1730312e8f21224312a9fe0c66a6113fdef2da22482ec00c682e2dc686
7
- data.tar.gz: d2ef37846e2c3930ff777d275369a9cbf568b2a25ed038d14013ddf82f7a3cffcb5c672f5e7f4d5df5f8df4d4ad7b6aaf27d700219c1fb85a8f326bf8fa4cf99
6
+ metadata.gz: f85bd84e27ab2652e0d494d42ff30ed318a544ced05b11c766e65734b4433d1b5c0873483fa901e4e40f83caee259fbf65428ca03ccf2c011fb169eaaca5da41
7
+ data.tar.gz: 9fad7d8f8ef8904d9e0d8ed214d32d4b58aa014ccdcb6a72db0404eeb1093240fe385d6115cd2bf4bcf1dddb59a716f2531e4e4447c089ab11ee4d8e829e754c
@@ -0,0 +1,47 @@
1
+ module SolidusInter
2
+ class Gateway
3
+ def initialize(options)
4
+ end
5
+
6
+ def void(transaction_id, options = {})
7
+ # Respondendo com falha pois atualmente todo pedido concluido ja teve seu pagamento processado
8
+ # e nesse caso o credit é mais adequado (Ao cancelar um pedido pela interface, o 'void' é chamado, se ele retornar falha o Solidus chama o 'credit')
9
+ failure_response("Pagamento já processado")
10
+ end
11
+
12
+ def credit(money, transaction_id, options = {})
13
+ payment = Spree::Payment.find_by(response_code: transaction_id)
14
+ payment_source = payment.source
15
+ refund = payment_source.refund!
16
+ if refund.status == "DEVOLVIDO"
17
+ response = successful_response("Pagamento reembolsado (#{refund.status})", transaction_id)
18
+ payment.log_entries.create(parsed_payment_response_details_with_fallback: response)
19
+ successful_response("Reembolso realizado", refund.id)
20
+ else
21
+ response = successful_response("Pagamento não reembolsado - #{refund.status} - #{refund.try(:motivo)}", transaction_id)
22
+ payment.log_entries.create(parsed_payment_response_details_with_fallback: response)
23
+ successful_response("Erro ao reembolsar", refund.id)
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def successful_response(message, transaction_id)
30
+ ActiveMerchant::Billing::Response.new(
31
+ true,
32
+ message,
33
+ {},
34
+ authorization: transaction_id
35
+ )
36
+ end
37
+
38
+ def failure_response(message, transaction_id = nil)
39
+ ActiveMerchant::Billing::Response.new(
40
+ false,
41
+ message,
42
+ {},
43
+ authorization: transaction_id
44
+ )
45
+ end
46
+ end
47
+ end
@@ -13,6 +13,10 @@ module SolidusInter
13
13
  PixPaymentSource
14
14
  end
15
15
 
16
+ def gateway_class
17
+ Gateway
18
+ end
19
+
16
20
  def supports?(source)
17
21
  source.is_a?(payment_source_class)
18
22
  end
@@ -92,6 +96,10 @@ module SolidusInter
92
96
  payment.checkout?
93
97
  end
94
98
 
99
+ def refund_payment(payment)
100
+ inter_client.refund_payment(end_to_end_id: payment.source.e2e_id, amount: payment.source.paid_amount)
101
+ end
102
+
95
103
  private
96
104
 
97
105
  def inter_client
@@ -19,5 +19,9 @@ module SolidusInter
19
19
  def void!
20
20
  payment_method.invalidate_payment(payments.sole)
21
21
  end
22
+
23
+ def refund!
24
+ payment_method.refund_payment(payments.sole)
25
+ end
22
26
  end
23
27
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusInter
4
- VERSION = "3.0.0"
4
+ VERSION = "3.1.0"
5
5
  end
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: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ulysses
@@ -60,6 +60,7 @@ extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
62
  - README.md
63
+ - app/models/solidus_inter/gateway.rb
63
64
  - app/models/solidus_inter/inter_client.rb
64
65
  - app/models/solidus_inter/inter_pix.rb
65
66
  - app/models/solidus_inter/pix_payment_source.rb