solidus_paypal_commerce_platform 1.0.0.beta2 → 1.0.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1ca5d1fd0c7ccd99dc39a66a53f0c9ddf902b8114bb420c9f1a070c13cb96ffa
4
- data.tar.gz: 9a16b551e567947e0e6b743626de2793113e7e12e51cc08dddaf7a00ea60d97c
3
+ metadata.gz: 8de51ca7968f49267b90b11183b233f9c2cdf643a2dcf1ba4cdb2de71b701708
4
+ data.tar.gz: efd5050d954c26c4948fcd5aa278c18722ad6868bb820f13ed1056da47bed7b9
5
5
  SHA512:
6
- metadata.gz: d6b54f9d01a843a63645844b65626aaefc85cad5885aaca64c2d72050e3b02502f0e00510b9a9ec1bcbd611025957fe2b008b4db85c1fed7558f2c1ccd4f056f
7
- data.tar.gz: 2bdd87d6c92d31282eb4cf566dfb59a247d759583553b670e7326ec806b6b1a1ea7c5a82f6eb49e9155b671f2933eb977d1bf02004b56dce37b00e4559a79bcf
6
+ metadata.gz: d166c6cfe27e852d8285b02c6a6d0d165c1121ff0f8c476ea1a3bfb7944bfbc9a6b54fe51dda40523917c51300a1b206ebcb331f2c6b928d88c0ae317c5675ac
7
+ data.tar.gz: cd177e48b2428f415c033238ac7ded3ac5e468cc65ff3047feddba5b7edc5a19f0c30bad1223ebf308bf0dec7a5f604740e667002e9855517520a491e75c2728
data/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # Changelog
2
2
 
3
+ ## [v1.0.0.beta3](https://github.com/solidusio/solidus_paypal_commerce_platform/tree/v1.0.0.beta3) (2023-01-18)
4
+
5
+ [Full Changelog](https://github.com/solidusio/solidus_paypal_commerce_platform/compare/v1.0.0.beta2...v1.0.0.beta3)
6
+
7
+ **Fixed bugs:**
8
+
9
+ - Allow cancelling orders \(v1 port of \#180\) [\#182](https://github.com/solidusio/solidus_paypal_commerce_platform/issues/182)
10
+ - Preferred paypal button color error message should be translated [\#178](https://github.com/solidusio/solidus_paypal_commerce_platform/issues/178)
11
+ - Allow cancelling orders [\#183](https://github.com/solidusio/solidus_paypal_commerce_platform/pull/183) ([kennyadsl](https://github.com/kennyadsl))
12
+
13
+ **Closed issues:**
14
+
15
+ - Make the Venmo button testable from outside US contries [\#137](https://github.com/solidusio/solidus_paypal_commerce_platform/issues/137)
16
+
17
+ **Merged pull requests:**
18
+
19
+ - \[v1\] Allow to use the auto\_capture global preference [\#186](https://github.com/solidusio/solidus_paypal_commerce_platform/pull/186) ([kennyadsl](https://github.com/kennyadsl))
20
+ - Uniform installer with Solidus Starter Frontend [\#184](https://github.com/solidusio/solidus_paypal_commerce_platform/pull/184) ([kennyadsl](https://github.com/kennyadsl))
21
+ - Do not break custom pricing options classes [\#181](https://github.com/solidusio/solidus_paypal_commerce_platform/pull/181) ([mamhoff](https://github.com/mamhoff))
22
+ - Fix: preferred\_paypal\_button\_color error message should be translated dynamically [\#179](https://github.com/solidusio/solidus_paypal_commerce_platform/pull/179) ([gsmendoza](https://github.com/gsmendoza))
23
+ - Add instructions on how to use the PayPal sandbox [\#177](https://github.com/solidusio/solidus_paypal_commerce_platform/pull/177) ([elia](https://github.com/elia))
24
+
3
25
  ## [v1.0.0.beta2](https://github.com/solidusio/solidus_paypal_commerce_platform/tree/v1.0.0.beta2) (2022-12-12)
4
26
 
5
27
  [Full Changelog](https://github.com/solidusio/solidus_paypal_commerce_platform/compare/v1.0.0.beta1...v1.0.0.beta2)
@@ -86,10 +108,6 @@
86
108
 
87
109
  [Full Changelog](https://github.com/solidusio/solidus_paypal_commerce_platform/compare/v0.3.1...v0.3.2)
88
110
 
89
- **Closed issues:**
90
-
91
- - Unable To Cancel An Order [\#120](https://github.com/solidusio/solidus_paypal_commerce_platform/issues/120)
92
-
93
111
  **Merged pull requests:**
94
112
 
95
113
  - Update solidus using solidus\_dev\_support [\#124](https://github.com/solidusio/solidus_paypal_commerce_platform/pull/124) ([DanielePalombo](https://github.com/DanielePalombo))
data/README.md CHANGED
@@ -16,6 +16,24 @@ gem 'solidus_paypal_commerce_platform'
16
16
  Bundle your dependencies and run the installation generator:
17
17
 
18
18
  ```shell
19
+ bundle install
20
+ bin/rails generate solidus_paypal_commerce_platform:install
21
+ ```
22
+
23
+ ### Compatibility with solidus_frontend (deprecated)
24
+
25
+ Support for the old frontend is terminated but if you are using the
26
+ `solidus_frontend` gem instead of Solidus Starter Frontend, you can
27
+ still use this gem for some time. Please, use `0.x` version.
28
+
29
+ ```ruby
30
+ gem 'solidus_paypal_commerce_platform', '< 1'
31
+ ```
32
+
33
+ Bundle your dependencies and run the installation generator:
34
+
35
+ ```shell
36
+ bundle install
19
37
  bin/rails generate solidus_paypal_commerce_platform:install
20
38
  ```
21
39
 
@@ -45,27 +63,46 @@ them in as a preference on initialization.
45
63
 
46
64
  ```ruby
47
65
  # config/initializers/spree.rb
48
- Spree::Config.configure do |config|
49
- config.static_model_preferences.add(
50
- SolidusPaypalCommercePlatform::PaymentMethod,
51
- 'paypal_commerce_platform_credentials', {
52
- test_mode: !Rails.env.production?,
53
- client_id: ENV['PAYPAL_CLIENT_ID'],
54
- client_secret: ENV['PAYPAL_CLIENT_SECRET'],
55
- display_on_product_page: true,
56
- display_on_cart: true,
57
- }
58
- )
66
+ Rails.application.config.to_prepare do
67
+ Spree::Config.configure do |config|
68
+ config.static_model_preferences.add(
69
+ SolidusPaypalCommercePlatform::PaymentMethod,
70
+ 'paypal_commerce_platform_credentials', {
71
+ test_mode: !Rails.env.production?,
72
+ client_id: ENV['PAYPAL_CLIENT_ID'],
73
+ client_secret: ENV['PAYPAL_CLIENT_SECRET'],
74
+ display_on_product_page: true,
75
+ display_on_cart: true,
76
+ venmo_standalone: 'disabled'
77
+ }
78
+ )
79
+ end
59
80
  end
60
81
  ```
61
82
 
83
+ With the payment method credentials statically configured, you can now go to the payment methods admin page and
84
+ create a payment method for PayPal. Remember that you need to create the payment method first before you can set its
85
+ Preference Source to `paypal_commerce_platform_credentials`.
86
+
62
87
  ### I don't have API credentials
63
88
 
64
89
  In this case, we still recommend following the above flow for security, but we have made a payment method setup
65
- wizard to make it easier to get started. On the payment_methods index page, you'll see a button to set up your
90
+ wizard to make it easier to get started. On the payment methods admin page, you'll see a button to set up your
66
91
  PayPal Commerce Platform payment method. Click on this button and follow the instructions provided by PayPal.
67
92
  When you return to your app, your payment method should be set up and ready to go.
68
93
 
94
+ ## Usage in development environment
95
+
96
+ When testing your PayPal integration, we recommend that you utilize the sandbox business and personal accounts that come
97
+ with your PayPal developer account. These sandbox accounts are designed to generate mock transactions for testing your
98
+ app. You can learn more about sandbox accounts at https://developer.paypal.com/tools/sandbox.
99
+
100
+ Please take note of a gotcha when you're in development environment and you click on the "Setup PayPal Commerce
101
+ Platform" button in the payment methods admin page. Once PayPal asks you to connect to a business account, we recommend
102
+ that you log in with the sandbox business account that comes with your PayPal developer account. If you create a new
103
+ sandbox business account here, the resulting account may not recognize your sandbox personal accounts, which can make
104
+ it difficult to test a successful cart checkout.
105
+
69
106
  ### Email Confirmation
70
107
 
71
108
  A confirmed email is required to get paid by PayPal. You'll need to check `Paypal Email Confirmed` on your new
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusPaypalCommercePlatform
4
+ module Spree
5
+ module Variant
6
+ module PricingOptionsDecorator
7
+ def cache_key
8
+ SolidusPaypalCommercePlatform::PaymentMethod.
9
+ active.
10
+ map(&:cache_key_with_version).
11
+ sort + [super]
12
+ end
13
+
14
+ ::Spree::Variant::PricingOptions.prepend self
15
+ end
16
+ end
17
+ end
18
+ end
@@ -17,7 +17,9 @@ module SolidusPaypalCommercePlatform
17
17
 
18
18
  validates :preferred_paypal_button_color, exclusion: {
19
19
  in: %w[gold],
20
- message: I18n.t("solidus_paypal_commerce_platform.payment_method.gold_button_message")
20
+ message: ->(_object, _data) do
21
+ I18n.t("solidus_paypal_commerce_platform.payment_method.gold_button_message")
22
+ end
21
23
  }, if: :venmo_standalone_enabled?
22
24
 
23
25
  def venmo_standalone_enabled?
@@ -83,7 +85,7 @@ module SolidusPaypalCommercePlatform
83
85
 
84
86
  parameters = {
85
87
  'client-id': client_id,
86
- intent: auto_capture ? "capture" : "authorize",
88
+ intent: auto_capture? ? "capture" : "authorize",
87
89
  commit: commit_immediately ? "false" : "true",
88
90
  components: options[:display_credit_messaging] ? "buttons,messages" : "buttons",
89
91
  currency: currency,
@@ -97,5 +99,22 @@ module SolidusPaypalCommercePlatform
97
99
 
98
100
  "https://www.paypal.com/sdk/js?#{parameters.compact.to_query}".html_safe # rubocop:disable Rails/OutputSafety
99
101
  end
102
+
103
+ # Will void the payment depending on its state or return false
104
+ #
105
+ # If the payment has not yet been captured, we can void the transaction.
106
+ # Otherwise, we return false so Solidus creates a refund instead.
107
+ #
108
+ # https://developer.paypal.com/docs/api/payments/v2/#authorizations_void
109
+ #
110
+ # @api public
111
+ # @param payment [Spree::Payment] the payment to void
112
+ # @return [Response|FalseClass]
113
+ def try_void(payment)
114
+ void_attempt = void(nil, { originator: payment })
115
+ return void_attempt if void_attempt.success?
116
+
117
+ false
118
+ end
100
119
  end
101
120
  end
data/bin/sandbox CHANGED
@@ -50,10 +50,12 @@ fi
50
50
  cd ./sandbox
51
51
  unbundled bundle add solidus --github solidusio/solidus --branch "${BRANCH:-master}" --version '> 0.a'
52
52
  unbundled bundle exec rake db:drop db:create
53
- unbundled bundle exec rails generate solidus:install --auto-accept "$@"
53
+ unbundled bundle exec rails generate solidus:install --payment-method=none --auto-accept "$@"
54
+ unbundled bundle add ${extension_name} --path '../'
55
+ unbundled bundle exec rails generate ${extension_name}:install --frontend=starter --migrate=true
54
56
 
55
57
  echo
56
- echo "🚀 Sandbox app successfully created for $extension_name!"
58
+ echo "🚀 Sandbox app successfully created for ${extension_name}!"
57
59
  echo "🚀 Using $RAILSDB and Solidus $BRANCH"
58
60
  echo "🚀 Use 'export DB=[postgres|mysql|sqlite]' to control the DB adapter"
59
61
  echo "🚀 Use 'export SOLIDUS_BRANCH=<BRANCH-NAME>' to control the Solidus version"
@@ -40,6 +40,7 @@ en:
40
40
  success: "Payment refunded for %{amount}"
41
41
  pay_pal_checkout_sdk/payments/authorizations_void_request:
42
42
  success: "Payment voided"
43
+ failure: "This payment can't be voided"
43
44
  payment_method:
44
45
  gold_button_message: "cannot be 'gold' when Venmo standalone is enabled."
45
46
  paypal_funding_sources:
@@ -5,7 +5,7 @@ module SolidusPaypalCommercePlatform
5
5
  class InstallGenerator < Rails::Generators::Base
6
6
  class_option :migrate, type: :boolean, default: true
7
7
  class_option :backend, type: :boolean, default: true
8
- class_option :starter_frontend, type: :boolean, default: true
8
+ class_option :frontend, type: :string, default: 'starter'
9
9
 
10
10
  # This is only used to run all-specs during development and CI, regular installation limits
11
11
  # installed specs to frontend, which are the ones related to code copied to the target application.
@@ -13,6 +13,14 @@ module SolidusPaypalCommercePlatform
13
13
 
14
14
  source_root File.expand_path('templates', __dir__)
15
15
 
16
+ def normalize_components_options
17
+ @components = {
18
+ backend: options[:backend],
19
+ starter_frontend: options[:frontend] == 'starter',
20
+ classic_frontend: options[:frontend] == 'classic',
21
+ }
22
+ end
23
+
16
24
  def install_solidus_core_support
17
25
  directory 'config/initializers', 'config/initializers'
18
26
  rake 'railties:install:migrations FROM=solidus_paypal_commerce_platform'
@@ -70,10 +78,21 @@ module SolidusPaypalCommercePlatform
70
78
  end
71
79
  end
72
80
 
81
+ def alert_no_classic_frontend_support
82
+ support_code_for(:classic_frontend) do
83
+ message = <<~TEXT
84
+ For solidus_frontend compatibility, please use the deprecated version 0.x.
85
+ The new version of this extension only supports Solidus Starter Frontend.
86
+ No frontend code has been copied to your application.
87
+ TEXT
88
+ say_status :error, set_color(message.tr("\n", ' '), :red), :red
89
+ end
90
+ end
91
+
73
92
  private
74
93
 
75
94
  def support_code_for(component_name, &block)
76
- if options[component_name]
95
+ if @components[component_name]
77
96
  say_status :install, "[#{engine.engine_name}] solidus_#{component_name}", :blue
78
97
  shell.indent(&block)
79
98
  else
@@ -7,7 +7,7 @@ module SolidusPaypalCommercePlatform
7
7
 
8
8
  def show
9
9
  authorize! :show, @order, order_token
10
- order_request = @payment_method.gateway.create_order(@order, @payment_method.auto_capture)
10
+ order_request = @payment_method.gateway.create_order(@order, @payment_method.auto_capture?)
11
11
 
12
12
  render json: order_request, status: order_request.status_code
13
13
  end
@@ -34,12 +34,6 @@ module SolidusPaypalCommercePlatform
34
34
  app.config.spree.payment_setup_wizards << "SolidusPaypalCommercePlatform::Wizard"
35
35
  end
36
36
 
37
- initializer "solidus_paypal_commerce_platform.set_pricing_options_class" do
38
- def (Spree::Config).pricing_options_class
39
- SolidusPaypalCommercePlatform::PricingOptions
40
- end
41
- end
42
-
43
37
  initializer "solidus_paypal_commerce_platform.webhooks" do
44
38
  SolidusWebhooks.config.register_webhook_handler :solidus_paypal_commerce_platform, ->(payload) {
45
39
  SolidusPaypalCommercePlatform::WebhooksJob.perform_now(payload)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusPaypalCommercePlatform
4
- VERSION = '1.0.0.beta2'
4
+ VERSION = '1.0.0.beta3'
5
5
  end
@@ -24,8 +24,12 @@ RSpec.describe SolidusPaypalCommercePlatform::PaymentMethod, type: :model do
24
24
 
25
25
  it 'cannot be gold when Venmo standalone is enabled' do
26
26
  expect(paypal_payment_method).to be_valid
27
+
27
28
  paypal_payment_method.preferences.update(venmo_standalone: 'enabled')
28
29
  expect(paypal_payment_method).to be_invalid
30
+ expect(paypal_payment_method.errors[:preferred_paypal_button_color])
31
+ .to include(I18n.t("solidus_paypal_commerce_platform.payment_method.gold_button_message"))
32
+
29
33
  paypal_payment_method.preferences.update(venmo_standalone: 'only render standalone')
30
34
  expect(paypal_payment_method).to be_invalid
31
35
  end
@@ -96,6 +100,32 @@ RSpec.describe SolidusPaypalCommercePlatform::PaymentMethod, type: :model do
96
100
  end
97
101
  end
98
102
 
103
+ describe "#try_void" do
104
+ context "when the payment is already captured" do
105
+ let(:status_code) { 500 }
106
+
107
+ it "returns false" do
108
+ authorization_id = SecureRandom.hex(8)
109
+ source = paypal_payment_method.payment_source_class.create(authorization_id: authorization_id)
110
+ payment.source = source
111
+
112
+ expect(paypal_payment_method.try_void(payment)).to be_falsey
113
+ end
114
+ end
115
+
116
+ context "when the payment is not yet captured" do
117
+ let(:status_code) { 204 }
118
+
119
+ it "returns the success response" do
120
+ authorization_id = SecureRandom.hex(8)
121
+ source = paypal_payment_method.payment_source_class.create(authorization_id: authorization_id)
122
+ payment.source = source
123
+
124
+ expect(paypal_payment_method.try_void(payment)).to be_success
125
+ end
126
+ end
127
+ end
128
+
99
129
  describe "#credit" do
100
130
  let(:result) { Struct(id: SecureRandom.hex(4)) }
101
131
 
@@ -127,6 +157,31 @@ RSpec.describe SolidusPaypalCommercePlatform::PaymentMethod, type: :model do
127
157
  end
128
158
  end
129
159
 
160
+ context 'when autocapture value is true' do
161
+ it 'sets the intent to capture' do
162
+ paypal_payment_method.update(auto_capture: true)
163
+
164
+ expect(url.query.split("&")).to include("intent=capture")
165
+ end
166
+ end
167
+
168
+ context 'when autocapture value is false' do
169
+ it 'sets the intent to capture' do
170
+ paypal_payment_method.update(auto_capture: false)
171
+
172
+ expect(url.query.split("&")).to include("intent=authorize")
173
+ end
174
+ end
175
+
176
+ context 'when autocapture value is nil' do
177
+ it 'sets the intent to the global auto_capture value' do
178
+ paypal_payment_method.update(auto_capture: nil)
179
+ stub_spree_preferences(auto_capture: true)
180
+
181
+ expect(url.query.split("&")).to include("intent=capture")
182
+ end
183
+ end
184
+
130
185
  context 'when messaging is turned on' do
131
186
  it 'includes messaging component' do
132
187
  paypal_payment_method.preferences.update(display_credit_messaging: true)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_paypal_commerce_platform
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta2
4
+ version: 1.0.0.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Denny
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-12-12 00:00:00.000000000 Z
12
+ date: 2023-01-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: deface
@@ -132,6 +132,7 @@ files:
132
132
  - app/assets/javascripts/spree/backend/solidus_paypal_commerce_platform/wizard.js
133
133
  - app/assets/stylesheets/spree/backend/solidus_paypal_commerce_platform.css
134
134
  - app/decorators/models/solidus_paypal_commerce_platform/spree/address_decorator.rb
135
+ - app/decorators/models/solidus_paypal_commerce_platform/spree/variant/pricing_options_decorator.rb
135
136
  - app/helpers/solidus_paypal_commerce_platform/button_options_helper.rb
136
137
  - app/jobs/solidus_paypal_commerce_platform/application_job.rb
137
138
  - app/jobs/solidus_paypal_commerce_platform/webhook_job.rb
@@ -140,7 +141,6 @@ files:
140
141
  - app/models/solidus_paypal_commerce_platform/payment_source.rb
141
142
  - app/models/solidus_paypal_commerce_platform/paypal_address.rb
142
143
  - app/models/solidus_paypal_commerce_platform/paypal_order.rb
143
- - app/models/solidus_paypal_commerce_platform/pricing_options.rb
144
144
  - app/models/solidus_paypal_commerce_platform/state_guesser.rb
145
145
  - app/models/solidus_paypal_commerce_platform/wizard.rb
146
146
  - app/overrides/spree/admin/payment_methods/form/insert_email_verification_notification.rb
@@ -274,7 +274,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
274
274
  - !ruby/object:Gem::Version
275
275
  version: 1.3.1
276
276
  requirements: []
277
- rubygems_version: 3.3.23
277
+ rubygems_version: 3.3.7
278
278
  signing_key:
279
279
  specification_version: 4
280
280
  summary: Integrate Solidus with Paypal Commerce Platform
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SolidusPaypalCommercePlatform
4
- class PricingOptions < ::Spree::Variant::PricingOptions
5
- def cache_key
6
- SolidusPaypalCommercePlatform::PaymentMethod.active.map(&:cache_key_with_version).sort + [super]
7
- end
8
- end
9
- end