Module: Auth::Concerns::Shopping::PaymentControllerConcern

Extended by:
ActiveSupport::Concern
Included in:
Shopping::PaymentsController
Defined in:
app/controllers/auth/concerns/shopping/payment_controller_concern.rb

Instance Method Summary collapse

Instance Method Details

#createObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/auth/concerns/shopping/payment_controller_concern.rb', line 41

def create
 
  check_for_create(@auth_shopping_payment)
 
  @auth_shopping_payment.payment_params = params
  
 

  @auth_shopping_payment = add_owner_and_signed_in_resource(@auth_shopping_payment)
 
  resp = @auth_shopping_payment.save
  
     
 
  respond_with @auth_shopping_payment
end

#destroyObject



82
83
84
85
86
87
88
# File 'app/controllers/auth/concerns/shopping/payment_controller_concern.rb', line 82

def destroy
   @auth_shopping_payment = add_signed_in_resource(@auth_shopping_payment)
   if @auth_shopping_payment.signed_in_resource.is_admin?
      @auth_shopping_payment.delete
   end
   respond_with @auth_shopping_payment
end

#editObject



37
38
39
# File 'app/controllers/auth/concerns/shopping/payment_controller_concern.rb', line 37

def edit

end

#indexObject



24
25
26
27
28
# File 'app/controllers/auth/concerns/shopping/payment_controller_concern.rb', line 24

def index
  ## need to find all the payments
  @auth_shopping_payments = @auth_shopping_payment_class.where(:resource_id => lookup_resource.id.to_s)
  respond_with @auth_shopping_payments
end

#initialize_varsObject



9
10
11
12
13
14
15
# File 'app/controllers/auth/concerns/shopping/payment_controller_concern.rb', line 9

def initialize_vars
 
  instantiate_shopping_classes
  @auth_shopping_payment_params = permitted_params.fetch(:payment,{})
 
  @auth_shopping_payment = params[:id] ? @auth_shopping_payment_class.find_self(params[:id],current_signed_in_resource) : @auth_shopping_payment_class.new(@auth_shopping_payment_params)
end

#newObject



30
31
32
33
34
35
# File 'app/controllers/auth/concerns/shopping/payment_controller_concern.rb', line 30

def new
 # puts "these are payment attributes"
 # puts @auth_shopping_payment.attributes.to_s
  @auth_shopping_payment = add_owner_and_signed_in_resource(@auth_shopping_payment)
  @auth_shopping_payment.set_cart(@auth_shopping_payment.cart_id)
end

#permitted_paramsObject



91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/controllers/auth/concerns/shopping/payment_controller_concern.rb', line 91

def permitted_params
  payment_params = [:payment_type, :amount, :cart_id,:payment_ack_proof, :refund, :payment_status, :is_verify_payment,:discount_id]

  if !current_signed_in_resource.is_admin?
    payment_params.delete(:payment_status)
    if action_name.to_s == "update"
      payment_params = [:is_verify_payment]
    end
  end
  params.permit({payment: payment_params},:id)
  
end

#showObject



17
18
19
20
21
22
# File 'app/controllers/auth/concerns/shopping/payment_controller_concern.rb', line 17

def show
  @auth_shopping_payment = add_signed_in_resource(@auth_shopping_payment)

  @auth_shopping_payment.set_payment_receipt
  respond_with @auth_shopping_payment
end

#updateObject

in the normal process of making a cash payment we render a cash form, then we create a payment and then we should in the show screen,to confirm and commit the payment which finally brings it here. validations in the create call should look into whether there is a picture/cash/cheque whatever requirements are there.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/controllers/auth/concerns/shopping/payment_controller_concern.rb', line 61

def update
  #puts "params coming to update are:"
  #puts params.to_s
  check_for_update(@auth_shopping_payment)
  
  @auth_shopping_payment.assign_attributes(@auth_shopping_payment_params)
  
  @auth_shopping_payment = add_owner_and_signed_in_resource(@auth_shopping_payment)
  
  ##note that params and not permitted_params is called, here because the gateway sends back all the params as a naked hash, and that is used directly to verify the authenticity, in the gateway functions.
  #puts "these are the attributes assigned in the update action."
  #puts @auth_shopping_payment.attributes.to_s
  @auth_shopping_payment.payment_params = params
 
  save_response = @auth_shopping_payment.save
  
  ## if save successfull then otherwise, respond_with edit.
  respond_with @auth_shopping_payment, location: (save_response == true ? payment_path(@auth_shopping_payment) : edit_payment_path(@auth_shopping_payment))

end