Class: Kaui::CreditsController
- Inherits:
-
EngineController
- Object
- EngineController
- Kaui::CreditsController
- Defined in:
- app/controllers/kaui/credits_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/controllers/kaui/credits_controller.rb', line 21 def create credit = Kaui::Credit.new(params[:credit].permit!.to_h.compact_blank) credit.account_id ||= params.require(:account_id) # No need to show the newly created invoice for account level credits should_redirect_to_invoice = credit.invoice_id.present? credits = credit.create(true, current_user.kb_username, params[:reason], params[:comment], ) flash[:notice] = 'Credit was successfully created' if should_redirect_to_invoice redirect_to kaui_engine.account_invoice_path(credits[0].account_id, credits[0].invoice_id) else redirect_to kaui_engine.account_path(credits[0].account_id) end end |
#new ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/controllers/kaui/credits_controller.rb', line 5 def new invoice_id = params[:invoice_id] amount = params[:amount] if invoice_id.present? @invoice = Kaui::Invoice.find_by_id(invoice_id, false, 'NONE', ) amount ||= @invoice.balance currency = @invoice.currency else @invoice = nil currency = params[:currency] || 'USD' end @credit = Kaui::Credit.new(account_id: params.require(:account_id), invoice_id:, amount:, currency:) end |