Class: Fuik::Event

Inherits:
Object
  • Object
show all
Defined in:
app/models/fuik/event.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(webhook_event) ⇒ Event

Returns a new instance of Event.



20
21
22
# File 'app/models/fuik/event.rb', line 20

def initialize(webhook_event)
  @webhook_event = webhook_event
end

Class Method Details

.event_id(key = nil, **options) ⇒ Object



15
16
17
# File 'app/models/fuik/event.rb', line 15

def event_id(key = nil, **options)
  self.event_id_config = key || options
end

.event_type(key = nil, **options) ⇒ Object



11
12
13
# File 'app/models/fuik/event.rb', line 11

def event_type(key = nil, **options)
  self.event_type_config = key || options
end

Instance Method Details

#payloadFuik::DotAccess::AccessPayload

Access the webhook payload with dot notation or standard hash access.

Examples:

Dot notation

payload.customer.email

Hash access

payload["line_items"][0]["product_id"]

Returns:



51
52
53
# File 'app/models/fuik/event.rb', line 51

def payload
  @webhook_event.payload.to_dot
end

#process!void

This method returns an undefined value.

Called when the webhook event is processed. Override to handle the event payload and transition the event's status to processed or failed.

Examples:

Implementing a checkout.session.completed handler

def process!
  User.find_by(id: payload.client_reference_id).tap do |user|
    user.activate_subscription!
    user.send_welcome_email
  end

  @webhook_event.processed!
end

Raises:

  • (NotImplementedError)


38
39
40
# File 'app/models/fuik/event.rb', line 38

def process!
  raise NotImplementedError, "#{self.class} must implement #process!"
end