solidus_stripe 4.2.0 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +5 -0
  3. data/.gem_release.yml +1 -1
  4. data/.github/stale.yml +4 -4
  5. data/.github_changelog_generator +2 -0
  6. data/.gitignore +3 -2
  7. data/.rubocop.yml +1 -3
  8. data/CHANGELOG.md +94 -17
  9. data/Gemfile +3 -9
  10. data/LICENSE +2 -1
  11. data/README.md +52 -47
  12. data/app/assets/javascripts/spree/frontend/solidus_stripe/stripe-cart-page-checkout.js +1 -0
  13. data/app/assets/javascripts/spree/frontend/solidus_stripe/stripe-payment-request-button-shared.js +2 -1
  14. data/app/controllers/solidus_stripe/payment_request_controller.rb +11 -1
  15. data/app/decorators/models/spree/refund_decorator.rb +1 -1
  16. data/app/models/solidus_stripe/address_from_params_service.rb +20 -8
  17. data/app/models/solidus_stripe/create_intents_payment_service.rb +2 -1
  18. data/app/models/spree/payment_method/stripe_credit_card.rb +26 -4
  19. data/bin/rails +4 -12
  20. data/bin/rails-engine +13 -0
  21. data/bin/rails-sandbox +16 -0
  22. data/bin/sandbox +2 -0
  23. data/config/locales/en.yml +5 -0
  24. data/lib/generators/solidus_stripe/install/install_generator.rb +1 -5
  25. data/lib/solidus_stripe/configuration.rb +21 -0
  26. data/lib/solidus_stripe/engine.rb +3 -14
  27. data/lib/solidus_stripe/testing_support/card_input_helper.rb +34 -0
  28. data/lib/solidus_stripe/{factories.rb → testing_support/factories.rb} +0 -0
  29. data/lib/solidus_stripe/version.rb +1 -1
  30. data/lib/solidus_stripe.rb +5 -5
  31. data/lib/views/frontend/spree/checkout/payment/v2/_javascript.html.erb +1 -1
  32. data/lib/views/frontend/spree/checkout/payment/v3/_form_elements.html.erb +2 -1
  33. data/solidus_stripe.gemspec +5 -5
  34. data/spec/features/stripe_checkout_spec.rb +31 -111
  35. data/spec/models/solidus_stripe/address_from_params_service_spec.rb +17 -6
  36. data/spec/models/solidus_stripe/create_intents_payment_service_spec.rb +1 -1
  37. data/spec/models/spree/payment_method/stripe_credit_card_spec.rb +29 -0
  38. data/spec/requests/payment_requests_spec.rb +152 -0
  39. data/spec/spec_helper.rb +16 -5
  40. data/spec/support/solidus_address_helper.rb +2 -2
  41. metadata +24 -16
@@ -0,0 +1,152 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe "Payment Request", type: :request do
6
+ describe "POST /stripe/update_order" do
7
+ it "responds with { success: true } when the order is correctly updated" do
8
+ order = create(:order_ready_to_complete)
9
+ allow_any_instance_of(SolidusStripe::PaymentRequestController).to receive(:current_order).and_return(order)
10
+
11
+ with_disabled_forgery_protection do
12
+ post "/stripe/update_order", params: stripe_update_request_params(order: order)
13
+ end
14
+
15
+ json = JSON.parse(response.body)
16
+ expect(json["success"]).to be_truthy
17
+ end
18
+
19
+ context "when phone number is provided as param and already set on the address" do
20
+ it "overrides the address field" do
21
+ order = create(:order_ready_to_complete)
22
+ allow_any_instance_of(SolidusStripe::PaymentRequestController).to receive(:current_order).and_return(order)
23
+
24
+ expect {
25
+ with_disabled_forgery_protection do
26
+ post "/stripe/update_order", params: stripe_update_request_params(order: order, shipping_address: default_shipping_address(phone: nil), phone: '911')
27
+ end
28
+ }.to change { order.shipping_address.phone }.to('911')
29
+ end
30
+ end
31
+
32
+ context "when phone number is provided both as shipping address param and main param, and already set on the address" do
33
+ it "overrides the address field giving precedence to the shipping address param" do
34
+ order = create(:order_ready_to_complete)
35
+ allow_any_instance_of(SolidusStripe::PaymentRequestController).to receive(:current_order).and_return(order)
36
+
37
+ expect {
38
+ with_disabled_forgery_protection do
39
+ post "/stripe/update_order", params: stripe_update_request_params(order: order, shipping_address: default_shipping_address(phone: '555'), phone: '911')
40
+ end
41
+ }.to change { order.shipping_address.phone }.to('555')
42
+ end
43
+ end
44
+
45
+ context "when phone number is not required, not provided as param and not set on the shipping address" do
46
+ it "does not populate the address field" do
47
+ with_address_phone_not_required
48
+ order = create(:order_ready_to_complete, shipping_address: create(:address, phone: nil))
49
+ allow_any_instance_of(SolidusStripe::PaymentRequestController).to receive(:current_order).and_return(order)
50
+
51
+ expect {
52
+ with_disabled_forgery_protection do
53
+ post "/stripe/update_order", params: stripe_update_request_params(order: order, shipping_address: default_shipping_address(phone: nil), phone: nil)
54
+ end
55
+ }.not_to change { order.shipping_address.phone }
56
+ end
57
+ end
58
+
59
+ context "when phone number is not required, provided as param and not set on the shipping address" do
60
+ it "populates the address field with the phone passed as param" do
61
+ with_address_phone_not_required
62
+ order = create(:order_ready_to_complete, shipping_address: create(:address, phone: nil))
63
+ allow_any_instance_of(SolidusStripe::PaymentRequestController).to receive(:current_order).and_return(order)
64
+
65
+ expect {
66
+ with_disabled_forgery_protection do
67
+ post "/stripe/update_order", params: stripe_update_request_params(order: order, shipping_address: default_shipping_address(phone: nil), phone: '911')
68
+ end
69
+ }.to change { order.shipping_address.phone }.from(nil).to('911')
70
+ end
71
+ end
72
+
73
+ context "when phone number is not required, provided as param but already set on the shipping address" do
74
+ it "populates the address field with the phone passed in the shipping field" do
75
+ with_address_phone_not_required
76
+ order = create(:order_ready_to_complete, shipping_address: create(:address, phone: nil))
77
+ allow_any_instance_of(SolidusStripe::PaymentRequestController).to receive(:current_order).and_return(order)
78
+
79
+ expect {
80
+ with_disabled_forgery_protection do
81
+ post "/stripe/update_order", params: stripe_update_request_params(order: order, shipping_address: default_shipping_address(phone: '555'), phone: '911')
82
+ end
83
+ }.to change { order.shipping_address.phone }.from(nil).to('555')
84
+ end
85
+ end
86
+ end
87
+
88
+ private
89
+
90
+ def with_address_phone_not_required
91
+ if Spree::Config.respond_to?(:address_requires_phone)
92
+ stub_spree_preferences(address_requires_phone: false)
93
+ else
94
+ allow_any_instance_of(Spree::Address).to receive(:require_phone?).and_return(false)
95
+ end
96
+ end
97
+
98
+ def with_disabled_forgery_protection
99
+ original_allow_forgery_protection_value = ActionController::Base.allow_forgery_protection
100
+ ActionController::Base.allow_forgery_protection = false
101
+
102
+ yield
103
+
104
+ ActionController::Base.allow_forgery_protection = original_allow_forgery_protection_value
105
+ end
106
+
107
+ def stripe_update_request_params(
108
+ order:,
109
+ shipping_address: nil,
110
+ name: 'Clark Kent',
111
+ phone: '555-555-0199'
112
+ )
113
+
114
+ {
115
+ shipping_address: shipping_address || default_shipping_address,
116
+ shipping_option: {
117
+ id: order.shipments.first.shipping_rates.first.shipping_method.id
118
+ },
119
+ name: name,
120
+ phone: phone,
121
+ email: order.email
122
+ }
123
+ end
124
+
125
+ def default_shipping_address(
126
+ country: nil,
127
+ region: nil,
128
+ recipient: 'Clark Kent',
129
+ city: 'Metropolis',
130
+ postal_code: '12345',
131
+ address_line: ['12, Lincoln Rd'],
132
+ phone: '555-555-0199'
133
+ )
134
+
135
+ if country.blank? || region.blank?
136
+ state = create(:state)
137
+
138
+ country ||= state.country.iso
139
+ region ||= state.abbr
140
+ end
141
+
142
+ {
143
+ country: country,
144
+ region: region,
145
+ recipient: recipient,
146
+ city: city,
147
+ postalCode: postal_code,
148
+ addressLine: address_line,
149
+ phone: phone
150
+ }
151
+ end
152
+ end
data/spec/spec_helper.rb CHANGED
@@ -6,21 +6,32 @@ ENV['RAILS_ENV'] = 'test'
6
6
  # Run Coverage report
7
7
  require 'solidus_dev_support/rspec/coverage'
8
8
 
9
- require File.expand_path('dummy/config/environment.rb', __dir__)
9
+ # Create the dummy app if it's still missing.
10
+ dummy_env = "#{__dir__}/dummy/config/environment.rb"
11
+ system 'bin/rake extension:test_app' unless File.exist? dummy_env
12
+ require dummy_env
10
13
 
11
14
  # Requires factories and other useful helpers defined in spree_core.
12
15
  require 'solidus_dev_support/rspec/feature_helper'
13
16
 
14
17
  # Requires supporting ruby files with custom matchers and macros, etc,
15
18
  # in spec/support/ and its subdirectories.
16
- Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
19
+ Dir["#{__dir__}/support/**/*.rb"].sort.each { |f| require f }
17
20
 
18
- # Requires factories defined in lib/solidus_stripe/factories.rb
19
- require 'solidus_stripe/factories'
21
+ # Requires factories defined in lib/solidus_stripe/testing_support/factories.rb
22
+ SolidusDevSupport::TestingSupport::Factories.load_for(SolidusStripe::Engine)
23
+
24
+ # Requires card input helper defined in lib/solidus_stripe/testing_support/card_input_helper.rb
25
+ require 'solidus_stripe/testing_support/card_input_helper'
20
26
 
21
27
  RSpec.configure do |config|
22
28
  config.infer_spec_type_from_file_location!
23
- FactoryBot.find_definitions
24
29
  config.use_transactional_fixtures = false
30
+
25
31
  config.include SolidusAddressNameHelper, type: :feature
32
+ config.include SolidusCardInputHelper, type: :feature
33
+
34
+ if Spree.solidus_gem_version < Gem::Version.new('2.11')
35
+ config.extend Spree::TestingSupport::AuthorizationHelpers::Request, type: :system
36
+ end
26
37
  end
@@ -2,10 +2,10 @@
2
2
 
3
3
  # Since https://github.com/solidusio/solidus/pull/3524 was merged,
4
4
  # we need to verify if we're using the single "Name" field or the
5
- # previous first/last name combination.
5
+ # previous first/last name combination.
6
6
  module SolidusAddressNameHelper
7
7
  def fill_in_name
8
- if Spree::Config.preferences[:use_combined_first_and_last_name_in_address]
8
+ if SolidusSupport.combined_first_and_last_name_in_address?
9
9
  fill_in "Name", with: "Han Solo"
10
10
  else
11
11
  fill_in "First Name", with: "Han"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_stripe
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ version: 4.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Solidus Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-20 00:00:00.000000000 Z
11
+ date: 2021-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: solidus_core
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '2.3'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '3'
22
+ version: '4'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,49 +29,49 @@ dependencies:
29
29
  version: '2.3'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '3'
32
+ version: '4'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: solidus_support
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '0.5'
39
+ version: '0.8'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '0.5'
46
+ version: '0.8'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: activemerchant
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
- version: '1.100'
53
+ version: '1.105'
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
- version: '1.100'
60
+ version: '1.105'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: solidus_dev_support
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - ">="
65
+ - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '0'
67
+ version: '2.3'
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - ">="
72
+ - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: '0'
74
+ version: '2.3'
75
75
  description: Stripe Payment Method for Solidus
76
76
  email: contact@solidus.io
77
77
  executables: []
@@ -81,6 +81,7 @@ files:
81
81
  - ".circleci/config.yml"
82
82
  - ".gem_release.yml"
83
83
  - ".github/stale.yml"
84
+ - ".github_changelog_generator"
84
85
  - ".gitignore"
85
86
  - ".rspec"
86
87
  - ".rubocop.yml"
@@ -111,18 +112,23 @@ files:
111
112
  - bin/console
112
113
  - bin/r
113
114
  - bin/rails
115
+ - bin/rails-engine
116
+ - bin/rails-sandbox
114
117
  - bin/rake
115
118
  - bin/sandbox
116
119
  - bin/sandbox_rails
117
120
  - bin/setup
121
+ - config/locales/en.yml
118
122
  - config/routes.rb
119
123
  - db/migrate/20181010123508_update_stripe_payment_method_type_to_credit_card.rb
120
124
  - db/seeds.rb
121
125
  - lib/assets/stylesheets/spree/frontend/solidus_stripe.scss
122
126
  - lib/generators/solidus_stripe/install/install_generator.rb
123
127
  - lib/solidus_stripe.rb
128
+ - lib/solidus_stripe/configuration.rb
124
129
  - lib/solidus_stripe/engine.rb
125
- - lib/solidus_stripe/factories.rb
130
+ - lib/solidus_stripe/testing_support/card_input_helper.rb
131
+ - lib/solidus_stripe/testing_support/factories.rb
126
132
  - lib/solidus_stripe/version.rb
127
133
  - lib/tasks/solidus_stripe/db/seed.rake
128
134
  - lib/views/api/spree/api/payments/source_views/_stripe.json.jbuilder
@@ -144,6 +150,7 @@ files:
144
150
  - spec/models/solidus_stripe/prepare_order_for_payment_service_spec.rb
145
151
  - spec/models/solidus_stripe/shipping_rates_service_spec.rb
146
152
  - spec/models/spree/payment_method/stripe_credit_card_spec.rb
153
+ - spec/requests/payment_requests_spec.rb
147
154
  - spec/spec_helper.rb
148
155
  - spec/support/solidus_address_helper.rb
149
156
  homepage: https://github.com/solidusio/solidus_stripe#readme
@@ -159,16 +166,16 @@ require_paths:
159
166
  - lib
160
167
  required_ruby_version: !ruby/object:Gem::Requirement
161
168
  requirements:
162
- - - "~>"
169
+ - - ">="
163
170
  - !ruby/object:Gem::Version
164
- version: '2.4'
171
+ version: 2.4.0
165
172
  required_rubygems_version: !ruby/object:Gem::Requirement
166
173
  requirements:
167
174
  - - ">="
168
175
  - !ruby/object:Gem::Version
169
176
  version: '0'
170
177
  requirements: []
171
- rubygems_version: 3.0.3
178
+ rubygems_version: 3.2.20
172
179
  signing_key:
173
180
  specification_version: 4
174
181
  summary: Stripe Payment Method for Solidus
@@ -179,5 +186,6 @@ test_files:
179
186
  - spec/models/solidus_stripe/prepare_order_for_payment_service_spec.rb
180
187
  - spec/models/solidus_stripe/shipping_rates_service_spec.rb
181
188
  - spec/models/spree/payment_method/stripe_credit_card_spec.rb
189
+ - spec/requests/payment_requests_spec.rb
182
190
  - spec/spec_helper.rb
183
191
  - spec/support/solidus_address_helper.rb