Class: Spree::Kashflow::SyncOrderJob
- Inherits:
-
BaseJob
- Object
- BaseJob
- Spree::Kashflow::SyncOrderJob
- Defined in:
- app/jobs/spree/kashflow/sync_order_job.rb
Overview
Posts a completed order to KashFlow as an invoice.
A resumable state machine, not an all-or-nothing job. Posting the invoice and recording its payment are two separate KashFlow calls, each with its own metafield marker written the instant it succeeds (Metafields::ORDER_INVOICE_NUMBER and Metafields::ORDER_PAYMENT_RECORDED_AT), and each guarded independently in #sync. A rerun therefore resumes at the first unfinished step rather than replaying the whole job or skipping it wholesale — which is what makes it safe both to retry and to enqueue from more than one trigger (a subscriber and a decorator both firing for the same event, for instance) without double-booking. Takes an id, never an Order, so ActiveJob's argument serialisation never has to round-trip a whole AR object.
Instance Method Summary collapse
Instance Method Details
#perform(order_id) ⇒ void
This method returns an undefined value.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/jobs/spree/kashflow/sync_order_job.rb', line 46 def perform(order_id) order = Spree::Order.find_by(id: order_id) return if order.nil? integration = Spree::Integrations::Kashflow.active.find_by(store: order.store) return if integration.nil? return if invoice_posted?(order) && payment_settled?(order) sync(order, integration) rescue Spree::Kashflow::Error => e Metafields.write(order, Metafields::ORDER_SYNC_ERROR, e.) raise end |