solidus_mp_dois 3.1.2 → 3.3.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: ff932081405e8bda2460d58946203de82bd68d1fe44d0e14bd9d49e73cf5f1ea
4
+ data.tar.gz: b8567a9c8385cd42e035c4e6891766bf684e75d41ecc2d2008f43b475bd8f831
5
5
  SHA512:
6
- metadata.gz: 8f21a8add7662bd01d8c8c05982a832b73d828e66bf2483f06a6a3f4ed74df801fa9c85da83dbaba275e8501db1219516553cd8e311fa7c5e2a99cc895d492df
7
- data.tar.gz: b0650ac259a3b7927fa4a773ac0922bc14f0d0470fd49b3ba995fb96d29555e24a4214475ee324f9e14eae18f18749e5612dc28f60c4c7ecfe0a2fed36ab1bb1
6
+ metadata.gz: c81188c78f4e128719c8cd450d60a9d380b6ed61bcdfb08350d50c3692d333a6747a2b3f84869860c9a3e0fa097dbc1a6ab0f003c6f43ba8e15831d4015dd896
7
+ data.tar.gz: 968270b5aca90c4e731b802a206f5401e1c767bbe9a796d4068604a327cff929196c21882b23527464477e64cb004da47ebcaf03daa4612e61e61d65809dd146
@@ -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
@@ -115,6 +123,7 @@ module SolidusMpDois
115
123
  payer_email: payment_source.email,
116
124
  payer_identification_type: payment_source.payer_identification_type,
117
125
  payer_identification_number: payment_source.tax_id,
126
+ external_reference: payment_source.payments.first.number || SecureRandom.hex(4),
118
127
  token: payment_source.token,
119
128
  issuer_id: payment_source.issuer_id,
120
129
  installments: payment_source.installments,
@@ -47,6 +47,7 @@ module SolidusMpDois
47
47
  payer_email: payment_source.email,
48
48
  payer_identification_type: identification_type,
49
49
  payer_identification_number: payment_source.tax_id
50
+ external_reference: payment.number || SecureRandom.hex(4),
50
51
  )
51
52
 
52
53
  process_payment_response(payment, mp_payment)
@@ -80,6 +81,14 @@ module SolidusMpDois
80
81
  sync(payment, mp_payment)
81
82
  end
82
83
 
84
+ def refund_payment(payment, amount = nil)
85
+ amount = payment.source.amount if amount.nil?
86
+ refund = mp_client.create_refund(id: payment.source.external_id, amount: amount.to_f)
87
+ mp_payment = payment.source.retrieve_from_api
88
+ payment.source.update(status: mp_payment.status, internal_details: mp_payment.status_detail)
89
+ refund
90
+ end
91
+
83
92
  private
84
93
 
85
94
  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,13 +1,14 @@
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.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todas Essas Coisas
8
+ autorequire:
8
9
  bindir: bin
9
10
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
11
+ date: 2026-04-30 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: solidus_brazilian_adaptations
@@ -76,6 +77,7 @@ files:
76
77
  homepage: https://github.com/todasessascoisas/solidus_mp_dois
77
78
  licenses: []
78
79
  metadata: {}
80
+ post_install_message:
79
81
  rdoc_options: []
80
82
  require_paths:
81
83
  - lib
@@ -90,7 +92,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
92
  - !ruby/object:Gem::Version
91
93
  version: '0'
92
94
  requirements: []
93
- rubygems_version: 3.6.9
95
+ rubygems_version: 3.5.3
96
+ signing_key:
94
97
  specification_version: 4
95
98
  summary: ''
96
99
  test_files: []