Class: OutletPurchase::ConversionReportHandler

Inherits:
Object
  • Object
show all
Defined in:
app/subscribers/outlet_purchase/conversion_report_handler.rb

Overview

Subscribes to Events::OutletPurchaseVerified. Tells the ad platforms that a
click we already paid for produced revenue — even though it closed on a
retailer rather than through our checkout.

Enqueues rather than reports inline: the upload talks to Google, and
OutletPurchaseConversionWorker already owns that with its own retry policy.
The handler exists so the DECISION to report lives in a subscription rather
than buried in the model.

Customer-level purchases carry no opportunity and so no click identifier; the
worker guards that too, but skipping the enqueue saves a pointless job.

No row lock here, unlike the two opportunity handlers. This writes nothing —
and OutletPurchaseConversionWorker re-checks attributed? when it runs, so
a job enqueued for a row rejected microseconds later is a clean no-op rather
than a wrong report.

Wired in config/initializers/event_store.rb.

Instance Method Summary collapse

Instance Method Details

#call(event) ⇒ void

This method returns an undefined value.

Parameters:

  • event (RubyEventStore::Event)


24
25
26
27
28
29
# File 'app/subscribers/outlet_purchase/conversion_report_handler.rb', line 24

def call(event)
  purchase = CustomerOutletPurchase.find_by(id: event.data[:customer_outlet_purchase_id])
  return unless purchase&.attributed? && purchase.opportunity_id

  OutletPurchaseConversionWorker.perform_async(purchase.id)
end