Class: StripeWebhooks::Callback

Inherits:
Object
  • Object
show all
Extended by:
ClassMethods
Defined in:
app/models/stripe_webhooks/callback.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary

Attributes included from ClassMethods

#event_types

Instance Method Summary collapse

Methods included from ClassMethods

handles_events, run_callbacks_for

Instance Method Details

#handles?(event_type) ⇒ Boolean

Return true if the Callback handles this type of event

Returns:

  • (Boolean)


61
62
63
# File 'app/models/stripe_webhooks/callback.rb', line 61

def handles?(event_type)
  return self.class.event_types.include?(event_type)
end

#labelObject

Return the label for the callback. Label is based on the class name.



46
47
48
# File 'app/models/stripe_webhooks/callback.rb', line 46

def label
  return self.class.to_s.underscore.gsub('_callback', '')
end

#loggerObject



40
41
42
# File 'app/models/stripe_webhooks/callback.rb', line 40

def logger
  return Rails.logger
end

#run_once(event) ⇒ Object

Run the callback only if we have not run it once before



52
53
54
55
56
57
# File 'app/models/stripe_webhooks/callback.rb', line 52

def run_once(event)
  if !StripeWebhooks::PerformedCallback.exists?(:stripe_event_id => event.id, :label => label)
    run(event)
    StripeWebhooks::PerformedCallback.create(:stripe_event_id => event.id, :label => label)
  end
end