Class: Caboose::MyAccountOrdersController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Caboose::MyAccountOrdersController
- Defined in:
- app/controllers/caboose/my_account_orders_controller.rb
Instance Method Summary collapse
-
#authnet_relay ⇒ Object
POST /my-account/orders/authnet-relay.
-
#authnet_response ⇒ Object
GET /my-account/orders/:id/authnet-response POST /my-account/orders/:id/authnet-response.
-
#edit ⇒ Object
GET /my-account/orders/:id.
-
#index ⇒ Object
GET /my-account/orders.
-
#order_json ⇒ Object
GET /my-account/orders/:id/json.
-
#payment_form ⇒ Object
GET /my-account/orders/:id/payment-form.
Methods inherited from ApplicationController
#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
POST /my-account/orders/authnet-relay
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 131 132 133 134 135 136 137 138 139 140 141 |
# File 'app/controllers/caboose/my_account_orders_controller.rb', line 103 def authnet_relay Caboose.log("Authorize.net relay for my account, order #{params[:x_invoice_id]}") order = Caboose::Order.find(params[:x_invoice_num]) ot = Caboose::OrderTransaction.new( :order_id => order.id, :date_processed => DateTime.now.utc, :transaction_type => Caboose::OrderTransaction::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 = order.total ot.save error = nil if ot.success order.financial_status = Order::FINANCIAL_STATUS_AUTHORIZED order.status = Order::STATUS_PENDING if order.status == Order::STATUS_CART order.order_number = @site.store_config.next_order_number if order.order_number.nil? # Send out emails OrdersMailer.configure_for_site(@site.id).customer_new_order(order).deliver # Emit order event Caboose.plugin_hook('order_authorized', order) else order.financial_status = Order::FINANCIAL_STATUS_PENDING error = "There was a problem processing your payment." end order.save @url = params[:x_after_relay] @url << (ot.success ? "?success=1" : "?error=#{error}") render :layout => false end |
#authnet_response ⇒ Object
GET /my-account/orders/:id/authnet-response POST /my-account/orders/:id/authnet-response
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'app/controllers/caboose/my_account_orders_controller.rb', line 145 def authnet_response Caboose.log("Authorize.net response for my account, order #{params[:id]}") @resp = Caboose::StdClass.new @resp.success = true if params[:success] @resp.error = params[:error] if params[:error] # Go ahead and capture funds if the order only contained downloadable items @order = Order.find(params[:id]) if !@order.has_shippable_items? capture_resp = @order.capture_funds if capture_resp.error @resp.success = false @resp.error = capture_resp.error end end render :layout => false end |
#edit ⇒ Object
GET /my-account/orders/:id
25 26 27 28 29 30 31 32 33 34 |
# File 'app/controllers/caboose/my_account_orders_controller.rb', line 25 def edit return if !verify_logged_in @order = Order.find(params[:id]) if @order.customer_id != logged_in_user.id @error = "The given order does not belong to you." render :file => 'caboose/extras/error' return end end |
#index ⇒ Object
GET /my-account/orders
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/controllers/caboose/my_account_orders_controller.rb', line 8 def index return if !verify_logged_in @pager = Caboose::PageBarGenerator.new(params, { 'customer_id' => logged_in_user.id, 'status' => [Order::STATUS_PENDING, Order::STATUS_CANCELED, Order::STATUS_READY_TO_SHIP, Order::STATUS_SHIPPED] }, { 'model' => 'Caboose::Order', 'sort' => 'order_number', 'desc' => 1, 'base_url' => '/my-account/orders', 'use_url_params' => false }) @orders = @pager.all_items end |
#order_json ⇒ Object
GET /my-account/orders/:id/json
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/controllers/caboose/my_account_orders_controller.rb', line 77 def order_json return if !logged_in? order = Order.find(params[:id]) if order.customer_id != logged_in_user.id render :json => { :error => "The given order does not belong to you." } return end if order.shipping_address_id.nil? sa = Address.create order.shipping_address_id = sa.id order.save end render :json => order.as_json(:include => [ { :line_items => { :include => { :variant => { :include => :product }}}}, { :order_packages => { :include => [:shipping_package, :shipping_method] }}, { :discounts => { :include => :gift_card }}, :customer, :shipping_address, :billing_address, :order_transactions ]) end |
#payment_form ⇒ Object
GET /my-account/orders/:id/payment-form
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 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/controllers/caboose/my_account_orders_controller.rb', line 37 def payment_form return if !logged_in? @order = Order.find(params[:id]) if @order.customer_id != logged_in_user.id @error = "The given order does not belong to you." render :file => 'caboose/extras/error' return end if @order.financial_status != Order::FINANCIAL_STATUS_PENDING @error = "This order 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.pp_username, sc.pp_password, @order.total, :relay_response => 'TRUE', :relay_url => "#{sc.pp_relay_domain}/my-account/orders/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' # TODO: Implement manual order payment for stripe end render :layout => false end |