Class: Kaui::ChargesController
- Inherits:
-
EngineController
- Object
- EngineController
- Kaui::ChargesController
- Defined in:
- app/controllers/kaui/charges_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/controllers/kaui/charges_controller.rb', line 21 def create charge = Kaui::InvoiceItem.new(params.require(:invoice_item).permit!.to_h.compact_blank) charge.account_id ||= params.require(:account_id) # Preserve the original invoice_id since the API may not return it original_invoice_id = charge.invoice_id auto_commit = params[:auto_commit] == '1' charge = charge.create(auto_commit, current_user.kb_username, params[:reason], params[:comment], ) redirect_to kaui_engine.account_invoice_path(charge.account_id, charge.invoice_id || original_invoice_id), notice: 'Charge was successfully created' end |
#new ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/controllers/kaui/charges_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 @charge = Kaui::InvoiceItem.new(account_id: params.require(:account_id), invoice_id:, amount:, currency:) end |