Browse files

partial view for payments, further cleanup (go away obsolete controll…

…ers)
  • Loading branch information...
1 parent 2ef5cbe commit 6f9feec6ca6b9e1c4003a18d727189b2e228773c @tomash tomash committed Dec 12, 2010
View
7 app/controllers/admin/orders_controller_decorator.rb
@@ -1,7 +0,0 @@
-# Add a partial for PaypalPayment txns
-Admin::OrdersController.class_eval do
- before_filter :add_pp_standard_txns, :only => :show
- def add_pp_standard_txns
- @txn_partials << 'pp_standard_txns'
- end
-end
View
13 app/controllers/orders_controller_decorator.rb
@@ -1,13 +0,0 @@
-# Add a filter to the OrdersController so that if user is reaching us from an email link we can
-# associate the order with the user (once they log in)
-OrdersController.class_eval do
- before_filter :associate_order, :only => :show
- private
- def associate_order
- return unless payer_id = params[:payer_id]
- orders = Order.find(:all, :include => :paypal_payments, :conditions => ['payments.payer_id = ? AND orders.user_id is null', payer_id])
- orders.each do |order|
- order.update_attribute("user", current_user)
- end
- end
-end
View
22 app/controllers/paypal_controller.rb
@@ -0,0 +1,22 @@
+class PaypalController < CheckoutController
+ protect_from_forgery :except => [:confirm]
+ skip_before_filter :persist_gender
+
+ def confirm
+ # XXX It works!
+ #redirect_to checkout_state_path("confirm")
+ # but we want this:
+ unless current_order
+ redirect_to root_path
+ else
+ order = current_order
+ while order.state != "complete"
+ order.next
+ state_callback(:after)
+ end
+ #order.finalize!
+ redirect_to order_path(current_order)
+ end
+ end
+
+end
View
89 app/controllers/paypal_payments_controller.rb
@@ -1,89 +0,0 @@
-class PaypalPaymentsController < Spree::BaseController
- include ActiveMerchant::Billing::Integrations
- skip_before_filter :verify_authenticity_token
- before_filter :load_object, :only => :successful
- layout 'application'
-
- resource_controller
- belongs_to :order
-
- # NOTE: The Paypal Instant Payment Notification (IPN) results in the creation of a PaypalPayment
- create.after do
- # mark the checkout process as complete (even if the ipn results in a failure - no point in letting the user
- # edit the order now)
- @order.update_attribute("checkout_complete", true)
- object.update_attributes(:email => params[:payer_email], :payer_id => params[:payer_id])
- ipn = Paypal::Notification.new(request.raw_post)
-
- # create a transaction which records the details of the notification
- object.txns.create(:transaction_id => ipn.transaction_id,
- :amount => ipn.gross,
- :fee => ipn.fee,
- :currency_type => ipn.currency,
- :status => ipn.status,
- :received_at => ipn.received_at)
- if ipn.acknowledge
- case ipn.status
- when "Completed"
- if ipn.gross.to_d == @order.total
- @order.pay!
- @order.update_attribute("tax_amount", params[:tax].to_d) if params[:tax]
- @order.update_attribute("ship_amount", params[:mc_shipping].to_d) if params[:mc_shipping]
- else
- @order.fail_payment!
- logger.error("Incorrect order total during Paypal's notification, please investigate (Paypal processed #{ipn.gross}, and order total is #{@order.total})")
- end
- when "Pending"
- @order.fail_payment!
- logger.info("Received an unexpected pending status for order: #{@order.number}")
- else
- @order.fail_payment!
- logger.info("Received an unexpected status for order: #{@order.number}")
- end
- else
- @order.fail_payment!
- logger.info("Failed to acknowledge Paypal's notification, please investigate [order: #{@order.number}]")
- end
- end
-
- create.response do |wants|
- wants.html do
- render :nothing => true
- end
- end
-
- # Action for handling the "return to site" link after user completes the transaction on the Paypal website.
- def successful
- # order doesn't have ip_address writable attribute now
- # @order.update_attribute("ip_address", request.env['REMOTE_ADDR'] || "unknown")
-
-
- # its possible that the IPN has already been received at this point so that
- if @order.paypal_payments.empty?
- # create a payment and record the successful transaction
- paypal_payment = @order.paypal_payments.create(:email => params[:payer_email], :payer_id => params[:payer_id])
- paypal_payment.txns.create(:amount => params[:mc_gross].to_d,
- :status => "Processed",
- :transaction_id => params[:txn_id],
- :fee => params[:payment_fee],
- :currency_type => params[:mc_currency],
- :received_at => params[:payment_date])
- # advance the state
- @order.pend_payment!
- else
- paypal_payment = @order.paypal_payments.last
- end
-
- # remove order from the session (its not really practical to allow the user to edit the session anymore)
- session[:order_id] = nil
-
- if logged_in?
- @order.update_attribute("user", current_user)
- redirect_to order_url(@order) and return
- else
- flash[:notice] = "Please create an account or login so we can associate this order with an account"
- session[:return_to] = "#{order_url(@order)}?payer_id=#{paypal_payment.payer_id}"
- redirect_to signup_path
- end
- end
-end
View
28 app/views/checkout/edit.html.erb
@@ -0,0 +1,28 @@
+<% content_for :head do %>
+ <%= javascript_include_tag 'checkout', '/states' %>
+<% end %>
+<div id="checkout">
+ <h1><%= t("checkout")%></h1>
+ <%= checkout_progress %>
+ <br clear="left" />
+ <%= render "shared/error_messages", :target => @order %>
+ <%= hook :checkout_summary_box do %>
+ <div id="checkout-summary">
+ <%= render 'summary', :order => @order %>
+ </div>
+ <% end %>
+
+
+ <% if(@order.state == "payment") %>
+ <%= render('checkout/paypal_checkout') if @order.payable_via_pay_pal? %>
+ <% else %>
+ <%= form_for @order, :url => update_checkout_path(@order.state), :html => { :id => "checkout_form_#{@order.state}" } do |form| %>
+ <%= render @order.state, :form => form %>
+ <input id="post-final" type="submit" style="display:none"/>
+ <% end %>
+ <% end %>
+</div>
+
+<div id="payment_step">
+
+</div>
View
12 config/routes.rb
@@ -1,12 +1,4 @@
Rails.application.routes.draw do
- # Add your extension routes here
- resources :orders do
- # we're kind of abusing the notion of a restful collection here but we're in the weird position of
- # not being able to create the payment before sending the request to paypal
- resources :paypal_payments do
- collection do
- post 'successful'
- end
- end
- end
+ post "paypal/confirm", :to => "paypal#confirm", :method => :post
+ resources :payment_notifications, :only => [:create]
end

0 comments on commit 6f9feec

Please sign in to comment.