Sha256: bd7265b45fcd78f1418a730bd57fc36daa80023853297bb2de3011c5020eed04

Contents?: true

Size: 832 Bytes

Versions: 3

Compression:

Stored size: 832 Bytes

Contents

# frozen_string_literal: true
module Decidim
  module Budgets
    # A command with all the business to checkout.
    class Checkout < Rectify::Command
      # Public: Initializes the command.
      #
      # order - The current order for the user.
      # feature - The current feature.
      def initialize(order, feature)
        @order = order
        @feature = feature
      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) unless @order&.can_checkout?
        checkout!
        broadcast(:ok, @order)
      end

      private

      def checkout!
        @order.update_attributes!(checked_out_at: Time.current)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
decidim-0.0.4 decidim-budgets/app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.0.3 app/commands/decidim/budgets/checkout.rb
decidim-0.0.3 decidim-budgets/app/commands/decidim/budgets/checkout.rb