Permalink
Browse files

first commit with edge spree compatibility, with some code revision (…

…shipping cost, config stuff, view code, routes and other minor stuff). still needs work on IPN, specs and readme update. Order State Machine stuff commented out (not working at all), I need some help here.
  • Loading branch information...
1 parent 487aca1 commit 4b3027b743e6e5e93e06ec52c928d99778f57efa @tomash tomash committed Nov 10, 2010
View
@@ -8,4 +8,9 @@
-----
* Significant database changes, do not run migrations until you have backed up your payment data.
-* Migrations will not port over your old payments, its suggested you write your own migration to do this in order to preserve legacy payments.
+* Migrations will not port over your old payments, its suggested you write your own migration to do this in order to preserve legacy payments.
+
+0.7.x
+-----
+
+* Rails 3 / Spree 0.30 compatibility, using new extension system (gem)
View
23 LICENSE
@@ -0,0 +1,23 @@
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of the Rails Dog LLC nor the names of its
+ contributors may be used to endorse or promote products derived from this
+ software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -11,58 +11,52 @@ Regarding Taxes and shipping, we assumed you'd want to use Paypal's system for t
You may want to implement your own custom logic by adding `state_machine` hooks. Just add these hooks in your site extension (don't change the `pp_website_standard` extension.) Here's an example of how to add the hooks to your site extension.
-<pre>
-fsm = Order.state_machines['state']
-fsm.after_transition :to => 'paid', :do => :after_payment
-fsm.after_transition :to => 'pending_payment', :do => :after_pending
-
-Order.class_eval do
- def after_payment
- # email user and tell them we received their payment
- end
-
- def after_pending
- # email user and thell them that we are processing their order, etc.
- end
-end
-</pre>
-
-# Configuration
+
+ fsm = Order.state_machines['state']
+ fsm.after_transition :to => 'paid', :do => :after_payment
+ fsm.after_transition :to => 'pending_payment', :do => :after_pending
+
+ Order.class_eval do
+ def after_payment
+ # email user and tell them we received their payment
+ end
+
+ def after_pending
+ # email user and thell them that we are processing their order, etc.
+ end
+ end
+
+
+## Configuration
Be sure to configure the following configuration parameters.
Example
-<pre>
-Spree::Paypal::Config[:account] = "foo@example.com"
-Spree::Paypal::Config[:ipn_notify_host] = "http://123.456.78:3000"
-Spree::Paypal::Config[:success_url] = "http://localhost:3000/checkout/success"
-</pre>
+ Spree::Paypal::Config[:account] = "foo@example.com"
+ Spree::Paypal::Config[:ipn_notify_host] = "http://123.456.78:3000"
+ Spree::Paypal::Config[:success_url] = "http://localhost:3000/checkout/success"
Or even better, you can configure these in a migration for your site extension.
-<pre>
-class AddPaypalStandardConfigurations < ActiveRecord::Migration
- def self.up
- Spree::Paypal::Config.set(:account => "foo@example.com")
- Spree::Paypal::Config.set(:ipn_notify_host => "http://123.456.78:3000")
- Spree::Paypal::Config.set(:success_url => "http://localhost:3000/checkout/success")
- end
-
- def self.down
- end
-end
-</pre>
+ class AddPaypalStandardConfigurations < ActiveRecord::Migration
+ def self.up
+ Spree::Paypal::Config.set(:account => "foo@example.com")
+ Spree::Paypal::Config.set(:ipn_notify_host => "http://123.456.78:3000")
+ Spree::Paypal::Config.set(:success_url => "http://localhost:3000/checkout/success")
+ end
+
+ def self.down
+ end
+ end
-# Installation
+## Installation
-<pre>
-script/extension install git://github.com/Gregg/spree-pp-website-standard.git
-</pre>
+ script/extension install git://github.com/Gregg/spree-pp-website-standard.git
-# IPN Notes
+## IPN Notes
-Real world testing indicates that IPN can be very slow. If you are wanting to test the IPN piece Paypal now has an IPN tool on their developer site. Just use the correct URL from the hidden field on your Spree checkout screen. In the IPN tool, change the transaction type to `cart checkout` and change the `mc_gross` variable to match your order total.
+Real world testing indicates that IPN can be very slow. If you want to test the IPN piece Paypal now has an IPN tool on their developer site. Just use the correct URL from the hidden field on your Spree checkout screen. In the IPN tool, change the transaction type to `cart checkout` and change the `mc_gross` variable to match your order total.
* TODO: Taxes
* TODO: Shipping
View
129 Rakefile
@@ -1,120 +1,31 @@
-# I think this is the one that should be moved to the extension Rakefile template
-
-# In rails 1.2, plugins aren't available in the path until they're loaded.
-# Check to see if the rspec plugin is installed first and require
-# it if it is. If not, use the gem version.
-
-# Determine where the RSpec plugin is by loading the boot
-unless defined? SPREE_ROOT
- ENV["RAILS_ENV"] = "test"
- case
- when ENV["SPREE_ENV_FILE"]
- require File.dirname(ENV["SPREE_ENV_FILE"]) + "/boot"
- when File.dirname(__FILE__) =~ %r{vendor/SPREE/vendor/extensions}
- require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../")}/config/boot"
- else
- require "#{File.expand_path(File.dirname(__FILE__) + "/../../../")}/config/boot"
- end
-end
+require File.expand_path('../../config/application', __FILE__)
+require 'rubygems'
require 'rake'
-require 'rake/rdoctask'
require 'rake/testtask'
+require 'rake/packagetask'
+require 'rake/gempackagetask'
-rspec_base = File.expand_path(SPREE_ROOT + '/vendor/plugins/rspec/lib')
-$LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
-require 'spec/rake/spectask'
-# require 'spec/translator'
-
-# Cleanup the SPREE_ROOT constant so specs will load the environment
-Object.send(:remove_const, :SPREE_ROOT)
-
-extension_root = File.expand_path(File.dirname(__FILE__))
-
-task :default => :spec
-task :stats => "spec:statsetup"
+spec = eval(File.read('pp_website_standard.gemspec'))
-desc "Run all specs in spec directory"
-Spec::Rake::SpecTask.new(:spec) do |t|
- t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
- t.spec_files = FileList['spec/**/*_spec.rb']
+Rake::GemPackageTask.new(spec) do |p|
+ p.gem_spec = spec
end
-namespace :spec do
- desc "Run all specs in spec directory with RCov"
- Spec::Rake::SpecTask.new(:rcov) do |t|
- t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
- t.spec_files = FileList['spec/**/*_spec.rb']
- t.rcov = true
- t.rcov_opts = ['--exclude', 'spec', '--rails']
- end
-
- desc "Print Specdoc for all specs"
- Spec::Rake::SpecTask.new(:doc) do |t|
- t.spec_opts = ["--format", "specdoc", "--dry-run"]
- t.spec_files = FileList['spec/**/*_spec.rb']
- end
-
- [:models, :controllers, :views, :helpers].each do |sub|
- desc "Run the specs under spec/#{sub}"
- Spec::Rake::SpecTask.new(sub) do |t|
- t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
- t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
- end
- end
-
- # Hopefully no one has written their extensions in pre-0.9 style
- # desc "Translate specs from pre-0.9 to 0.9 style"
- # task :translate do
- # translator = ::Spec::Translator.new
- # dir = RAILS_ROOT + '/spec'
- # translator.translate(dir, dir)
- # end
-
- # Setup specs for stats
- task :statsetup do
- require 'code_statistics'
- ::STATS_DIRECTORIES << %w(Model\ specs spec/models)
- ::STATS_DIRECTORIES << %w(View\ specs spec/views)
- ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers)
- ::STATS_DIRECTORIES << %w(Helper\ specs spec/views)
- ::CodeStatistics::TEST_TYPES << "Model specs"
- ::CodeStatistics::TEST_TYPES << "View specs"
- ::CodeStatistics::TEST_TYPES << "Controller specs"
- ::CodeStatistics::TEST_TYPES << "Helper specs"
- ::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
- end
-
- namespace :db do
- namespace :fixtures do
- desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
- task :load => :environment do
- require 'active_record/fixtures'
- ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
- (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
- Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
- end
- end
- end
- end
+desc "Release to gemcutter"
+task :release => :package do
+ require 'rake/gemcutter'
+ Rake::Gemcutter::Tasks.new(spec).define
+ Rake::Task['gem:push'].invoke
end
-desc 'Generate documentation for the spree_pp_website_standard extension.'
-Rake::RDocTask.new(:rdoc) do |rdoc|
- rdoc.rdoc_dir = 'rdoc'
- rdoc.title = 'SpreePpWebsiteStandardExtension'
- rdoc.options << '--line-numbers' << '--inline-source'
- rdoc.rdoc_files.include('README')
- rdoc.rdoc_files.include('lib/**/*.rb')
-end
+desc "Default Task"
+task :default => [ :spec ]
-# For extensions that are in transition
-desc 'Test the spree_pp_website_standard extension.'
-Rake::TestTask.new(:test) do |t|
- t.libs << 'lib'
- t.pattern = 'test/**/*_test.rb'
- t.verbose = true
-end
+require 'rspec/core/rake_task'
+RSpec::Core::RakeTask.new
-# Load any custom rakefiles for extension
-Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
+# require 'cucumber/rake/task'
+# Cucumber::Rake::Task.new do |t|
+# t.cucumber_opts = %w{--format pretty}
+# end
@@ -0,0 +1,9 @@
+puts "orders controller decorator loading"
+
+# 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
@@ -0,0 +1,15 @@
+puts "orders controller decorator loading..."
+
+# 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
@@ -1,3 +1,5 @@
+puts "loading paypal_payments controller..."
+
class PaypalPaymentsController < Spree::BaseController
include ActiveMerchant::Billing::Integrations
skip_before_filter :verify_authenticity_token
@@ -0,0 +1,9 @@
+puts "order model decorator loading..."
+
+Order.class_eval do
+ has_many :paypal_payments
+
+ def shipment_cost
+ adjustment_total - credit_total
+ end
+end
@@ -1,3 +1,5 @@
+puts "loading paypal_payment model..."
+
class PaypalPayment < Payment
has_many :paypal_txns
alias :txns :paypal_txns
View
@@ -1,3 +1,5 @@
+puts "loading paypal_txn model..."
+
class PaypalTxn < ActiveRecord::Base
belongs_to :paypal_payment
validates_numericality_of :amount
@@ -1,50 +0,0 @@
-<div id="shopping-cart">
- <h1><%= t("Shopping Cart") %></h1>
-
- <%=error_messages_for :cart_item%>
-
- <% form_tag do-%>
- <table class="cart-summary" width="100% ">
- <tr>
- <th colspan="2"><%= t("Item") %></th>
- <th><%= t("Price") %></th>
- <th><%= t("Qty") %></th>
- <!--<th>Delete</th>-->
- <th><%= t("Total") %></th>
- </tr>
- <% for @item in @cart_items %>
- <tr class="<%= cycle('even', 'odd') %>">
- <td width="100">
- <%= small_image(@item.variant.product) %>
- </td>
- <td valign="top">
- <%=link_to @item.variant.product.name, product_path(@item.variant.product) %>
- <%= variant_options @item.variant %><br/>
- <%=truncate(@item.variant.product.description, length = 100, truncate_string = "...")-%>
- </td>
- <td valign="top" width="75"><%= number_to_currency(@item.price) %></td>
- <td valign="top" width="50"><%= text_field "item[]", :quantity, :size => 3 -%></td>
- <td valign="top" width="75"><%= number_to_currency(@item.price * @item.quantity) unless @item.quantity.nil? %></td>
- </tr>
- <% end %>
- </table>
- <div id="subtotal">
- <h3><%= "#{t("Subtotal")}: #{number_to_currency(@cart.total)}" %></h3>
- <%= submit_tag t('Update') %>
- <% end %>
- <%= render :partial => 'paypal_checkout' %>
- </div>
-
- <%if previous_location %>
- <p><%=link_to t("Continue Shopping"), products_path %></p>
- <%end%>
- <% unless @cart.cart_items.empty? %>
- <p id="clear_cart_link">
- <small>
- <%= link_to t("Empty Cart"), :action => 'empty' %>
- </small>
- </p>
- <% end %>
-</div>
-
-
Oops, something went wrong.

0 comments on commit 4b3027b

Please sign in to comment.