Class: Caboose::MyAccountInvoicesController
Instance Method Summary
collapse
#add_ga_event, #admin_add, #admin_bulk_add, #admin_bulk_delete, #admin_bulk_update, #admin_delete, #admin_edit, #admin_index, #admin_json, #admin_json_single, #admin_update, #before_action, #before_before_action, #hashify_query_string, #init_cart, #logged_in?, #logged_in_user, #login_user, #logout_user, #parse_url_params, #reject_param, #under_construction_or_forwarding_domain?, #user_is_allowed, #user_is_allowed_to, #validate_cookie, #validate_token, #var, #verify_logged_in
Instance Method Details
#authnet_relay ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
# File 'app/controllers/caboose/my_account_invoices_controller.rb', line 92
def authnet_relay
Caboose.log("Authorize.net relay for my account, invoice #{params[:x_invoice_id]}")
invoice = Caboose::Invoice.find(params[:x_invoice_num])
ot = Caboose::InvoiceTransaction.new(
:invoice_id => invoice.id,
:date_processed => DateTime.now.utc,
:transaction_type => Caboose::InvoiceTransaction::TYPE_AUTHORIZE
)
ot.success = params[:x_response_code] && params[:x_response_code] == '1'
ot.transaction_id = params[:x_trans_id] if params[:x_trans_id]
ot.auth_code = params[:x_auth_code] if params[:x_auth_code]
ot.response_code = params[:x_response_code] if params[:x_response_code]
ot.amount = invoice.total
ot.save
error = nil
if ot.success
invoice.financial_status = Invoice::FINANCIAL_STATUS_AUTHORIZED
invoice.status = Invoice::STATUS_PENDING if invoice.status == Invoice::STATUS_CART
invoice.invoice_number = @site.store_config.next_invoice_number if invoice.invoice_number.nil?
InvoicesMailer.configure_for_site(@site.id).customer_new_invoice(invoice).deliver
Caboose.plugin_hook('invoice_authorized', invoice)
else
invoice.financial_status = Invoice::FINANCIAL_STATUS_PENDING
error = "There was a problem processing your payment."
end
invoice.save
@url = params[:x_after_relay]
@url << (ot.success ? "?success=1" : "?error=#{error}")
render :layout => false
end
|
#authnet_response ⇒ Object
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
# File 'app/controllers/caboose/my_account_invoices_controller.rb', line 134
def authnet_response
Caboose.log("Authorize.net response for my account, invoice #{params[:id]}")
@resp = Caboose::StdClass.new
@resp.success = true if params[:success]
@resp.error = params[:error] if params[:error]
@invoice = Invoice.find(params[:id])
if !@invoice.has_shippable_items?
capture_resp = @invoice.capture_funds
if capture_resp.error
@resp.success = false
@resp.error = capture_resp.error
end
end
render :layout => false
end
|
#edit ⇒ Object
154
155
156
157
158
159
160
161
162
163
|
# File 'app/controllers/caboose/my_account_invoices_controller.rb', line 154
def edit
return if !verify_logged_in
@invoice = Invoice.find(params[:id])
if @invoice.customer_id != logged_in_user.id
@error = "The given invoice does not belong to you."
render :file => 'caboose/extras/error'
return
end
end
|
#index ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'app/controllers/caboose/my_account_invoices_controller.rb', line 8
def index
return if !verify_logged_in
@pager = Caboose::PageBarGenerator.new(params, {
'customer_id' => logged_in_user.id,
'status' => [Invoice::STATUS_PENDING, Invoice::STATUS_CANCELED, Invoice::STATUS_READY_TO_SHIP, Invoice::STATUS_SHIPPED]
}, {
'model' => 'Caboose::Invoice',
'sort' => 'invoice_number',
'desc' => 1,
'base_url' => '/my-account/invoices',
'use_url_params' => false
})
@invoices = @pager.all_items
end
|
#invoice_json ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'app/controllers/caboose/my_account_invoices_controller.rb', line 65
def invoice_json
return if !logged_in?
invoice = Invoice.find(params[:id])
if invoice.customer_id != logged_in_user.id
render :json => { :error => "The given invoice does not belong to you." }
return
end
if invoice.shipping_address_id.nil?
sa = Address.create
invoice.shipping_address_id = sa.id
invoice.save
end
render :json => invoice.as_json(:include => [
{ :line_items => { :include => { :variant => { :include => :product }}}},
{ :invoice_packages => { :include => [:shipping_package, :shipping_method] }},
{ :discounts => { :include => :gift_card }},
:customer,
:shipping_address,
:billing_address,
:invoice_transactions
])
end
|
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
55
56
57
58
59
60
61
62
|
# File 'app/controllers/caboose/my_account_invoices_controller.rb', line 25
def payment_form
return if !logged_in?
@invoice = Invoice.find(params[:id])
if @invoice.customer_id != logged_in_user.id
@error = "The given invoice does not belong to you."
render :file => 'caboose/extras/error'
return
end
if @invoice.financial_status != Invoice::FINANCIAL_STATUS_PENDING
@error = "This invoice does not require payment at this time."
render :file => 'caboose/extras/error'
return
end
sc = @site.store_config
case sc.pp_name
when 'authorize.net'
@sim_transaction = AuthorizeNet::SIM::Transaction.new(
sc.authnet_api_login_id,
sc.authnet_api_transaction_key,
@invoice.total,
:relay_response => 'TRUE',
:relay_url => "#{sc.authnet_relay_domain}/my-account/invoices/authnet-relay",
:transaction_type => 'AUTH_ONLY',
:test => sc.pp_testing
)
@request = request
@show_relay = params[:show_relay] && params[:show_relay].to_i == 1
when 'stripe'
end
render :layout => false
end
|