Class: Decidim::Budgets::OrdersController

Inherits:
ApplicationController show all
Includes:
NeedsCurrentOrder
Defined in:
decidim-budgets/app/controllers/decidim/budgets/orders_controller.rb

Overview

Exposes the order resource so users can checkout it.

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_workflow, #voting_finished?, #voting_open?

Methods inherited from Components::BaseController

#current_component, #current_manifest, #current_participatory_space, #permission_class_chain, #permission_scope, #redirect_unless_feature_private, #set_component_breadcrumb_item, #share_token

Methods included from RegistersPermissions

register_permissions

Methods included from UserBlockedChecker

#check_user_block_status, #check_user_not_blocked

Methods included from NeedsSnippets

#snippets

Methods included from Headers::HttpCachingDisabler

#disable_http_caching

Methods included from HasStoredPath

#skip_store_location?, #store_current_location

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#checkoutObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'decidim-budgets/app/controllers/decidim/budgets/orders_controller.rb', line 9

def checkout
  enforce_permission_to :vote, :project, order: current_order, budget:, workflow: current_workflow

  Checkout.call(current_order) do
    on(:ok) do
      i18n_key = pending_to_vote_budgets.any? ? "success_html" : "success_no_left_budgets_html"
      flash[:notice] = I18n.t(i18n_key, scope: "decidim.orders.checkout", rest_of_budgets_link: "#budgets")
      redirect_to budgets_path
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("orders.checkout.error", scope: "decidim")
      redirect_to budgets_path
    end
  end
end

#destroyObject



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'decidim-budgets/app/controllers/decidim/budgets/orders_controller.rb', line 26

def destroy
  CancelOrder.call(current_order) do
    on(:ok) do
      flash[:notice] = I18n.t("orders.destroy.success", scope: "decidim")
      redirect_to redirect_path
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("orders.destroy.error", scope: "decidim")
      redirect_to redirect_path
    end
  end
end