solidus_mp_dois 3.1.2 → 3.2.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: 890c24765fb805a7b5a3689db4b015a0d061a399ce53149a75a9f3c23626263e
4
- data.tar.gz: '09dd3fc598f692fbb14d5081d806135c2eb252fb4c4c996e11593e4cdabc269e'
3
+ metadata.gz: 92b18f841403c9cb29fb65538649f5b7bbb4e88ed521b454054348b01526af51
4
+ data.tar.gz: 38f52e2b13822db9646ca952950bc3b91bcccd446badcde45deee29ed499c329
5
5
  SHA512:
6
- metadata.gz: 8f21a8add7662bd01d8c8c05982a832b73d828e66bf2483f06a6a3f4ed74df801fa9c85da83dbaba275e8501db1219516553cd8e311fa7c5e2a99cc895d492df
7
- data.tar.gz: b0650ac259a3b7927fa4a773ac0922bc14f0d0470fd49b3ba995fb96d29555e24a4214475ee324f9e14eae18f18749e5612dc28f60c4c7ecfe0a2fed36ab1bb1
6
+ metadata.gz: b75772da3c67abd24923d2fa90a78fb1e42a812f0ab6ab9d7eac41d47c73c19f4b6a2421cfcbfa0a11ebff7a7ce9fa4a123cefd4f693dba8cc56f22d73b13692
7
+ data.tar.gz: 3d19b962b1243ffa4a064d59f68c26415c3dcd84407990a3fe28f6f24ce0ba969e210acf7e666a429527a97de4b28cd967abfc6e15255a30813493264e2c8836
@@ -7,5 +7,18 @@ module SolidusMpDois
7
7
  def void!
8
8
  payment_method.cancel!(payments.sole)
9
9
  end
10
+
11
+ def refund!(amount: nil)
12
+ payment_method.refund_payment(payments.sole, amount)
13
+ end
14
+
15
+ # Definir para sempre false pois atualmente não implementados o void do Solidus
16
+ def can_void?(payment)
17
+ false
18
+ end
19
+
20
+ def can_credit?(payment)
21
+ payment.completed? && payment.credit_allowed > 0
22
+ end
10
23
  end
11
24
  end
@@ -4,12 +4,33 @@ module SolidusMpDois
4
4
  end
5
5
 
6
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)
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
+ amount = converted_money(money)
16
+ refund = payment_source.refund!(amount: amount)
17
+ if refund.status == "approved"
18
+ response = successful_response("Pagamento reembolsado - #{refund.status} (#{amount})", transaction_id)
19
+ payment.log_entries.create(parsed_payment_response_details_with_fallback: response)
20
+ successful_response("Reembolso realizado", refund.id)
21
+ else
22
+ response = successful_response("Pagamento não reembolsado - #{refund.status}", transaction_id)
23
+ payment.log_entries.create(parsed_payment_response_details_with_fallback: response)
24
+ successful_response("Erro ao reembolsar", refund.id)
25
+ end
9
26
  end
10
27
 
11
28
  private
12
29
 
30
+ def converted_money(money)
31
+ money / 100.0
32
+ end
33
+
13
34
  def successful_response(message, transaction_id)
14
35
  ActiveMerchant::Billing::Response.new(
15
36
  true,
@@ -19,10 +40,12 @@ module SolidusMpDois
19
40
  )
20
41
  end
21
42
 
22
- def failure_response(message)
43
+ def failure_response(message, transaction_id = nil)
23
44
  ActiveMerchant::Billing::Response.new(
24
45
  false,
25
- message
46
+ message,
47
+ {},
48
+ authorization: transaction_id
26
49
  )
27
50
  end
28
51
  end
@@ -73,6 +73,14 @@ module SolidusMpDois
73
73
  sync(payment, mp_payment)
74
74
  end
75
75
 
76
+ def refund_payment(payment, amount = nil)
77
+ amount = payment.source.amount if amount.nil?
78
+ refund = mp_client.create_refund(id: payment.source.external_id, amount: amount.to_f)
79
+ mp_payment = payment.source.retrieve_from_api
80
+ payment.source.update(status: mp_payment.status, internal_details: mp_payment.status_detail)
81
+ refund
82
+ end
83
+
76
84
  private
77
85
 
78
86
  def mp_client
@@ -80,6 +80,14 @@ module SolidusMpDois
80
80
  sync(payment, mp_payment)
81
81
  end
82
82
 
83
+ def refund_payment(payment, amount = nil)
84
+ amount = payment.source.amount if amount.nil?
85
+ refund = mp_client.create_refund(id: payment.source.external_id, amount: amount.to_f)
86
+ mp_payment = payment.source.retrieve_from_api
87
+ payment.source.update(status: mp_payment.status, internal_details: mp_payment.status_detail)
88
+ refund
89
+ end
90
+
83
91
  private
84
92
 
85
93
  def mp_client
@@ -15,5 +15,18 @@ module SolidusMpDois
15
15
  def void!
16
16
  payment_method.invalidate_payment(payments.sole)
17
17
  end
18
+
19
+ def refund!(amount: nil)
20
+ payment_method.refund_payment(payments.sole, amount)
21
+ end
22
+
23
+ # Definir para sempre false pois atualmente não implementados o void do Solidus
24
+ def can_void?(payment)
25
+ false
26
+ end
27
+
28
+ def can_credit?(payment)
29
+ payment.completed? && payment.credit_allowed > 0
30
+ end
18
31
  end
19
32
  end
@@ -42,6 +42,11 @@
42
42
  <%= label_tag :expiration, "Expiração" %>
43
43
  <%= text_field_tag :expiration, payment.source.expiration.in_time_zone('America/Sao_Paulo').strftime("%d/%m/%Y às %H:%M"), class:"fullwidth", disabled: true %>
44
44
  </div>
45
+
46
+ <div class="field">
47
+ <%= label_tag :internal_details, "Detalhes" %>
48
+ <%= text_field_tag :internal_details, payment.source.internal_details, class:"fullwidth", disabled: true %>
49
+ </div>
45
50
  </div>
46
51
 
47
52
  <div class="col-12">
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_mp_dois
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.2
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todas Essas Coisas