Class: Kaui::PaymentMethodsController

Inherits:
EngineController show all
Defined in:
app/controllers/kaui/payment_methods_controller.rb

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

#createObject



8
9
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
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/kaui/payment_methods_controller.rb', line 8

def create
  @payment_method             = Kaui::PaymentMethod.new(params[:payment_method].delete_if { |key, value| value.blank? })
  # Transform "1" into boolean
  @payment_method.is_default  = @payment_method.is_default == '1'
  # Sensible default
  @payment_method.plugin_name ||= Kaui.creditcard_plugin_name.call

  # Instance variables needed in case of failure
  @card_type                  = params[:card_type]
  @card_holder_name           = params[:card_holder_name]
  @expiration_year            = params[:expiration_year]
  @expiration_month           = params[:expiration_month]
  @credit_card_number         = params[:credit_card_number]
  @verification_value         = params[:verification_value]
  @address1                   = params[:address1]
  @address2                   = params[:address2]
  @city                       = params[:city]
  @postal_code                = params[:postal_code]
  @state                      = params[:state]
  @country                    = params[:country]

  # Magic from lib/killbill/helpers/active_merchant/payment_plugin.rb
  @payment_method.plugin_info = {
      'type'                => 'CreditCard',
      'ccType'              => @card_type,
      'ccFirstName'         => @card_holder_name,
      'ccLastName'          => @card_holder_name,
      'ccExpirationMonth'   => @expiration_month,
      'ccExpirationYear'    => @expiration_year,
      'ccNumber'            => @credit_card_number,
      'ccVerificationValue' => @verification_value,
      'address1'            => @address1,
      'address2'            => @address2,
      'city'                => @city,
      'country'             => @country,
      'zip'                 => @postal_code,
      'state'               => @state
  }

  begin
    @payment_method = @payment_method.create(@payment_method.is_default, current_user.kb_username, @reason, @comment, options_for_klient)
    redirect_to kaui_engine.(@payment_method.), :notice => 'Payment method was successfully created'
  rescue => e
    flash.now[:error] = "Error while creating payment method: #{as_string(e)}"
    render :action => :new
  end
end

#destroyObject



56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/kaui/payment_methods_controller.rb', line 56

def destroy
  payment_method_id = params[:id]

  payment_method = Kaui::PaymentMethod.find_by_id(payment_method_id, false, options_for_klient)
  begin
    Kaui::PaymentMethod.destroy(payment_method_id, params[:set_auto_pay_off], false, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
    redirect_to kaui_engine.(payment_method.), :notice => "Payment method #{payment_method_id} successfully deleted"
  rescue => e
    flash[:error] = "Error while deleting payment method #{payment_method_id}: #{as_string(e)}"
    redirect_to kaui_engine.(payment_method.)
  end
end

#newObject



3
4
5
6
# File 'app/controllers/kaui/payment_methods_controller.rb', line 3

def new
  @payment_method = Kaui::PaymentMethod.new(:account_id  => params[:account_id],
                                            :plugin_name => params[:plugin_name] || Kaui.creditcard_plugin_name.call)
end

#restful_showObject



73
74
75
76
# File 'app/controllers/kaui/payment_methods_controller.rb', line 73

def restful_show
  payment_method = Kaui::PaymentMethod.find_by_id(params.require(:id), false, options_for_klient)
  redirect_to kaui_engine.(payment_method.)
end

#showObject



69
70
71
# File 'app/controllers/kaui/payment_methods_controller.rb', line 69

def show
  restful_show
end