solidus_inter 3.0.1 → 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: 68978582e05c3a6391cc622865892b77ca8b28e2d98388213bf6d58a489ef446
4
- data.tar.gz: 7759c7ac13c686895ed6a8848f33875d2bac0fd4f0c1045fafa3ae487ab5b807
3
+ metadata.gz: fb213ef73a6677b7b49dcc1912667b3f45540d76f8cb80fb2120a261f18dff6f
4
+ data.tar.gz: c3a0928c11a41c3169aaae2698c601b18ef86a136f6fa027766161caa466457d
5
5
  SHA512:
6
- metadata.gz: 3508d43d52924bbdde45b088cd81c44dd65d8c7697535f1bb8c8e39a6a98f98e97c8470eb6ed81d1a34d1c715b79e93134df2940ad9950f7546f8764586ca593
7
- data.tar.gz: d6851bf2cd670b75074668824d9bdba9ae9522b073fb58abe51496864f7816d9cfcd671f1b7a8a59fe4135df1fc3c62b7bc5846f582fb2fbc7eb0ab5569b10b9
6
+ metadata.gz: f85bd84e27ab2652e0d494d42ff30ed318a544ced05b11c766e65734b4433d1b5c0873483fa901e4e40f83caee259fbf65428ca03ccf2c011fb169eaaca5da41
7
+ data.tar.gz: 9fad7d8f8ef8904d9e0d8ed214d32d4b58aa014ccdcb6a72db0404eeb1093240fe385d6115cd2bf4bcf1dddb59a716f2531e4e4447c089ab11ee4d8e829e754c
@@ -3,9 +3,25 @@ module SolidusInter
3
3
  def initialize(options)
4
4
  end
5
5
 
6
- def void(transaction_id, _options = {})
7
- # Respondendo sempre com successful_response para funcionar o botão de "Cancelar" do pedido. Reembolso deve ser feito por fora.
8
- successful_response("Pagamento cancelado. Se necessário, realize o reembolso.", transaction_id)
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
9
25
  end
10
26
 
11
27
  private
@@ -19,10 +35,12 @@ module SolidusInter
19
35
  )
20
36
  end
21
37
 
22
- def failure_response(message)
38
+ def failure_response(message, transaction_id = nil)
23
39
  ActiveMerchant::Billing::Response.new(
24
40
  false,
25
- message
41
+ message,
42
+ {},
43
+ authorization: transaction_id
26
44
  )
27
45
  end
28
46
  end
@@ -96,6 +96,10 @@ module SolidusInter
96
96
  payment.checkout?
97
97
  end
98
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
+
99
103
  private
100
104
 
101
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.1"
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.1
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ulysses