From 9e063b2d66dc9a0297ecfe1d30b949e1f2de2e95 Mon Sep 17 00:00:00 2001 From: Diego Franciosi Date: Tue, 9 Feb 2016 11:59:27 +0100 Subject: [PATCH 01/10] Solidification of the gem --- LICENSE.md | 2 +- README.md | 12 +++++------- Rakefile | 2 +- ...paypal_express.js => solidus_paypal_express.js} | 0 ...ypal_express.css => solidus_paypal_express.css} | 0 ...ypal_express.css => solidus_paypal_express.css} | 0 app/views/spree/checkout/payment/_paypal.html.erb | 5 ++--- .../install/install_generator.rb | 12 ++++++------ lib/solidus_paypal_express.rb | 4 ++++ .../engine.rb | 2 +- .../factories.rb | 2 +- lib/solidus_paypal_express/version.rb | 3 +++ lib/spree_paypal_express.rb | 4 ---- lib/spree_paypal_express/version.rb | 3 --- ...press.gemspec => solidus_paypal_express.gemspec | 14 +++++++------- spec/spec_helper.rb | 2 +- 16 files changed, 32 insertions(+), 35 deletions(-) rename app/assets/javascripts/spree/backend/{spree_paypal_express.js => solidus_paypal_express.js} (100%) rename app/assets/stylesheets/spree/backend/{spree_paypal_express.css => solidus_paypal_express.css} (100%) rename app/assets/stylesheets/spree/frontend/{spree_paypal_express.css => solidus_paypal_express.css} (100%) rename lib/generators/{spree_paypal_express => solidus_paypal_express}/install/install_generator.rb (79%) create mode 100644 lib/solidus_paypal_express.rb rename lib/{spree_paypal_express => solidus_paypal_express}/engine.rb (96%) rename lib/{spree_paypal_express => solidus_paypal_express}/factories.rb (83%) create mode 100644 lib/solidus_paypal_express/version.rb delete mode 100644 lib/spree_paypal_express.rb delete mode 100644 lib/spree_paypal_express/version.rb rename spree_paypal_express.gemspec => solidus_paypal_express.gemspec (81%) diff --git a/LICENSE.md b/LICENSE.md index 7dc304e..c61d1fe 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -Copyright (c) 2013-2015 Spree Commerce and contributors. +Copyright (c) 2016 Solidus Commerce and contributors. All rights reserved. Redistribution and use in source and binary forms, with or without modification, diff --git a/README.md b/README.md index 130b7ef..aac6529 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,7 @@ Behind-the-scenes, this extension uses [PayPal's Merchant Ruby SDK](https://gith 1. Add this extension to your Gemfile with this line: - gem 'spree_paypal_express', github: 'spree-contrib/better_spree_paypal_express', branch: '2-4-stable' - -The `branch` option is important: it must match the version of Spree you're using. Use 2-2-stable if you're using Spree 2-2-stable or any 2.2.x version. + gem 'solidus_paypal_express', github: 'solidusio-contrib/solidus_paypal_express', branch: 'master' 2. Install the gem using Bundler: @@ -126,9 +124,9 @@ Starting point: * Ensure specs pass by running `bundle exec rspec spec` * Submit your pull request -Copyright (c) 2013-2015 Spree Commerce and contributors, released under the [New BSD License][3] +Copyright (c) 2016 Solidus Commerce and contributors, released under the [New BSD License][3] [1]: http://www.fsf.org/licensing/essays/free-sw.html -[2]: https://github.com/spree/better_spree_paypal_express/issues -[3]: https://github.com/spree/better_spree_paypal_express/tree/master/LICENSE.md -[4]: https://github.com/spree/spree_paypal_express +[2]: https://github.com/solidusio/solidus_paypal_express/issues +[3]: https://github.com/solidusio/solidus_paypal_express/tree/master/LICENSE.md +[4]: https://github.com/solidusio/solidus_paypal_express diff --git a/Rakefile b/Rakefile index fe7543c..c9b3f5b 100644 --- a/Rakefile +++ b/Rakefile @@ -6,7 +6,7 @@ require 'rubygems/package_task' desc 'Generates a dummy app for testing' task :test_app do - ENV['LIB_NAME'] = 'spree_paypal_express' + ENV['LIB_NAME'] = 'solidus_paypal_express' Rake::Task['extension:test_app'].invoke end diff --git a/app/assets/javascripts/spree/backend/spree_paypal_express.js b/app/assets/javascripts/spree/backend/solidus_paypal_express.js similarity index 100% rename from app/assets/javascripts/spree/backend/spree_paypal_express.js rename to app/assets/javascripts/spree/backend/solidus_paypal_express.js diff --git a/app/assets/stylesheets/spree/backend/spree_paypal_express.css b/app/assets/stylesheets/spree/backend/solidus_paypal_express.css similarity index 100% rename from app/assets/stylesheets/spree/backend/spree_paypal_express.css rename to app/assets/stylesheets/spree/backend/solidus_paypal_express.css diff --git a/app/assets/stylesheets/spree/frontend/spree_paypal_express.css b/app/assets/stylesheets/spree/frontend/solidus_paypal_express.css similarity index 100% rename from app/assets/stylesheets/spree/frontend/spree_paypal_express.css rename to app/assets/stylesheets/spree/frontend/solidus_paypal_express.css diff --git a/app/views/spree/checkout/payment/_paypal.html.erb b/app/views/spree/checkout/payment/_paypal.html.erb index f01452e..01a09ef 100644 --- a/app/views/spree/checkout/payment/_paypal.html.erb +++ b/app/views/spree/checkout/payment/_paypal.html.erb @@ -1,6 +1,5 @@ - <%= link_to(image_tag("https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif"), paypal_express_url(:payment_method_id => payment_method.id), :method => :post, :id => "paypal_button") %> \ No newline at end of file + SpreePaypalExpress.paymentMethodID = "<%= payment_method.id %>" + diff --git a/lib/generators/spree_paypal_express/install/install_generator.rb b/lib/generators/solidus_paypal_express/install/install_generator.rb similarity index 79% rename from lib/generators/spree_paypal_express/install/install_generator.rb rename to lib/generators/solidus_paypal_express/install/install_generator.rb index 0cfd88e..fdc5bf4 100644 --- a/lib/generators/spree_paypal_express/install/install_generator.rb +++ b/lib/generators/solidus_paypal_express/install/install_generator.rb @@ -1,12 +1,12 @@ -module SpreePaypalExpress +module SolidusPaypalExpress module Generators class InstallGenerator < Rails::Generators::Base class_option :auto_run_migrations, type: :boolean, default: false def add_javascripts - append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/spree_paypal_express\n" - append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/spree_paypal_express\n" + append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_paypal_express\n" + append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_paypal_express\n" end def add_stylesheets @@ -14,13 +14,13 @@ def add_stylesheets backend_css_file = "vendor/assets/stylesheets/spree/backend/all.css" if File.exist?(backend_css_file) && File.exist?(frontend_css_file) - inject_into_file frontend_css_file, " *= require spree/frontend/spree_paypal_express\n", before: /\*\//, verbose: true - inject_into_file backend_css_file, " *= require spree/backend/spree_paypal_express\n", before: /\*\//, verbose: true + inject_into_file frontend_css_file, " *= require spree/frontend/solidus_paypal_express\n", before: /\*\//, verbose: true + inject_into_file backend_css_file, " *= require spree/backend/solidus_paypal_express\n", before: /\*\//, verbose: true end end def add_migrations - run 'bundle exec rake railties:install:migrations FROM=spree_paypal_express' + run 'bundle exec rake railties:install:migrations FROM=solidus_paypal_express' end def run_migrations diff --git a/lib/solidus_paypal_express.rb b/lib/solidus_paypal_express.rb new file mode 100644 index 0000000..456d242 --- /dev/null +++ b/lib/solidus_paypal_express.rb @@ -0,0 +1,4 @@ +require 'solidus_core' +require 'solidus_paypal_express/version' +require 'solidus_paypal_express/engine' +require 'sass/rails' diff --git a/lib/spree_paypal_express/engine.rb b/lib/solidus_paypal_express/engine.rb similarity index 96% rename from lib/spree_paypal_express/engine.rb rename to lib/solidus_paypal_express/engine.rb index 9801550..81c7c55 100644 --- a/lib/spree_paypal_express/engine.rb +++ b/lib/solidus_paypal_express/engine.rb @@ -1,4 +1,4 @@ -module SpreePaypalExpress +module SolidusPaypalExpress class Engine < Rails::Engine require 'spree/core' isolate_namespace Spree diff --git a/lib/spree_paypal_express/factories.rb b/lib/solidus_paypal_express/factories.rb similarity index 83% rename from lib/spree_paypal_express/factories.rb rename to lib/solidus_paypal_express/factories.rb index 498d735..3a278e9 100644 --- a/lib/spree_paypal_express/factories.rb +++ b/lib/solidus_paypal_express/factories.rb @@ -2,5 +2,5 @@ # Define your Spree extensions Factories within this file to enable applications, and other extensions to use and override them. # # Example adding this to your spec_helper will load these Factories for use: - # require 'spree_paypal_express/factories' + # require 'solidus_paypal_express/factories' end diff --git a/lib/solidus_paypal_express/version.rb b/lib/solidus_paypal_express/version.rb new file mode 100644 index 0000000..ab5adf6 --- /dev/null +++ b/lib/solidus_paypal_express/version.rb @@ -0,0 +1,3 @@ +module SolidusPayPalExpress + VERSION = '0.1.0' +end diff --git a/lib/spree_paypal_express.rb b/lib/spree_paypal_express.rb deleted file mode 100644 index e04a87c..0000000 --- a/lib/spree_paypal_express.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'spree_core' -require 'spree_paypal_express/version' -require 'spree_paypal_express/engine' -require 'sass/rails' diff --git a/lib/spree_paypal_express/version.rb b/lib/spree_paypal_express/version.rb deleted file mode 100644 index d5d5f00..0000000 --- a/lib/spree_paypal_express/version.rb +++ /dev/null @@ -1,3 +0,0 @@ -module SpreePayPalExpress - VERSION = '2.0.3' -end \ No newline at end of file diff --git a/spree_paypal_express.gemspec b/solidus_paypal_express.gemspec similarity index 81% rename from spree_paypal_express.gemspec rename to solidus_paypal_express.gemspec index 4cffecd..47034ea 100644 --- a/spree_paypal_express.gemspec +++ b/solidus_paypal_express.gemspec @@ -2,19 +2,19 @@ lib = File.expand_path('../lib/', __FILE__) $:.unshift lib unless $:.include?(lib) -require 'spree_paypal_express/version' +require 'solidus_paypal_express/version' Gem::Specification.new do |s| s.platform = Gem::Platform::RUBY - s.name = 'spree_paypal_express' - s.version = SpreePayPalExpress::VERSION - s.summary = 'Adds PayPal Express as a Payment Method to Spree Commerce' + s.name = 'solidus_paypal_express' + s.version = SolidusPayPalExpress::VERSION + s.summary = 'Adds PayPal Express as a Payment Method to Solidus Commerce' s.description = s.summary s.required_ruby_version = '>= 1.9.3' - s.author = 'Spree Commerce' - s.email = 'gems@spreecommerce.com' - s.homepage = 'http://www.spreecommerce.com' + s.author = 'Solidus Commerce' + s.email = 'info@solidus.io' + s.homepage = 'https://www.solidus.io' s.license = %q{BSD-3} s.files = `git ls-files`.split("\n") diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7bda976..ec6c1f2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -47,7 +47,7 @@ require 'spree/testing_support/authorization_helpers' require 'spree/testing_support/url_helpers' -require 'spree_paypal_express/factories' +require 'solidus_paypal_express/factories' FactoryGirl.find_definitions RSpec.configure do |config| From e5bc98b474dd26f3e95f626c35cedc31b0e61841 Mon Sep 17 00:00:00 2001 From: Diego Franciosi Date: Tue, 9 Feb 2016 15:34:14 +0100 Subject: [PATCH 02/10] Add URI namespace to encode_www_form --- app/models/spree/gateway/pay_pal_express.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/spree/gateway/pay_pal_express.rb b/app/models/spree/gateway/pay_pal_express.rb index ecd4a66..5d20208 100644 --- a/app/models/spree/gateway/pay_pal_express.rb +++ b/app/models/spree/gateway/pay_pal_express.rb @@ -101,7 +101,7 @@ def express_checkout_url(pp_response, extra_params={}) "https://www.#{server_domain}paypal.com/cgi-bin/webscr?" + "cmd=_express-checkout&force_sa=true&" end + - encode_www_form(params) + URI.encode_www_form(params) end def do_authorize(token, payer_id) From d756ac2b80a6eaf4867a67719655f9790d21fb1b Mon Sep 17 00:00:00 2001 From: Diego Franciosi Date: Tue, 9 Feb 2016 16:44:50 +0100 Subject: [PATCH 03/10] Naming conversion tuning --- .../spree/backend/solidus_paypal_express.js | 10 +++++----- ...ee_paypal_express.js => solidus_paypal_express.js} | 8 ++++---- .../admin/payments/source_forms/_paypal.html.erb | 4 ++-- app/views/spree/checkout/payment/_paypal.html.erb | 2 +- spec/factories/spree_gateway_pay_pal_express.rb | 1 - spec/models/pay_pal_express_spec.rb | 11 +++-------- 6 files changed, 15 insertions(+), 21 deletions(-) rename app/assets/javascripts/spree/frontend/{spree_paypal_express.js => solidus_paypal_express.js} (73%) diff --git a/app/assets/javascripts/spree/backend/solidus_paypal_express.js b/app/assets/javascripts/spree/backend/solidus_paypal_express.js index 28eecd9..c850c8d 100644 --- a/app/assets/javascripts/spree/backend/solidus_paypal_express.js +++ b/app/assets/javascripts/spree/backend/solidus_paypal_express.js @@ -1,13 +1,13 @@ //= require spree/backend -SpreePaypalExpress = { +SolidusPaypalExpress = { hideSettings: function(paymentMethod) { - if (SpreePaypalExpress.paymentMethodID && paymentMethod.val() == SpreePaypalExpress.paymentMethodID) { + if (SolidusPaypalExpress.paymentMethodID && paymentMethod.val() == SolidusPaypalExpress.paymentMethodID) { $('.payment-method-settings').children().hide(); $('#payment_amount').prop('disabled', 'disabled'); $('button[type="submit"]').prop('disabled', 'disabled'); $('#paypal-warning').show(); - } else if (SpreePaypalExpress.paymentMethodID) { + } else if (SolidusPaypalExpress.paymentMethodID) { $('.payment-method-settings').children().show(); $('button[type=submit]').prop('disabled', ''); $('#payment_amount').prop('disabled', '') @@ -18,8 +18,8 @@ SpreePaypalExpress = { $(document).ready(function() { checkedPaymentMethod = $('[data-hook="payment_method_field"] input[type="radio"]:checked'); - SpreePaypalExpress.hideSettings(checkedPaymentMethod); + SolidusPaypalExpress.hideSettings(checkedPaymentMethod); paymentMethods = $('[data-hook="payment_method_field"] input[type="radio"]').click(function (e) { - SpreePaypalExpress.hideSettings($(e.target)); + SolidusPaypalExpress.hideSettings($(e.target)); }); }) diff --git a/app/assets/javascripts/spree/frontend/spree_paypal_express.js b/app/assets/javascripts/spree/frontend/solidus_paypal_express.js similarity index 73% rename from app/assets/javascripts/spree/frontend/spree_paypal_express.js rename to app/assets/javascripts/spree/frontend/solidus_paypal_express.js index 09c80d8..87ed8d1 100644 --- a/app/assets/javascripts/spree/frontend/spree_paypal_express.js +++ b/app/assets/javascripts/spree/frontend/solidus_paypal_express.js @@ -1,6 +1,6 @@ //= require spree/frontend -SpreePaypalExpress = { +SolidusPaypalExpress = { updateSaveAndContinueVisibility: function() { if (this.isButtonHidden()) { $(this).trigger('hideSaveAndContinue') @@ -10,7 +10,7 @@ SpreePaypalExpress = { }, isButtonHidden: function () { paymentMethod = this.checkedPaymentMethod(); - return (!$('#use_existing_card_yes:checked').length && SpreePaypalExpress.paymentMethodID && paymentMethod.val() == SpreePaypalExpress.paymentMethodID); + return (!$('#use_existing_card_yes:checked').length && SolidusPaypalExpress.paymentMethodID && paymentMethod.val() == SolidusPaypalExpress.paymentMethodID); }, checkedPaymentMethod: function() { return $('div[data-hook="checkout_payment_step"] input[type="radio"][name="order[payments_attributes][][payment_method_id]"]:checked'); @@ -24,8 +24,8 @@ SpreePaypalExpress = { } $(document).ready(function() { - SpreePaypalExpress.updateSaveAndContinueVisibility(); + SolidusPaypalExpress.updateSaveAndContinueVisibility(); paymentMethods = $('div[data-hook="checkout_payment_step"] input[type="radio"]').click(function (e) { - SpreePaypalExpress.updateSaveAndContinueVisibility(); + SolidusPaypalExpress.updateSaveAndContinueVisibility(); }); }) diff --git a/app/views/spree/admin/payments/source_forms/_paypal.html.erb b/app/views/spree/admin/payments/source_forms/_paypal.html.erb index 8634e65..06f789a 100644 --- a/app/views/spree/admin/payments/source_forms/_paypal.html.erb +++ b/app/views/spree/admin/payments/source_forms/_paypal.html.erb @@ -2,5 +2,5 @@ <%= Spree.t('no_payment_via_admin_backend', :scope => 'paypal') %> \ No newline at end of file + SolidusPaypalExpress.paymentMethodID = "<%= payment_method.id %>" + diff --git a/app/views/spree/checkout/payment/_paypal.html.erb b/app/views/spree/checkout/payment/_paypal.html.erb index 01a09ef..8a1082a 100644 --- a/app/views/spree/checkout/payment/_paypal.html.erb +++ b/app/views/spree/checkout/payment/_paypal.html.erb @@ -1,5 +1,5 @@ <%= link_to(image_tag("https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif"), paypal_express_url(:payment_method_id => payment_method.id), :method => :post, :id => "paypal_button") %> diff --git a/spec/factories/spree_gateway_pay_pal_express.rb b/spec/factories/spree_gateway_pay_pal_express.rb index fa32026..63a9a28 100644 --- a/spec/factories/spree_gateway_pay_pal_express.rb +++ b/spec/factories/spree_gateway_pay_pal_express.rb @@ -7,6 +7,5 @@ preferred_use_new_layout true name "PayPal" active true - environment { Rails.env } end end diff --git a/spec/models/pay_pal_express_spec.rb b/spec/models/pay_pal_express_spec.rb index 90c8dea..1c863f5 100644 --- a/spec/models/pay_pal_express_spec.rb +++ b/spec/models/pay_pal_express_spec.rb @@ -1,10 +1,10 @@ describe Spree::Gateway::PayPalExpress do - let(:gateway) { Spree::Gateway::PayPalExpress.create!(name: "PayPalExpress", environment: Rails.env) } + let(:gateway) { Spree::Gateway::PayPalExpress.create!(name: "PayPalExpress") } context "payment purchase" do let(:payment) do payment = FactoryGirl.create(:payment, payment_method: gateway, amount: 10) - allow(payment).to receive_messages source: mock_model(Spree::PaypalExpressCheckout, token: 'fake_token', payer_id: 'fake_payer_id', update: true) + allow(payment).to receive_messages source: double(Spree::PaypalExpressCheckout, token: 'fake_token', payer_id: 'fake_payer_id', update: true) payment end @@ -45,17 +45,12 @@ # Test for #11 it "succeeds" do - response = double( - 'pp_response', - success?: true, - errors: [] - ) + response = double('pp_response', success?: true) allow(response). to receive_message_chain("do_express_checkout_payment_response_details.payment_info.first.transaction_id").and_return '12345' expect(provider). to receive(:do_express_checkout_payment). and_return(response) - expect { payment.authorize! }.to_not raise_error end From a83ca7ceff7f19cb4da116891e1cb9bb9b68cc9d Mon Sep 17 00:00:00 2001 From: Diego Franciosi Date: Tue, 9 Feb 2016 16:45:48 +0100 Subject: [PATCH 04/10] Remove Capybara deprecated method --- spec/spec_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ec6c1f2..a7757fa 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -38,7 +38,7 @@ require 'capybara/poltergeist' Capybara.javascript_driver = :poltergeist -Capybara.default_wait_time = 15 +Capybara.default_max_wait_time = 15 Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f } From f7408789254661bed3e065ca5d330844774602b7 Mon Sep 17 00:00:00 2001 From: Diego Franciosi Date: Tue, 9 Feb 2016 19:32:41 +0100 Subject: [PATCH 05/10] Update Capybara to match the new PayPal express pop-up --- spec/features/paypal_spec.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/features/paypal_spec.rb b/spec/features/paypal_spec.rb index d00e14c..e1f410e 100644 --- a/spec/features/paypal_spec.rb +++ b/spec/features/paypal_spec.rb @@ -364,8 +364,9 @@ def switch_to_paypal_login end def login_to_paypal - fill_in "Email", with: "solidus-test@example.com" - fill_in "Password", with: "spree1234" + click_on "paypal_button" + fill_in "email", with: "solidus-test@example.com" + fill_in "mypassword", with: "spree1234" click_button "Log in to PayPal" end From 78fa978089a9e1c4dcf9fa9252aeec000c9ff665 Mon Sep 17 00:00:00 2001 From: Diego Franciosi Date: Wed, 17 Feb 2016 02:19:21 +0100 Subject: [PATCH 06/10] Readme update --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index aac6529..e71bf28 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Spree PayPal Express +# Solidus PayPal Express [![Build Status](https://travis-ci.org/spree-contrib/better_spree_paypal_express.svg?branch=2-4-stable)](https://travis-ci.org/spree-contrib/better_spree_paypal_express) @@ -18,7 +18,7 @@ Behind-the-scenes, this extension uses [PayPal's Merchant Ruby SDK](https://gith 3. Copy & run migrations - bundle exec rails g spree_paypal_express:install + bundle exec rails g solidus_paypal_express:install 4. Restart your server From e71f29fa8c7d47f52a1d613d05ce707127679bea Mon Sep 17 00:00:00 2001 From: mapteo Date: Mon, 20 Nov 2017 15:02:30 +0100 Subject: [PATCH 07/10] enable auto capture (?) --- app/models/spree/gateway/pay_pal_express.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/spree/gateway/pay_pal_express.rb b/app/models/spree/gateway/pay_pal_express.rb index 5d20208..5f08347 100644 --- a/app/models/spree/gateway/pay_pal_express.rb +++ b/app/models/spree/gateway/pay_pal_express.rb @@ -28,7 +28,7 @@ def provider end def auto_capture? - false + true end def method_type From bd716c7b3110c22a0859fd4cc4d610caeea477cf Mon Sep 17 00:00:00 2001 From: apellizz Date: Tue, 21 Nov 2017 11:13:20 +0100 Subject: [PATCH 08/10] Try to add purchase --- app/models/spree/gateway/pay_pal_express.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/spree/gateway/pay_pal_express.rb b/app/models/spree/gateway/pay_pal_express.rb index 5f08347..6498fa9 100644 --- a/app/models/spree/gateway/pay_pal_express.rb +++ b/app/models/spree/gateway/pay_pal_express.rb @@ -188,5 +188,7 @@ def build_checkout_payment_params(token, payer_id, payment_details) def sandbox? self.preferred_server == "sandbox" end + + alias_method :purchase, :capture end end From 329c313e798eb531c870d9c84c0e25d106a13e81 Mon Sep 17 00:00:00 2001 From: FanaHOVA Date: Thu, 30 Nov 2017 10:45:05 +0000 Subject: [PATCH 09/10] Setup PayPal payments --- .rubocop_todo.yml | 287 ------------------ app/controllers/spree/paypal_controller.rb | 187 ------------ .../spree/paypal_express_controller.rb | 34 +++ app/models/spree/gateway/pay_pal_express.rb | 195 ++---------- .../spree/checkout/payment/_paypal.html.erb | 5 - .../checkout/payment/_paypal_express.html.erb | 14 + config/routes.rb | 10 +- 7 files changed, 73 insertions(+), 659 deletions(-) delete mode 100644 .rubocop_todo.yml delete mode 100644 app/controllers/spree/paypal_controller.rb create mode 100644 app/controllers/spree/paypal_express_controller.rb delete mode 100644 app/views/spree/checkout/payment/_paypal.html.erb create mode 100644 app/views/spree/checkout/payment/_paypal_express.html.erb diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml deleted file mode 100644 index 216c695..0000000 --- a/.rubocop_todo.yml +++ /dev/null @@ -1,287 +0,0 @@ -# This configuration was generated by -# `rubocop --auto-gen-config` -# on 2015-10-14 11:57:44 -0700 using RuboCop version 0.34.2. -# The point is for the user to remove these configuration records -# one by one as the offenses are removed from the code base. -# Note that changes in the inspected code, or installation of new -# versions of RuboCop, may require this file to be generated again. - -# Offense count: 1 -Lint/AmbiguousOperator: - Exclude: - - 'lib/spree_paypal_express/engine.rb' - - -# Offense count: 1 -Lint/Debugger: - Exclude: - - 'spec/features/paypal_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: AlignWith, SupportedStyles, AutoCorrect. -Lint/DefEndAlignment: - Enabled: false - -# Offense count: 3 -Lint/NestedMethodDefinition: - Exclude: - - 'app/models/spree/gateway/pay_pal_express.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -Lint/UnusedMethodArgument: - Exclude: - - 'app/models/spree/gateway/pay_pal_express.rb' - -# Offense count: 1 -Lint/Void: - Exclude: - - 'spec/features/paypal_spec.rb' - -# Offense count: 27 -Metrics/AbcSize: - Max: 364 - -# Offense count: 3 -# Configuration parameters: CountComments. -Metrics/ClassLength: - Max: 412 - -# Offense count: 473 -# Configuration parameters: AllowURI, URISchemes. -Metrics/LineLength: - Max: 243 - -# Offense count: 42 -# Configuration parameters: CountComments. -Metrics/MethodLength: - Max: 410 - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles. -Style/AlignHash: - Exclude: - - 'spec/models/pay_pal_express_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods. -Style/BlockDelimiters: - Enabled: false - -# Offense count: 8 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/BracesAroundHashParameters: - Exclude: - - 'app/controllers/spree/paypal_controller.rb' - - 'app/models/spree/gateway/pay_pal_express.rb' - - 'spec/models/pay_pal_express_spec.rb' - -# Offense count: 3 -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/ClassAndModuleChildren: - Exclude: - - 'app/controllers/spree/admin/paypal_payments_controller.rb' - - 'app/models/spree/gateway/pay_pal_express.rb' - -# Offense count: 11 -# Configuration parameters: Exclude. -Style/Documentation: - Exclude: - - 'app/controllers/spree/admin/paypal_payments_controller.rb' - - 'app/controllers/spree/paypal_controller.rb' - - 'app/models/spree/gateway/pay_pal_express.rb' - - 'db/migrate/20130723042610_create_spree_paypal_express_checkouts.rb' - - 'db/migrate/20130808030836_add_transaction_id_to_spree_paypal_express_checkouts.rb' - - 'db/migrate/20130809013846_add_state_to_spree_paypal_express_checkouts.rb' - - 'db/migrate/20130809014319_add_refunded_fields_to_spree_paypal_express_checkouts.rb' - - 'db/migrate/20140117051315_rename_payment_methods.rb' - - 'lib/generators/spree_paypal_express/install/install_generator.rb' - - 'lib/spree_paypal_express/engine.rb' - - 'lib/spree_paypal_express/version.rb' - -# Offense count: 10 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/DotPosition: - Enabled: false - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: AllowAdjacentOneLineDefs. -Style/EmptyLineBetweenDefs: - Exclude: - - 'app/models/spree/gateway/pay_pal_express.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -Style/EmptyLines: - Exclude: - - 'Rakefile' - - 'spec/spec_helper.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/EmptyLinesAroundBlockBody: - Exclude: - - 'spec/models/spree/gateway/pay_pal_express_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/EmptyLinesAroundClassBody: - Exclude: - - 'lib/generators/spree_paypal_express/install/install_generator.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: AllowForAlignment. -Style/ExtraSpacing: - Exclude: - - 'spec/spec_helper.rb' - - 'spree_paypal_express.gemspec' - -# Offense count: 13 -# Configuration parameters: MinBodyLength. -Style/GuardClause: - Exclude: - - 'lib/generators/spree_paypal_express/install/install_generator.rb' - - 'spec/features/paypal_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: MaxLineLength. -Style/IfUnlessModifier: - Exclude: - - 'spec/features/paypal_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: Width. -Style/IndentationWidth: - Exclude: - - 'Gemfile' - -# Offense count: 2 -# Cop supports --auto-correct. -Style/Lambda: - Exclude: - - 'spec/models/pay_pal_express_spec.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -Style/LineEndConcatenation: - Exclude: - - 'app/models/spree/gateway/pay_pal_express.rb' - - 'spec/models/spree/gateway/pay_pal_express_spec.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/MethodDefParentheses: - Enabled: false - -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/MultilineOperationIndentation: - Enabled: false - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: PreferredDelimiters. -Style/PercentLiteralDelimiters: - Exclude: - - 'spree_paypal_express.gemspec' - -# Offense count: 2 -# Cop supports --auto-correct. -Style/RedundantSelf: - Exclude: - - 'app/models/spree/gateway/pay_pal_express.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes. -Style/RegexpLiteral: - Exclude: - - 'lib/generators/spree_paypal_express/install/install_generator.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/SignalException: - Exclude: - - 'app/controllers/spree/paypal_controller.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: AllowIfMethodIsEmpty. -Style/SingleLineMethods: - Exclude: - - 'app/models/spree/gateway/pay_pal_express.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: SupportedStyles. -Style/SpaceAroundEqualsInParameterDefault: - EnforcedStyle: no_space - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: MultiSpaceAllowedForOperators. -Style/SpaceAroundOperators: - Exclude: - - 'app/models/spree/gateway/pay_pal_express.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/SpaceBeforeBlockBraces: - Enabled: false - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles. -Style/SpaceInsideHashLiteralBraces: - Enabled: false - -# Offense count: 2 -# Cop supports --auto-correct. -Style/SpecialGlobalVars: - Exclude: - - 'spree_paypal_express.gemspec' - -# Offense count: 1743 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/StringLiterals: - Enabled: false - -# Offense count: 5 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/TrailingBlankLines: - Exclude: - - 'app/controllers/spree/admin/payments_controller_decorator.rb' - - 'app/controllers/spree/admin/paypal_payments_controller.rb' - - 'app/models/spree/paypal_express_checkout.rb' - - 'config/routes.rb' - - 'lib/spree_paypal_express/version.rb' - -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleForMultiline, SupportedStyles. -Style/TrailingComma: - Exclude: - - 'app/controllers/spree/paypal_controller.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/UnneededPercentQ: - Exclude: - - 'spree_paypal_express.gemspec' diff --git a/app/controllers/spree/paypal_controller.rb b/app/controllers/spree/paypal_controller.rb deleted file mode 100644 index f2999a0..0000000 --- a/app/controllers/spree/paypal_controller.rb +++ /dev/null @@ -1,187 +0,0 @@ -module Spree - class PaypalController < StoreController - # This is the entry point for after being redirected from the cart - # payment page. - def express - order = current_order || raise(ActiveRecord::RecordNotFound) - items = order.line_items.map(&method(:line_item)) - - additional_adjustments = order.all_adjustments.additional - tax_adjustments = additional_adjustments.tax - shipping_adjustments = additional_adjustments.shipping - - additional_adjustments.eligible.each do |adjustment| - next if (tax_adjustments + shipping_adjustments).include?(adjustment) - items << { - Name: adjustment.label, - Quantity: 1, - Amount: { - currencyID: order.currency, - value: adjustment.amount - } - } - end - - # Because PayPal doesn't accept $0 items at all. - # See #10 - # https://cms.paypal.com/uk/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ECCustomizing - # "It can be a positive or negative value but not zero." - items.reject! do |item| - item[:Amount][:value].zero? - end - pp_request = provider.build_set_express_checkout(express_checkout_request_details(order, items)) - - begin - pp_response = provider.set_express_checkout(pp_request) - if pp_response.success? - redirect_to payment_method. - express_checkout_url(pp_response, useraction: 'commit') - else - flash[:error] = Spree.t('flash.generic_error', scope: 'paypal', reasons: pp_response.errors.map(&:long_message).join(" ")) - redirect_to checkout_state_path(:payment) - end - rescue SocketError - flash[:error] = Spree.t('flash.connection_failed', scope: 'paypal') - redirect_to checkout_state_path(:payment) - end - end - - # This is the entry point for PayPal after the user has completed payment - # on the hosted payment page within PayPal's domain. - def confirm - order = current_order || raise(ActiveRecord::RecordNotFound) - order.payments.create!( - { - source: Spree::PaypalExpressCheckout.create( - { - token: params[:token], - payer_id: params[:PayerID] - } - ), - amount: order.total, - payment_method: payment_method - } - ) - order.next - if order.complete? - flash.notice = Spree.t(:order_processed_successfully) - flash[:order_completed] = true - session[:order_id] = nil - redirect_to completion_route(order) - else - redirect_to checkout_state_path(order.state) - end - end - - def cancel - flash[:notice] = Spree.t('flash.cancel', scope: 'paypal') - order = current_order || raise(ActiveRecord::RecordNotFound) - redirect_to checkout_state_path(order.state, paypal_cancel_token: params[:token]) - end - - private - - def line_item(item) - { - Name: item.product.name, - Number: item.variant.sku, - Quantity: item.quantity, - Amount: { - currencyID: item.order.currency, - value: item.price - }, - ItemCategory: "Physical" - } - end - - def express_checkout_request_details order, items - { SetExpressCheckoutRequestDetails: { - InvoiceID: order.number, - BuyerEmail: order.email, - ReturnURL: confirm_paypal_url(payment_method_id: params[:payment_method_id], utm_nooverride: 1), - CancelURL: cancel_paypal_url, - SolutionType: payment_method.preferred_solution.present? ? payment_method.preferred_solution : "Mark", - LandingPage: payment_method.preferred_landing_page.present? ? payment_method.preferred_landing_page : "Billing", - cppheaderimage: payment_method.preferred_logourl.present? ? payment_method.preferred_logourl : "", - NoShipping: 1, - PaymentDetails: [payment_details(items)] - }} - end - - def payment_method - Spree::PaymentMethod.find(params[:payment_method_id]) - end - - def provider - payment_method.provider - end - - def payment_details items - # This retrieves the cost of shipping after promotions are applied - # For example, if shippng costs $10, and is free with a promotion, shipment_sum is now $10 - shipment_sum = current_order.shipments.map(&:discounted_cost).sum - - # This calculates the item sum based upon what is in the order total, but not for shipping - # or tax. This is the easiest way to determine what the items should cost, as that - # functionality doesn't currently exist in Spree core - item_sum = current_order.total - shipment_sum - current_order.additional_tax_total - - if item_sum.zero? - # Paypal does not support no items or a zero dollar ItemTotal - # This results in the order summary being simply "Current purchase" - { - OrderTotal: { - currencyID: current_order.currency, - value: current_order.total - } - } - else - { - OrderTotal: { - currencyID: current_order.currency, - value: current_order.total - }, - ItemTotal: { - currencyID: current_order.currency, - value: item_sum - }, - ShippingTotal: { - currencyID: current_order.currency, - value: shipment_sum, - }, - TaxTotal: { - currencyID: current_order.currency, - value: current_order.additional_tax_total - }, - ShipToAddress: address_options, - PaymentDetailsItem: items, - ShippingMethod: "Shipping Method Name Goes Here", - PaymentAction: "Authorization" - } - end - end - - def address_options - return {} unless address_required? - - { - Name: current_order.bill_address.try(:full_name), - Street1: current_order.bill_address.address1, - Street2: current_order.bill_address.address2, - CityName: current_order.bill_address.city, - Phone: current_order.bill_address.phone, - StateOrProvince: current_order.bill_address.state_text, - Country: current_order.bill_address.country.iso, - PostalCode: current_order.bill_address.zipcode - } - end - - def completion_route(order) - order_path(order) - end - - def address_required? - payment_method.preferred_solution.eql?('Sole') - end - end -end diff --git a/app/controllers/spree/paypal_express_controller.rb b/app/controllers/spree/paypal_express_controller.rb new file mode 100644 index 0000000..03a7ad0 --- /dev/null +++ b/app/controllers/spree/paypal_express_controller.rb @@ -0,0 +1,34 @@ +module Spree + class PaypalExpressController < Spree::StoreController + def return + @order = current_order || raise(ActiveRecord::RecordNotFound) + pm = Spree::PaymentMethod.find params[:payment_method_id] + ps = Spree::PaypalExpressCheckout.create!(token: params['token'], payer_id: params['PayerID']) + @order.payments.create!(source: ps, amount: @order.total, payment_method: pm) + advance_order + if @order.complete? + flash.notice = I18n.t('spree.order.successful') + flash[:order_completed] = true + session[:order_id] = nil + redirect_to completion_route(@order) + else + redirect_to spree.checkout_state_path(@order.state) + end + end + + def cancel + flash[:notice] = I18n.t('spree.paypal.flash.cancel') + order = current_order || raise(ActiveRecord::RecordNotFound) + redirect_to spree.checkout_state_path(order.state) + end + + private + + # Advance the order to the confirm state + def advance_order + until @order.state == 'confirm' + @order.next! + end + end + end +end diff --git a/app/models/spree/gateway/pay_pal_express.rb b/app/models/spree/gateway/pay_pal_express.rb index 6498fa9..1c65522 100644 --- a/app/models/spree/gateway/pay_pal_express.rb +++ b/app/models/spree/gateway/pay_pal_express.rb @@ -1,194 +1,41 @@ -require 'paypal-sdk-merchant' module Spree class Gateway::PayPalExpress < Gateway - preference :use_new_layout, :boolean, default: true preference :login, :string preference :password, :string preference :signature, :string - preference :server, :string, default: 'sandbox' - preference :solution, :string, default: 'Mark' - preference :landing_page, :string, default: 'Billing' - preference :logourl, :string, default: '' + preference :currency_code, :string, default: 'EUR' def supports?(source) - true + source.is_a? Spree::PaypalExpressCheckout end def provider_class - ::PayPal::SDK::Merchant::API - end - - def provider - ::PayPal::SDK.configure( - mode: preferred_server.present? ? preferred_server : "sandbox", - username: preferred_login, - password: preferred_password, - signature: preferred_signature) - provider_class.new - end - - def auto_capture? - true + ActiveMerchant::Billing::PaypalExpressGateway end def method_type - 'paypal' + 'paypal_express' end - # amount :: float - # express_checkout :: Spree::PaypalExpressCheckout - # gateway_options :: hash - def authorize(amount, express_checkout, gateway_options={}) - response = - do_authorize(express_checkout.token, express_checkout.payer_id) - - # TODO don't do this, use authorization instead - # this is a hold over from old code. - # I don't think this actually even used by anything? - express_checkout.update transaction_id: response.authorization - - response + def purchase(money, source, options = {}) + params = options.merge({ + token: source.token, + payer_id: source.payer_id, + currency: preferred_currency_code + }) + provider.purchase(money, params) end - # https://developer.paypal.com/docs/classic/api/merchant/DoCapture_API_Operation_NVP/ - # for more information - def capture(amount_cents, authorization, currency:, **_options) - do_capture(amount_cents, authorization, currency) - end - - def credit(credit_cents, transaction_id, originator:, **_options) - payment = originator.payment - amount = credit_cents / 100.0 - - refund_type = payment.amount == amount.to_f ? "Full" : "Partial" - - refund_transaction = provider.build_refund_transaction( - { TransactionID: payment.transaction_id, - RefundType: refund_type, - Amount: { - currencyID: payment.currency, - value: amount }, - RefundSource: "any" }) - - refund_transaction_response = provider.refund_transaction(refund_transaction) - - if refund_transaction_response.success? - payment.source.update_attributes( - { refunded_at: Time.now, - refund_transaction_id: refund_transaction_response.RefundTransactionID, - state: "refunded", - refund_type: refund_type - }) - end - - build_response( - refund_transaction_response, - refund_transaction_response.refund_transaction_id) - end - - def server_domain - self.preferred_server == "live" ? "" : "sandbox." - end - - def express_checkout_url(pp_response, extra_params={}) - params = { - token: pp_response.Token - }.merge(extra_params) - - if self.preferred_use_new_layout - "https://www.#{server_domain}paypal.com/checkoutnow/2?" - else - "https://www.#{server_domain}paypal.com/cgi-bin/webscr?" + - "cmd=_express-checkout&force_sa=true&" - end + - URI.encode_www_form(params) - end - - def do_authorize(token, payer_id) - response = - self. - provider. - do_express_checkout_payment( - checkout_payment_params(token, payer_id)) - - build_response(response, authorization_transaction_id(response)) + def purchase_link(order, options) + total_cents = order.display_total.cents + options.merge!({ + max_amount: total_cents, + allow_guest_checkout: true, + currency: preferred_currency_code + }) + response = provider.setup_purchase total_cents, options + token = response.params['token'] + provider.redirect_url_for(token) end - - def do_capture(amount_cents, authorization, currency) - response = provider. - do_capture( - provider.build_do_capture( - amount: amount_cents / 100.0, - authorization_id: authorization, - completetype: "Complete", - currencycode: options[:currency])) - - build_response(response, capture_transaction_id(response)) - end - - def capture_transaction_id(response) - response.do_capture_response_details.payment_info.transaction_id - end - - # response :: - # PayPal::SDK::Merchant::DataTypes::DoExpressCheckoutPaymentResponseType - def authorization_transaction_id(response) - response. - do_express_checkout_payment_response_details. - payment_info. - first. - transaction_id - end - - def build_response(response, transaction_id) - ActiveMerchant::Billing::Response.new( - response.success?, - JSON.pretty_generate(response.to_hash), - response.to_hash, - authorization: transaction_id, - test: sandbox?) - end - - def payment_details(token) - self. - provider. - get_express_checkout_details( - checkout_details_params(token)). - get_express_checkout_details_response_details. - payment_details - end - - def checkout_payment_params(token, payer_id) - self. - provider. - build_do_express_checkout_payment( - build_checkout_payment_params( - token, - payer_id, - payment_details(token))) - end - - def checkout_details_params(token) - self. - provider. - build_get_express_checkout_details(Token: token) - end - - def build_checkout_payment_params(token, payer_id, payment_details) - { - DoExpressCheckoutPaymentRequestDetails: { - PaymentAction: "Authorization", - Token: token, - PayerID: payer_id, - PaymentDetails: payment_details - } - } - end - - def sandbox? - self.preferred_server == "sandbox" - end - - alias_method :purchase, :capture end end diff --git a/app/views/spree/checkout/payment/_paypal.html.erb b/app/views/spree/checkout/payment/_paypal.html.erb deleted file mode 100644 index 8a1082a..0000000 --- a/app/views/spree/checkout/payment/_paypal.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -<%= link_to(image_tag("https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif"), paypal_express_url(:payment_method_id => payment_method.id), :method => :post, :id => "paypal_button") %> - - diff --git a/app/views/spree/checkout/payment/_paypal_express.html.erb b/app/views/spree/checkout/payment/_paypal_express.html.erb new file mode 100644 index 0000000..89da112 --- /dev/null +++ b/app/views/spree/checkout/payment/_paypal_express.html.erb @@ -0,0 +1,14 @@ +<% + options = { + return_url: paypal_return_url(payment_method_id: payment_method.id), + cancel_return_url: paypal_cancel_url(payment_method_id: payment_method.id) + } + link = payment_method.purchase_link(@order, options) +%> + + +Buy now with PayPal diff --git a/config/routes.rb b/config/routes.rb index 57e6e7d..6c208f3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,8 +1,6 @@ -Spree::Core::Engine.add_routes do - post '/paypal', to: "paypal#express", as: :paypal_express - get '/paypal/confirm', to: "paypal#confirm", as: :confirm_paypal - get '/paypal/cancel', to: "paypal#cancel", as: :cancel_paypal - get '/paypal/notify', to: "paypal#notify", as: :notify_paypal +Spree::Core::Engine.routes.draw do + get 'paypal_return', to: 'paypal_express#return', as: :paypal_return + get 'paypal_cancel', to: 'paypal_express#cancel', as: :paypal_cancel namespace :admin do # Using :only here so it doesn't redraw those routes @@ -15,4 +13,4 @@ end end end -end \ No newline at end of file +end From 18b361dfd4d1745ae55dc7f753c80a4b94661ccd Mon Sep 17 00:00:00 2001 From: FanaHOVA Date: Thu, 30 Nov 2017 10:50:45 +0000 Subject: [PATCH 10/10] Update readme and add auto_capture flag --- README.md | 26 ++++----------------- app/models/spree/gateway/pay_pal_express.rb | 3 ++- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index e71bf28..32b910d 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,13 @@ [![Build Status](https://travis-ci.org/spree-contrib/better_spree_paypal_express.svg?branch=2-4-stable)](https://travis-ci.org/spree-contrib/better_spree_paypal_express) -This is a "re-do" of the official [spree_paypal_express][4] extension. The old extension is extremely hard to maintain and complex. - -Behind-the-scenes, this extension uses [PayPal's Merchant Ruby SDK](https://github.com/paypal/merchant-sdk-ruby). +This is an enhanced version of the [solidus_paypal_express](https://github.com/dfranciosi/solidus_paypal_express) by `dfranciosi`. Instead of using [PayPal's Merchant Ruby SDK](https://github.com/paypal/merchant-sdk-ruby) we run `ActiveMerchant::Billing::PaypalExpressGateway` as a provider. ## Installation 1. Add this extension to your Gemfile with this line: - gem 'solidus_paypal_express', github: 'solidusio-contrib/solidus_paypal_express', branch: 'master' + gem 'solidus_paypal_express', github: 'mikamai/solidus_enhanced_paypal_express' 2. Install the gem using Bundler: @@ -32,6 +30,8 @@ Go to [PayPal's Developer Website](https://developer.paypal.com/), sign in with You will also need a "Personal" account to test the transactions on your site. Create this in the same way, finding the account information under "Profile" as well. You may need to set a password in order to be able to log in to PayPal's sandbox for this user. +Remember to set the server as `test` instead of `live`. + #### Spree Setup In Spree, go to the admin backend, click "Configuration" and then "Payment Methods" and create a new payment method. Select "Spree::Gateway::PayPalExpress" as the provider, and click "Create". Enter the email address, password and signature from the "API Credentials" tab for the **Business** account on PayPal. @@ -46,13 +46,7 @@ If you are unable to find it, then follow [PayPal's own documentation](https://d #### Spree Setup -Same as sandbox setup, but change "Server" from "sandbox" to "live". - -## Configuration - -The PayPal Express Checkout has [no less than 4.5 billion configuration options](https://github.com/paypal/merchant-sdk-ruby/blob/1d65e598d2f9f200f85c6b3338d4293dbed576d8/lib/paypal-sdk/merchant/data_types.rb#L830-L959). - -This Spree extension supports *some* of those. If your favourite is not here, then please submit an issue about it, or better still a patch to add it in. +Same as sandbox setup, but change "Server" from "test" to "live". ### Solution Type @@ -78,16 +72,6 @@ payment_method.preferred_landing_page = "Billing" "Login" will show the users the login form for PayPal, and "Billing" will show them a form where they can enter their credit card data and possibly sign up for a PayPal account (depending on the Solution Type setting above). -### Logo - -Determines what logo, if any, to display at the top left of the PayPal express checkout: - -```ruby -payment_method.preferred_logourl = 'http://yoursite.com/images/checkout.jpg' -``` - -**Must** be an absolute path to the image. - ## Caveats *Caveat venditor* diff --git a/app/models/spree/gateway/pay_pal_express.rb b/app/models/spree/gateway/pay_pal_express.rb index 1c65522..4a19cde 100644 --- a/app/models/spree/gateway/pay_pal_express.rb +++ b/app/models/spree/gateway/pay_pal_express.rb @@ -4,7 +4,8 @@ class Gateway::PayPalExpress < Gateway preference :password, :string preference :signature, :string preference :currency_code, :string, default: 'EUR' - + preference :auto_capture, :boolean, default: true + def supports?(source) source.is_a? Spree::PaypalExpressCheckout end