Sha256: 5ecb6694d0c3683191a8089a87d52518f8ec48b271ea568749a0d0f341f6b17c

Contents?: true

Size: 1.9 KB

Versions: 8

Compression:

Stored size: 1.9 KB

Contents

class Kaui::ChargebacksController < Kaui::EngineController

  def new
    payment = Kaui::Payment::find_by_id(params.require(:payment_id), false, false, options_for_klient)
    @chargeback = Kaui::Chargeback.new(:payment_id => payment.payment_id,
                                       :amount => payment.paid_amount_to_money.to_f,
                                       :currency => payment.currency)
  end

  def create
    cached_options_for_klient = options_for_klient

    @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], cached_options_for_klient)
    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, cached_options_for_klient)
        account.bundles(cached_options_for_klient).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], cached_options_for_klient)
          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
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
kaui-2.1.0 app/controllers/kaui/chargebacks_controller.rb
kaui-2.0.4 app/controllers/kaui/chargebacks_controller.rb
kaui-2.0.3 app/controllers/kaui/chargebacks_controller.rb
kaui-2.0.2 app/controllers/kaui/chargebacks_controller.rb
kaui-2.0.1 app/controllers/kaui/chargebacks_controller.rb
kaui-2.0.0 app/controllers/kaui/chargebacks_controller.rb
kaui-1.4.1 app/controllers/kaui/chargebacks_controller.rb
kaui-1.4.0 app/controllers/kaui/chargebacks_controller.rb