Class: Spree::SolidusSixSaferpay::CheckoutController
- Inherits:
-
StoreController
- Object
- StoreController
- Spree::SolidusSixSaferpay::CheckoutController
show all
- Defined in:
- app/controllers/spree/solidus_six_saferpay/checkout_controller.rb
Instance Method Summary
collapse
Instance Method Details
#fail ⇒ Object
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'app/controllers/spree/solidus_six_saferpay/checkout_controller.rb', line 107
def fail
order_number = params[:order_number]
@order = Spree::Order.find_by(number: order_number)
if @order.nil?
OrderNotFoundHandler.call(controller_context: self, order_number: order_number)
flash[:error] = t('.error_while_processing_payment')
@redirect_path ||= spree.cart_path
render :iframe_breakout_redirect, layout: false
return
end
saferpay_payment = Spree::SixSaferpayPayment.where(order_id: @order.id).order(:created_at).last
if saferpay_payment.nil?
PaymentNotFoundHandler.call(controller_context: self, order: @order)
flash[:error] = t('.error_while_processing_payment')
@redirect_path = spree.cart_path
render :iframe_breakout_redirect, layout: false
return
end
payment_inquiry = inquire_payment(saferpay_payment)
flash[:error] = payment_inquiry.user_message
@redirect_path = order_checkout_path(:payment)
render :iframe_breakout_redirect, layout: false
end
|
#init ⇒ Object
5
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
35
36
37
38
|
# File 'app/controllers/spree/solidus_six_saferpay/checkout_controller.rb', line 5
def init
order_number = params[:order_number]
@order = Spree::Order.find_by(number: order_number)
if @order.nil? || @order != current_order
render json: {
redirect_url: spree.cart_path,
errors: t('.order_was_modified_after_confirmation')
}, status: 422
return
end
payment_method = Spree::PaymentMethod.find(params[:payment_method_id])
initialized_payment = initialize_payment(@order, payment_method)
if initialized_payment.success?
redirect_url = initialized_payment.redirect_url
render json: { redirect_url: redirect_url }
else
render json: {
redirect_url: spree.cart_path,
errors: t('.checkout_not_initialized')
}, status: 422
end
end
|
#success ⇒ Object
40
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'app/controllers/spree/solidus_six_saferpay/checkout_controller.rb', line 40
def success
order_number = params[:order_number]
@order = Spree::Order.find_by(number: order_number)
if @order.nil?
OrderNotFoundHandler.call(controller_context: self, order_number: order_number)
flash[:error] = t('.error_while_processing_payment')
@redirect_path ||= spree.cart_path
render :iframe_breakout_redirect, layout: false
return
end
saferpay_payment = Spree::SixSaferpayPayment.where(order_id: @order.id).order(:created_at).last
if saferpay_payment.nil?
PaymentNotFoundHandler.call(controller_context: self, order: @order)
flash[:error] = t('.error_while_processing_payment')
@redirect_path ||= spree.cart_path
render :iframe_breakout_redirect, layout: false
return
end
if @order.completed?
@redirect_path = spree.cart_path
render :iframe_breakout_redirect, layout: false
return
end
payment_authorization = authorize_payment(saferpay_payment)
if payment_authorization.success?
processed_authorization = process_authorization(saferpay_payment)
if processed_authorization.success?
PaymentProcessingSuccessHandler.call(controller_context: self, order: @order)
else
flash[:error] = processed_authorization.user_message
end
else
payment_inquiry = inquire_payment(saferpay_payment)
flash[:error] = payment_inquiry.user_message
end
@redirect_path ||= order_checkout_path(@order.state)
render :iframe_breakout_redirect, layout: false
end
|