Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Set the payer_id for the paypal payment.

  • Loading branch information...
commit 7548b59337be586c2d132dda5005c04881b0f675 1 parent 7fb2df1
@schof schof authored
View
4 app/controllers/paypal_payments_controller.rb
@@ -12,7 +12,7 @@ class PaypalPaymentsController < Spree::BaseController
# 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_attribute("email", params[:payer_email])
+ 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
@@ -58,7 +58,7 @@ def successful
# its possible that the IPN has already been received at this point so that
unless @order.paypal_payment
# create a payment and record the successful transaction
- paypal_payment = PaypalPayment.create(:order => @order, :email => params[:payer_email])
+ paypal_payment = PaypalPayment.create(:order => @order, :email => params[:payer_email], :payer_id => params[:payer_id])
@order.paypal_payment = paypal_payment
paypal_payment.txns.create(:amount => params[:mc_gross].to_d,
:status => "Processed",
View
13 db/migrate/20081029221005_add_payer_id.rb
@@ -0,0 +1,13 @@
+class AddPayerId < ActiveRecord::Migration
+ def self.up
+ change_table :paypal_payments do |t|
+ t.string :payer_id
+ end
+ end
+
+ def self.down
+ change_table :paypal_payments do |t|
+ t.remove :payer_id
+ end
+ end
+end
View
13 pp_website_standard_extension.rb
@@ -14,7 +14,6 @@ class PpWebsiteStandardExtension < Spree::Extension
url "http://yourwebsite.com/spree_pp_website_standard"
define_routes do |map|
- #map.resources :orders, :has_one => [:paypal_payment]
map.resources :orders do |order|
# 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
@@ -31,6 +30,18 @@ def add_pp_standard_txns
@txn_partials << 'pp_standard_txns'
end
end
+
+ # 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)
+ Admin::OrdersController.class_eval do
+ before_filter :associate_order, :only => :show
+ private
+ def associate_order
+puts ">>>>>>> associating order"
+ return unless params[:payer_id]
+ # TODO - do stuff
+ end
+ end
# add new events and states to the FSM
fsm = Order.state_machines['state']
View
22 spec/controllers/orders_controller_spec.rb
@@ -0,0 +1,22 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe OrdersController do
+ fixtures :users
+
+ before(:each) do
+ @order = Order.create(:id => 102, :number => "SAMP-1002", :state => "paid")
+ Order.stub!(:find).with(any_args).and_return(@order)
+ @paypal_payment = PaypalPayment.create(:payer_id => "FOOFAH")
+ PaypalPayment.stub!(:find).with(any_args).and_return([@paypal_payment])
+ end
+
+ describe "show" do
+ it "should associate the order with the user (once authenticated)" do
+puts ">>>>> order.number: #{@order.number}"
+ @user = login(:pp_standard)
+ post :show, :order_id => @order.id, :payer_id => "FOOFAH"
+ #@order.user.should == users(:pp_standard)
+ end
+
+ end
+end
View
14 spec/controllers/paypal_payments_controllers_spec.rb
@@ -15,7 +15,7 @@
describe "create" do
def do_create
- post :create, :order_id => @order.id, :payer_email => "test@example.com"
+ post :create, :order_id => @order.id, :payer_email => "test@example.com", :payer_id => "FOO"
end
before(:each) { @ipn.stub!(:acknowledge).and_return(true) }
@@ -27,6 +27,10 @@ def do_create
do_create
@order.paypal_payment.email.should == "test@example.com"
end
+ it "should set the paypal payment payer id" do
+ do_create
+ @order.paypal_payment.payer_id.should == "FOO"
+ end
it "should create a transaction for the paypal payment" do
do_create
@order.paypal_payment.txns.first.should_not be_nil
@@ -78,7 +82,7 @@ def do_create
describe "successful" do
describe "successful in general", :shared => true do
def do_successful
- post :successful, :order_id => @order.id, :mc_gross => @order.total.to_s, :payer_email => "test@example.com"
+ post :successful, :order_id => @order.id, :mc_gross => @order.total.to_s, :payer_email => "test@example.com", :payer_id => "FOO"
end
it "should set the IP address of the order" do
request.env['REMOTE_ADDR'] = "1.2.3.4"
@@ -114,10 +118,14 @@ def do_successful
do_successful
@order.checkout_complete.should be_true
end
- it "should set the payment email" do
+ it "should set the paypal payment email" do
do_successful
@order.paypal_payment.email.should == "test@example.com"
end
+ it "should set the paypal payment payer id" do
+ do_successful
+ @order.paypal_payment.payer_id.should == "FOO"
+ end
it_should_behave_like "successful in general"
end
describe "when ipn has already been received" do
Please sign in to comment.
Something went wrong with that request. Please try again.