From 36828fb913abe19536154c57c666a3db974eb015 Mon Sep 17 00:00:00 2001 From: hoverlover Date: Thu, 26 Jan 2012 09:53:29 -0600 Subject: [PATCH 01/15] Fixed namespacing of PaymentMethod. --- app/models/spree/order_decorator.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 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) From 048c0515509f2893f4c68a116baf51761035b987 Mon Sep 17 00:00:00 2001 From: hoverlover Date: Thu, 26 Jan 2012 13:17:41 -0600 Subject: [PATCH 02/15] Don't destroy line items. --- app/controllers/spree/base_controller_decorator.rb.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/spree/base_controller_decorator.rb.rb b/app/controllers/spree/base_controller_decorator.rb.rb index b83bdd0..404172e 100644 --- a/app/controllers/spree/base_controller_decorator.rb.rb +++ b/app/controllers/spree/base_controller_decorator.rb.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 From af5fa778dc2df7317d0f30890f8c106e9f0f597f Mon Sep 17 00:00:00 2001 From: hoverlover Date: Sun, 29 Jan 2012 17:08:51 -0600 Subject: [PATCH 03/15] Set up config before initializers run. --- lib/spree_paypal_website_standard/engine.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/spree_paypal_website_standard/engine.rb b/lib/spree_paypal_website_standard/engine.rb index 3686f46..21145ec 100644 --- a/lib/spree_paypal_website_standard/engine.rb +++ b/lib/spree_paypal_website_standard/engine.rb @@ -11,7 +11,7 @@ class Engine < Rails::Engine 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 From 491c078f34a1119d179129e0cfa2cd1660bd4b30 Mon Sep 17 00:00:00 2001 From: hoverlover Date: Thu, 1 Mar 2012 21:25:11 -0600 Subject: [PATCH 04/15] Use Deface override instead of duplicating the entire view. --- app/helpers/spree/paypal_helper.rb | 7 ++++++ app/overrides/paypal_form.rb | 4 +++ app/views/spree/checkout/edit.html.erb | 28 --------------------- lib/spree_paypal_website_standard/engine.rb | 8 ++++-- 4 files changed, 17 insertions(+), 30 deletions(-) create mode 100644 app/helpers/spree/paypal_helper.rb create mode 100644 app/overrides/paypal_form.rb delete mode 100755 app/views/spree/checkout/edit.html.erb 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/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/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/lib/spree_paypal_website_standard/engine.rb b/lib/spree_paypal_website_standard/engine.rb index 21145ec..9db24c1 100644 --- a/lib/spree_paypal_website_standard/engine.rb +++ b/lib/spree_paypal_website_standard/engine.rb @@ -24,8 +24,12 @@ class Engine < Rails::Engine 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 =begin From f6b4d92e3504c4f07a86e03c24c306840791b5a6 Mon Sep 17 00:00:00 2001 From: hoverlover Date: Sun, 4 Mar 2012 15:54:14 -0600 Subject: [PATCH 05/15] Don't include Gemfile.lock. --- .gitignore | 1 + 1 file changed, 1 insertion(+) 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 From 2641288150ea30245e3e54fd9f5c0e4070c32699 Mon Sep 17 00:00:00 2001 From: hoverlover Date: Sun, 4 Mar 2012 15:54:24 -0600 Subject: [PATCH 06/15] Now list out IPN notifications in admin interface. --- .../admin/orders/_pp_standard_txns.html.erb | 23 ---------------- .../payments/source_views/_gateway.html.erb | 26 +++++++++++++++++++ config/locales/en.yml | 7 +++++ 3 files changed, 33 insertions(+), 23 deletions(-) delete mode 100644 app/views/spree/admin/orders/_pp_standard_txns.html.erb create mode 100644 app/views/spree/admin/payments/source_views/_gateway.html.erb 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") %> - - - - - - - - - - <% @order.paypal_payment.txns.each do |t| %> - - - - - - - - <% end %> -
<%= t("Amount") %><%= t("Fee") %><%= t("Status") %><%= t("Transaction Id") %><%= t("Received At") %>
<%=number_to_currency t.amount %><%=number_to_currency t.fee %><%=t.status %><%=t.transaction_id %><%=t.received_at %>
-<% 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') %>

+ + + + + + + + + + + + + <% payment.order.payment_notifications.each do |notification| -%> + + + + + + + + + + + <% end -%> +
<%= 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') %>
<%= 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 => "$" %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index e62c5a4..2894d77 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -8,3 +8,10 @@ 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) From 5693b6aaad6db69914df37fc6591a7480511c4a8 Mon Sep 17 00:00:00 2001 From: hoverlover Date: Fri, 16 Mar 2012 15:43:10 -0500 Subject: [PATCH 07/15] Add Spree::PayPalPaymentMethod. --- app/models/spree/pay_pal_payment_method.rb | 15 +++++++++++++++ lib/spree_paypal_website_standard/engine.rb | 4 ++++ 2 files changed, 19 insertions(+) create mode 100644 app/models/spree/pay_pal_payment_method.rb 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/lib/spree_paypal_website_standard/engine.rb b/lib/spree_paypal_website_standard/engine.rb index 9db24c1..534840c 100644 --- a/lib/spree_paypal_website_standard/engine.rb +++ b/lib/spree_paypal_website_standard/engine.rb @@ -22,6 +22,10 @@ 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) From 2ad889af1ed65a89a293aec4df2c9059ad6636e2 Mon Sep 17 00:00:00 2001 From: hoverlover Date: Sun, 4 Mar 2012 15:54:24 -0600 Subject: [PATCH 08/15] Now list out IPN notifications in admin interface. --- .../admin/orders/_pp_standard_txns.html.erb | 23 ---------------- .../payments/source_views/_gateway.html.erb | 26 +++++++++++++++++++ config/locales/en.yml | 7 +++++ 3 files changed, 33 insertions(+), 23 deletions(-) delete mode 100644 app/views/spree/admin/orders/_pp_standard_txns.html.erb create mode 100644 app/views/spree/admin/payments/source_views/_gateway.html.erb 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") %> - - - - - - - - - - <% @order.paypal_payment.txns.each do |t| %> - - - - - - - - <% end %> -
<%= t("Amount") %><%= t("Fee") %><%= t("Status") %><%= t("Transaction Id") %><%= t("Received At") %>
<%=number_to_currency t.amount %><%=number_to_currency t.fee %><%=t.status %><%=t.transaction_id %><%=t.received_at %>
-<% 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') %>

+ + + + + + + + + + + + + <% payment.order.payment_notifications.each do |notification| -%> + + + + + + + + + + + <% end -%> +
<%= 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') %>
<%= 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 => "$" %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index e62c5a4..2894d77 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -8,3 +8,10 @@ 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) From 33c52222355dfce73fdba41c00e658712d50923d Mon Sep 17 00:00:00 2001 From: hoverlover Date: Fri, 16 Mar 2012 22:19:26 -0500 Subject: [PATCH 09/15] Renamed _gateway partial to match new PayPayPaymentMethod. --- .../{_gateway.html.erb => _paypalpaymentmethod.html.erb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename app/views/spree/admin/payments/source_views/{_gateway.html.erb => _paypalpaymentmethod.html.erb} (100%) diff --git a/app/views/spree/admin/payments/source_views/_gateway.html.erb b/app/views/spree/admin/payments/source_views/_paypalpaymentmethod.html.erb similarity index 100% rename from app/views/spree/admin/payments/source_views/_gateway.html.erb rename to app/views/spree/admin/payments/source_views/_paypalpaymentmethod.html.erb From 5a4cf547f42f69cb04e153ad0c7619999c47e718 Mon Sep 17 00:00:00 2001 From: hoverlover Date: Sat, 17 Mar 2012 17:48:22 -0500 Subject: [PATCH 10/15] Incorrect extension: rb.rb --- ...se_controller_decorator.rb.rb => base_controller_decorator.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename app/controllers/spree/{base_controller_decorator.rb.rb => base_controller_decorator.rb} (100%) diff --git a/app/controllers/spree/base_controller_decorator.rb.rb b/app/controllers/spree/base_controller_decorator.rb similarity index 100% rename from app/controllers/spree/base_controller_decorator.rb.rb rename to app/controllers/spree/base_controller_decorator.rb From 4f6463175bdb2addd767f62f5662de6e6cb94a53 Mon Sep 17 00:00:00 2001 From: hoverlover Date: Sat, 17 Mar 2012 17:55:43 -0500 Subject: [PATCH 11/15] Add some gems to make testing more enjoyable. --- Gemfile | 9 ++ Gemfile.lock | 226 +++++++++++++++++++++++++++++++++++++++++++++++++++ Guardfile | 19 +++++ 3 files changed, 254 insertions(+) create mode 100644 Gemfile.lock create mode 100644 Guardfile 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 + From b3450bba167c3f663e18361aa831178c4b78d79a Mon Sep 17 00:00:00 2001 From: hoverlover Date: Sat, 17 Mar 2012 17:56:59 -0500 Subject: [PATCH 12/15] Stuff for testing engine. --- app/controllers/application_controller.rb | 1 + spec/internal/config/database.yml | 3 +++ spec/internal/config/routes.rb | 4 ++++ spec/internal/db/schema.rb | 3 +++ spec/internal/log/.gitignore | 1 + spec/spec_helper.rb | 5 +++-- 6 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 app/controllers/application_controller.rb create mode 100644 spec/internal/config/database.yml create mode 100644 spec/internal/config/routes.rb create mode 100644 spec/internal/db/schema.rb create mode 100644 spec/internal/log/.gitignore 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/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, From 7f8755426b8dbf08d18fe8376c47015ef0948656 Mon Sep 17 00:00:00 2001 From: hoverlover Date: Sat, 17 Mar 2012 17:57:20 -0500 Subject: [PATCH 13/15] Fixed indentation. --- lib/spree_paypal_website_standard/engine.rb | 26 ++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/spree_paypal_website_standard/engine.rb b/lib/spree_paypal_website_standard/engine.rb index 3686f46..f54b8b7 100644 --- a/lib/spree_paypal_website_standard/engine.rb +++ b/lib/spree_paypal_website_standard/engine.rb @@ -7,7 +7,7 @@ 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 @@ -24,20 +24,20 @@ class Engine < Rails::Engine 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 - # 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 From c1f9213f7ff2ff1dd4bae42f257283c980541cbe Mon Sep 17 00:00:00 2001 From: hoverlover Date: Sat, 17 Mar 2012 17:57:53 -0500 Subject: [PATCH 14/15] Ignore IPN that aren't associated with a Spree order. --- .../spree/payment_notifications_controller.rb | 11 ++++++++-- config/locales/en.yml | 2 ++ .../payment_notifications_controller_spec.rb | 20 +++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 spec/controllers/payment_notifications_controller_spec.rb diff --git a/app/controllers/spree/payment_notifications_controller.rb b/app/controllers/spree/payment_notifications_controller.rb index 1fa4517..c2b2e6a 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 + unless params[:invoice].index /R[0-9]{9}/ + 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/config/locales/en.yml b/config/locales/en.yml index e62c5a4..942e75c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -8,3 +8,5 @@ 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: + foreign_ipn_message: "Ignoring IPN with invoice # %{invoice_num} as it didn't originate from a Spree order" diff --git a/spec/controllers/payment_notifications_controller_spec.rb b/spec/controllers/payment_notifications_controller_spec.rb new file mode 100644 index 0000000..c808d5e --- /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 => "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 From c0381e29266c65bb1ba07fdaa5deb3e8e867032d Mon Sep 17 00:00:00 2001 From: hoverlover Date: Sat, 17 Mar 2012 18:30:08 -0500 Subject: [PATCH 15/15] Whoops! Failed to notice that when not Spree order, param is actually invoice_id. --- app/controllers/spree/payment_notifications_controller.rb | 2 +- spec/controllers/payment_notifications_controller_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/spree/payment_notifications_controller.rb b/app/controllers/spree/payment_notifications_controller.rb index c2b2e6a..7f7b7b6 100644 --- a/app/controllers/spree/payment_notifications_controller.rb +++ b/app/controllers/spree/payment_notifications_controller.rb @@ -87,7 +87,7 @@ def default_country end def ignore_foreign_notifications - unless params[:invoice].index /R[0-9]{9}/ + if params[:invoice_id].present? logger.info(I18n.t(:foreign_ipn_message, :scope => "paypal")) render :nothing => true end diff --git a/spec/controllers/payment_notifications_controller_spec.rb b/spec/controllers/payment_notifications_controller_spec.rb index c808d5e..d2caeb8 100644 --- a/spec/controllers/payment_notifications_controller_spec.rb +++ b/spec/controllers/payment_notifications_controller_spec.rb @@ -3,7 +3,7 @@ module Spree describe PaymentNotificationsController do context "when the IPN has an invoice number that is not from a Spree order" do - let(:ipn) { { :invoice => "INV2-AAAA-BBBB-CCCC-DDDD" } } + let(:ipn) { { :invoice_id => "INV2-AAAA-BBBB-CCCC-DDDD" } } it "doesn't create a PaymentNotification" do expect {