Class: Payflow::Webhooks::Dispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/payflow/webhooks/dispatcher.rb

Constant Summary collapse

PAYMENT_OVERDUE =
"PAYMENT_OVERDUE"
PAYMENT_RECEIVED =
"PAYMENT_RECEIVED"
SUBSCRIPTION_DELETED =
"SUBSCRIPTION_DELETED"

Instance Method Summary collapse

Constructor Details

#initialize(webhook_event:) ⇒ Dispatcher

Returns a new instance of Dispatcher.



10
11
12
# File 'lib/payflow/webhooks/dispatcher.rb', line 10

def initialize(webhook_event:)
  @webhook_event = webhook_event
end

Instance Method Details

#dispatch!Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/payflow/webhooks/dispatcher.rb', line 14

def dispatch!
  payload = @webhook_event.payload
  event_type = payload["event"]

  case event_type
  when PAYMENT_OVERDUE
    mark_subscription_overdue(payload)
  when PAYMENT_RECEIVED
    mark_subscription_active(payload)
  when SUBSCRIPTION_DELETED
    mark_subscription_cancelled(payload)
  end
end