Sha256: 251e22433d4bf87b5e53f83ca2cd30ab336c1ea4b58d7465cdeddfd4d4c75967

Contents?: true

Size: 765 Bytes

Versions: 30

Compression:

Stored size: 765 Bytes

Contents

module Spree
  module Cart
    class Destroy
      prepend Spree::ServiceModule::Base

      def call(order:)
        run :check_if_can_be_destroyed
        run :cancel_shipments
        run :void_payments
        run :destroy_order
      end

      private

      def check_if_can_be_destroyed(order:)
        return failure(Spree.t(:cannot_be_destroyed)) unless order&.can_be_destroyed?

        success(order: order)
      end

      def cancel_shipments(order:)
        order.shipments.each(&:cancel!)

        success(order: order)
      end

      def void_payments(order:)
        order.payments.each(&:void!)

        success(order: order)
      end

      def destroy_order(order:)
        order.destroy

        success(order)
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
spree_core-4.8.3 app/services/spree/cart/destroy.rb
spree_core-4.8.2 app/services/spree/cart/destroy.rb
spree_core-4.7.3 app/services/spree/cart/destroy.rb
spree_core-4.6.6 app/services/spree/cart/destroy.rb
spree_core-4.5.5 app/services/spree/cart/destroy.rb
spree_core-4.3.3 app/services/spree/cart/destroy.rb
spree_core-4.4.1 app/services/spree/cart/destroy.rb
spree_core-4.5.4 app/services/spree/cart/destroy.rb
spree_core-4.6.5 app/services/spree/cart/destroy.rb
spree_core-4.7.2 app/services/spree/cart/destroy.rb
spree_core-4.7.1 app/services/spree/cart/destroy.rb
spree_core-4.6.4 app/services/spree/cart/destroy.rb
spree_core-4.7.0 app/services/spree/cart/destroy.rb
spree_core-4.6.3 app/services/spree/cart/destroy.rb
spree_core-4.6.2 app/services/spree/cart/destroy.rb
spree_core-4.6.1 app/services/spree/cart/destroy.rb
spree_core-4.6.0 app/services/spree/cart/destroy.rb
spree_core-4.5.3 app/services/spree/cart/destroy.rb
spree_core-4.5.2 app/services/spree/cart/destroy.rb
spree_core-4.5.1 app/services/spree/cart/destroy.rb