Class: Spree::Payments::HandleWebhook

Inherits:
Object
  • Object
show all
Includes:
ServiceModule::Base
Defined in:
app/services/spree/payments/handle_webhook.rb

Instance Method Summary collapse

Methods included from ServiceModule::Base

prepended

Instance Method Details

#call(payment_method:, action:, payment_session:, metadata: {}) ⇒ Object

Parameters:

  • payment_method (Spree::PaymentMethod)

    the payment method that received the webhook

  • action (Symbol)

    normalized action (:captured, :authorized, :failed, :canceled)

  • payment_session (Spree::PaymentSession)

    the payment session associated with the webhook

  • metadata (Hash) (defaults to: {})

    gateway-specific metadata (e.g. charge data, psp reference)



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/services/spree/payments/handle_webhook.rb', line 10

def call(payment_method:, action:, payment_session:, metadata: {})
  return success(nil) if payment_session.nil?

  order = payment_session.order

  case action
  when :captured, :authorized
    handle_success(payment_session, order, )
  when :failed
    payment_session.fail if payment_session.can_fail?
    success(payment_session)
  when :canceled
    payment_session.cancel if payment_session.can_cancel?
    success(payment_session)
  else
    failure(payment_session, "Unknown webhook action: #{action}")
  end
end