solidus_paypal_commerce_platform 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/.github/stale.yml +4 -4
  3. data/.github_changelog_generator +2 -0
  4. data/.rubocop.yml +1 -14
  5. data/CHANGELOG.md +96 -0
  6. data/README.md +22 -25
  7. data/app/controllers/solidus_paypal_commerce_platform/orders_controller.rb +6 -4
  8. data/app/models/solidus_paypal_commerce_platform/payment_method.rb +2 -0
  9. data/bin/sandbox +1 -1
  10. data/lib/generators/solidus_paypal_commerce_platform/install/install_generator.rb +9 -0
  11. data/lib/generators/solidus_paypal_commerce_platform/install/templates/initializer.rb +6 -0
  12. data/lib/solidus_paypal_commerce_platform.rb +7 -5
  13. data/lib/solidus_paypal_commerce_platform/client.rb +2 -2
  14. data/lib/solidus_paypal_commerce_platform/configuration.rb +4 -0
  15. data/lib/solidus_paypal_commerce_platform/{factories.rb → testing_support/factories.rb} +0 -0
  16. data/lib/solidus_paypal_commerce_platform/version.rb +1 -1
  17. data/lib/views/frontend/solidus_paypal_commerce_platform/shared/_javascript_sdk_tag.html.erb +4 -0
  18. data/lib/views/frontend/spree/checkout/payment/_paypal_commerce_platform.html.erb +6 -1
  19. data/lib/views/frontend/spree/orders/payment/_paypal_commerce_platform.html.erb +3 -2
  20. data/lib/views/frontend/spree/products/payment/_paypal_commerce_platform.html.erb +3 -2
  21. data/solidus_paypal_commerce_platform.gemspec +3 -3
  22. data/spec/features/frontend/cart_spec.rb +16 -14
  23. data/spec/features/frontend/checkout_spec.rb +16 -14
  24. data/spec/features/frontend/product_spec.rb +17 -15
  25. data/spec/lib/solidus_paypal_commerce_platform/configuration_spec.rb +6 -0
  26. data/spec/models/solidus_paypal_commerce_platform/payment_method_spec.rb +19 -0
  27. data/spec/spec_helper.rb +2 -2
  28. data/spec/support/paypal_sdk_script_tag_helper.rb +13 -0
  29. metadata +16 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9978b8449f0f9ae68173743517e3b4c1316a590e9407fff1768eeef0b3a087a2
4
- data.tar.gz: 3fc6310b89a972b8950917e2ead0b23144e262d536f8465a9d2096ca51ec967b
3
+ metadata.gz: e33941522d8f8b2364c0ff2d374034c9dd4fb1e097902945ef39646ba5c1010a
4
+ data.tar.gz: 661106b06c08efb525dc3e869646f4ece38cabf4a92a895b923066f234d8dfd6
5
5
  SHA512:
6
- metadata.gz: 4d17b5204087cc10c13db4dc384cb7b961e37c50d13e775f05e4d7531e454be94798a072274b36e4b30557a1e58c2afe9671e035d7a50a8d7c7160845aa224e4
7
- data.tar.gz: 0df8558dd967fd6c8c62157a35f7b17809bb92cdbf5d8cfca5d622c34faef779f54bda2b61eb46a8ede1932db91f6a4b63fe7e6dde6b58c7f08d0edd29986d5c
6
+ metadata.gz: 007ff9cf231887d503172920a7585a832f3a109cab7557f72eaeb2f8493bc1c54dcac442ad2ba7c2c881b6bc71e7ac23dc5ece0a47290fc0af96d471812bb4b6
7
+ data.tar.gz: 25e7205d4bfa71b754660dab04ca2f627bbbab92d7ee8a751243aeae13df318ebe017139a024484411921c94d92974a0690e862cfdcb16ff6a1f73ac1d57cc98
@@ -1,17 +1,17 @@
1
1
  # Number of days of inactivity before an issue becomes stale
2
2
  daysUntilStale: 60
3
3
  # Number of days of inactivity before a stale issue is closed
4
- daysUntilClose: 7
4
+ daysUntilClose: false
5
5
  # Issues with these labels will never be considered stale
6
6
  exemptLabels:
7
7
  - pinned
8
8
  - security
9
9
  # Label to use when marking an issue as stale
10
- staleLabel: wontfix
10
+ staleLabel: stale
11
11
  # Comment to post when marking an issue as stale. Set to `false` to disable
12
12
  markComment: >
13
13
  This issue has been automatically marked as stale because it has not had
14
- recent activity. It will be closed if no further activity occurs. Thank you
14
+ recent activity. It might be closed if no further activity occurs. Thank you
15
15
  for your contributions.
16
16
  # Comment to post when closing a stale issue. Set to `false` to disable
17
- closeComment: false
17
+ closeComment: false
@@ -0,0 +1,2 @@
1
+ issues=false
2
+ exclude-labels=infrastructure
@@ -2,6 +2,7 @@ require:
2
2
  - solidus_dev_support/rubocop
3
3
 
4
4
  AllCops:
5
+ NewCops: enable
5
6
  Exclude:
6
7
  - sandbox/**/*
7
8
  - spec/dummy/**/*
@@ -62,17 +63,3 @@ Rails/Inquiry:
62
63
  Enabled: true
63
64
  Exclude:
64
65
  - spec/lib/solidus_paypal_commerce_platform/configuration_spec.rb
65
-
66
- # New cops (2020-09-03)
67
-
68
- Rails/ActiveRecordCallbacksOrder: {Enabled: true}
69
- Rails/FindById: {Enabled: true}
70
- Rails/MailerName: {Enabled: true}
71
- Rails/MatchRoute: {Enabled: true}
72
- Rails/NegateInclude: {Enabled: true}
73
- Rails/Pluck: {Enabled: true}
74
- Rails/PluckInWhere: {Enabled: true}
75
- Rails/RenderInline: {Enabled: true}
76
- Rails/RenderPlainText: {Enabled: true}
77
- Rails/ShortI18n: {Enabled: true}
78
- Rails/WhereExists: {Enabled: true}
@@ -0,0 +1,96 @@
1
+ # Changelog
2
+
3
+ ## [Unreleased](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/tree/HEAD)
4
+
5
+ [Full Changelog](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/compare/v0.1.0...HEAD)
6
+
7
+ **Merged pull requests:**
8
+
9
+ - Add PayPal messaging component [\#102](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/102) ([seand7565](https://github.com/seand7565))
10
+ - Add partner ID attribute to SDK javascript tag [\#101](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/101) ([seand7565](https://github.com/seand7565))
11
+ - Set current\_order\_id and token during payment step [\#100](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/100) ([MFRWDesign](https://github.com/MFRWDesign))
12
+ - Remove incorrect/unclear info from README [\#98](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/98) ([seand7565](https://github.com/seand7565))
13
+ - Update the extension with the latest solidus\_dev\_support defaults [\#95](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/95) ([elia](https://github.com/elia))
14
+ - Add skip migration option to installer [\#94](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/94) ([seand7565](https://github.com/seand7565))
15
+ - Update README to reflect referral fee [\#93](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/93) ([seand7565](https://github.com/seand7565))
16
+
17
+ ## [v0.1.0](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/tree/v0.1.0) (2020-09-03)
18
+
19
+ [Full Changelog](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/compare/v0.0.1...v0.1.0)
20
+
21
+ **Merged pull requests:**
22
+
23
+ - Temporarily switch from apparition to cuprite [\#92](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/92) ([elia](https://github.com/elia))
24
+ - Update links after moving the repo to solidusio-contrib [\#91](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/91) ([elia](https://github.com/elia))
25
+ - Add a configurable state\_guesser class to guess states [\#90](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/90) ([seand7565](https://github.com/seand7565))
26
+ - Add better error handling to button\_actions.js [\#89](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/89) ([seand7565](https://github.com/seand7565))
27
+
28
+ ## [v0.0.1](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/tree/v0.0.1) (2020-08-10)
29
+
30
+ [Full Changelog](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/compare/11111204cc53e8bcfd365ae70506c07940446b0c...v0.0.1)
31
+
32
+ **Implemented enhancements:**
33
+
34
+ - Webhooks [\#83](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/83) ([elia](https://github.com/elia))
35
+ - Display paypal email to customer on confirmation [\#54](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/54) ([seand7565](https://github.com/seand7565))
36
+ - Use an env accessor to control live/sandbox urls and classes [\#31](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/31) ([elia](https://github.com/elia))
37
+ - Add response object to API calls to PayPal [\#30](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/30) ([seand7565](https://github.com/seand7565))
38
+
39
+ **Fixed bugs:**
40
+
41
+ - Have different nonce for every click of the wizard button [\#87](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/87) ([elia](https://github.com/elia))
42
+ - Correctly communicate errors when updating shipping rates [\#86](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/86) ([elia](https://github.com/elia))
43
+ - Add deface to deps [\#57](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/57) ([elia](https://github.com/elia))
44
+
45
+ **Merged pull requests:**
46
+
47
+ - Use live partner ids [\#85](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/85) ([elia](https://github.com/elia))
48
+ - Update README to account for checkouts without a confirmation step [\#84](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/84) ([seand7565](https://github.com/seand7565))
49
+ - Replace order simulator with something simpler [\#82](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/82) ([seand7565](https://github.com/seand7565))
50
+ - Cleanup [\#81](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/81) ([elia](https://github.com/elia))
51
+ - Send line\_item and shipping promotions to PayPal [\#80](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/80) ([seand7565](https://github.com/seand7565))
52
+ - Change outstanding\_balance to total in order total checker [\#79](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/79) ([seand7565](https://github.com/seand7565))
53
+ - Add overlay to ease transition to confirmation page [\#78](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/78) ([seand7565](https://github.com/seand7565))
54
+ - Default available\_to\_users to true [\#77](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/77) ([seand7565](https://github.com/seand7565))
55
+ - Add info about PayPal Terminal to README [\#76](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/76) ([seand7565](https://github.com/seand7565))
56
+ - Return a payment declined error on the frontend [\#74](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/74) ([seand7565](https://github.com/seand7565))
57
+ - Only use the necessary data to let the spec pass [\#73](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/73) ([elia](https://github.com/elia))
58
+ - Display capture\_id instead of order\_id to admin user [\#72](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/72) ([seand7565](https://github.com/seand7565))
59
+ - Use options instead of preferences [\#67](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/67) ([seand7565](https://github.com/seand7565))
60
+ - Update README to reflect new preferences [\#66](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/66) ([seand7565](https://github.com/seand7565))
61
+ - Add version to cache\_key [\#65](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/65) ([seand7565](https://github.com/seand7565))
62
+ - Include payment method information in pricing options cache key [\#62](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/62) ([seand7565](https://github.com/seand7565))
63
+ - Only use available payment\_methods [\#61](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/61) ([seand7565](https://github.com/seand7565))
64
+ - Explicitly require deface [\#60](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/60) ([elia](https://github.com/elia))
65
+ - Verify email address is verified before allowing payment method to be available [\#59](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/59) ([seand7565](https://github.com/seand7565))
66
+ - Use the ORB definition of lint-code [\#58](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/58) ([elia](https://github.com/elia))
67
+ - Send amount of payment to PayPal on capture [\#56](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/56) ([seand7565](https://github.com/seand7565))
68
+ - Verify amount to charge with order total [\#55](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/55) ([seand7565](https://github.com/seand7565))
69
+ - Linting the project with rubocop [\#53](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/53) ([elia](https://github.com/elia))
70
+ - Add PayPal Debug ID to log entries [\#52](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/52) ([seand7565](https://github.com/seand7565))
71
+ - Fix PayPal request success message en.yml paths [\#51](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/51) ([seand7565](https://github.com/seand7565))
72
+ - Add configuration options to SolidusPaypalCommercePlatform [\#50](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/50) ([seand7565](https://github.com/seand7565))
73
+ - Add PayPal button to product page [\#45](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/45) ([seand7565](https://github.com/seand7565))
74
+ - Add PayPal Button To Cart Page [\#43](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/43) ([seand7565](https://github.com/seand7565))
75
+ - Add ability to change address on PayPal [\#42](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/42) ([seand7565](https://github.com/seand7565))
76
+ - Add a basic codecov config to show commit status [\#41](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/41) ([elia](https://github.com/elia))
77
+ - Add CI & Coverage badges to the readme [\#40](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/40) ([elia](https://github.com/elia))
78
+ - Rely on sdk request classes [\#39](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/39) ([elia](https://github.com/elia))
79
+ - Use "commit=false" in the JS SDK url when "confirm" step is present [\#33](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/33) ([elia](https://github.com/elia))
80
+ - Renames: Gateway → PaymentMethod / Requests → Gateway [\#32](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/32) ([elia](https://github.com/elia))
81
+ - Add PayPal Virtual Terminal notice to backend [\#25](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/25) ([seand7565](https://github.com/seand7565))
82
+ - Add missing partials necessary for backend [\#24](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/24) ([seand7565](https://github.com/seand7565))
83
+ - Add the ability to void authorized payments [\#23](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/23) ([seand7565](https://github.com/seand7565))
84
+ - Fix order controller response [\#22](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/22) ([seand7565](https://github.com/seand7565))
85
+ - Add refund ability to admin payment management [\#21](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/21) ([seand7565](https://github.com/seand7565))
86
+ - Fixes and refactoring [\#20](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/20) ([elia](https://github.com/elia))
87
+ - Add ability for admin users to customize paypal button [\#16](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/16) ([seand7565](https://github.com/seand7565))
88
+ - Restore the generic bin/rails command [\#11](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/11) ([elia](https://github.com/elia))
89
+ - Add PayPal buttons to frontend checkout flow [\#10](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/10) ([seand7565](https://github.com/seand7565))
90
+ - Update readme to reflect onboarding and wizards 🧙 [\#4](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/4) ([seand7565](https://github.com/seand7565))
91
+ - Add setup wizard for paypal commerce platform [\#3](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/3) ([seand7565](https://github.com/seand7565))
92
+ - Add paypal\_commerce\_platform as a payment method [\#2](https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/pull/2) ([seand7565](https://github.com/seand7565))
93
+
94
+
95
+
96
+ \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
data/README.md CHANGED
@@ -16,8 +16,7 @@ gem 'solidus_paypal_commerce_platform'
16
16
  Bundle your dependencies and run the installation generator:
17
17
 
18
18
  ```shell
19
- bundle
20
- bundle exec rails g solidus_paypal_commerce_platform:install
19
+ bin/rails generate solidus_paypal_commerce_platform:install
21
20
  ```
22
21
 
23
22
  ### PayPal Sandbox/Live Environment
@@ -26,26 +25,6 @@ This extension will automatically select a PayPal environment based on Rails env
26
25
 
27
26
  If you want to override these values you can either set `SolidusPaypalCommercePlatform.config.env` to `"live"` or `"sandbox"` inside an initializer. Or, alternatively, you can set the `PAYPAL_ENV` environment variable to one of the same two values.
28
27
 
29
- ### Custom PartnerID & PartnerClientID
30
-
31
- You can declare your PayPal Partner-ID and Partner-Client-ID as environment
32
- variables or set their values directly on `SolidusPaypalCommercePlatform.config`
33
- or by using the configuration method detailed in the Customization section.
34
-
35
- #### Use ENV variables
36
-
37
- ```shell
38
- export PAYPAL_PARTNER_ID="xxxxxxxxxxKG2"
39
- export PAYPAL_PARTNER_CLIENT_ID="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxVSX"
40
- ```
41
-
42
- #### Set them directly
43
-
44
- ```ruby
45
- SolidusPaypalCommercePlatform.config.partner_id = "xxxxxxxxxxKG2"
46
- SolidusPaypalCommercePlatform.config.partner_client_id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxVSX"
47
- ```
48
-
49
28
  ## Address Phone Number Validation
50
29
 
51
30
  Since PayPal is being used as the checkout if the user checks out on the product or cart page, and PayPal doesn't collect phone numbers, this extension disables phone number required validation for `Spree::Address`. To turn phone number validation back on, you'll need to either:
@@ -73,7 +52,6 @@ Spree::Config.configure do |config|
73
52
  test_mode: !Rails.env.production?,
74
53
  client_id: ENV['PAYPAL_CLIENT_ID'],
75
54
  client_secret: ENV['PAYPAL_CLIENT_SECRET'],
76
- paypal_email_confirmed: true,
77
55
  display_on_product_page: true,
78
56
  display_on_cart: true,
79
57
  }
@@ -172,7 +150,7 @@ the sandbox app is `./sandbox` and `bin/rails` will forward any Rails commands t
172
150
 
173
151
  Here's an example:
174
152
 
175
- ```shell
153
+ ```
176
154
  $ bin/rails server
177
155
  => Booting Puma
178
156
  => Rails 6.0.2.1 application starting in development
@@ -180,14 +158,33 @@ $ bin/rails server
180
158
  Use Ctrl-C to stop
181
159
  ```
182
160
 
161
+ ### Updating the changelog
162
+
163
+ Before and after releases the changelog should be updated to reflect the up-to-date status of
164
+ the project:
165
+
166
+ ```shell
167
+ bin/rake changelog
168
+ git add CHANGELOG.md
169
+ git commit -m "Update the changelog"
170
+ ```
171
+
183
172
  ### Releasing new versions
184
173
 
185
174
  Your new extension version can be released using `gem-release` like this:
186
175
 
187
176
  ```shell
188
- bundle exec gem bump -v VERSION --tag --push --remote origin && gem release
177
+ bundle exec gem bump -v 1.6.0
178
+ bin/rake changelog
179
+ git commit -a --amend
180
+ git push
181
+ bundle exec gem release
189
182
  ```
190
183
 
184
+ ## Referral Fee
185
+
186
+ By using this extension, you are giving back to Solidus. PayPal will pay a fee to the maintainers ([Nebulab](https://nebulab.it)) for each order made through the payment gateway.
187
+
191
188
  ## License
192
189
 
193
190
  Copyright (c) 2020 Nebulab srls, released under the New BSD License
@@ -64,10 +64,12 @@ module SolidusPaypalCommercePlatform
64
64
  ],
65
65
  recipient: [
66
66
  :email_address,
67
- name: [
68
- :given_name,
69
- :surname,
70
- ]
67
+ {
68
+ name: [
69
+ :given_name,
70
+ :surname,
71
+ ]
72
+ }
71
73
  ]
72
74
  )
73
75
  end
@@ -11,6 +11,7 @@ module SolidusPaypalCommercePlatform
11
11
  preference :paypal_button_layout, :paypal_select, default: "vertical"
12
12
  preference :display_on_cart, :boolean, default: true
13
13
  preference :display_on_product_page, :boolean, default: true
14
+ preference :display_credit_messaging, :boolean, default: true
14
15
 
15
16
  def partial_name
16
17
  "paypal_commerce_platform"
@@ -67,6 +68,7 @@ module SolidusPaypalCommercePlatform
67
68
  'client-id': client_id,
68
69
  intent: auto_capture ? "capture" : "authorize",
69
70
  commit: commit_immediately ? "false" : "true",
71
+ components: options[:display_credit_messaging] ? "buttons,messages" : "buttons",
70
72
  }
71
73
 
72
74
  "https://www.paypal.com/sdk/js?#{parameters.to_query}"
@@ -72,7 +72,7 @@ unbundled bundle exec rails generate spree:install \
72
72
  --user_class=Spree::User \
73
73
  --enforce_available_locales=true \
74
74
  --with-authentication=false \
75
- --payment-method=none
75
+ --payment-method=none \
76
76
  $@
77
77
 
78
78
  unbundled bundle exec rails generate solidus:auth:install
@@ -4,6 +4,13 @@ module SolidusPaypalCommercePlatform
4
4
  module Generators
5
5
  class InstallGenerator < Rails::Generators::Base
6
6
  class_option :auto_run_migrations, type: :boolean, default: false
7
+ class_option :skip_migrations, type: :boolean, default: false
8
+
9
+ source_root File.expand_path('templates', __dir__)
10
+
11
+ def copy_initializer
12
+ template 'initializer.rb', 'config/initializers/solidus_paypal_commerce_platform.rb'
13
+ end
7
14
 
8
15
  def add_javascripts
9
16
  append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_paypal_commerce_platform\n" # rubocop:disable Layout/LineLength
@@ -26,6 +33,8 @@ module SolidusPaypalCommercePlatform
26
33
  end
27
34
 
28
35
  def run_migrations
36
+ return if options[:skip_migrations]
37
+
29
38
  run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) # rubocop:disable Layout/LineLength
30
39
  if run_migrations
31
40
  run 'bin/rails db:migrate'
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ SolidusPaypalCommercePlatform.configure do |config|
4
+ # TODO: Remember to change this with the actual preferences you have implemented!
5
+ # config.sample_preference = 'sample_value'
6
+ end
@@ -3,19 +3,21 @@
3
3
  require 'solidus_core'
4
4
  require 'solidus_support'
5
5
 
6
- require 'solidus_paypal_commerce_platform/version'
7
- require 'solidus_paypal_commerce_platform/configuration'
8
6
  require 'solidus_paypal_commerce_platform/client'
7
+ require 'solidus_paypal_commerce_platform/configuration'
8
+ require 'solidus_paypal_commerce_platform/version'
9
9
  require 'solidus_paypal_commerce_platform/engine'
10
10
 
11
11
  module SolidusPaypalCommercePlatform
12
12
  class << self
13
- def config
14
- @config ||= Configuration.new
13
+ def configuration
14
+ @configuration ||= Configuration.new
15
15
  end
16
16
 
17
+ alias config configuration
18
+
17
19
  def configure
18
- yield config
20
+ yield configuration
19
21
  end
20
22
  end
21
23
  end
@@ -10,12 +10,12 @@ module SolidusPaypalCommercePlatform
10
10
  SUCCESS_STATUS_CODES = [201, 204].freeze
11
11
 
12
12
  PARTNER_ATTRIBUTION_INJECTOR = ->(request) {
13
- request.headers["PayPal-Partner-Attribution-Id"] = "Solidus_PCP_SP"
13
+ request.headers["PayPal-Partner-Attribution-Id"] = SolidusPaypalCommercePlatform.config.partner_code
14
14
  }.freeze
15
15
 
16
16
  attr_reader :environment
17
17
 
18
- def initialize(test_mode: nil, client_id:, client_secret: "")
18
+ def initialize(client_id:, client_secret: "", test_mode: nil)
19
19
  test_mode = SolidusPaypalCommercePlatform.config.env.sandbox? if test_mode.nil?
20
20
  env_class = test_mode ? PayPal::SandboxEnvironment : PayPal::LiveEnvironment
21
21
 
@@ -66,5 +66,9 @@ module SolidusPaypalCommercePlatform
66
66
  def partner_client_id
67
67
  @partner_client_id ||= ENV['PAYPAL_PARTNER_CLIENT_ID'] || DEFAULT_PARTNER_CLIENT_ID[env.to_sym]
68
68
  end
69
+
70
+ def partner_code
71
+ "Solidus_PCP_SP"
72
+ end
69
73
  end
70
74
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusPaypalCommercePlatform
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -0,0 +1,4 @@
1
+ <script
2
+ src="<%= payment_method.javascript_sdk_url(order: @order) %>"
3
+ data-partner-attribution-id="<%= SolidusPaypalCommercePlatform.config.partner_code %>">
4
+ </script>
@@ -1,10 +1,15 @@
1
- <script src="<%= payment_method.javascript_sdk_url(order: @order) %>"></script>
1
+ <%= render partial: "solidus_paypal_commerce_platform/shared/javascript_sdk_tag", locals: {payment_method: payment_method} %>
2
2
 
3
3
  <div id="paypal-button-container"></div>
4
+
5
+ <div data-pp-message data-pp-placement="payment" data-pp-amount="<%= @order.total %>"></div>
6
+
4
7
  <input type="hidden" name="payment_source[<%= payment_method.id %>][paypal_order_id]" id="payments_source_paypal_order_id">
5
8
  <input type="hidden" name="payment_source[<%= payment_method.id %>][paypal_email]" id="payments_source_paypal_email">
6
9
 
7
10
  <script>
11
+ Spree.current_order_id = "<%= @order.number %>"
12
+ Spree.current_order_token = "<%= @order.guest_token %>"
8
13
  $( document ).ready(function() {
9
14
  SolidusPaypalCommercePlatform.renderButton("<%= payment_method.id %>",<%= raw payment_method.button_style.to_json %>)
10
15
  })
@@ -1,9 +1,10 @@
1
1
  <div style="margin-left:auto;margin-right:auto;width:50%;margin-top:20px;">
2
- <script src="<%= payment_method.javascript_sdk_url(order: @order) %>">
3
- </script>
2
+ <%= render partial: "solidus_paypal_commerce_platform/shared/javascript_sdk_tag", locals: {payment_method: payment_method} %>
4
3
 
5
4
  <div id="paypal-button-container"></div>
6
5
 
6
+ <div data-pp-message data-pp-placement="cart" data-pp-amount="<%= @order.total %>"></div>
7
+
7
8
  <script>
8
9
  Spree.current_order_id = "<%= @order.number %>"
9
10
  Spree.current_order_token = "<%= @order.guest_token %>"
@@ -1,9 +1,10 @@
1
1
  <div style="margin-top:20px;">
2
- <script src="<%= payment_method.javascript_sdk_url %>">
3
- </script>
2
+ <%= render partial: "solidus_paypal_commerce_platform/shared/javascript_sdk_tag", locals: {payment_method: payment_method} %>
4
3
 
5
4
  <div id="paypal-button-container"></div>
6
5
 
6
+ <div data-pp-message data-pp-placement="product" data-pp-amount="<%= @product.price %>"></div>
7
+
7
8
  <script>
8
9
  SolidusPaypalCommercePlatform.checkout_url = "<%= checkout_url %>"
9
10
  $( document ).ready(function() {
@@ -9,11 +9,11 @@ Gem::Specification.new do |spec|
9
9
  spec.email = 'contact@solidus.io'
10
10
 
11
11
  spec.summary = 'Integrate Solidus with Paypal Commerce Platform'
12
- spec.homepage = 'https://github.com/solidusio-contrib/solidus_paypal_commerce_platform#readme'
12
+ spec.homepage = 'https://github.com/solidusio-contrib/solidus_paypal_commerce_platform'
13
13
  spec.license = 'BSD-3-Clause'
14
14
 
15
15
  spec.metadata['homepage_uri'] = spec.homepage
16
- spec.metadata['source_code_uri'] = 'https://github.com/solidusio-contrib/solidus_paypal_commerce_platform#readme'
16
+ spec.metadata['source_code_uri'] = 'https://github.com/solidusio-contrib/solidus_paypal_commerce_platform'
17
17
  spec.metadata['changelog_uri'] = 'https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/releases'
18
18
 
19
19
  spec.required_ruby_version = Gem::Requirement.new('~> 2.5')
@@ -36,5 +36,5 @@ Gem::Specification.new do |spec|
36
36
  spec.add_dependency 'paypal-checkout-sdk'
37
37
 
38
38
  spec.add_development_dependency 'cuprite'
39
- spec.add_development_dependency 'solidus_dev_support'
39
+ spec.add_development_dependency 'solidus_dev_support', '~> 2.1'
40
40
  end
@@ -16,22 +16,24 @@ RSpec.describe "Cart page" do
16
16
  )
17
17
  end
18
18
 
19
- def paypal_script_options
20
- script_tag_url = URI(page.find('script[src*="sdk/js?"]', visible: false)[:src])
21
- script_tag_url.query.split('&')
22
- end
23
-
24
- it "generate a js file with the correct credentials and intent attached" do
25
- visit '/cart'
26
- expect(paypal_script_options).to include("client-id=#{paypal_payment_method.preferences[:client_id]}")
27
- end
19
+ context "when generating a script tag" do
20
+ it "generates a url with the correct credentials attached" do
21
+ visit '/cart'
22
+ expect(js_sdk_script_query).to include("client-id=#{paypal_payment_method.preferences[:client_id]}")
23
+ end
28
24
 
29
- context "when auto-capture is set to true" do
30
- it "generate a js file with intent capture" do
31
- paypal_payment_method.update(auto_capture: true)
25
+ it "generates a partner_id attribute with the correct partner code attached" do
32
26
  visit '/cart'
33
- expect(paypal_script_options).to include("client-id=#{paypal_payment_method.preferences[:client_id]}")
34
- expect(paypal_script_options).to include("intent=capture")
27
+ expect(js_sdk_script_partner_id).to eq("Solidus_PCP_SP")
28
+ end
29
+
30
+ context "when auto-capture is set to true" do
31
+ it "generates a url with intent capture" do
32
+ paypal_payment_method.update(auto_capture: true)
33
+ visit '/cart'
34
+ expect(js_sdk_script_query).to include("client-id=#{paypal_payment_method.preferences[:client_id]}")
35
+ expect(js_sdk_script_query).to include("intent=capture")
36
+ end
35
37
  end
36
38
  end
37
39
  end
@@ -17,22 +17,24 @@ RSpec.describe "Checkout" do
17
17
  )
18
18
  end
19
19
 
20
- def paypal_script_options
21
- script_tag_url = URI(page.find('script[src*="sdk/js?"]', visible: false)[:src])
22
- script_tag_url.query.split('&')
23
- end
24
-
25
- it "generates a js file with the correct credentials and intent attached" do
26
- visit '/checkout/payment'
27
- expect(paypal_script_options).to include("client-id=#{paypal_payment_method.preferences[:client_id]}")
28
- end
20
+ context "when generating a script tag" do
21
+ it "generates a url with the correct credentials attached" do
22
+ visit '/checkout/payment'
23
+ expect(js_sdk_script_query).to include("client-id=#{paypal_payment_method.preferences[:client_id]}")
24
+ end
29
25
 
30
- context "when auto-capture is set to true" do
31
- it "generates a js file with intent capture" do
32
- paypal_payment_method.update(auto_capture: true)
26
+ it "generates a partner_id attribute with the correct partner code attached" do
33
27
  visit '/checkout/payment'
34
- expect(paypal_script_options).to include("client-id=#{paypal_payment_method.preferences[:client_id]}")
35
- expect(paypal_script_options).to include("intent=capture")
28
+ expect(js_sdk_script_partner_id).to eq("Solidus_PCP_SP")
29
+ end
30
+
31
+ context "when auto-capture is set to true" do
32
+ it "generates a url with intent capture" do
33
+ paypal_payment_method.update(auto_capture: true)
34
+ visit '/checkout/payment'
35
+ expect(js_sdk_script_query).to include("client-id=#{paypal_payment_method.preferences[:client_id]}")
36
+ expect(js_sdk_script_query).to include("intent=capture")
37
+ end
36
38
  end
37
39
  end
38
40
 
@@ -12,29 +12,31 @@ RSpec.describe "Product page", js: true do
12
12
  paypal_payment_method
13
13
  end
14
14
 
15
- def paypal_script_options
16
- script_tag_url = URI(page.find('script[src*="sdk/js?"]', visible: false)[:src])
17
- script_tag_url.query.split('&')
18
- end
15
+ context "when generating a script tag" do
16
+ it "generates a url with the correct credentials attached" do
17
+ visit "/products/#{product.slug}"
18
+ expect(js_sdk_script_query).to include("client-id=#{paypal_payment_method.preferences[:client_id]}")
19
+ end
19
20
 
20
- it "generates a js file with the correct credentials and intent attached" do
21
- visit '/products/' + product.slug
22
- expect(paypal_script_options).to include("client-id=#{paypal_payment_method.preferences[:client_id]}")
23
- end
21
+ it "generates a partner_id attribute with the correct partner code attached" do
22
+ visit "/products/#{product.slug}"
23
+ expect(js_sdk_script_partner_id).to eq("Solidus_PCP_SP")
24
+ end
24
25
 
25
- context "when auto-capture is set to true" do
26
- it "generates a js file with intent capture" do
27
- paypal_payment_method.update(auto_capture: true)
28
- visit '/products/' + product.slug
29
- expect(paypal_script_options).to include("client-id=#{paypal_payment_method.preferences[:client_id]}")
30
- expect(paypal_script_options).to include("intent=capture")
26
+ context "when auto-capture is set to true" do
27
+ it "generates a url with intent capture" do
28
+ paypal_payment_method.update(auto_capture: true)
29
+ visit "/products/#{product.slug}"
30
+ expect(js_sdk_script_query).to include("client-id=#{paypal_payment_method.preferences[:client_id]}")
31
+ expect(js_sdk_script_query).to include("intent=capture")
32
+ end
31
33
  end
32
34
  end
33
35
 
34
36
  describe "order creation" do
35
37
  before do
36
38
  allow_any_instance_of(Spree::Core::ControllerHelpers::Store).to receive(:current_store) { store }
37
- visit '/products/' + product.slug
39
+ visit "/products/#{product.slug}"
38
40
 
39
41
  # Stubbing out paypal methods since their JS doesn't load in correctly on tests
40
42
  page.execute_script("paypal = {}")
@@ -82,4 +82,10 @@ RSpec.describe SolidusPaypalCommercePlatform::Configuration do
82
82
  expect(subject.state_guesser_class).to eq(SolidusPaypalCommercePlatform::BetterStateGuesser)
83
83
  end
84
84
  end
85
+
86
+ describe "#partner_code" do
87
+ it "returns the correct code" do
88
+ expect(subject.partner_code).to eq("Solidus_PCP_SP")
89
+ end
90
+ end
85
91
  end
@@ -92,6 +92,25 @@ RSpec.describe SolidusPaypalCommercePlatform::PaymentMethod, type: :model do
92
92
  expect(url.query.split("&")).to include("commit=true")
93
93
  end
94
94
  end
95
+
96
+ context 'when messaging is turned on' do
97
+ let(:order) { instance_double(Spree::Order, checkout_steps: { "foo" => "bar" }) }
98
+
99
+ it 'includes messaging component' do
100
+ paypal_payment_method.preferences.update(display_credit_messaging: true)
101
+ expect(url.query.split("&")).to include("components=buttons%2Cmessages")
102
+ end
103
+ end
104
+
105
+ context 'when messaging is turned off' do
106
+ let(:order) { instance_double(Spree::Order, checkout_steps: { "foo" => "bar" }) }
107
+
108
+ it 'only includes buttons components' do
109
+ paypal_payment_method.preferences.update(display_credit_messaging: false)
110
+ expect(url.query.split("&")).not_to include("messages")
111
+ expect(url.query.split("&")).to include("components=buttons")
112
+ end
113
+ end
95
114
  end
96
115
 
97
116
  private
@@ -19,8 +19,8 @@ require 'spree/testing_support/order_walkthrough'
19
19
  # in spec/support/ and its subdirectories.
20
20
  Dir["#{__dir__}/support/**/*.rb"].sort.each { |f| require f }
21
21
 
22
- # Requires factories defined in lib/solidus_paypal_commerce_platform/factories.rb
23
- require 'solidus_paypal_commerce_platform/factories'
22
+ # Requires factories defined in lib/solidus_paypal_commerce_platform/testing_support/factories.rb
23
+ require 'solidus_paypal_commerce_platform/testing_support/factories'
24
24
 
25
25
  RSpec.configure do |config|
26
26
  config.infer_spec_type_from_file_location!
@@ -0,0 +1,13 @@
1
+ module PaypalSdkScriptTagHelper
2
+ def js_sdk_script_query
3
+ URI(page.find('script[src*="sdk/js?"]', visible: false)[:src]).query.split('&')
4
+ end
5
+
6
+ def js_sdk_script_partner_id
7
+ page.find('script[src*="sdk/js?"]', visible: false)['data-partner-attribution-id']
8
+ end
9
+ end
10
+
11
+ RSpec.configure do |config|
12
+ config.include PaypalSdkScriptTagHelper, type: :feature
13
+ end
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: 0.1.0
4
+ version: 0.2.0
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: 2020-09-03 00:00:00.000000000 Z
12
+ date: 2020-10-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: deface
@@ -105,16 +105,16 @@ dependencies:
105
105
  name: solidus_dev_support
106
106
  requirement: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: '2.1'
111
111
  type: :development
112
112
  prerelease: false
113
113
  version_requirements: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">="
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0'
117
+ version: '2.1'
118
118
  description:
119
119
  email: contact@solidus.io
120
120
  executables: []
@@ -124,9 +124,11 @@ files:
124
124
  - ".circleci/config.yml"
125
125
  - ".gem_release.yml"
126
126
  - ".github/stale.yml"
127
+ - ".github_changelog_generator"
127
128
  - ".gitignore"
128
129
  - ".rspec"
129
130
  - ".rubocop.yml"
131
+ - CHANGELOG.md
130
132
  - Gemfile
131
133
  - LICENSE
132
134
  - README.md
@@ -179,13 +181,14 @@ files:
179
181
  - config/routes.rb
180
182
  - db/migrate/20200521190038_add_paypal_commerce_platform_sources.rb
181
183
  - lib/generators/solidus_paypal_commerce_platform/install/install_generator.rb
184
+ - lib/generators/solidus_paypal_commerce_platform/install/templates/initializer.rb
182
185
  - lib/solidus_paypal_commerce_platform.rb
183
186
  - lib/solidus_paypal_commerce_platform/access_token_authorization_request.rb
184
187
  - lib/solidus_paypal_commerce_platform/client.rb
185
188
  - lib/solidus_paypal_commerce_platform/configuration.rb
186
189
  - lib/solidus_paypal_commerce_platform/engine.rb
187
- - lib/solidus_paypal_commerce_platform/factories.rb
188
190
  - lib/solidus_paypal_commerce_platform/fetch_merchant_credentials_request.rb
191
+ - lib/solidus_paypal_commerce_platform/testing_support/factories.rb
189
192
  - lib/solidus_paypal_commerce_platform/version.rb
190
193
  - lib/views/api/spree/api/payments/source_views/_paypal_commerce_platform.json.jbuilder
191
194
  - lib/views/backend/spree/admin/payments/source_forms/_paypal_commerce_platform.html.erb
@@ -194,6 +197,7 @@ files:
194
197
  - lib/views/frontend/solidus_paypal_commerce_platform/cart/_cart_buttons.html.erb
195
198
  - lib/views/frontend/solidus_paypal_commerce_platform/payments/_payment.html.erb
196
199
  - lib/views/frontend/solidus_paypal_commerce_platform/product/_product_buttons.html.erb
200
+ - lib/views/frontend/solidus_paypal_commerce_platform/shared/_javascript_sdk_tag.html.erb
197
201
  - lib/views/frontend/spree/checkout/payment/_paypal_commerce_platform.html.erb
198
202
  - lib/views/frontend/spree/orders/payment/_paypal_commerce_platform.html.erb
199
203
  - lib/views/frontend/spree/products/payment/_paypal_commerce_platform.html.erb
@@ -223,12 +227,13 @@ files:
223
227
  - spec/requests/solidus_paypal_commerce_platform/wizard_controller_spec.rb
224
228
  - spec/spec_helper.rb
225
229
  - spec/support/capybara.rb
226
- homepage: https://github.com/solidusio-contrib/solidus_paypal_commerce_platform#readme
230
+ - spec/support/paypal_sdk_script_tag_helper.rb
231
+ homepage: https://github.com/solidusio-contrib/solidus_paypal_commerce_platform
227
232
  licenses:
228
233
  - BSD-3-Clause
229
234
  metadata:
230
- homepage_uri: https://github.com/solidusio-contrib/solidus_paypal_commerce_platform#readme
231
- source_code_uri: https://github.com/solidusio-contrib/solidus_paypal_commerce_platform#readme
235
+ homepage_uri: https://github.com/solidusio-contrib/solidus_paypal_commerce_platform
236
+ source_code_uri: https://github.com/solidusio-contrib/solidus_paypal_commerce_platform
232
237
  changelog_uri: https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/releases
233
238
  post_install_message:
234
239
  rdoc_options: []
@@ -275,3 +280,4 @@ test_files:
275
280
  - spec/requests/solidus_paypal_commerce_platform/wizard_controller_spec.rb
276
281
  - spec/spec_helper.rb
277
282
  - spec/support/capybara.rb
283
+ - spec/support/paypal_sdk_script_tag_helper.rb