Class: SolidusMollie::PaymentMethod
- Inherits:
-
Spree::PaymentMethod
- Object
- Spree::PaymentMethod
- SolidusMollie::PaymentMethod
- Defined in:
- app/models/solidus_mollie/payment_method.rb
Overview
A Solidus payment method backed by Mollie’s hosted (redirect) checkout.
Unlike credit-card gateways, Mollie does not authorise/capture synchronously. The buyer is redirected to Mollie, and the webhook is the source of truth for whether payment succeeded. See SolidusMollie::CreateOrderPayment (redirect) and SolidusMollie::ProcessWebhook (settlement).
Instance Method Summary collapse
-
#authorize(_amount, _source, _gateway_options = {}) ⇒ Object
— Solidus gateway interface —————————————— These are deliberately defensive.
-
#auto_capture? ⇒ Boolean
Money is moved on Mollie’s side, so there is nothing to auto-capture here.
- #capture(_amount, _response_code, _gateway_options = {}) ⇒ Object
- #client ⇒ Object
-
#credit(amount_cents, *rest) ⇒ Object
Refund.
-
#partial_name ⇒ Object
Frontend/admin look for spree/checkout/payment/_mollie and friends.
- #payment_profiles_supported? ⇒ Boolean
- #payment_source_class ⇒ Object
- #purchase(_amount, _source, _gateway_options = {}) ⇒ Object
- #source_required? ⇒ Boolean
- #test_mode? ⇒ Boolean
-
#try_void(payment) ⇒ Object
Solidus calls try_void before issuing a refund.
Instance Method Details
#authorize(_amount, _source, _gateway_options = {}) ⇒ Object
— Solidus gateway interface —————————————— These are deliberately defensive. The normal checkout flow never calls purchase/authorize/capture (we redirect instead), but implementing them keeps Solidus happy if Order#process_payments! is ever invoked.
52 53 54 |
# File 'app/models/solidus_mollie/payment_method.rb', line 52 def (_amount, _source, = {}) SolidusMollie::Response.pending('Awaiting Mollie redirect') end |
#auto_capture? ⇒ Boolean
Money is moved on Mollie’s side, so there is nothing to auto-capture here.
35 36 37 |
# File 'app/models/solidus_mollie/payment_method.rb', line 35 def auto_capture? false end |
#capture(_amount, _response_code, _gateway_options = {}) ⇒ Object
60 61 62 |
# File 'app/models/solidus_mollie/payment_method.rb', line 60 def capture(_amount, _response_code, = {}) SolidusMollie::Response.success('Captured by Mollie webhook') end |
#client ⇒ Object
43 44 45 |
# File 'app/models/solidus_mollie/payment_method.rb', line 43 def client SolidusMollie::Client.new(api_key: preferred_api_key) end |
#credit(amount_cents, *rest) ⇒ Object
Refund. Solidus’ Spree::Refund#perform! has varied across versions; accept both (amount, response_code, options) and (amount, source, response_code, options).
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/models/solidus_mollie/payment_method.rb', line 67 def credit(amount_cents, *rest) = rest.last.is_a?(Hash) ? rest.last : {} response_code = rest.reverse.find { |arg| arg.is_a?(String) } || [:response_code] currency = refund_currency() client.create_refund( payment_id: response_code, amount: SolidusMollie::Client.cents_to_major(amount_cents, currency), currency: currency ) SolidusMollie::Response.success('Mollie refund created', authorization: response_code) rescue StandardError => e Rails.logger.error("[solidus_mollie] refund failed: #{e.}") SolidusMollie::Response.failure(e.) end |
#partial_name ⇒ Object
Frontend/admin look for spree/checkout/payment/_mollie and friends.
22 23 24 |
# File 'app/models/solidus_mollie/payment_method.rb', line 22 def partial_name 'mollie' end |
#payment_profiles_supported? ⇒ Boolean
30 31 32 |
# File 'app/models/solidus_mollie/payment_method.rb', line 30 def payment_profiles_supported? false end |
#payment_source_class ⇒ Object
17 18 19 |
# File 'app/models/solidus_mollie/payment_method.rb', line 17 def payment_source_class SolidusMollie::MollieSource end |
#purchase(_amount, _source, _gateway_options = {}) ⇒ Object
56 57 58 |
# File 'app/models/solidus_mollie/payment_method.rb', line 56 def purchase(_amount, _source, = {}) SolidusMollie::Response.pending('Awaiting Mollie redirect') end |
#source_required? ⇒ Boolean
26 27 28 |
# File 'app/models/solidus_mollie/payment_method.rb', line 26 def source_required? true end |
#test_mode? ⇒ Boolean
39 40 41 |
# File 'app/models/solidus_mollie/payment_method.rb', line 39 def test_mode? preferred_api_key.to_s.start_with?('test_') end |
#try_void(payment) ⇒ Object
Solidus calls try_void before issuing a refund. Cancel the Mollie payment if it is still cancelable; otherwise return false so Solidus falls back to a refund.
86 87 88 89 90 91 92 93 94 95 |
# File 'app/models/solidus_mollie/payment_method.rb', line 86 def try_void(payment) remote = client.get_payment(payment.response_code) return false unless remote.respond_to?(:cancelable?) ? remote.cancelable? : remote.try(:cancelable) client.cancel_payment(payment.response_code) SolidusMollie::Response.success('Mollie payment canceled', authorization: payment.response_code) rescue StandardError => e Rails.logger.error("[solidus_mollie] void failed: #{e.}") false end |