caboose-cms 0.8.71 → 0.8.72

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c2bdccd0f70ac5bf7db43d791b2daee4365bc25
4
- data.tar.gz: ff312c0a6e625462f187b4fd4a2b7cd76350126b
3
+ metadata.gz: ff4636d1c7691eb9e2ef8df84c5ec0afbf2f9553
4
+ data.tar.gz: 54891a3bce5dbfb5c4d85eb1f34c0a6892686940
5
5
  SHA512:
6
- metadata.gz: ad4ea9b173b2063b471ba237017687fdfad81d034058b745ad8ee763b75aaed737c4c880369d8b5989f1990918f589c4bcc0b4bfbdab0e35e60569da556091b1
7
- data.tar.gz: 23cbd2e369ef1ba6bd0c5b52a761a026448e42f9c4ffcb760aecbf4bd9c0ee2d69a071f2d7fa49bcc8ef18c5a4ed09f5931890142562d255e7e0fcb367175fd0
6
+ metadata.gz: a962ebe3ffded5572ac732c25af33408b5af984f5f96c885870b767ae21999bae8df9a9268c1309d4ed675578b900a65512e30ec7e6685236c14fb755551256e
7
+ data.tar.gz: 3bc3408005b7ea9b7aefb7631d71c953d3ee354a1d68d595c61314221f9c96afae10317d335566b034ddc61b146b70b984e4d40c5d867c32efc85d2512c79e2a
@@ -1,642 +1,643 @@
1
- require 'authorize_net'
2
-
3
- module Caboose
4
- class TheCheckoutController < Caboose::ApplicationController
5
-
6
- helper :authorize_net
7
- before_filter :ensure_line_items, :only => [:step_one, :step_two]
8
- protect_from_forgery :except => :authnet_relay
9
-
10
- def ensure_line_items
11
- redirect_to '/checkout/empty' if @order.line_items.empty?
12
- end
13
-
14
- # GET /checkout/json
15
- def order_json
16
- render :json => @order.as_json(
17
- :include => [
18
- :customer,
19
- :shipping_address,
20
- :billing_address,
21
- :order_transactions,
22
- {
23
- :line_items => {
24
- :include => {
25
- :variant => {
26
- :include => [
27
- { :product_images => { :methods => :urls }},
28
- { :product => { :include => { :product_images => { :methods => :urls }}}}
29
- ],
30
- :methods => :title
31
- }
32
- }
33
- }
34
- },
35
- { :order_packages => { :include => [:shipping_package, :shipping_method] }},
36
- { :discounts => { :include => :gift_card }}
37
- ]
38
- )
39
- end
40
-
41
- # Step 1 - Login or register
42
- # GET /checkout
43
- def index
44
- if logged_in?
45
- if @order.customer_id.nil?
46
- @order.customer_id = logged_in_user.id
47
- @order.save
48
- end
49
- #redirect_to '/checkout/addresses'
50
- #return
51
- render :file => "caboose/checkout/checkout_#{@site.store_config.pp_name}"
52
- end
53
- end
54
-
55
- # Step 2 - Shipping and billing addresses
56
- # GET /checkout/addresses
57
- def addresses
58
- redirect_to '/checkout' if !logged_in?
59
- @logged_in_user = logged_in_user
60
- end
61
-
62
- # Step 3 - Shipping method
63
- # GET /checkout/shipping
64
- def shipping
65
- redirect_to '/checkout' and return if !logged_in?
66
- redirect_to '/checkout/addresses' and return if @order.billing_address.nil? || (@order.has_shippable_items? && @order.shipping_address.nil?)
67
-
68
- @order.calculate
69
-
70
- if !@order.has_shippable_items?
71
- redirect_to '/checkout/gift-cards'
72
- return
73
- end
74
-
75
- # Remove any order packages
76
- LineItem.where(:order_id => @order.id).update_all(:order_package_id => nil)
77
- OrderPackage.where(:order_id => @order.id).destroy_all
78
-
79
- # Calculate what shipping packages we'll need
80
- OrderPackage.create_for_order(@order)
81
-
82
- # Now get the rates for those packages
83
- @rates = ShippingCalculator.rates(@order)
84
- Caboose.log(@rates)
85
-
86
- #Caboose.log(@rates.inspect)
87
- @logged_in_user = logged_in_user
88
-
89
- add_ga_event('Ecommerce', 'Checkout', 'Shipping')
90
- end
91
-
92
- # Step 3 - Shipping method
93
- # GET /checkout/shipping/json
94
- def shipping_json
95
- render :json => { :error => 'Not logged in.' } and return if !logged_in?
96
- render :json => { :error => 'No shippable items.' } and return if !@order.has_shippable_items?
97
- render :json => { :error => 'Empty shipping address.' } and return if @order.shipping_address.nil?
98
-
99
- @order.calculate
100
-
101
- # Remove any order packages
102
- LineItem.where(:order_id => @order.id).update_all(:order_package_id => nil)
103
- OrderPackage.where(:order_id => @order.id).destroy_all
104
-
105
- # Calculate what shipping packages we'll need
106
- OrderPackage.create_for_order(@order)
107
-
108
- # Now get the rates for those packages
109
- rates = ShippingCalculator.rates(@order)
110
- render :json => rates
111
- end
112
-
113
- # Step 4 - Gift cards
114
- # GET /checkout/gift-cards
115
- def gift_cards
116
- redirect_to '/checkout' and return if !logged_in?
117
- redirect_to '/checkout/addresses' and return if @order.billing_address.nil? || (@order.has_shippable_items? && @order.shipping_address.nil?)
118
- redirect_to '/checkout/shipping' and return if @order.has_shippable_items? && @order.has_empty_shipping_methods?
119
- @logged_in_user = logged_in_user
120
- add_ga_event('Ecommerce', 'Checkout', 'Gift Cards')
121
- end
122
-
123
- # Step 5 - Payment
124
- # GET /checkout/payment
125
- def payment
126
- redirect_to '/checkout' and return if !logged_in?
127
- redirect_to '/checkout/addresses' and return if @order.billing_address.nil? || (@order.has_shippable_items? && @order.shipping_address.nil?)
128
- redirect_to '/checkout/shipping' and return if @order.has_shippable_items? && @order.has_empty_shipping_methods?
129
- redirect_to '/checkout/confirm' and return if @order.total == 0.00
130
-
131
- # Make sure all the variants still exist
132
- @order.line_items.each do |li|
133
- v = Variant.where(:id => li.variant_id).first
134
- if v.nil? || v.status == 'Deleted'
135
- render :file => 'caboose/checkout/deleted_variant'
136
- return
137
- end
138
- end
139
-
140
- sc = @site.store_config
141
- case sc.pp_name
142
- when StoreConfig::PAYMENT_PROCESSOR_AUTHNET
143
-
144
- @sim_transaction = AuthorizeNet::SIM::Transaction.new(
145
- sc.authnet_api_login_id,
146
- sc.authnet_api_transaction_key,
147
- @order.total,
148
- :relay_response => 'TRUE',
149
- #:relay_url => "#{request.protocol}#{request.host_with_port}/checkout/authnet-relay/#{@order.id}",
150
- #:relay_url => "#{request.protocol}#{request.host_with_port}/checkout/authnet-relay",
151
- :relay_url => "#{sc.authnet_relay_domain}/checkout/authnet-relay",
152
- :transaction_type => 'AUTH_ONLY',
153
- :test => sc.pp_testing
154
- )
155
- @request = request
156
- @show_relay = params[:show_relay] && params[:show_relay].to_i == 1
157
- render :file => 'caboose/checkout/payment_authnet'
158
-
159
- when StoreConfig::PAYMENT_PROCESSOR_STRIPE
160
- render :file => 'caboose/checkout/payment_stripe'
161
-
162
- end
163
- @logged_in_user = logged_in_user
164
- add_ga_event('Ecommerce', 'Checkout', 'Payment Form')
165
- end
166
-
167
- # Step 5 - Update Stripe Details
168
- # PUT /checkout/stripe-details
169
- def update_stripe_details
170
- render :json => false and return if !logged_in?
171
-
172
- sc = @site.store_config
173
- Stripe.api_key = sc.stripe_secret_key.strip
174
-
175
- u = logged_in_user
176
-
177
- c = nil
178
- if u.stripe_customer_id
179
- c = Stripe::Customer.retrieve(u.stripe_customer_id)
180
- begin
181
- c.source = params[:token]
182
- c.save
183
- rescue
184
- c = nil
185
- end
186
- end
187
-
188
- if c.nil?
189
- c = Stripe::Customer.create(
190
- :source => params[:token],
191
- :email => u.email,
192
- :metadata => { :user_id => u.id }
193
- )
194
- end
195
-
196
- u.stripe_customer_id = c.id
197
- u.card_last4 = params[:card][:last4]
198
- u.card_brand = params[:card][:brand]
199
- u.card_exp_month = params[:card][:exp_month]
200
- u.card_exp_year = params[:card][:exp_year]
201
- u.save
202
-
203
- render :json => true
204
- end
205
-
206
- # GET /checkout/confirm
207
- def confirm_without_payment
208
- redirect_to '/checkout' and return if !logged_in?
209
- redirect_to '/checkout/addresses' and return if @order.billing_address.nil? || (@order.has_shippable_items? && @order.shipping_address.nil?)
210
- redirect_to '/checkout/shipping' and return if @order.has_shippable_items? && @order.has_empty_shipping_methods?
211
- redirect_to '/checkout/payment' and return if @order.total > 0.00
212
-
213
- # Make sure all the variants still exist
214
- @order.line_items.each do |li|
215
- v = Variant.where(:id => li.variant_id).first
216
- if v.nil? || v.status == 'Deleted'
217
- render :file => 'caboose/checkout/deleted_variant'
218
- return
219
- end
220
- end
221
- @logged_in_user = logged_in_user
222
- add_ga_event('Ecommerce', 'Checkout', 'Confirm Without Payment')
223
- end
224
-
225
- # POST /checkout/confirm
226
- def confirm
227
- render :json => { :error => 'Not logged in.' } and return if !logged_in?
228
- render :json => { :error => 'Invalid addresses.' } and return if @order.billing_address.nil? || (@order.has_shippable_items? && @order.shipping_address.nil?)
229
- render :json => { :error => 'Invalid shipping methods.' } and return if @order.has_shippable_items? && @order.has_empty_shipping_methods?
230
- render :json => { :error => 'Order requires payment.' } and return if @order.total > 0.00
231
-
232
- resp = Caboose::StdClass.new
233
-
234
- @order.financial_status = Order::FINANCIAL_STATUS_AUTHORIZED
235
- @order.status = Order::STATUS_PENDING
236
- @order.order_number = @site.store_config.next_order_number
237
-
238
- # Take funds from any gift cards that were used on the order
239
- @order.take_gift_card_funds
240
-
241
- # Send out emails
242
- begin
243
- OrdersMailer.configure_for_site(@site.id).customer_new_order(@order).deliver
244
- OrdersMailer.configure_for_site(@site.id).fulfillment_new_order(@order).deliver
245
- rescue
246
- puts "=================================================================="
247
- puts "Error sending out order confirmation emails for order ID #{@order.id}"
248
- puts "=================================================================="
249
- end
250
-
251
- # Emit order event
252
- Caboose.plugin_hook('order_authorized', @order)
253
-
254
- # Save the order
255
- @order.save
256
-
257
- # Decrement quantities of variants
258
- @order.decrement_quantities
259
-
260
- # Clear the cart and re-initialize
261
- session[:cart_id] = nil
262
- init_cart
263
-
264
- resp.success = true
265
- resp.redirect = '/checkout/thanks'
266
- render :json => resp
267
- end
268
-
269
- # GET /checkout/thanks
270
- def thanks
271
- @logged_in_user = logged_in_user
272
-
273
- # Find the last order for the user
274
- @last_order = Order.where(:customer_id => @logged_in_user.id).order("id desc").limit(1).first
275
- add_ga_event('Ecommerce', 'Checkout', 'Payment', (@last_order.total*100).to_i)
276
- end
277
-
278
- #===========================================================================
279
-
280
- # GET /checkout/total
281
- def verify_total
282
- total = 0.00
283
- if logged_in?
284
- @order.calculate
285
- total = @order.total
286
- end
287
- render :json => total.to_f
288
- end
289
-
290
- # GET /checkout/address
291
- def address
292
- render :json => {
293
- :shipping_address => @order.shipping_address,
294
- :billing_address => @order.billing_address
295
- }
296
- end
297
-
298
- # PUT /checkout/addresses
299
- def update_addresses
300
-
301
- # Grab or create addresses
302
- shipping_address = if @order.shipping_address then @order.shipping_address else Address.new end
303
- billing_address = if @order.billing_address then @order.billing_address else Address.new end
304
-
305
- has_shippable_items = @order.has_shippable_items?
306
-
307
- # Shipping address
308
- if has_shippable_items
309
- shipping_address.first_name = params[:shipping][:first_name]
310
- shipping_address.last_name = params[:shipping][:last_name]
311
- shipping_address.company = params[:shipping][:company]
312
- shipping_address.address1 = params[:shipping][:address1]
313
- shipping_address.address2 = params[:shipping][:address2]
314
- shipping_address.city = params[:shipping][:city]
315
- shipping_address.state = params[:shipping][:state]
316
- shipping_address.zip = params[:shipping][:zip]
317
- end
318
-
319
- # Billing address
320
- if has_shippable_items && params[:use_as_billing]
321
- billing_address.update_attributes(shipping_address.attributes)
322
- else
323
- billing_address.first_name = params[:billing][:first_name]
324
- billing_address.last_name = params[:billing][:last_name]
325
- billing_address.company = params[:billing][:company]
326
- billing_address.address1 = params[:billing][:address1]
327
- billing_address.address2 = params[:billing][:address2]
328
- billing_address.city = params[:billing][:city]
329
- billing_address.state = params[:billing][:state]
330
- billing_address.zip = params[:billing][:zip]
331
- end
332
-
333
- # Save address info; generate ids
334
- render :json => { :success => false, :errors => shipping_address.errors.full_messages, :address => 'shipping' } and return if has_shippable_items && !shipping_address.save
335
- render :json => { :success => false, :errors => billing_address.errors.full_messages, :address => 'billing' } and return if !billing_address.save
336
-
337
- # Associate address info with order
338
- @order.shipping_address_id = shipping_address.id
339
- @order.billing_address_id = billing_address.id
340
-
341
- #render :json => { :redirect => 'checkout/shipping' }
342
- render :json => { :success => @order.save, :errors => @order.errors.full_messages }
343
- end
344
-
345
- # PUT /checkout/shipping-address
346
- def update_shipping_address
347
-
348
- # Grab or create addresses
349
- sa = @order.shipping_address
350
- if sa.nil?
351
- sa = Address.create
352
- @order.shipping_address_id = sa.id
353
- @order.save
354
- end
355
-
356
- sa.first_name = params[:first_name]
357
- sa.last_name = params[:last_name]
358
- sa.company = params[:company]
359
- sa.address1 = params[:address1]
360
- sa.address2 = params[:address2]
361
- sa.city = params[:city]
362
- sa.state = params[:state]
363
- sa.zip = params[:zip]
364
- sa.save
365
-
366
- render :json => { :success => true }
367
- end
368
-
369
- # PUT /checkout/billing-address
370
- def update_billing_address
371
-
372
- # Grab or create addresses
373
- ba = @order.billing_address
374
- if ba.nil?
375
- ba = Address.create
376
- @order.billing_address_id = ba.id
377
- @order.save
378
- end
379
-
380
- ba.first_name = params[:first_name]
381
- ba.last_name = params[:last_name]
382
- ba.company = params[:company]
383
- ba.address1 = params[:address1]
384
- ba.address2 = params[:address2]
385
- ba.city = params[:city]
386
- ba.state = params[:state]
387
- ba.zip = params[:zip]
388
- ba.save
389
-
390
- render :json => { :success => true }
391
- end
392
-
393
- # POST /checkout/attach-user
394
- def attach_user
395
- render :json => { :success => false, :errors => ['User is not logged in'] } and return if !logged_in?
396
- @order.customer_id = logged_in_user.id
397
- #Caboose.log("Attaching user to order: customer_id = #{@order.customer_id}")
398
- render :json => { :success => @order.save, :errors => @order.errors.full_messages, :logged_in => logged_in? }
399
- end
400
-
401
- # POST /checkout/guest
402
- def attach_guest
403
- resp = Caboose::StdClass.new
404
- email = params[:email]
405
-
406
- if email != params[:confirm_email]
407
- resp.error = "Emails do not match."
408
- elsif Caboose::User.where(:email => email, :is_guest => false).exists?
409
- resp.error = "A user with that email address already exists."
410
- else
411
- user = Caboose::User.where(:email => email, :is_guest => true).first
412
- if user.nil?
413
- user = Caboose::User.create(:email => email)
414
- user.is_guest = true
415
- user.save
416
- user = Caboose::User.where(:email => email).first
417
- end
418
- @order.customer_id = user.id
419
- login_user(user)
420
-
421
- if !@order.valid?
422
- resp.errors = @order.errors.full_messages
423
- else
424
- @order.save
425
- resp.redirect = '/checkout/addresses'
426
- end
427
- end
428
- render :json => resp
429
- end
430
-
431
- # PUT /checkout/shipping
432
- def update_shipping
433
- op = OrderPackage.find(params[:order_package_id])
434
- op.shipping_method_id = params[:shipping_method_id]
435
- op.total = params[:total]
436
- op.save
437
- op.order.calculate
438
-
439
- render :json => { :success => true }
440
- end
441
-
442
- # @route PUT /checkout/invoice
443
- def update_invoice
444
- render :json => false and return if !logged_in?
445
- resp = Caboose::StdClass.new
446
-
447
- params.each do |k,v|
448
- case k
449
- when 'instore_pickup'
450
- @invoice.instore_pickup = v
451
- @invoice.save
452
-
453
- @invoice.invoice_packages.each do |ip
454
- ip.instore_pickup = v
455
- ip.save
456
- end
457
- end
458
- end
459
-
460
- resp.success = true
461
- render :json => resp
462
- end
463
-
464
- # GET /checkout/payment
465
- #def payment
466
- # case Caboose::payment_processor
467
- # when StoreConfig::PAYMENT_PROCESSOR_AUTHNET
468
- # @sim_transaction = AuthorizeNet::SIM::Transaction.new(
469
- # Caboose::authorize_net_login_id,
470
- # Caboose::authorize_net_transaction_key,
471
- # @order.total,
472
- # :relay_url => "#{Caboose::root_url}/checkout/relay/#{@order.id}",
473
- # :transaction_type => 'AUTH_ONLY',
474
- # :test => true
475
- # )
476
- # when StoreConfig::PAYMENT_PROCESSOR_STRIPE
477
- #
478
- # end
479
- # render :layout => false
480
- #end
481
-
482
- # POST /checkout/authnet-relay
483
- def authnet_relay
484
- Caboose.log("Authorize.net relay, order #{params[:x_invoice_id]}")
485
-
486
- if params[:x_invoice_num].nil? || params[:x_invoice_num].strip.length == 0
487
- Caboose.log("Error: no x_invoice_id in given parameters.")
488
- render :json => { :error => "Invalid x_invoice_id." }
489
- return
490
- end
491
-
492
- order = Caboose::Order.where(:id => params[:x_invoice_num].to_i).first
493
- if order.nil?
494
- Caboose.log("Error: can't find order for x_invoice_num #{params[:x_invoice_num]}.")
495
- render :json => { :error => "Invalid x_invoice_id." }
496
- return
497
- end
498
-
499
- ot = Caboose::OrderTransaction.new(
500
- :order_id => order.id,
501
- :date_processed => DateTime.now.utc,
502
- :transaction_type => Caboose::OrderTransaction::TYPE_AUTHORIZE
503
- )
504
- ot.success = params[:x_response_code] && params[:x_response_code] == '1'
505
- ot.transaction_id = params[:x_trans_id] if params[:x_trans_id]
506
- ot.auth_code = params[:x_auth_code] if params[:x_auth_code]
507
- ot.response_code = params[:x_response_code] if params[:x_response_code]
508
- ot.amount = order.total
509
- ot.save
510
-
511
- error = nil
512
- if ot.success
513
- order.financial_status = Order::FINANCIAL_STATUS_AUTHORIZED
514
- order.status = Order::STATUS_PENDING
515
- order.order_number = @site.store_config.next_order_number
516
- order.date_authorized = DateTime.now.utc
517
-
518
- # Tell taxcloud the order was authorized
519
- #Caboose::TaxCalculator.authorized(order)
520
-
521
- # Take funds from any gift cards that were used on the order
522
- order.take_gift_card_funds
523
-
524
- # Send out emails
525
- begin
526
- OrdersMailer.configure_for_site(@site.id).customer_new_order(order).deliver
527
- OrdersMailer.configure_for_site(@site.id).fulfillment_new_order(order).deliver
528
- rescue
529
- puts "=================================================================="
530
- puts "Error sending out order confirmation emails for order ID #{@order.id}"
531
- puts "=================================================================="
532
- end
533
-
534
- # Emit order event
535
- Caboose.plugin_hook('order_authorized', order)
536
- else
537
- order.financial_status = 'unauthorized'
538
- error = "There was a problem processing your payment."
539
- end
540
-
541
- order.save
542
-
543
- @url = params[:x_after_relay]
544
- @url << (ot.success ? "?success=1" : "?error=#{error}")
545
-
546
- render :layout => false
547
- end
548
-
549
- # GET /checkout/authnet-response/:order_id
550
- # POST /checkout/authnet-response/:order_id
551
- def authnet_response
552
- Caboose.log("Authorize.net response, order #{params[:order_id]}")
553
-
554
- @resp = Caboose::StdClass.new
555
- @resp.success = true if params[:success]
556
- @resp.error = params[:error] if params[:error]
557
-
558
- # Go ahead and capture funds if the order only contained downloadable items
559
- @order = Order.find(params[:order_id])
560
-
561
- if @resp.success
562
- if !@order.has_shippable_items?
563
- capture_resp = @order.capture_funds
564
- if capture_resp.error
565
- @resp.success = false
566
- @resp.error = capture_resp.error
567
- end
568
- end
569
-
570
- # Decrement quantities of variants
571
- @order.decrement_quantities
572
-
573
- session[:cart_id] = nil
574
- init_cart
575
- end
576
-
577
- render :layout => false
578
- end
579
-
580
- #def relay
581
- #
582
- # # Check to see that the order has a valid total and was authorized
583
- # if @order.total > 0 && PaymentProcessor.authorize(@order, params)
584
- #
585
- # # Update order
586
- # @order.date_authorized = DateTime.now
587
- # @order.auth_amount = @order.total
588
- # @order.financial_status = 'authorized'
589
- # @order.status = if @order.test? then 'testing' else 'pending' end
590
- #
591
- # # Send out notifications
592
- # OrdersMailer.customer_new_order(@order).deliver
593
- # OrdersMailer.fulfillment_new_order(@order).deliver
594
- #
595
- # # Clear everything
596
- # session[:cart_id] = nil
597
- #
598
- # # Emit order event
599
- # Caboose.plugin_hook('order_authorized', @order)
600
- #
601
- # # Decrement quantities of variants
602
- # @order.decrement_quantities
603
- # else
604
- # @order.financial_status = 'unauthorized'
605
- # end
606
- #
607
- # @order.save
608
- #end
609
-
610
- # GET /checkout/authorize-by-gift-card
611
- #def authorize_by_gift_card
612
- # if @order.total < @order.discounts.first.amount_current
613
- #
614
- # # Update order
615
- # @order.date_authorized = DateTime.now
616
- # @order.auth_amount = @order.total
617
- # @order.financial_status = 'authorized'
618
- # @order.status = if @order.test? then 'testing' else 'pending' end
619
- #
620
- # # Send out notifications
621
- # OrdersMailer.customer_new_order(@order).deliver
622
- # OrdersMailer.fulfillment_new_order(@order).deliver
623
- #
624
- # # Clear everything
625
- # session[:cart_id] = nil
626
- #
627
- # # Emit order event
628
- # Caboose.plugin_hook('order_authorized', @order)
629
- #
630
- # # Decrement quantities of variants
631
- # @order.decrement_quantities
632
- #
633
- # @order.save
634
- #
635
- # redirect_to '/checkout/thanks'
636
- # else
637
- # redirect_to '/checkout/error'
638
- # end
639
- #end
640
-
641
- end
642
- end
1
+ #require 'authorize_net'
2
+ #
3
+ #module Caboose
4
+ # class TheCheckoutController < Caboose::ApplicationController
5
+ #
6
+ # helper :authorize_net
7
+ # before_filter :ensure_line_items, :only => [:step_one, :step_two]
8
+ # protect_from_forgery :except => :authnet_relay
9
+ #
10
+ # def ensure_line_items
11
+ # redirect_to '/checkout/empty' if @order.line_items.empty?
12
+ # end
13
+ #
14
+ # # GET /checkout/json
15
+ # def order_json
16
+ # render :json => @order.as_json(
17
+ # :include => [
18
+ # :customer,
19
+ # :shipping_address,
20
+ # :billing_address,
21
+ # :order_transactions,
22
+ # {
23
+ # :line_items => {
24
+ # :include => {
25
+ # :variant => {
26
+ # :include => [
27
+ # { :product_images => { :methods => :urls }},
28
+ # { :product => { :include => { :product_images => { :methods => :urls }}}}
29
+ # ],
30
+ # :methods => :title
31
+ # }
32
+ # }
33
+ # }
34
+ # },
35
+ # { :order_packages => { :include => [:shipping_package, :shipping_method] }},
36
+ # { :discounts => { :include => :gift_card }}
37
+ # ]
38
+ # )
39
+ # end
40
+ #
41
+ # # Step 1 - Login or register
42
+ # # GET /checkout
43
+ # def index
44
+ # if logged_in?
45
+ # if @order.customer_id.nil?
46
+ # @order.customer_id = logged_in_user.id
47
+ # @order.save
48
+ # end
49
+ # #redirect_to '/checkout/addresses'
50
+ # #return
51
+ # render :file => "caboose/checkout/checkout_#{@site.store_config.pp_name}"
52
+ # end
53
+ # end
54
+ #
55
+ # # Step 2 - Shipping and billing addresses
56
+ # # GET /checkout/addresses
57
+ # def addresses
58
+ # redirect_to '/checkout' if !logged_in?
59
+ # @logged_in_user = logged_in_user
60
+ # end
61
+ #
62
+ # # Step 3 - Shipping method
63
+ # # GET /checkout/shipping
64
+ # def shipping
65
+ # redirect_to '/checkout' and return if !logged_in?
66
+ # redirect_to '/checkout/addresses' and return if @order.billing_address.nil? || (@order.has_shippable_items? && @order.shipping_address.nil?)
67
+ #
68
+ # @order.calculate
69
+ #
70
+ # if !@order.has_shippable_items?
71
+ # redirect_to '/checkout/gift-cards'
72
+ # return
73
+ # end
74
+ #
75
+ # # Remove any order packages
76
+ # LineItem.where(:order_id => @order.id).update_all(:order_package_id => nil)
77
+ # OrderPackage.where(:order_id => @order.id).destroy_all
78
+ #
79
+ # # Calculate what shipping packages we'll need
80
+ # OrderPackage.create_for_order(@order)
81
+ #
82
+ # # Now get the rates for those packages
83
+ # @rates = ShippingCalculator.rates(@order)
84
+ # Caboose.log(@rates)
85
+ #
86
+ # #Caboose.log(@rates.inspect)
87
+ # @logged_in_user = logged_in_user
88
+ #
89
+ # add_ga_event('Ecommerce', 'Checkout', 'Shipping')
90
+ # end
91
+ #
92
+ # # Step 3 - Shipping method
93
+ # # GET /checkout/shipping/json
94
+ # def shipping_json
95
+ # render :json => { :error => 'Not logged in.' } and return if !logged_in?
96
+ # render :json => { :error => 'No shippable items.' } and return if !@order.has_shippable_items?
97
+ # render :json => { :error => 'Empty shipping address.' } and return if @order.shipping_address.nil?
98
+ #
99
+ # @order.calculate
100
+ #
101
+ # # Remove any order packages
102
+ # LineItem.where(:order_id => @order.id).update_all(:order_package_id => nil)
103
+ # OrderPackage.where(:order_id => @order.id).destroy_all
104
+ #
105
+ # # Calculate what shipping packages we'll need
106
+ # OrderPackage.create_for_order(@order)
107
+ #
108
+ # # Now get the rates for those packages
109
+ # rates = ShippingCalculator.rates(@order)
110
+ # render :json => rates
111
+ # end
112
+ #
113
+ # # Step 4 - Gift cards
114
+ # # GET /checkout/gift-cards
115
+ # def gift_cards
116
+ # redirect_to '/checkout' and return if !logged_in?
117
+ # redirect_to '/checkout/addresses' and return if @order.billing_address.nil? || (@order.has_shippable_items? && @order.shipping_address.nil?)
118
+ # redirect_to '/checkout/shipping' and return if @order.has_shippable_items? && @order.has_empty_shipping_methods?
119
+ # @logged_in_user = logged_in_user
120
+ # add_ga_event('Ecommerce', 'Checkout', 'Gift Cards')
121
+ # end
122
+ #
123
+ # # Step 5 - Payment
124
+ # # GET /checkout/payment
125
+ # def payment
126
+ # redirect_to '/checkout' and return if !logged_in?
127
+ # redirect_to '/checkout/addresses' and return if @order.billing_address.nil? || (@order.has_shippable_items? && @order.shipping_address.nil?)
128
+ # redirect_to '/checkout/shipping' and return if @order.has_shippable_items? && @order.has_empty_shipping_methods?
129
+ # redirect_to '/checkout/confirm' and return if @order.total == 0.00
130
+ #
131
+ # # Make sure all the variants still exist
132
+ # @order.line_items.each do |li|
133
+ # v = Variant.where(:id => li.variant_id).first
134
+ # if v.nil? || v.status == 'Deleted'
135
+ # render :file => 'caboose/checkout/deleted_variant'
136
+ # return
137
+ # end
138
+ # end
139
+ #
140
+ # sc = @site.store_config
141
+ # case sc.pp_name
142
+ # when StoreConfig::PAYMENT_PROCESSOR_AUTHNET
143
+ #
144
+ # @sim_transaction = AuthorizeNet::SIM::Transaction.new(
145
+ # sc.authnet_api_login_id,
146
+ # sc.authnet_api_transaction_key,
147
+ # @order.total,
148
+ # :relay_response => 'TRUE',
149
+ # #:relay_url => "#{request.protocol}#{request.host_with_port}/checkout/authnet-relay/#{@order.id}",
150
+ # #:relay_url => "#{request.protocol}#{request.host_with_port}/checkout/authnet-relay",
151
+ # :relay_url => "#{sc.authnet_relay_domain}/checkout/authnet-relay",
152
+ # :transaction_type => 'AUTH_ONLY',
153
+ # :test => sc.pp_testing
154
+ # )
155
+ # @request = request
156
+ # @show_relay = params[:show_relay] && params[:show_relay].to_i == 1
157
+ # render :file => 'caboose/checkout/payment_authnet'
158
+ #
159
+ # when StoreConfig::PAYMENT_PROCESSOR_STRIPE
160
+ # render :file => 'caboose/checkout/payment_stripe'
161
+ #
162
+ # end
163
+ # @logged_in_user = logged_in_user
164
+ # add_ga_event('Ecommerce', 'Checkout', 'Payment Form')
165
+ # end
166
+ #
167
+ # # Step 5 - Update Stripe Details
168
+ # # PUT /checkout/stripe-details
169
+ # def update_stripe_details
170
+ # render :json => false and return if !logged_in?
171
+ #
172
+ # sc = @site.store_config
173
+ # Stripe.api_key = sc.stripe_secret_key.strip
174
+ #
175
+ # u = logged_in_user
176
+ #
177
+ # c = nil
178
+ # if u.stripe_customer_id
179
+ # c = Stripe::Customer.retrieve(u.stripe_customer_id)
180
+ # begin
181
+ # c.source = params[:token]
182
+ # c.save
183
+ # rescue
184
+ # c = nil
185
+ # end
186
+ # end
187
+ #
188
+ # if c.nil?
189
+ # c = Stripe::Customer.create(
190
+ # :source => params[:token],
191
+ # :email => u.email,
192
+ # :metadata => { :user_id => u.id }
193
+ # )
194
+ # end
195
+ #
196
+ # u.stripe_customer_id = c.id
197
+ # u.card_last4 = params[:card][:last4]
198
+ # u.card_brand = params[:card][:brand]
199
+ # u.card_exp_month = params[:card][:exp_month]
200
+ # u.card_exp_year = params[:card][:exp_year]
201
+ # u.save
202
+ #
203
+ # render :json => true
204
+ # end
205
+ #
206
+ # # GET /checkout/confirm
207
+ # def confirm_without_payment
208
+ # redirect_to '/checkout' and return if !logged_in?
209
+ # redirect_to '/checkout/addresses' and return if @order.billing_address.nil? || (@order.has_shippable_items? && @order.shipping_address.nil?)
210
+ # redirect_to '/checkout/shipping' and return if @order.has_shippable_items? && @order.has_empty_shipping_methods?
211
+ # redirect_to '/checkout/payment' and return if @order.total > 0.00
212
+ #
213
+ # # Make sure all the variants still exist
214
+ # @order.line_items.each do |li|
215
+ # v = Variant.where(:id => li.variant_id).first
216
+ # if v.nil? || v.status == 'Deleted'
217
+ # render :file => 'caboose/checkout/deleted_variant'
218
+ # return
219
+ # end
220
+ # end
221
+ # @logged_in_user = logged_in_user
222
+ # add_ga_event('Ecommerce', 'Checkout', 'Confirm Without Payment')
223
+ # end
224
+ #
225
+ # # POST /checkout/confirm
226
+ # def confirm
227
+ # render :json => { :error => 'Not logged in.' } and return if !logged_in?
228
+ # render :json => { :error => 'Invalid addresses.' } and return if @order.billing_address.nil? || (@order.has_shippable_items? && @order.shipping_address.nil?)
229
+ # render :json => { :error => 'Invalid shipping methods.' } and return if @order.has_shippable_items? && @order.has_empty_shipping_methods?
230
+ # render :json => { :error => 'Order requires payment.' } and return if @order.total > 0.00
231
+ #
232
+ # resp = Caboose::StdClass.new
233
+ #
234
+ # @order.financial_status = Order::FINANCIAL_STATUS_AUTHORIZED
235
+ # @order.status = Order::STATUS_PENDING
236
+ # @order.order_number = @site.store_config.next_order_number
237
+ #
238
+ # # Take funds from any gift cards that were used on the order
239
+ # @order.take_gift_card_funds
240
+ #
241
+ # # Send out emails
242
+ # begin
243
+ # OrdersMailer.configure_for_site(@site.id).customer_new_order(@order).deliver
244
+ # OrdersMailer.configure_for_site(@site.id).fulfillment_new_order(@order).deliver
245
+ # rescue
246
+ # puts "=================================================================="
247
+ # puts "Error sending out order confirmation emails for order ID #{@order.id}"
248
+ # puts "=================================================================="
249
+ # end
250
+ #
251
+ # # Emit order event
252
+ # Caboose.plugin_hook('order_authorized', @order)
253
+ #
254
+ # # Save the order
255
+ # @order.save
256
+ #
257
+ # # Decrement quantities of variants
258
+ # @order.decrement_quantities
259
+ #
260
+ # # Clear the cart and re-initialize
261
+ # session[:cart_id] = nil
262
+ # init_cart
263
+ #
264
+ # resp.success = true
265
+ # resp.redirect = '/checkout/thanks'
266
+ # render :json => resp
267
+ # end
268
+ #
269
+ # # GET /checkout/thanks
270
+ # def thanks
271
+ # @logged_in_user = logged_in_user
272
+ #
273
+ # # Find the last order for the user
274
+ # @last_order = Order.where(:customer_id => @logged_in_user.id).order("id desc").limit(1).first
275
+ # add_ga_event('Ecommerce', 'Checkout', 'Payment', (@last_order.total*100).to_i)
276
+ # end
277
+ #
278
+ # #===========================================================================
279
+ #
280
+ # # GET /checkout/total
281
+ # def verify_total
282
+ # total = 0.00
283
+ # if logged_in?
284
+ # @order.calculate
285
+ # total = @order.total
286
+ # end
287
+ # render :json => total.to_f
288
+ # end
289
+ #
290
+ # # GET /checkout/address
291
+ # def address
292
+ # render :json => {
293
+ # :shipping_address => @order.shipping_address,
294
+ # :billing_address => @order.billing_address
295
+ # }
296
+ # end
297
+ #
298
+ # # PUT /checkout/addresses
299
+ # def update_addresses
300
+ #
301
+ # # Grab or create addresses
302
+ # shipping_address = if @order.shipping_address then @order.shipping_address else Address.new end
303
+ # billing_address = if @order.billing_address then @order.billing_address else Address.new end
304
+ #
305
+ # has_shippable_items = @order.has_shippable_items?
306
+ #
307
+ # # Shipping address
308
+ # if has_shippable_items
309
+ # shipping_address.first_name = params[:shipping][:first_name]
310
+ # shipping_address.last_name = params[:shipping][:last_name]
311
+ # shipping_address.company = params[:shipping][:company]
312
+ # shipping_address.address1 = params[:shipping][:address1]
313
+ # shipping_address.address2 = params[:shipping][:address2]
314
+ # shipping_address.city = params[:shipping][:city]
315
+ # shipping_address.state = params[:shipping][:state]
316
+ # shipping_address.zip = params[:shipping][:zip]
317
+ # end
318
+ #
319
+ # # Billing address
320
+ # if has_shippable_items && params[:use_as_billing]
321
+ # billing_address.update_attributes(shipping_address.attributes)
322
+ # else
323
+ # billing_address.first_name = params[:billing][:first_name]
324
+ # billing_address.last_name = params[:billing][:last_name]
325
+ # billing_address.company = params[:billing][:company]
326
+ # billing_address.address1 = params[:billing][:address1]
327
+ # billing_address.address2 = params[:billing][:address2]
328
+ # billing_address.city = params[:billing][:city]
329
+ # billing_address.state = params[:billing][:state]
330
+ # billing_address.zip = params[:billing][:zip]
331
+ # end
332
+ #
333
+ # # Save address info; generate ids
334
+ # render :json => { :success => false, :errors => shipping_address.errors.full_messages, :address => 'shipping' } and return if has_shippable_items && !shipping_address.save
335
+ # render :json => { :success => false, :errors => billing_address.errors.full_messages, :address => 'billing' } and return if !billing_address.save
336
+ #
337
+ # # Associate address info with order
338
+ # @order.shipping_address_id = shipping_address.id
339
+ # @order.billing_address_id = billing_address.id
340
+ #
341
+ # #render :json => { :redirect => 'checkout/shipping' }
342
+ # render :json => { :success => @order.save, :errors => @order.errors.full_messages }
343
+ # end
344
+ #
345
+ # # PUT /checkout/shipping-address
346
+ # def update_shipping_address
347
+ #
348
+ # # Grab or create addresses
349
+ # sa = @order.shipping_address
350
+ # if sa.nil?
351
+ # sa = Address.create
352
+ # @order.shipping_address_id = sa.id
353
+ # @order.save
354
+ # end
355
+ #
356
+ # sa.first_name = params[:first_name]
357
+ # sa.last_name = params[:last_name]
358
+ # sa.company = params[:company]
359
+ # sa.address1 = params[:address1]
360
+ # sa.address2 = params[:address2]
361
+ # sa.city = params[:city]
362
+ # sa.state = params[:state]
363
+ # sa.zip = params[:zip]
364
+ # sa.save
365
+ #
366
+ # render :json => { :success => true }
367
+ # end
368
+ #
369
+ # # PUT /checkout/billing-address
370
+ # def update_billing_address
371
+ #
372
+ # # Grab or create addresses
373
+ # ba = @order.billing_address
374
+ # if ba.nil?
375
+ # ba = Address.create
376
+ # @order.billing_address_id = ba.id
377
+ # @order.save
378
+ # end
379
+ #
380
+ # ba.first_name = params[:first_name]
381
+ # ba.last_name = params[:last_name]
382
+ # ba.company = params[:company]
383
+ # ba.address1 = params[:address1]
384
+ # ba.address2 = params[:address2]
385
+ # ba.city = params[:city]
386
+ # ba.state = params[:state]
387
+ # ba.zip = params[:zip]
388
+ # ba.save
389
+ #
390
+ # render :json => { :success => true }
391
+ # end
392
+ #
393
+ # # POST /checkout/attach-user
394
+ # def attach_user
395
+ # render :json => { :success => false, :errors => ['User is not logged in'] } and return if !logged_in?
396
+ # @order.customer_id = logged_in_user.id
397
+ # #Caboose.log("Attaching user to order: customer_id = #{@order.customer_id}")
398
+ # render :json => { :success => @order.save, :errors => @order.errors.full_messages, :logged_in => logged_in? }
399
+ # end
400
+ #
401
+ # # POST /checkout/guest
402
+ # def attach_guest
403
+ # resp = Caboose::StdClass.new
404
+ # email = params[:email]
405
+ #
406
+ # if email != params[:confirm_email]
407
+ # resp.error = "Emails do not match."
408
+ # elsif Caboose::User.where(:email => email, :is_guest => false).exists?
409
+ # resp.error = "A user with that email address already exists."
410
+ # else
411
+ # user = Caboose::User.where(:email => email, :is_guest => true).first
412
+ # if user.nil?
413
+ # user = Caboose::User.create(:email => email)
414
+ # user.is_guest = true
415
+ # user.save
416
+ # user = Caboose::User.where(:email => email).first
417
+ # end
418
+ # @order.customer_id = user.id
419
+ # login_user(user)
420
+ #
421
+ # if !@order.valid?
422
+ # resp.errors = @order.errors.full_messages
423
+ # else
424
+ # @order.save
425
+ # resp.redirect = '/checkout/addresses'
426
+ # end
427
+ # end
428
+ # render :json => resp
429
+ # end
430
+ #
431
+ # # PUT /checkout/shipping
432
+ # def update_shipping
433
+ # op = OrderPackage.find(params[:order_package_id])
434
+ # op.shipping_method_id = params[:shipping_method_id]
435
+ # op.total = params[:total]
436
+ # op.save
437
+ # op.order.calculate
438
+ #
439
+ # render :json => { :success => true }
440
+ # end
441
+ #
442
+ # # @route PUT /checkout/invoice
443
+ # def update_invoice
444
+ # render :json => false and return if !logged_in?
445
+ # resp = Caboose::StdClass.new
446
+ #
447
+ # params.each do |k,v|
448
+ # case k
449
+ # when 'instore_pickup'
450
+ # @invoice.instore_pickup = v
451
+ # @invoice.save
452
+ #
453
+ # @invoice.invoice_packages.each do |ip
454
+ # ip.instore_pickup = v
455
+ # ip.save
456
+ # end
457
+ # end
458
+ # end
459
+ #
460
+ # resp.success = true
461
+ # render :json => resp
462
+ # end
463
+ #
464
+ # # GET /checkout/payment
465
+ # #def payment
466
+ # # case Caboose::payment_processor
467
+ # # when StoreConfig::PAYMENT_PROCESSOR_AUTHNET
468
+ # # @sim_transaction = AuthorizeNet::SIM::Transaction.new(
469
+ # # Caboose::authorize_net_login_id,
470
+ # # Caboose::authorize_net_transaction_key,
471
+ # # @order.total,
472
+ # # :relay_url => "#{Caboose::root_url}/checkout/relay/#{@order.id}",
473
+ # # :transaction_type => 'AUTH_ONLY',
474
+ # # :test => true
475
+ # # )
476
+ # # when StoreConfig::PAYMENT_PROCESSOR_STRIPE
477
+ # #
478
+ # # end
479
+ # # render :layout => false
480
+ # #end
481
+ #
482
+ # # POST /checkout/authnet-relay
483
+ # def authnet_relay
484
+ # Caboose.log("Authorize.net relay, order #{params[:x_invoice_id]}")
485
+ #
486
+ # if params[:x_invoice_num].nil? || params[:x_invoice_num].strip.length == 0
487
+ # Caboose.log("Error: no x_invoice_id in given parameters.")
488
+ # render :json => { :error => "Invalid x_invoice_id." }
489
+ # return
490
+ # end
491
+ #
492
+ # order = Caboose::Order.where(:id => params[:x_invoice_num].to_i).first
493
+ # if order.nil?
494
+ # Caboose.log("Error: can't find order for x_invoice_num #{params[:x_invoice_num]}.")
495
+ # render :json => { :error => "Invalid x_invoice_id." }
496
+ # return
497
+ # end
498
+ #
499
+ # ot = Caboose::OrderTransaction.new(
500
+ # :order_id => order.id,
501
+ # :date_processed => DateTime.now.utc,
502
+ # :transaction_type => Caboose::OrderTransaction::TYPE_AUTHORIZE
503
+ # )
504
+ # ot.success = params[:x_response_code] && params[:x_response_code] == '1'
505
+ # ot.transaction_id = params[:x_trans_id] if params[:x_trans_id]
506
+ # ot.auth_code = params[:x_auth_code] if params[:x_auth_code]
507
+ # ot.response_code = params[:x_response_code] if params[:x_response_code]
508
+ # ot.amount = order.total
509
+ # ot.save
510
+ #
511
+ # error = nil
512
+ # if ot.success
513
+ # order.financial_status = Order::FINANCIAL_STATUS_AUTHORIZED
514
+ # order.status = Order::STATUS_PENDING
515
+ # order.order_number = @site.store_config.next_order_number
516
+ # order.date_authorized = DateTime.now.utc
517
+ #
518
+ # # Tell taxcloud the order was authorized
519
+ # #Caboose::TaxCalculator.authorized(order)
520
+ #
521
+ # # Take funds from any gift cards that were used on the order
522
+ # order.take_gift_card_funds
523
+ #
524
+ # # Send out emails
525
+ # begin
526
+ # OrdersMailer.configure_for_site(@site.id).customer_new_order(order).deliver
527
+ # OrdersMailer.configure_for_site(@site.id).fulfillment_new_order(order).deliver
528
+ # rescue
529
+ # puts "=================================================================="
530
+ # puts "Error sending out order confirmation emails for order ID #{@order.id}"
531
+ # puts "=================================================================="
532
+ # end
533
+ #
534
+ # # Emit order event
535
+ # Caboose.plugin_hook('order_authorized', order)
536
+ # else
537
+ # order.financial_status = 'unauthorized'
538
+ # error = "There was a problem processing your payment."
539
+ # end
540
+ #
541
+ # order.save
542
+ #
543
+ # @url = params[:x_after_relay]
544
+ # @url << (ot.success ? "?success=1" : "?error=#{error}")
545
+ #
546
+ # render :layout => false
547
+ # end
548
+ #
549
+ # # GET /checkout/authnet-response/:order_id
550
+ # # POST /checkout/authnet-response/:order_id
551
+ # def authnet_response
552
+ # Caboose.log("Authorize.net response, order #{params[:order_id]}")
553
+ #
554
+ # @resp = Caboose::StdClass.new
555
+ # @resp.success = true if params[:success]
556
+ # @resp.error = params[:error] if params[:error]
557
+ #
558
+ # # Go ahead and capture funds if the order only contained downloadable items
559
+ # @order = Order.find(params[:order_id])
560
+ #
561
+ # if @resp.success
562
+ # if !@order.has_shippable_items?
563
+ # capture_resp = @order.capture_funds
564
+ # if capture_resp.error
565
+ # @resp.success = false
566
+ # @resp.error = capture_resp.error
567
+ # end
568
+ # end
569
+ #
570
+ # # Decrement quantities of variants
571
+ # @order.decrement_quantities
572
+ #
573
+ # session[:cart_id] = nil
574
+ # init_cart
575
+ # end
576
+ #
577
+ # render :layout => false
578
+ # end
579
+ #
580
+ # #def relay
581
+ # #
582
+ # # # Check to see that the order has a valid total and was authorized
583
+ # # if @order.total > 0 && PaymentProcessor.authorize(@order, params)
584
+ # #
585
+ # # # Update order
586
+ # # @order.date_authorized = DateTime.now
587
+ # # @order.auth_amount = @order.total
588
+ # # @order.financial_status = 'authorized'
589
+ # # @order.status = if @order.test? then 'testing' else 'pending' end
590
+ # #
591
+ # # # Send out notifications
592
+ # # OrdersMailer.customer_new_order(@order).deliver
593
+ # # OrdersMailer.fulfillment_new_order(@order).deliver
594
+ # #
595
+ # # # Clear everything
596
+ # # session[:cart_id] = nil
597
+ # #
598
+ # # # Emit order event
599
+ # # Caboose.plugin_hook('order_authorized', @order)
600
+ # #
601
+ # # # Decrement quantities of variants
602
+ # # @order.decrement_quantities
603
+ # # else
604
+ # # @order.financial_status = 'unauthorized'
605
+ # # end
606
+ # #
607
+ # # @order.save
608
+ # #end
609
+ #
610
+ # # GET /checkout/authorize-by-gift-card
611
+ # #def authorize_by_gift_card
612
+ # # if @order.total < @order.discounts.first.amount_current
613
+ # #
614
+ # # # Update order
615
+ # # @order.date_authorized = DateTime.now
616
+ # # @order.auth_amount = @order.total
617
+ # # @order.financial_status = 'authorized'
618
+ # # @order.status = if @order.test? then 'testing' else 'pending' end
619
+ # #
620
+ # # # Send out notifications
621
+ # # OrdersMailer.customer_new_order(@order).deliver
622
+ # # OrdersMailer.fulfillment_new_order(@order).deliver
623
+ # #
624
+ # # # Clear everything
625
+ # # session[:cart_id] = nil
626
+ # #
627
+ # # # Emit order event
628
+ # # Caboose.plugin_hook('order_authorized', @order)
629
+ # #
630
+ # # # Decrement quantities of variants
631
+ # # @order.decrement_quantities
632
+ # #
633
+ # # @order.save
634
+ # #
635
+ # # redirect_to '/checkout/thanks'
636
+ # # else
637
+ # # redirect_to '/checkout/error'
638
+ # # end
639
+ # #end
640
+ #
641
+ # end
642
+ #end
643
+ #