Sha256: bd93d26e09d41975f9af6f62af77a27db872f402b604c47781f276c417f2ca78

Contents?: true

Size: 1.05 KB

Versions: 29

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module Decidim
  module Budgets
    # A command with all the business to checkout.
    class Checkout < Decidim::Command
      # Public: Initializes the command.
      #
      # order - The current order for the user.
      def initialize(order)
        @order = order
      end

      # Executes the command. Broadcasts these events:
      #
      # - :ok when everything is valid.
      # - :invalid if the there is an error.
      #
      # Returns nothing.
      def call
        return broadcast(:invalid, order) unless checkout!

        broadcast(:ok, order)
      end

      private

      attr_reader :order

      def checkout!
        return unless order && order.valid?

        @order.with_lock do
          SendOrderSummaryJob.perform_later(@order)

          Decidim.traceability.update!(
            @order,
            @order.user,
            { checked_out_at: Time.current },
            visibility: "private-only"
          )
        rescue ActiveRecord::RecordInvalid
          false
        end
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
decidim-budgets-0.30.0.rc2 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.30.0.rc1 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.29.2 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.28.5 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.29.1 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.28.4 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.27.9 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.29.0 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.28.3 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.27.8 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.29.0.rc4 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.29.0.rc3 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.29.0.rc2 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.29.0.rc1 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.28.2 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.27.7 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.28.1 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.27.6 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.28.0 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.27.5 app/commands/decidim/budgets/checkout.rb