Class: SolidusMollie::ProcessWebhook
- Inherits:
-
Object
- Object
- SolidusMollie::ProcessWebhook
- Defined in:
- app/services/solidus_mollie/process_webhook.rb
Overview
Settlement logic, driven by Mollie’s webhook (the source of truth). Looks up the local payment from the Mollie id, re-fetches the authoritative status from Mollie, then advances the Spree::Payment and order. Designed to be idempotent: Mollie may call the webhook several times.
Defined Under Namespace
Classes: PaymentNotFound
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(mollie_payment_id:) ⇒ ProcessWebhook
constructor
A new instance of ProcessWebhook.
Constructor Details
#initialize(mollie_payment_id:) ⇒ ProcessWebhook
Returns a new instance of ProcessWebhook.
15 16 17 |
# File 'app/services/solidus_mollie/process_webhook.rb', line 15 def initialize(mollie_payment_id:) @mollie_payment_id = mollie_payment_id end |
Class Method Details
.call(mollie_payment_id:) ⇒ Object
11 12 13 |
# File 'app/services/solidus_mollie/process_webhook.rb', line 11 def self.call(mollie_payment_id:) new(mollie_payment_id: mollie_payment_id).call end |
Instance Method Details
#call ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/services/solidus_mollie/process_webhook.rb', line 19 def call raise PaymentNotFound, 'missing id' if @mollie_payment_id.to_s.empty? source = SolidusMollie::MollieSource.find_by(mollie_payment_id: @mollie_payment_id) raise PaymentNotFound, @mollie_payment_id unless source payment = ::Spree::Payment.find_by(source: source) raise PaymentNotFound, "no payment for #{@mollie_payment_id}" unless payment remote = payment.payment_method.client.get_payment(@mollie_payment_id) source.update!(status: remote.status) settle(payment, remote.status) payment end |