From 9e063b2d66dc9a0297ecfe1d30b949e1f2de2e95 Mon Sep 17 00:00:00 2001 From: Diego Franciosi Date: Tue, 9 Feb 2016 11:59:27 +0100 Subject: [PATCH 01/14] 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/14] 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/14] 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/14] 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/14] 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/14] 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 a9f7bfb0e8b7cefdf5c083ef60a6ea66f527afa9 Mon Sep 17 00:00:00 2001 From: Antonio Facciolo Date: Tue, 17 Jul 2018 14:33:19 +0200 Subject: [PATCH 07/14] Revert "Update README.md" This reverts commit 664fae3eead2957de23a8a2547d932474a728348. --- README.md | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 127 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index dd6b3f7..b651d3f 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,132 @@ -# Warning +> This project is unmaintained doesn't work with the latest versions of Solidus or `paypal-sdk-merchant`. We recommend using [solidus_braintree](https://github.com/solidusio/solidus_braintree) (which has paypal support) instead. -# This project is no longer mainainted or used by Lostmyname. Please use Braintree instead. +# Spree PayPal Express -# License +[![Build Status](https://travis-ci.org/solidusio-contrib/solidus_paypal_express.svg?branch=master)](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). + +## Installation + +1. Add this extension to your Gemfile with this line: + + gem 'spree_paypal_express', github: 'solidusio-contrib/solidus_paypal_express' + +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. + +2. Install the gem using Bundler: + + bundle install + +3. Copy & run migrations + + bundle exec rails g spree_paypal_express:install + +4. Restart your server + +If your server was running, restart it so that it can find the assets properly. + +### Sandbox Setup + +#### PayPal + +Go to [PayPal's Developer Website](https://developer.paypal.com/), sign in with your PayPal account, click "Applications" then "Sandbox Accounts" and create a new "Business" account. Once the account is created, click on the triangle next to its email address, then "Profile". The "API Credentials" tab will provide your API credentials (probably). If this tab is blank, try refreshing the page. + +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. + +#### 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. + +### Production setup + +#### PayPal + +Sign in to PayPal, then click "Profile" and then (under "Account Information" on the left), click "API Access". On this page, select "Option 2" and click "View API Signature". The username, password and signature will be displayed on this screen. + +If you are unable to find it, then follow [PayPal's own documentation](https://developer.paypal.com/webapps/developer/docs/classic/api/apiCredentials/). + +#### 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. + +### Solution Type + +Determines whether or not a user needs a PayPal account to check out. + +```ruby +payment_method.preferred_solution_type = "Mark" +# or +payment_method.preferred_solution_type = "Sole" +``` + +"Mark" if you do want users to have a paypal account, "Sole" otherwise. + +### Landing Page + +Determines which page to show users once they're redirected to PayPal. + +```ruby +payment_method.preferred_landing_page = "Login" +# or +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* + +Paypal will refuse any order with a zero cost item. +Any such item will be skipped and not displayed. + +PayPal will also refuse any order where item total (before taxes and shipping costs) is zero. +In this case the PayPal checkout page will simply display "Current order". + +## Contributing + +In the spirit of [free software][1], **everyone** is encouraged to help improve this project. + +Here are some ways *you* can contribute: + +* by using prerelease versions +* by reporting [bugs][2] +* by suggesting new features +* by writing or editing documentation +* by writing specifications +* by writing code (*no patch is too small*: fix typos, add comments, clean up inconsistent whitespace) +* by refactoring code +* by resolving [issues][2] +* by reviewing patches + +Starting point: + +* Fork the repo +* Clone your repo +* Run `bundle install` +* Run `bundle exec rake test_app` to create the test application in `spec/dummy` +* Make your changes +* 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] From 26fcd54df496af0260da152a6a53d96cff5b9e8d Mon Sep 17 00:00:00 2001 From: Antonio Facciolo Date: Tue, 17 Jul 2018 15:38:27 +0200 Subject: [PATCH 08/14] add missing English translations --- config/locales/en.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index e072284..9ff1260 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,6 +1,8 @@ --- en: spree: + landing_page: Landing Page + logourl: Logo Url paypal: already_refunded: "This payment has been refunded and no further action can be taken on it." no_payment_via_admin_backend: "You cannot charge PayPal accounts through the admin backend at this time." @@ -18,4 +20,7 @@ en: flash: cancel: "Don't want to use PayPal? No problems." connection_failed: "Could not connect to PayPal." - generic_error: "PayPal failed. %{reasons}" \ No newline at end of file + generic_error: "PayPal failed. %{reasons}" + signature: Signature + solution: Solution + use_new_layout: Use new layout From 705415697c545bf972c9ce71790fe79ce43d42e9 Mon Sep 17 00:00:00 2001 From: Antonio Facciolo Date: Thu, 19 Jul 2018 15:43:18 +0200 Subject: [PATCH 09/14] fix final_amount_without_additional_tax no method error --- app/controllers/spree/paypal_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/spree/paypal_controller.rb b/app/controllers/spree/paypal_controller.rb index 5d26c7a..3d3db8b 100644 --- a/app/controllers/spree/paypal_controller.rb +++ b/app/controllers/spree/paypal_controller.rb @@ -120,7 +120,7 @@ def gateway 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(&:final_amount_without_additional_tax).sum + shipment_sum = current_order.shipments.sum(&:total_before_tax) # 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 From ea466af20ddf630dcace08b277671ead5e628ef1 Mon Sep 17 00:00:00 2001 From: Antonio Facciolo Date: Thu, 19 Jul 2018 15:48:22 +0200 Subject: [PATCH 10/14] bump version --- lib/solidus_paypal_express/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/solidus_paypal_express/version.rb b/lib/solidus_paypal_express/version.rb index ab5adf6..f5a6a68 100644 --- a/lib/solidus_paypal_express/version.rb +++ b/lib/solidus_paypal_express/version.rb @@ -1,3 +1,3 @@ module SolidusPayPalExpress - VERSION = '0.1.0' + VERSION = '0.2.0' end From ee124a6837a0263bd1464bf5eca97996f11c213b Mon Sep 17 00:00:00 2001 From: Antonio Facciolo Date: Thu, 24 Jan 2019 13:20:39 +0100 Subject: [PATCH 11/14] update README, travis config and bump version --- .travis.yml | 42 ++++++++++++++++++++++----- CONTRIBUTING.md | 4 +-- README.md | 10 +++---- lib/solidus_paypal_express/version.rb | 2 +- 4 files changed, 42 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index bb39952..e54fc8e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,38 @@ -language: ruby sudo: false -cache: bundler language: ruby +dist: trusty +cache: + bundler: true + directories: + - travis_phantomjs before_install: - - mkdir -p "$HOME/bin" && curl -o "$HOME/bin/phantomjs" https://s3.amazonaws.com/circle-downloads/phantomjs-2.1.1 && chmod +x "$HOME/bin/phantomjs" - - export PATH="$HOME/bin:$PATH" -env: - - SOLIDUS_BRANCH=v1.0 DB=mysql - - SOLIDUS_BRANCH=v1.0 DB=postgres + - "gem install bundler -v 1.14.6" + - "bundler -v" + - "phantomjs --version" + - "export PATH=$PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64/bin:$PATH" + - "if [ $(phantomjs --version) != '2.1.1' ]; then rm -rf $PWD/travis_phantomjs; mkdir -p $PWD/travis_phantomjs; fi" + - "if [ $(phantomjs --version) != '2.1.1' ]; then wget https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-linux-x86_64.tar.bz2 -O $PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2; fi" + - "if [ $(phantomjs --version) != '2.1.1' ]; then tar -xvf $PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2 -C $PWD/travis_phantomjs; fi" + - "phantomjs --version" rvm: - - 2.3.0 + - 2.3.1 +env: + matrix: + - SOLIDUS_BRANCH=v2.0 DB=postgres + - SOLIDUS_BRANCH=v2.1 DB=postgres + - SOLIDUS_BRANCH=v2.2 DB=postgres + - SOLIDUS_BRANCH=v2.3 DB=postgres + - SOLIDUS_BRANCH=v2.4 DB=postgres + - SOLIDUS_BRANCH=v2.5 DB=postgres + - SOLIDUS_BRANCH=v2.6 DB=postgres + - SOLIDUS_BRANCH=v2.7 DB=postgres + - SOLIDUS_BRANCH=master DB=postgres + - SOLIDUS_BRANCH=v2.0 DB=mysql + - SOLIDUS_BRANCH=v2.1 DB=mysql + - SOLIDUS_BRANCH=v2.2 DB=mysql + - SOLIDUS_BRANCH=v2.3 DB=mysql + - SOLIDUS_BRANCH=v2.4 DB=mysql + - SOLIDUS_BRANCH=v2.5 DB=mysql + - SOLIDUS_BRANCH=v2.6 DB=mysql + - SOLIDUS_BRANCH=v2.7 DB=mysql + - SOLIDUS_BRANCH=master DB=mysql diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 12bef7d..ad8014d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -42,9 +42,9 @@ Here's a quick guide: 1. Fork the repo. 2. Run the tests. We only take pull requests with passing tests, and it's great -to know that you have a clean slate: +to know that you have a clean state: - $ bash build.sh + $ bundle exec rspec 3. Create new branch then make changes and add tests for your changes. Only refactoring and documentation changes require no new tests. If you are adding diff --git a/README.md b/README.md index 6a78868..5b6cc32 100644 --- a/README.md +++ b/README.md @@ -10,7 +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 'solidus_paypal_express', github: 'solidusio-contrib/solidus_paypal_express', branch: 'master' + gem 'solidus_paypal_express', github: 'adnotam/solidus_paypal_express', branch: 'master' 2. Install the gem using Bundler: @@ -124,9 +124,9 @@ Starting point: * Ensure specs pass by running `bundle exec rspec spec` * Submit your pull request -Copyright (c) 2016 Solidus Commerce and contributors, released under the [New BSD License][3] +Copyright (c) 2019 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/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 +[2]: https://github.com/adnotam/solidus_paypal_express/issues +[3]: https://github.com/adnotam/solidus_paypal_express/tree/master/LICENSE.md +[4]: https://github.com/adnotam/solidus_paypal_express diff --git a/lib/solidus_paypal_express/version.rb b/lib/solidus_paypal_express/version.rb index f5a6a68..d10a0c4 100644 --- a/lib/solidus_paypal_express/version.rb +++ b/lib/solidus_paypal_express/version.rb @@ -1,3 +1,3 @@ module SolidusPayPalExpress - VERSION = '0.2.0' + VERSION = '1.0.0' end From 1eb35f4362676aaffda513f3103b47d6262e9597 Mon Sep 17 00:00:00 2001 From: Antonio Facciolo Date: Thu, 24 Jan 2019 14:00:06 +0100 Subject: [PATCH 12/14] update README with travis url --- LICENSE.md | 2 +- README.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index 9e9d3dd..fb12899 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -Copyright (c) 2018 Solidus Commerce and contributors. +Copyright (c) 2019 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 5b6cc32..1846055 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Solidus PayPal Express -[![Build Status](https://travis-ci.org/solidusio-contrib/solidus_paypal_express.svg?branch=master)](https://travis-ci.org/spree-contrib/better_spree_paypal_express) +[![Build Status](https://travis-ci.org/adnotam/solidus_paypal_express.svg?branch=master)](https://travis-ci.org/adnotam/solidus_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. +This is a port of the official [spree_paypal_express][4] extension. Behind-the-scenes, this extension uses [PayPal's Merchant Ruby SDK](https://github.com/paypal/merchant-sdk-ruby). @@ -129,4 +129,4 @@ Copyright (c) 2019 Solidus Commerce and contributors, released under the [New BS [1]: http://www.fsf.org/licensing/essays/free-sw.html [2]: https://github.com/adnotam/solidus_paypal_express/issues [3]: https://github.com/adnotam/solidus_paypal_express/tree/master/LICENSE.md -[4]: https://github.com/adnotam/solidus_paypal_express +[4]: https://github.com/spree-contrib/better_spree_paypal_express From ebf93dd07765f07f905cd97e584e8acb9d55726a Mon Sep 17 00:00:00 2001 From: Antonio Facciolo Date: Mon, 12 Oct 2020 10:30:41 +0200 Subject: [PATCH 13/14] use the system's cert file instead of bundle paypal.crt --- app/models/spree/gateway/pay_pal_express.rb | 7 ++++++- lib/solidus_paypal_express/version.rb | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/models/spree/gateway/pay_pal_express.rb b/app/models/spree/gateway/pay_pal_express.rb index 778eee8..ff0baf2 100644 --- a/app/models/spree/gateway/pay_pal_express.rb +++ b/app/models/spree/gateway/pay_pal_express.rb @@ -23,7 +23,12 @@ def gateway mode: preferred_server.present? ? preferred_server : "sandbox", username: preferred_login, password: preferred_password, - signature: preferred_signature) + signature: preferred_signature, + + # Deliberately set ca_file to nil so the system's Cert Authority is used, + # instead of the bundled paypal.crt file which is out-of-date due to: + # https://www.paypal.com/va/smarthelp/article/discontinue-use-of-verisign-g5-root-certificates-ts2240 + ssl_options: { ca_file: nil }) gateway_class.new end diff --git a/lib/solidus_paypal_express/version.rb b/lib/solidus_paypal_express/version.rb index d10a0c4..611c71f 100644 --- a/lib/solidus_paypal_express/version.rb +++ b/lib/solidus_paypal_express/version.rb @@ -1,3 +1,3 @@ module SolidusPayPalExpress - VERSION = '1.0.0' + VERSION = '2.0.0' end From decc014771650a99f6ab09b8eb2a164e1816df72 Mon Sep 17 00:00:00 2001 From: Antonio Facciolo Date: Fri, 16 Oct 2020 16:53:59 +0200 Subject: [PATCH 14/14] add api view to avoid error in solidus backend --- .../spree/api/payments/source_views/_paypal.json.jbuilder | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 app/views/spree/api/payments/source_views/_paypal.json.jbuilder diff --git a/app/views/spree/api/payments/source_views/_paypal.json.jbuilder b/app/views/spree/api/payments/source_views/_paypal.json.jbuilder new file mode 100644 index 0000000..4816b81 --- /dev/null +++ b/app/views/spree/api/payments/source_views/_paypal.json.jbuilder @@ -0,0 +1,3 @@ +# frozen_string_literal: true + +json.call(payment_source, :id, :token, :created_at)