Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't destroy line items #11

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ tmp
nbproject
*.swp
spec/dummy
Gemfile.lock
9 changes: 9 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ source 'http://rubygems.org'

group :test do
gem 'ffaker'
gem "fuubar"
end

group :development do
gem "guard-rspec"
end

group :development, :test do
gem "combustion"
end

if RUBY_VERSION < "1.9"
Expand Down
226 changes: 226 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
PATH
remote: .
specs:
spree_paypal_website_standard (1.0.0.beta1)
spree_core (>= 1.0.0.rc1)

GEM
remote: http://rubygems.org/
specs:
actionmailer (3.1.4)
actionpack (= 3.1.4)
mail (~> 2.3.0)
actionpack (3.1.4)
activemodel (= 3.1.4)
activesupport (= 3.1.4)
builder (~> 3.0.0)
erubis (~> 2.7.0)
i18n (~> 0.6)
rack (~> 1.3.6)
rack-cache (~> 1.1)
rack-mount (~> 0.8.2)
rack-test (~> 0.6.1)
sprockets (~> 2.0.3)
active_utils (1.0.3)
activesupport (>= 2.3.11)
i18n
activemerchant (1.20.1)
active_utils (>= 1.0.1)
activesupport (>= 2.3.11)
braintree (>= 2.0.0)
builder (>= 2.0.0)
i18n
json (>= 1.5.1)
money (<= 3.7.1)
activemodel (3.1.4)
activesupport (= 3.1.4)
builder (~> 3.0.0)
i18n (~> 0.6)
activerecord (3.1.4)
activemodel (= 3.1.4)
activesupport (= 3.1.4)
arel (~> 2.2.3)
tzinfo (~> 0.3.29)
activeresource (3.1.4)
activemodel (= 3.1.4)
activesupport (= 3.1.4)
activesupport (3.1.4)
multi_json (~> 1.0)
acts_as_list (0.1.4)
archive-tar-minitar (0.5.2)
arel (2.2.3)
braintree (2.14.0)
builder (>= 2.0.0)
builder (3.0.0)
capybara (1.0.1)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
selenium-webdriver (~> 2.0)
xpath (~> 0.1.4)
childprocess (0.3.1)
ffi (~> 1.0.6)
cocaine (0.2.1)
columnize (0.3.6)
combustion (0.3.2)
rails (>= 3.0.0)
thor (>= 0.14.6)
deface (0.8.0)
nokogiri (~> 1.5.0)
rails (>= 3.0.9)
diff-lcs (1.1.3)
erubis (2.7.0)
factory_girl (2.6.4)
activesupport (>= 2.3.9)
ffaker (1.12.1)
ffi (1.0.11)
fuubar (1.0.0)
rspec (~> 2.0)
rspec-instafail (~> 0.2.0)
ruby-progressbar (~> 0.0.10)
guard (1.0.1)
ffi (>= 0.5.0)
thor (~> 0.14.6)
guard-rspec (0.6.0)
guard (>= 0.10.0)
highline (1.6.8)
hike (1.2.1)
i18n (0.6.0)
jquery-rails (1.0.19)
railties (~> 3.0)
thor (~> 0.14)
json (1.6.5)
kaminari (0.13.0)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
railties (>= 3.0.0)
linecache19 (0.5.12)
ruby_core_source (>= 0.1.4)
mail (2.3.3)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
meta_search (1.1.1)
actionpack (~> 3.1.0)
activerecord (~> 3.1.0)
activesupport (~> 3.1.0)
polyamorous (~> 0.5.0)
mime-types (1.17.2)
money (3.7.1)
i18n (~> 0.4)
multi_json (1.1.0)
nested_set (1.6.8)
activerecord (>= 3.0.0)
railties (>= 3.0.0)
nokogiri (1.5.2)
paperclip (2.5.0)
activerecord (>= 2.3.0)
activesupport (>= 2.3.2)
cocaine (>= 0.0.2)
mime-types
polyamorous (0.5.0)
activerecord (~> 3.0)
polyglot (0.3.3)
rack (1.3.6)
rack-cache (1.2)
rack (>= 0.4)
rack-mount (0.8.3)
rack (>= 1.0.0)
rack-ssl (1.3.2)
rack
rack-test (0.6.1)
rack (>= 1.0)
rails (3.1.4)
actionmailer (= 3.1.4)
actionpack (= 3.1.4)
activerecord (= 3.1.4)
activeresource (= 3.1.4)
activesupport (= 3.1.4)
bundler (~> 1.0)
railties (= 3.1.4)
railties (3.1.4)
actionpack (= 3.1.4)
activesupport (= 3.1.4)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.6)
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
rspec (2.8.0)
rspec-core (~> 2.8.0)
rspec-expectations (~> 2.8.0)
rspec-mocks (~> 2.8.0)
rspec-core (2.8.0)
rspec-expectations (2.8.0)
diff-lcs (~> 1.1.2)
rspec-instafail (0.2.2)
rspec-mocks (2.8.0)
rspec-rails (2.8.1)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec (~> 2.8.0)
ruby-debug-base19 (0.11.25)
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
ruby_core_source (>= 0.1.4)
ruby-debug19 (0.11.6)
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
ruby-debug-base19 (>= 0.11.19)
ruby-progressbar (0.0.10)
ruby_core_source (0.1.5)
archive-tar-minitar (>= 0.5.2)
rubyzip (0.9.6.1)
selenium-webdriver (2.20.0)
childprocess (>= 0.2.5)
ffi (~> 1.0)
multi_json (~> 1.0)
rubyzip
spree_core (1.0.3)
activemerchant (= 1.20.1)
acts_as_list (= 0.1.4)
deface (>= 0.7.2)
ffaker (~> 1.12.0)
highline (= 1.6.8)
jquery-rails (>= 1.0.18, <= 1.0.19)
kaminari (>= 0.13.0)
meta_search (= 1.1.1)
nested_set (= 1.6.8)
paperclip (= 2.5.0)
rails (>= 3.1.1, <= 3.1.4)
state_machine (= 1.1.1)
stringex (~> 1.3.0)
sprockets (2.0.3)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.5)
state_machine (1.1.1)
stringex (1.3.2)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.32)
xpath (0.1.4)
nokogiri (~> 1.3)

PLATFORMS
ruby

DEPENDENCIES
capybara (= 1.0.1)
combustion
factory_girl
ffaker
fuubar
guard-rspec
rspec-rails (~> 2.7)
ruby-debug19
spree_paypal_website_standard!
sqlite3
19 changes: 19 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme

guard 'rspec', :version => 2, :cli => "--format Fuubar" do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }

# Rails example
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
# Capybara request specs
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
end

1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class ApplicationController < ActionController::Base; end
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def check_current_order
order = current_order
if (order.payment_state == "paid") or (order.payment_state == "credit_owed")
session[:order_id] = nil
order.line_items.destroy_all
@current_order = nil
flash[:notice] = t(:pp_ws_payment_received)
end
end
Expand Down
11 changes: 9 additions & 2 deletions app/controllers/spree/payment_notifications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Spree
class PaymentNotificationsController < BaseController
protect_from_forgery :except => [:create]
skip_before_filter :restriction_access
before_filter :ignore_foreign_notifications

def create
if(Spree::PaypalWebsiteStandard::Config.encrypted && (params[:secret] != Spree::PaypalWebsiteStandard::Config.ipn_secret))
Expand Down Expand Up @@ -84,6 +85,12 @@ def after_complete
def default_country
Country.find Spree::PaypalWebsiteStandard::Config.default_country_id
end


def ignore_foreign_notifications
if params[:invoice_id].present?
logger.info(I18n.t(:foreign_ipn_message, :scope => "paypal"))
render :nothing => true
end
end
end
end
end
7 changes: 7 additions & 0 deletions app/helpers/spree/paypal_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Spree
module PaypalHelper
def pay_with_paypal?
@order.state == 'payment' and @order.payable_via_paypal?
end
end
end
18 changes: 9 additions & 9 deletions app/models/spree/order_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
Spree::Order.class_eval do
has_many :payment_notifications

# SSL certificates for encrypting paypal link
PAYPAL_CERT_PEM = "#{Rails.root}/certs/paypal_cert_#{Rails.env}.pem"
APP_CERT_PEM = "#{Rails.root}/certs/app_cert.pem"
APP_KEY_PEM = "#{Rails.root}/certs/app_key.pem"
def shipment_cost
adjustment_total - credit_total
end

def payable_via_paypal?
!!self.class.paypal_payment_method
end

def self.paypal_payment_method
PaymentMethod.select{ |pm| pm.name.downcase =~ /paypal/}.first
Spree::PaymentMethod.select{ |pm| pm.name.downcase =~ /paypal/}.first
end

def self.use_encrypted_paypal_link?
Spree::PaypalWebsiteStandard::Config.encrypted &&
Spree::PaypalWebsiteStandard::Config.ipn_secret &&
Expand All @@ -25,7 +25,7 @@ def self.use_encrypted_paypal_link?
File.exist?(APP_CERT_PEM) &&
File.exist?(APP_KEY_PEM)
end

def paypal_encrypted(payment_notifications_url, options = {})
values = {
:business => Spree::PaypalWebsiteStandard::Config.account,
Expand All @@ -41,7 +41,7 @@ def paypal_encrypted(payment_notifications_url, options = {})
:page_style => Spree::PaypalWebsiteStandard::Config.page_style,
:tax_cart => self.tax_total
}

self.line_items.each_with_index do |item, index|
values.merge!({
"amount_#{index + 1}" => item.price,
Expand All @@ -50,10 +50,10 @@ def paypal_encrypted(payment_notifications_url, options = {})
"quantity_#{index + 1}" => item.quantity
})
end

encrypt_for_paypal(values)
end

def encrypt_for_paypal(values)
paypal_cert = File.read(PAYPAL_CERT_PEM)
app_cert = File.read(APP_CERT_PEM)
Expand Down
15 changes: 15 additions & 0 deletions app/models/spree/pay_pal_payment_method.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Spree
class PayPalPaymentMethod < PaymentMethod
def provider_class
self.class
end

def payment_source_class
self.class
end

def source_required?
false
end
end
end
4 changes: 4 additions & 0 deletions app/overrides/paypal_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Deface::Override.new(:virtual_path => "spree/checkout/edit",
:surround_contents => "[data-hook='checkout_form_wrapper']",
:text => "<% if pay_with_paypal? -%><%= render :partial => 'spree/checkout/paypal_checkout' %><% else -%><%= render_original %><% end -%>",
:name => "paypal_form")
Loading