Created
May 9, 2018 18:58
-
-
Save cored/add6d61ad2593c83c1cd01fe322021b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Casper | |
module OrderPublishing | |
def publish_to_queue(routing_key) | |
::Hutch::Casper::Publisher.publish(routing_key, serialized_order, {type: 'order'}) | |
end | |
def publish_tax_breakdown(routing_key) | |
::Hutch::Casper::Publisher.publish(routing_key, TaxBreakdownSerializer.new(self).as_json) | |
end | |
def publish_to_shipments_create | |
shipments.each do |shipment| | |
shipment.publish_if_order_complete(shipments_create_key) | |
end | |
end | |
def publish_finalize_messages | |
publish_to_queue(orders_complete_key) | |
publish_to_shipments_create | |
# We need to record tax in JDE at the time of order completion at the order level, | |
# and then on a transactional basis (as adjustments are created/ updated/ destroyed) | |
# at the adjustment level after the order is complete. | |
publish_tax_breakdown(adjustments_tax_update_key) | |
# We need to record promo adjustments in JDE at the time of order completion, and then on a | |
# transactional basis after the order is complete | |
publish_adjustments | |
publish_fees(line_items.surcharge) | |
# Commenting this out until we use store credit | |
# publish_store_credit | |
end | |
private | |
def publish_adjustments | |
all_adjustments.non_surcharge_or_tax.each do |adjustment| | |
::Hutch::Casper::Publisher.publish(adjustments_create_cx_key, adjustment.serialize(adjustment, root: :adjustment)) | |
end | |
end | |
def publish_fees(surcharges) | |
surcharges.each(&:publish_fee) | |
end | |
def publish_store_credit | |
payments.select(&:store_credit?).each do |credit_payment| | |
credit_payment.source.publish_to_jde("store_credits.capture", number) | |
end | |
end | |
def publish_shipment_state_if_order_complete | |
unless Groupments.publish_order_ready_to_group(CasperOrderSerializer.new(self)).success? | |
shipments.each do |shipment| | |
# Hardcoding the routing keys here until we can re-implement our | |
# method_missing override such that it doesn't blow up on them | |
# (see notes: https://github.com/CasperSleep/Casper/pull/5985). | |
shipment.publish_if_order_complete('shipments.ready') if shipment.ready? | |
shipment.publish_if_order_complete('shipments.pending') if shipment.pending? | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment