Sha256: c11e4cfbbf6e8813e7059fc160fbcedd9760b995477dc50690c93cd2697cc811

Contents?: true

Size: 1.88 KB

Versions: 6

Compression:

Stored size: 1.88 KB

Contents

class Kaui::ChargebacksController < Kaui::EngineController

  def show
    @payment_id = params[:id]
    if @payment_id.present?
      begin
        data = Kaui::KillbillHelper::get_chargebacks_for_payment(@payment_id)
      rescue => e
        flash[:error] = "Error while getting chargeback information: #{as_string(e)}"
      end
      if data.present?
        @chargeback = Kaui::Chargeback.new(data)
      else
        Rails.logger.warn("Did not get back chargebacks #{response_body}")
      end
    else
      flash[:notice] = "No id given"
    end
  end

  def new
    @payment_id = params[:payment_id]
    @account_id = params[:account_id]
    @invoice_id = params[:invoice_id]

    begin
      @account = Kaui::KillbillHelper::get_account(@account_id)
      @payment = Kaui::KillbillHelper::get_payment(@payment_id)
      @invoice = Kaui::KillbillHelper::get_invoice(@invoice_id)
    rescue => e
      flash[:error] = "Error while starting a new chargeback: #{as_string(e)}"
      redirect_to kaui_engine.account_timeline_path(:id => params[:account_id])
    end

    # The payment method may have been deleted
    @payment_method = Kaui::KillbillHelper::get_payment_method(@payment.payment_method_id) rescue nil

    @chargeback = Kaui::Chargeback.new("paymentId" => @payment_id,
                                       "chargebackAmount" => @payment.amount)
  end

  def create
    account_id = params[:account_id]
    chargeback = Kaui::Chargeback.new(params[:chargeback])

    if chargeback.present?
      begin
        Kaui::KillbillHelper::create_chargeback(chargeback, params[:reason], params[:comment])
        flash[:info] = "Chargeback created"
      rescue => e
        flash[:error] = "Error while creating a new chargeback: #{as_string(e)}"
      end
    else
      flash[:error] = "No chargeback to process"
    end
    redirect_to kaui_engine.account_timeline_path(:id => params[:account_id])
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
kaui-0.2.6 app/controllers/kaui/chargebacks_controller.rb
kaui-0.2.5 app/controllers/kaui/chargebacks_controller.rb
kaui-0.2.4 app/controllers/kaui/chargebacks_controller.rb
kaui-0.2.3 app/controllers/kaui/chargebacks_controller.rb
kaui-0.2.2 app/controllers/kaui/chargebacks_controller.rb
kaui-0.2.1 app/controllers/kaui/chargebacks_controller.rb