Class: Kaui::ChargebacksController
- Inherits:
-
EngineController
- Object
- ApplicationController
- EngineController
- Kaui::ChargebacksController
- Defined in:
- app/controllers/kaui/chargebacks_controller.rb
Constant Summary
Constants included from EngineControllerUtil
EngineControllerUtil::SIMPLE_PAGINATION_THRESHOLD
Instance Method Summary collapse
Methods inherited from EngineController
#check_for_redirect_to_tenant_screen, #current_ability, #current_user, #options_for_klient, #populate_account_details, #retrieve_allowed_users_for_current_user, #retrieve_tenants_for_current_user
Instance Method Details
#create ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/kaui/chargebacks_controller.rb', line 10 def create @chargeback = Kaui::Chargeback.new(params.require(:chargeback)) should_cancel_subs = (params[:cancel_all_subs] == '1') begin payment = @chargeback.chargeback(current_user.kb_username, params[:reason], params[:comment], ) rescue => e flash.now[:error] = "Error while creating a new chargeback: #{as_string(e)}" render :action => :new and return end # Cancel all subscriptions on the account, if required if should_cancel_subs begin account = Kaui::Account.find_by_id(payment.account_id, false, false, ) account.bundles().each do |bundle| bundle.subscriptions.each do |subscription| # Already cancelled? next unless subscription.billing_end_date.blank? # Cancel the entitlement immediately but use the default billing policy entitlement = Kaui::Subscription.new(:subscription_id => subscription.subscription_id) entitlement.cancel_entitlement_immediately(current_user.kb_username, params[:reason], params[:comment], ) end end rescue => e flash[:error] = "Error while cancelling subscriptions: #{as_string(e)}" render :action => :new and return end end redirect_to kaui_engine.account_payment_path(payment.account_id, payment.payment_id), :notice => 'Chargeback created' end |
#new ⇒ Object
3 4 5 6 7 8 |
# File 'app/controllers/kaui/chargebacks_controller.rb', line 3 def new payment = Kaui::Payment::find_by_id(params.require(:payment_id), false, false, ) @chargeback = Kaui::Chargeback.new(:payment_id => payment.payment_id, :amount => payment.paid_amount_to_money.to_f, :currency => payment.currency) end |