Module: Order::AuthorizationSplittable
- Extended by:
- ActiveSupport::Concern
- Included in:
- Order
- Defined in:
- app/models/order/authorization_splittable.rb
Overview
Lets a split-off child order pull its share of the parent order's
authorization once it has a committed delivery to attach payment to.
Splitting moves line items into the child immediately, but its delivery
(and therefore the unit payments attach to) is committed later. The original
splitter only allocated payment when that delivery happened to exist at split
time; this concern + AuthorizationSplitWorker close the gap by
reacting when the delivery is finally committed.
Belongs to collapse
Has many collapse
Instance Method Summary collapse
-
#needs_authorization_split_from_parent? ⇒ Boolean
True when this is a split-off child that is funded by a parent authorization that hasn't been allocated to it yet, and whose deliveries are now committed (so the amount is final and there's something to attach payment to).
Instance Method Details
#children ⇒ ActiveRecord::Relation<Order>
19 |
# File 'app/models/order/authorization_splittable.rb', line 19 has_many :children, class_name: 'Order', foreign_key: :parent_id, inverse_of: :parent, dependent: :nullify |
#needs_authorization_split_from_parent? ⇒ Boolean
True when this is a split-off child that is funded by a parent
authorization that hasn't been allocated to it yet, and whose deliveries
are now committed (so the amount is final and there's something to attach
payment to).
The authoritative idempotency guard — re-checked under the advisory lock in
Order::AuthorizationSplitWorker.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/models/order/authorization_splittable.rb', line 31 def return false if parent_id.blank? own_deliveries = deliveries.to_a return false if own_deliveries.empty? return false if own_deliveries.any?(&:quoting?) # wait until shipping is finalized return false unless balance.positive? # nothing left to fund return false if payments..exists? # already has its own authorization par = parent return false unless par # A parent authorization is still "unsplit" while its original CC auth is # intact (the shared-PI split voids it), or there's an authorized PO/PayPal. par.payments. .where(category: [Payment::CREDIT_CARD, Payment::PO, Payment::VPO, Payment::CHECK, Payment::CASH, Payment::PAYPAL]) .exists? end |
#parent ⇒ Order
18 |
# File 'app/models/order/authorization_splittable.rb', line 18 belongs_to :parent, class_name: 'Order', optional: true, inverse_of: :children |