Sha256: dfd9f121ec2b48abd0710ab1a416e1c31318552a866e9ccbaca2d6643c0a5f87

Contents?: true

Size: 936 Bytes

Versions: 2

Compression:

Stored size: 936 Bytes

Contents

module Workarea
  module GlobalE
    module Api
      class UpdateOrderStatus::Canceled
        attr_reader :order

        def self.perform(order)
          new(order).perform
        end

        def initialize(order)
          @order = order
        end

        def perform
          restock
          update_fulfillment
          order.cancel
        end

        private

          def restock
            transaction = Inventory::Transaction.captured_for_order(order.id)
            transaction.rollback unless transaction.blank?
          end

          def fulfillment
            @fulfillment ||= Fulfillment.find_or_initialize_by(id: order.id)
          end

          def update_fulfillment
            cancellations = order.items.map do |item|
              { 'id' => item.id.to_s, 'quantity' => item.quantity }
            end

            fulfillment.cancel_items(cancellations)
          end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
workarea-global_e-1.3.0 app/services/workarea/global_e/api/update_order_status/canceled.rb
workarea-global_e-1.2.1 app/services/workarea/global_e/api/update_order_status/canceled.rb