Class: Vindi::WebhookJob
- Inherits:
-
ActiveJob::Base
- Object
- ActiveJob::Base
- Vindi::WebhookJob
- Defined in:
- lib/generators/vindi/templates/webhook_job.rb
Overview
VINDI WEBHOOK PAYLOAD STRUCTURE EXAMPLE: {
event: {
id: 123456, # Unique ID for the webhook event (useful for idempotency)
type: "bill_paid", # Type of event (e.g. subscription_created, bill_paid, charge_rejected)
created_at: "2026-06-10T15:00:00.000-03:00",
data: { # Object data (context depends on the event type)
bill: {
id: 555,
amount: "100.00",
status: "paid",
customer: { id: 123, email: "john@example.com", code: "app_user_id" },
charges: [...]
}
}
}
}
Instance Method Summary collapse
Instance Method Details
#perform(payload) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/generators/vindi/templates/webhook_job.rb', line 26 def perform(payload) event_id = payload.dig(:event, :id) event_type = payload.dig(:event, :type) # BEST PRACTICE 1: Idempotency Check # Check if this event_id has already been processed to avoid duplicate actions. return if already_processed?(event_id) process_event(event_type, payload.dig(:event, :data)) # BEST PRACTICE 2: Record that this event was successfully processed mark_as_processed!(event_id) end |