Class: Spree::OrderCommissionSubscriber

Inherits:
Subscriber
  • Object
show all
Defined in:
app/subscribers/spree/order_commission_subscriber.rb

Overview

Charges commission once an order is placed.

Synchronous, like the other placement side effects, because the commission lines are what a seller is told they owe: a marketplace that showed an order before its commission existed would be showing an incomplete book, and the work is a handful of rows against already-loaded records.

Idempotency is the service's own — an order that already carries commission is left alone — so a replayed event cannot charge a seller twice.

Instance Method Summary collapse

Instance Method Details

#handle(event) ⇒ Object



16
17
18
19
20
21
# File 'app/subscribers/spree/order_commission_subscriber.rb', line 16

def handle(event)
  order = Spree::Order.find_by_prefix_id(event.payload['id'])
  return unless order

  Spree.commissions_commission_order_service.call(order: order)
end