diff --git a/.gitignore b/.gitignore
index 2b54990..b2c9314 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,4 @@ tmp
nbproject
*.swp
spec/dummy
+Gemfile.lock
diff --git a/Gemfile b/Gemfile
index 0bf92bd..9941e6f 100644
--- a/Gemfile
+++ b/Gemfile
@@ -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"
diff --git a/Gemfile.lock b/Gemfile.lock
new file mode 100644
index 0000000..a275dd1
--- /dev/null
+++ b/Gemfile.lock
@@ -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
diff --git a/Guardfile b/Guardfile
new file mode 100644
index 0000000..8320ec2
--- /dev/null
+++ b/Guardfile
@@ -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
+
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
new file mode 100644
index 0000000..c7056de
--- /dev/null
+++ b/app/controllers/application_controller.rb
@@ -0,0 +1 @@
+class ApplicationController < ActionController::Base; end
diff --git a/app/controllers/spree/base_controller_decorator.rb.rb b/app/controllers/spree/base_controller_decorator.rb
similarity index 91%
rename from app/controllers/spree/base_controller_decorator.rb.rb
rename to app/controllers/spree/base_controller_decorator.rb
index b83bdd0..404172e 100644
--- a/app/controllers/spree/base_controller_decorator.rb.rb
+++ b/app/controllers/spree/base_controller_decorator.rb
@@ -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
diff --git a/app/controllers/spree/payment_notifications_controller.rb b/app/controllers/spree/payment_notifications_controller.rb
index 1fa4517..7f7b7b6 100644
--- a/app/controllers/spree/payment_notifications_controller.rb
+++ b/app/controllers/spree/payment_notifications_controller.rb
@@ -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))
@@ -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
\ No newline at end of file
+end
diff --git a/app/helpers/spree/paypal_helper.rb b/app/helpers/spree/paypal_helper.rb
new file mode 100644
index 0000000..c4d9feb
--- /dev/null
+++ b/app/helpers/spree/paypal_helper.rb
@@ -0,0 +1,7 @@
+module Spree
+ module PaypalHelper
+ def pay_with_paypal?
+ @order.state == 'payment' and @order.payable_via_paypal?
+ end
+ end
+end
diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb
index 8c6f570..2088b40 100644
--- a/app/models/spree/order_decorator.rb
+++ b/app/models/spree/order_decorator.rb
@@ -1,6 +1,6 @@
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"
@@ -8,15 +8,15 @@
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 &&
@@ -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,
@@ -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,
@@ -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)
diff --git a/app/models/spree/pay_pal_payment_method.rb b/app/models/spree/pay_pal_payment_method.rb
new file mode 100644
index 0000000..8ff75f2
--- /dev/null
+++ b/app/models/spree/pay_pal_payment_method.rb
@@ -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
diff --git a/app/overrides/paypal_form.rb b/app/overrides/paypal_form.rb
new file mode 100644
index 0000000..f2d2c2d
--- /dev/null
+++ b/app/overrides/paypal_form.rb
@@ -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")
diff --git a/app/views/spree/admin/orders/_pp_standard_txns.html.erb b/app/views/spree/admin/orders/_pp_standard_txns.html.erb
deleted file mode 100644
index bcd5ac3..0000000
--- a/app/views/spree/admin/orders/_pp_standard_txns.html.erb
+++ /dev/null
@@ -1,23 +0,0 @@
-<% if @order.paypal_payment %>
-
-<%= t("Paypal Transaction") %>
-
-
-
- <%= t("Amount") %>
- <%= t("Fee") %>
- <%= t("Status") %>
- <%= t("Transaction Id") %>
- <%= t("Received At") %>
-
- <% @order.paypal_payment.txns.each do |t| %>
-
- <%=number_to_currency t.amount %>
- <%=number_to_currency t.fee %>
- <%=t.status %>
- <%=t.transaction_id %>
- <%=t.received_at %>
-
- <% end %>
-
-<% end %>
\ No newline at end of file
diff --git a/app/views/spree/admin/payments/source_views/_gateway.html.erb b/app/views/spree/admin/payments/source_views/_gateway.html.erb
new file mode 100644
index 0000000..ea2512e
--- /dev/null
+++ b/app/views/spree/admin/payments/source_views/_gateway.html.erb
@@ -0,0 +1,26 @@
+<%= t(:ipn_notifications, :scope => 'paypal') %>
+
+
+
+ <%= t(:transaction_type, :scope => 'paypal') %>
+ <%= t(:payer_email, :scope => 'paypal') %>
+ <%= t(:deposit_amount, :scope => 'paypal') %>
+ <%= t(:mc_currency, :scope => 'paypal') %>
+ <%= t(:mc_gross, :scope => 'paypal') %>
+ <%= t(:mc_fee, :scope => 'paypal') %>
+ <%= t(:payment_gross, :scope => 'paypal') %>
+ <%= t(:payment_fee, :scope => 'paypal') %>
+
+ <% payment.order.payment_notifications.each do |notification| -%>
+
+ <%= notification.params["txn_type"] or notification.params["reason_code"] %>
+ <%= notification.params["payer_email"] %>
+ <%= number_to_currency notification.params["payment_gross"].to_f - notification.params["payment_fee"].to_f, :unit => "$" %>
+ <%= notification.params["mc_currency"] %>
+ <%= notification.params["mc_gross"] %>
+ <%= notification.params["mc_fee"] %>
+ <%= number_to_currency notification.params["payment_gross"].to_f, :unit => "$" %>
+ <%= number_to_currency notification.params["payment_fee"].to_f, :unit => "$" %>
+
+ <% end -%>
+
diff --git a/app/views/spree/admin/payments/source_views/_paypalpaymentmethod.html.erb b/app/views/spree/admin/payments/source_views/_paypalpaymentmethod.html.erb
new file mode 100644
index 0000000..ea2512e
--- /dev/null
+++ b/app/views/spree/admin/payments/source_views/_paypalpaymentmethod.html.erb
@@ -0,0 +1,26 @@
+<%= t(:ipn_notifications, :scope => 'paypal') %>
+
+
+
+ <%= t(:transaction_type, :scope => 'paypal') %>
+ <%= t(:payer_email, :scope => 'paypal') %>
+ <%= t(:deposit_amount, :scope => 'paypal') %>
+ <%= t(:mc_currency, :scope => 'paypal') %>
+ <%= t(:mc_gross, :scope => 'paypal') %>
+ <%= t(:mc_fee, :scope => 'paypal') %>
+ <%= t(:payment_gross, :scope => 'paypal') %>
+ <%= t(:payment_fee, :scope => 'paypal') %>
+
+ <% payment.order.payment_notifications.each do |notification| -%>
+
+ <%= notification.params["txn_type"] or notification.params["reason_code"] %>
+ <%= notification.params["payer_email"] %>
+ <%= number_to_currency notification.params["payment_gross"].to_f - notification.params["payment_fee"].to_f, :unit => "$" %>
+ <%= notification.params["mc_currency"] %>
+ <%= notification.params["mc_gross"] %>
+ <%= notification.params["mc_fee"] %>
+ <%= number_to_currency notification.params["payment_gross"].to_f, :unit => "$" %>
+ <%= number_to_currency notification.params["payment_fee"].to_f, :unit => "$" %>
+
+ <% end -%>
+
diff --git a/app/views/spree/checkout/edit.html.erb b/app/views/spree/checkout/edit.html.erb
deleted file mode 100755
index 44f9931..0000000
--- a/app/views/spree/checkout/edit.html.erb
+++ /dev/null
@@ -1,28 +0,0 @@
-<% content_for :head do %>
- <%= javascript_include_tag '/states' %>
-<% end %>
-
-
<%= t("checkout")%>
- <%= checkout_progress %>
-
- <%= render "spree/shared/error_messages", :target => @order %>
- <%= hook :checkout_summary_box do %>
-
- <%= render 'summary', :order => @order %>
-
- <% end %>
-
-
- <% if(@order.state == "payment") %>
- <%= render('spree/checkout/paypal_checkout') if @order.payable_via_paypal? %>
- <% else %>
- <%= form_for @order, :url => update_checkout_path(@order.state), :html => { :id => "checkout_form_#{@order.state}" } do |form| %>
- <%= render @order.state, :form => form %>
-
- <% end %>
- <% end %>
-
-
-
-
-
diff --git a/config/locales/en.yml b/config/locales/en.yml
index e62c5a4..8e4f150 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -8,3 +8,11 @@ en:
check_out_with_paypal: "Check out with PayPal"
pp_ws_payment_received: "Thank you.. We received the payment for your order from PayPal. Your order will be shipped shortly"
pp_ws_order_processed_successfully: "Thank you.. Your order processed succesfully. You will be notified once we receive the payment from PayPal"
+ paypal:
+ ipn_notifications: IPN Notifications
+ mc_currency: Payment Currency
+ mc_gross: Payment Gross (before fees)
+ mc_fee: Transaction Fee
+ payment_gross: Payment Gross (USD)
+ payment_fee: Payment Fee (USD)
+ foreign_ipn_message: "Ignoring IPN with invoice # %{invoice_num} as it didn't originate from a Spree order"
diff --git a/lib/spree_paypal_website_standard/engine.rb b/lib/spree_paypal_website_standard/engine.rb
index 3686f46..8ee3302 100644
--- a/lib/spree_paypal_website_standard/engine.rb
+++ b/lib/spree_paypal_website_standard/engine.rb
@@ -7,11 +7,11 @@ class Engine < Rails::Engine
initializer "spree.active_shipping.configuration", :after => "spree.environment" do |app|
Dir.glob(File.join(File.dirname(__FILE__), "../../lib/spree_paypal_website_standard_configuration.rb")) do |c|
- Rails.configuration.cache_classes ? require(c) : load(c)
+ Rails.configuration.cache_classes ? require(c) : load(c)
end
end
- initializer "spree.paypal_website_standard.preferences", :after => "spree.active_shipping.configuration" do |app|
+ initializer "spree.paypal_website_standard.preferences", :before => :load_config_initializers do |app|
Spree::PaypalWebsiteStandard::Config = Spree::PaypalWebsiteStandardConfiguration.new
end
@@ -22,22 +22,30 @@ class Engine < Rails::Engine
g.test_framework :rspec
end
+ initializer "spree.paypal_website_standard.register.payment_methods", :after => "spree.register.payment_methods" do |app|
+ app.config.spree.payment_methods << Spree::PayPalPaymentMethod
+ end
+
def self.activate
Dir.glob(File.join(File.dirname(__FILE__), "../../app/**/*_decorator*.rb")) do |c|
- Rails.configuration.cache_classes ? require(c) : load(c)
- end
+ Rails.configuration.cache_classes ? require(c) : load(c)
+ end
+
+ Dir.glob(File.join(File.dirname(__FILE__), "../../app/overrides/*.rb")) do |c|
+ Rails.configuration.cache_classes ? require(c) : load(c)
+ end
- # add new events and states to the FSM
+ # add new events and states to the FSM
=begin
- fsm = Order.state_machines[:state]
- fsm.events << StateMachine::Event.new(fsm, "fail_payment")
- fsm.events["fail_payment"].transition(:to => 'payment_failure', :from => ['in_progress', 'payment_pending'])
-
- fsm.events << StateMachine::Event.new(fsm, "pend_payment")
- fsm.events["pend_payment"].transition(:to => 'payment_pending', :from => 'in_progress')
- fsm.after_transition(:to => 'payment_pending', :do => lambda {|order| order.update_attribute(:checkout_complete, true)})
-
- fsm.events["pay"].transition(:to => 'paid', :from => ['payment_pending', 'in_progress'])
+ fsm = Order.state_machines[:state]
+ fsm.events << StateMachine::Event.new(fsm, "fail_payment")
+ fsm.events["fail_payment"].transition(:to => 'payment_failure', :from => ['in_progress', 'payment_pending'])
+
+ fsm.events << StateMachine::Event.new(fsm, "pend_payment")
+ fsm.events["pend_payment"].transition(:to => 'payment_pending', :from => 'in_progress')
+ fsm.after_transition(:to => 'payment_pending', :do => lambda {|order| order.update_attribute(:checkout_complete, true)})
+
+ fsm.events["pay"].transition(:to => 'paid', :from => ['payment_pending', 'in_progress'])
=end
end
diff --git a/spec/controllers/payment_notifications_controller_spec.rb b/spec/controllers/payment_notifications_controller_spec.rb
new file mode 100644
index 0000000..d2caeb8
--- /dev/null
+++ b/spec/controllers/payment_notifications_controller_spec.rb
@@ -0,0 +1,20 @@
+require "spec_helper"
+
+module Spree
+ describe PaymentNotificationsController do
+ context "when the IPN has an invoice number that is not from a Spree order" do
+ let(:ipn) { { :invoice_id => "INV2-AAAA-BBBB-CCCC-DDDD" } }
+
+ it "doesn't create a PaymentNotification" do
+ expect {
+ post :create, ipn
+ }.to_not change { PaymentNotification.count }
+ end
+
+ it "returns a 200 response" do
+ post :create, ipn
+ response.code.should == "200"
+ end
+ end
+ end
+end
diff --git a/spec/internal/config/database.yml b/spec/internal/config/database.yml
new file mode 100644
index 0000000..b978119
--- /dev/null
+++ b/spec/internal/config/database.yml
@@ -0,0 +1,3 @@
+test:
+ adapter: sqlite3
+ database: db/combustion_test.sqlite
diff --git a/spec/internal/config/routes.rb b/spec/internal/config/routes.rb
new file mode 100644
index 0000000..58c83a5
--- /dev/null
+++ b/spec/internal/config/routes.rb
@@ -0,0 +1,4 @@
+Rails.application.routes.draw do
+ resources :payment_notifications, module: 'spree'
+ mount Spree::Core::Engine, :at => "/"
+end
diff --git a/spec/internal/db/schema.rb b/spec/internal/db/schema.rb
new file mode 100644
index 0000000..a4ab1bb
--- /dev/null
+++ b/spec/internal/db/schema.rb
@@ -0,0 +1,3 @@
+ActiveRecord::Schema.define do
+ #
+end
diff --git a/spec/internal/log/.gitignore b/spec/internal/log/.gitignore
new file mode 100644
index 0000000..bf0824e
--- /dev/null
+++ b/spec/internal/log/.gitignore
@@ -0,0 +1 @@
+*.log
\ No newline at end of file
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index a350164..50d5dfc 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,8 +1,9 @@
# Configure Rails Environment
ENV["RAILS_ENV"] = "test"
-require File.expand_path("../dummy/config/environment.rb", __FILE__)
-
+require 'spree_paypal_website_standard'
+require 'combustion'
+Combustion.initialize!
require 'rspec/rails'
# Requires supporting ruby files with custom matchers and macros, etc,