Class: Kaui::PaymentMethodsController
- Inherits:
-
EngineController
- Object
- ApplicationController
- EngineController
- Kaui::PaymentMethodsController
- Defined in:
- app/controllers/kaui/payment_methods_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #pagination ⇒ Object
- #show ⇒ Object
Methods inherited from EngineController
#check_for_redirect_to_tenant_screen, #current_ability, #current_user, #options_for_klient
Instance Method Details
#create ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'app/controllers/kaui/payment_methods_controller.rb', line 41 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, ) redirect_to payment_method_path(@payment_method.payment_method_id), :notice => 'Payment method was successfully created' rescue => e flash.now[:error] = "Error while creating payment method: #{as_string(e)}" render :action => :new end end |
#destroy ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 |
# File 'app/controllers/kaui/payment_methods_controller.rb', line 98 def destroy payment_method_id = params[:id] begin Kaui::PaymentMethod.destroy(payment_method_id, params[:set_auto_pay_off], current_user.kb_username, params[:reason], params[:comment], ) redirect_to payment_methods_path, :notice => "Payment method #{payment_method_id} successfully deleted" rescue => e flash.now[:error] = "Error while deleting payment method #{payment_method_id}: #{as_string(e)}" render :action => :index end end |
#index ⇒ Object
3 4 |
# File 'app/controllers/kaui/payment_methods_controller.rb', line 3 def index end |
#new ⇒ Object
36 37 38 39 |
# File 'app/controllers/kaui/payment_methods_controller.rb', line 36 def new @payment_method = Kaui::PaymentMethod.new(:account_id => params[:account_id], :plugin_name => params[:plugin_name] || Kaui.creditcard_plugin_name.call) end |
#pagination ⇒ Object
6 7 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 |
# File 'app/controllers/kaui/payment_methods_controller.rb', line 6 def pagination search_key = params[:sSearch] offset = params[:iDisplayStart] || 0 limit = params[:iDisplayLength] || 10 payment_methods = Kaui::PaymentMethod.list_or_search(search_key, offset, limit, ) json = { :sEcho => params[:sEcho], :iTotalRecords => payment_methods.pagination_max_nb_records, :iTotalDisplayRecords => payment_methods.pagination_total_nb_records, :aaData => [] } payment_methods.each do |payment_method| info_plugin = payment_method.plugin_info || OpenStruct.new json[:aaData] << [ view_context.link_to(view_context.truncate_uuid(payment_method.payment_method_id), view_context.url_for(:controller => :payment_methods, :action => :show, :id => payment_method.payment_method_id)), view_context.link_to(view_context.truncate_uuid(payment_method.account_id), view_context.url_for(:controller => :accounts, :action => :show, :id => payment_method.account_id)), info_plugin.external_payment_id, find_value_from_properties(info_plugin.properties, 'ccName'), find_value_from_properties(info_plugin.properties, 'ccLast4'), ] end respond_to do |format| format.json { render :json => json } end end |
#show ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'app/controllers/kaui/payment_methods_controller.rb', line 89 def show begin @payment_methods = [Kaui::PaymentMethod.find_by_id(params[:id], true, )] rescue => e flash.now[:error] = "Error while retrieving payment method #{params[:id]}: #{as_string(e)}" render :action => :index end end |