Class: Iugu::AccountController
- Inherits:
-
AccountSettingsController
- Object
- AccountSettingsController
- Iugu::AccountController
- Defined in:
- app/controllers/iugu/account_controller.rb
Instance Method Summary collapse
- #activate ⇒ Object
- #cancel_destruction ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #generate_new_token ⇒ Object
- #index ⇒ Object
- #payment_history ⇒ Object
- #remove_token ⇒ Object
- #select ⇒ Object
- #suspend ⇒ Object
- #update ⇒ Object
- #view ⇒ Object
Instance Method Details
#activate ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'app/controllers/iugu/account_controller.rb', line 118 def activate get_account if @account.subscription.try :activate if @account.subscription.suspended notice = I18n.t("iugu.notices.account_will_be_activated") else notice = I18n.t("iugu.notices.account_activated") end @account.clear_cached_subscription_active else notice = I18n.t("iugu.notices.error_activating_account") end redirect_to account_view_path(params[:account_id]), :notice => notice end |
#cancel_destruction ⇒ Object
42 43 44 45 46 |
# File 'app/controllers/iugu/account_controller.rb', line 42 def cancel_destruction current_user.accounts.find(params[:id]).cancel_destruction notice = I18n.t("iugu.account_destruction_undone") redirect_to(account_settings_path, :notice => notice) end |
#create ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/controllers/iugu/account_controller.rb', line 64 def create create_parameters = {} if IuguSDK::enable_subscription_features plan_identifier = params[:plan] || IuguSDK::default_subscription_name currency = locale_to_currency I18n.locale create_parameters = {plan_identifier: plan_identifier, currency: currency, email: current_user.email} end acc = Account.create(create_parameters) current_user.accounts << acc #redirect_to account_view_path(acc) set_account(current_user, acc.id.to_param) redirect_to IuguSDK::app_main_url end |
#destroy ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/iugu/account_controller.rb', line 32 def destroy if IuguSDK::enable_account_cancel account = current_user.accounts.find(params[:id]) account.destroy redirect_to(account_settings_path, :notice => I18n.t("iugu.account_destruction_in") + account.destruction_job.run_at.to_s) else raise ActionController::RoutingError.new('Not found') end end |
#generate_new_token ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/controllers/iugu/account_controller.rb', line 78 def generate_new_token if IuguSDK::enable_account_api @account = current_user.accounts.find(params[:account_id]) token = @account.tokens.create(description: params[:description], api_type: params[:api_type]) if token.new_record? notice = token.errors. else notice = I18n.t("iugu.notices.new_token_generated") end flash[:group] = :api_token redirect_to account_view_path(params[:account_id]), :notice => notice else raise ActionController::RoutingError.new('Not found') end end |
#index ⇒ Object
6 7 8 9 |
# File 'app/controllers/iugu/account_controller.rb', line 6 def index @accounts = current_user.accounts.order(:created_at) render 'iugu/settings/accounts' end |
#payment_history ⇒ Object
110 111 112 113 114 115 116 |
# File 'app/controllers/iugu/account_controller.rb', line 110 def payment_history get_account subscription = Iugu::Api::Subscription.find @account.subscription_id.to_uuid.to_s customer = Iugu::Api::Customer.find subscription.customer_id @invoices = Iugu::Api::Invoice.find :all, params: {hl: current_user.locale, customer_id: customer.id.to_param, status_filter: ["pending", "paid"], limit: 10} render 'iugu/account/payment_history' end |
#remove_token ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'app/controllers/iugu/account_controller.rb', line 94 def remove_token if IuguSDK::enable_account_api account = current_user.accounts.find params[:account_id] token = account.tokens.find params[:token] if token.destroy notice = I18n.t("iugu.notices.token_removed") else notice = token.errors. end flash[:group] = :api_token redirect_to account_view_path(params[:account_id]), :notice => notice else raise ActionController::RoutingError.new('Not found') end end |
#select ⇒ Object
48 49 50 51 52 53 54 |
# File 'app/controllers/iugu/account_controller.rb', line 48 def select set_account(current_user, params[:id]) #redirect_to :back redirect_to IuguSDK::app_main_url rescue ActionController::RedirectBackError redirect_to(account_settings_path, :notice => "Account selected") end |
#suspend ⇒ Object
133 134 135 136 137 138 139 140 141 142 |
# File 'app/controllers/iugu/account_controller.rb', line 133 def suspend get_account if @account.subscription.try :suspend notice = I18n.t("iugu.notices.account_suspended") @account.clear_cached_subscription_active else notice = I18n.t("iugu.notices.error_suspending_account") end redirect_to account_view_path(params[:account_id]), :notice => notice end |
#update ⇒ Object
57 58 59 60 61 62 |
# File 'app/controllers/iugu/account_controller.rb', line 57 def update @account = Account.find(params[:id]) @account.update_attributes(params[:account]) flash[:group] = :account_update redirect_to account_view_path(params[:id]), :notice => I18n.t("iugu.notices.account_updated") end |
#view ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/controllers/iugu/account_controller.rb', line 11 def view if params[:id] @account = current_user.accounts.find(params[:id]) else @account = current_user_account.account end @has_subscription = false if IuguSDK::enable_subscription_features unless @account.subscription_id.blank? @has_subscription = true @subscription = @account.subscription plan = Iugu::Api::Plan.find_by_identifier @subscription.plan_identifier @plan_name = plan.try :name end end @primary_domain = @account.account_domains.where(:primary => true).first if @account render 'iugu/settings/account' end |