Class: Spree::Billing::PaymentsController
Instance Method Summary
collapse
#fire, #fire_action, #supported_events
#create
#current_vendor, #default_url_options, #edit_object_url, #handle_unauthorized_vendor, #page, #per_page, #required_vendor_user!, #set_locale, #switch_vendor, #vendors
#auth_action, #auth_entry, #auth_user, #authorize!, #authorize?, #authorize_admin, #authorize_role!, #redirect_unauthorized_access
Instance Method Details
#check_payment_source ⇒ Object
92
93
94
95
96
|
# File 'app/controllers/spree/billing/payments_controller.rb', line 92
def check_payment_source
return unless @payment.payment_source.nil? || @payment.payment_source.blank?
raise SpreeCmCommissioner::PaymentSourceMissingError
end
|
#collection_url(options = {}) ⇒ Object
128
129
130
|
# File 'app/controllers/spree/billing/payments_controller.rb', line 128
def collection_url(options = {})
billing_order_payments_url(options)
end
|
#handle_payment_creation_error ⇒ Object
110
111
112
113
114
|
# File 'app/controllers/spree/billing/payments_controller.rb', line 110
def handle_payment_creation_error
flash[:error] = Spree.t(:payment_creation_error)
redirect_to request.referer || spree.billing_order_payments_path(@order)
end
|
#handle_payment_source_missing ⇒ Object
98
99
100
101
102
|
# File 'app/controllers/spree/billing/payments_controller.rb', line 98
def handle_payment_source_missing
flash[:error] = Spree.t(:payment_source_missing)
redirect_to request.referer || spree.billing_order_payments_path(@order)
end
|
#handle_spree_core_gateway_error(error) ⇒ Object
104
105
106
107
108
|
# File 'app/controllers/spree/billing/payments_controller.rb', line 104
def handle_spree_core_gateway_error(error)
flash[:error] = error.message.to_s
redirect_to request.referer || spree.billing_order_payments_path(@order)
end
|
#index ⇒ Object
37
38
39
40
41
42
|
# File 'app/controllers/spree/billing/payments_controller.rb', line 37
def index
@payments = @order.payments.includes(refunds: :reason)
@refunds = @payments.flat_map(&:refunds)
redirect_to new_billing_order_payment_url(@order) if @payments.empty?
end
|
#load_data ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'app/controllers/spree/billing/payments_controller.rb', line 22
def load_data
@amount = params[:amount] || @order.total
@payment_methods = @order.collect_backend_payment_methods
@penalty_in_day = SpreeCmCommissioner::PenaltyCalculator.calculate_penalty_in_days(Time.zone.now, @order.line_items.first.due_date)
if @payment&.payment_method
@payment_method = @payment.payment_method
else
@payment_method = @payment_methods.find { |p| p.id == params[:payment][:payment_method_id].to_i } if params[:payment]
@payment_method ||= @payment_methods.first
end
end
|
#load_resource_instance ⇒ Object
86
87
88
89
90
|
# File 'app/controllers/spree/billing/payments_controller.rb', line 86
def load_resource_instance
return order.payments.build if new_actions.include?(action)
order.payments.find_by!(number: params[:id])
end
|
#model_class ⇒ Object
120
121
122
|
# File 'app/controllers/spree/billing/payments_controller.rb', line 120
def model_class
Spree::Payment
end
|
#object_name ⇒ Object
124
125
126
|
# File 'app/controllers/spree/billing/payments_controller.rb', line 124
def object_name
'payment'
end
|
#order ⇒ Object
116
117
118
|
# File 'app/controllers/spree/billing/payments_controller.rb', line 116
def order
@order ||= Spree::Order.find_by!(number: params[:order_id])
end
|
#set_current_user_instance ⇒ Object
18
19
20
|
# File 'app/controllers/spree/billing/payments_controller.rb', line 18
def set_current_user_instance
@payment.current_user_instance = spree_current_user
end
|
#show ⇒ Object
44
45
46
|
# File 'app/controllers/spree/billing/payments_controller.rb', line 44
def show
@payment = @object
end
|
#update ⇒ Object
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
|
# File 'app/controllers/spree/billing/payments_controller.rb', line 48
def update
check_payment_source
update_payment_amount
unless @payment.save
flash[:error] = @payment.errors.full_messages.join('. ')
return redirect_to request.referer || spree.billing_order_payments_path(@order)
end
unless @payment.send("#{params[:e]}!")
flash[:error] = Spree.t(:cannot_perform_operation)
raise Spree::Core::GatewayError
end
flash[:success] = Spree.t(:payment_updated)
return if params[:e] == 'void_transaction'
return unless @order.outstanding_balance.positive?
@payment = @order.payments.build(amount: @order.outstanding_balance, payment_method: @order.collect_backend_payment_methods.first)
raise SpreeCmCommissioner::PaymentCreationError unless @payment.save
redirect_to request.referer || spree.billing_order_payments_path(@order)
end
|
#verify_event ⇒ Object
supported_events is a method from Spree::Billing::PaymentFireable
76
77
78
79
80
81
82
83
84
|
# File 'app/controllers/spree/billing/payments_controller.rb', line 76
def verify_event
params[:e] = 'void_transaction' if params[:e] == 'void'
return if supported_events.include?(params[:e])
flash[:error] = Spree.t(:unsupported_event)
raise Spree::Core::GatewayError
end
|