solidus_stripe 4.2.0 → 4.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +26 -0
- data/.gem_release.yml +1 -1
- data/.github/stale.yml +1 -17
- data/.github_changelog_generator +2 -0
- data/.gitignore +3 -2
- data/.rubocop.yml +3 -3
- data/.rubocop_todo.yml +298 -0
- data/CHANGELOG.md +128 -17
- data/Gemfile +9 -10
- data/LICENSE +2 -1
- data/README.md +61 -54
- data/Rakefile +3 -0
- data/app/assets/javascripts/spree/frontend/solidus_stripe/stripe-cart-page-checkout.js +1 -0
- data/app/assets/javascripts/spree/frontend/solidus_stripe/stripe-payment-request-button-shared.js +2 -1
- data/app/controllers/solidus_stripe/intents_controller.rb +2 -2
- data/app/controllers/solidus_stripe/payment_request_controller.rb +14 -4
- data/app/decorators/models/spree/refund_decorator.rb +1 -1
- data/app/models/solidus_stripe/address_from_params_service.rb +20 -8
- data/app/models/solidus_stripe/create_intents_payment_service.rb +2 -1
- data/app/models/spree/payment_method/stripe_credit_card.rb +46 -11
- data/bin/rails +4 -12
- data/bin/rails-engine +13 -0
- data/bin/rails-sandbox +16 -0
- data/bin/sandbox +3 -1
- data/config/locales/en.yml +5 -0
- data/lib/generators/solidus_stripe/install/install_generator.rb +1 -5
- data/lib/solidus_stripe/configuration.rb +21 -0
- data/lib/solidus_stripe/engine.rb +3 -14
- data/lib/solidus_stripe/testing_support/card_input_helper.rb +34 -0
- data/lib/solidus_stripe/{factories.rb → testing_support/factories.rb} +0 -0
- data/lib/solidus_stripe/version.rb +1 -1
- data/lib/solidus_stripe.rb +5 -5
- data/lib/views/frontend/spree/checkout/payment/v2/_javascript.html.erb +1 -1
- data/lib/views/frontend/spree/checkout/payment/v3/_form_elements.html.erb +2 -1
- data/solidus_stripe.gemspec +6 -5
- data/spec/features/stripe_checkout_spec.rb +33 -113
- data/spec/models/solidus_stripe/address_from_params_service_spec.rb +17 -6
- data/spec/models/solidus_stripe/create_intents_payment_service_spec.rb +4 -4
- data/spec/models/spree/payment_method/stripe_credit_card_spec.rb +63 -0
- data/spec/requests/payment_requests_spec.rb +152 -0
- data/spec/spec_helper.rb +16 -5
- data/spec/support/solidus_address_helper.rb +2 -2
- metadata +37 -14
data/LICENSE
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
Copyright (c) 2014 Spree Commerce Inc. and other contributors.
|
2
|
+
Copyright (c) 2021 Solidus Team and other contributors.
|
2
3
|
All rights reserved.
|
3
4
|
|
4
5
|
Redistribution and use in source and binary forms, with or without modification,
|
@@ -9,7 +10,7 @@ are permitted provided that the following conditions are met:
|
|
9
10
|
* Redistributions in binary form must reproduce the above copyright notice,
|
10
11
|
this list of conditions and the following disclaimer in the documentation
|
11
12
|
and/or other materials provided with the distribution.
|
12
|
-
* Neither the name
|
13
|
+
* Neither the name Solidus nor the names of its contributors may be used to
|
13
14
|
endorse or promote products derived from this software without specific
|
14
15
|
prior written permission.
|
15
16
|
|
data/README.md
CHANGED
@@ -1,27 +1,18 @@
|
|
1
|
-
Solidus Stripe
|
2
|
-
===============
|
1
|
+
# Solidus Stripe
|
3
2
|
|
4
|
-
[![CircleCI](https://circleci.com/gh/solidusio/solidus_stripe.svg?style=
|
3
|
+
[![CircleCI](https://circleci.com/gh/solidusio/solidus_stripe.svg?style=shield)](https://circleci.com/gh/solidusio/solidus_stripe)
|
4
|
+
[![codecov](https://codecov.io/gh/solidusio/solidus_stripe/branch/master/graph/badge.svg)](https://codecov.io/gh/solidusio/solidus_stripe)
|
5
5
|
|
6
6
|
Stripe Payment Method for Solidus. It works as a wrapper for the ActiveMerchant Stripe gateway.
|
7
7
|
|
8
|
-
|
8
|
+
## Installation
|
9
9
|
|
10
|
-
Installation
|
11
|
-
------------
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
```ruby
|
16
|
-
gem 'solidus_stripe', '~> 3.0'
|
17
|
-
```
|
18
|
-
|
19
|
-
Then run from the command line:
|
11
|
+
Run from the command line:
|
20
12
|
|
21
13
|
```shell
|
22
|
-
bundle
|
14
|
+
bundle add solidus_stripe
|
23
15
|
bundle exec rails g solidus_stripe:install
|
24
|
-
bundle exec rails db:migrate
|
25
16
|
```
|
26
17
|
|
27
18
|
Usage
|
@@ -45,20 +36,15 @@ variables you can create the following static configuration:
|
|
45
36
|
|
46
37
|
```ruby
|
47
38
|
# config/initializers/spree.rb
|
48
|
-
|
49
|
-
Spree.
|
50
|
-
# ...
|
51
|
-
|
52
|
-
config.static_model_preferences.add(
|
39
|
+
Rails.application.config.to_prepare do
|
40
|
+
Spree::Config.static_model_preferences.add(
|
53
41
|
Spree::PaymentMethod::StripeCreditCard,
|
54
42
|
'stripe_env_credentials',
|
55
43
|
secret_key: ENV['STRIPE_SECRET_KEY'],
|
56
44
|
publishable_key: ENV['STRIPE_PUBLISHABLE_KEY'],
|
57
45
|
stripe_country: 'US',
|
58
46
|
v3_elements: false,
|
59
|
-
v3_intents: false
|
60
|
-
server: Rails.env.production? ? 'production' : 'test',
|
61
|
-
test_mode: !Rails.env.production?
|
47
|
+
v3_intents: false
|
62
48
|
)
|
63
49
|
end
|
64
50
|
```
|
@@ -82,7 +68,7 @@ account. Conversely, if you need to disable the button you can simply remove
|
|
82
68
|
the `stripe_country` preference.
|
83
69
|
|
84
70
|
Please refer to Stripe official
|
85
|
-
[documentation](https://stripe.com/docs/
|
71
|
+
[documentation](https://stripe.com/docs/payments/payment-intents)
|
86
72
|
for further instructions on how to make this work properly.
|
87
73
|
|
88
74
|
The following configuration will use both Payment Intents and the
|
@@ -100,9 +86,7 @@ Spree.config do |config|
|
|
100
86
|
publishable_key: ENV['STRIPE_PUBLISHABLE_KEY'],
|
101
87
|
stripe_country: 'US',
|
102
88
|
v3_elements: false,
|
103
|
-
v3_intents: true
|
104
|
-
server: Rails.env.production? ? 'production' : 'test',
|
105
|
-
test_mode: !Rails.env.production?
|
89
|
+
v3_intents: true
|
106
90
|
)
|
107
91
|
end
|
108
92
|
```
|
@@ -263,52 +247,75 @@ SolidusStripe.Payment.prototype.elementsBaseOptions = function () {
|
|
263
247
|
};
|
264
248
|
```
|
265
249
|
|
266
|
-
|
267
|
-
Migrating from solidus_gateway
|
268
|
-
------------------------------
|
250
|
+
## Migrating from solidus_gateway
|
269
251
|
|
270
252
|
If you were previously using `solidus_gateway` gem you might want to
|
271
253
|
check out our [Wiki page](https://github.com/solidusio/solidus_stripe/wiki/Migrating-from-solidus_gateway)
|
272
254
|
that describes how to handle this migration.
|
273
255
|
|
274
|
-
|
275
|
-
|
256
|
+
## Development
|
257
|
+
|
258
|
+
### Testing the extension
|
276
259
|
|
277
|
-
|
278
|
-
run
|
260
|
+
First bundle your dependencies, then run `bin/rake`. `bin/rake` will default to building the dummy
|
261
|
+
app if it does not exist, then it will run specs. The dummy app can be regenerated by using
|
262
|
+
`bin/rake extension:test_app`.
|
279
263
|
|
280
264
|
```shell
|
281
|
-
|
265
|
+
bin/rake
|
282
266
|
```
|
283
267
|
|
284
|
-
|
285
|
-
---------
|
268
|
+
To run [Rubocop](https://github.com/bbatsov/rubocop) static code analysis run
|
286
269
|
|
287
|
-
|
288
|
-
|
270
|
+
```shell
|
271
|
+
bundle exec rubocop
|
272
|
+
```
|
289
273
|
|
290
|
-
|
291
|
-
|
292
|
-
can simply run:
|
274
|
+
When testing your application's integration with this extension you may use its factories.
|
275
|
+
Simply add this require statement to your `spec/spec_helper.rb`:
|
293
276
|
|
277
|
+
```ruby
|
278
|
+
require 'solidus_stripe/testing_support/factories'
|
294
279
|
```
|
295
|
-
|
280
|
+
|
281
|
+
Or, if you are using `FactoryBot.definition_file_paths`, you can load Solidus core
|
282
|
+
factories along with this extension's factories using this statement:
|
283
|
+
|
284
|
+
```ruby
|
285
|
+
SolidusDevSupport::TestingSupport::Factories.load_for(SolidusStripe::Engine)
|
296
286
|
```
|
297
287
|
|
298
|
-
|
288
|
+
### Running the sandbox
|
299
289
|
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
- push the tag to the upstream remote
|
304
|
-
- release the new version on RubyGems
|
290
|
+
To run this extension in a sandboxed Solidus application, you can run `bin/sandbox`. The path for
|
291
|
+
the sandbox app is `./sandbox` and `bin/rails` will forward any Rails commands to
|
292
|
+
`sandbox/bin/rails`.
|
305
293
|
|
306
|
-
|
294
|
+
Here's an example:
|
307
295
|
|
308
296
|
```
|
309
|
-
|
310
|
-
|
311
|
-
|
297
|
+
$ bin/rails server
|
298
|
+
=> Booting Puma
|
299
|
+
=> Rails 6.0.2.1 application starting in development
|
300
|
+
* Listening on tcp://127.0.0.1:3000
|
301
|
+
Use Ctrl-C to stop
|
302
|
+
```
|
303
|
+
|
304
|
+
### Updating the changelog
|
305
|
+
|
306
|
+
Before and after releases the changelog should be updated to reflect the up-to-date status of
|
307
|
+
the project:
|
308
|
+
|
309
|
+
```shell
|
310
|
+
bin/rake changelog
|
311
|
+
git add CHANGELOG.md
|
312
|
+
git commit -m "Update the changelog"
|
312
313
|
```
|
313
314
|
|
314
|
-
|
315
|
+
### Releasing new versions
|
316
|
+
|
317
|
+
Please refer to the dedicated [page](https://github.com/solidusio/solidus/wiki/How-to-release-extensions) on Solidus wiki.
|
318
|
+
|
319
|
+
## License
|
320
|
+
Copyright (c) 2014 Spree Commerce Inc., released under the New BSD License
|
321
|
+
Copyright (c) 2021 Solidus Team, released under the New BSD License
|
data/Rakefile
CHANGED
@@ -53,6 +53,7 @@ SolidusStripe.CartPageCheckout.prototype.onPrPayment = function(payment) {
|
|
53
53
|
shipping_option: payment.shippingOption,
|
54
54
|
email: payment.payerEmail,
|
55
55
|
name: payment.payerName,
|
56
|
+
phone: payment.payerPhone,
|
56
57
|
authenticity_token: this.authToken
|
57
58
|
})
|
58
59
|
}).then(function(response) {
|
data/app/assets/javascripts/spree/frontend/solidus_stripe/stripe-payment-request-button-shared.js
CHANGED
@@ -22,6 +22,7 @@
|
|
22
22
|
},
|
23
23
|
requestPayerName: true,
|
24
24
|
requestPayerEmail: true,
|
25
|
+
requestPayerPhone: true,
|
25
26
|
requestShipping: config.requestShipping,
|
26
27
|
shippingOptions: []
|
27
28
|
});
|
@@ -50,7 +51,7 @@
|
|
50
51
|
};
|
51
52
|
paymentRequest.on('paymentmethod', onPrPaymentMethod.bind(this));
|
52
53
|
|
53
|
-
onShippingAddressChange = function(ev) {
|
54
|
+
var onShippingAddressChange = function(ev) {
|
54
55
|
var showError = this.showError.bind(this);
|
55
56
|
|
56
57
|
fetch('/stripe/shipping_rates', {
|
@@ -19,7 +19,7 @@ module SolidusStripe
|
|
19
19
|
if create_payment_service.call
|
20
20
|
render json: { success: true }
|
21
21
|
else
|
22
|
-
render json: { error: "Could not create payment" }, status:
|
22
|
+
render json: { error: "Could not create payment" }, status: :internal_server_error
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -45,7 +45,7 @@ module SolidusStripe
|
|
45
45
|
stripe_payment_intent_id: response['id']
|
46
46
|
}
|
47
47
|
else
|
48
|
-
render json: { error: response['error']['message'] }, status:
|
48
|
+
render json: { error: response['error']['message'] }, status: :internal_server_error
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -14,7 +14,7 @@ module SolidusStripe
|
|
14
14
|
if rates.any?
|
15
15
|
render json: { success: true, shipping_rates: rates }
|
16
16
|
else
|
17
|
-
render json: { success: false, error: 'No shipping method available for that address' }, status:
|
17
|
+
render json: { success: false, error: 'No shipping method available for that address' }, status: :internal_server_error
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -22,7 +22,7 @@ module SolidusStripe
|
|
22
22
|
current_order.restart_checkout_flow
|
23
23
|
|
24
24
|
address = SolidusStripe::AddressFromParamsService.new(
|
25
|
-
|
25
|
+
shipping_address_from_params,
|
26
26
|
spree_current_user
|
27
27
|
).call
|
28
28
|
|
@@ -32,11 +32,21 @@ module SolidusStripe
|
|
32
32
|
if current_order.payment?
|
33
33
|
render json: { success: true }
|
34
34
|
else
|
35
|
-
render json: { success: false, error: 'Order not ready for payment. Try manual checkout.' }, status:
|
35
|
+
render json: { success: false, error: 'Order not ready for payment. Try manual checkout.' }, status: :internal_server_error
|
36
36
|
end
|
37
37
|
else
|
38
|
-
render json: { success: false, error: address.errors.full_messages.to_sentence }, status:
|
38
|
+
render json: { success: false, error: address.errors.full_messages.to_sentence }, status: :internal_server_error
|
39
39
|
end
|
40
40
|
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def shipping_address_from_params
|
45
|
+
return {} unless params[:shipping_address]
|
46
|
+
return params[:shipping_address] if params.dig(:shipping_address, :phone).present?
|
47
|
+
|
48
|
+
params[:shipping_address][:phone] = params[:phone]
|
49
|
+
params[:shipping_address]
|
50
|
+
end
|
41
51
|
end
|
42
52
|
end
|
@@ -26,14 +26,26 @@ module SolidusStripe
|
|
26
26
|
lines = address_params[:addressLine]
|
27
27
|
names = address_params[:recipient].split(' ')
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
29
|
+
name_attributes = if SolidusSupport.combined_first_and_last_name_in_address? && Spree::Address.column_names.include?("name")
|
30
|
+
{
|
31
|
+
name: address_params[:recipient]
|
32
|
+
}
|
33
|
+
else
|
34
|
+
{
|
35
|
+
firstname: names.first,
|
36
|
+
lastname: names.last,
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
attributes
|
41
|
+
.merge!(name_attributes)
|
42
|
+
.merge!(
|
43
|
+
state_id: state&.id,
|
44
|
+
phone: phone,
|
45
|
+
address1: lines.first,
|
46
|
+
address2: lines.second
|
47
|
+
)
|
48
|
+
.reject! { |_, value| value.blank? }
|
37
49
|
end
|
38
50
|
end
|
39
51
|
end
|
@@ -102,7 +102,8 @@ module SolidusStripe
|
|
102
102
|
end
|
103
103
|
|
104
104
|
def address_full_name
|
105
|
-
current_order.bill_address&.
|
105
|
+
bill_address_name = SolidusSupport.combined_first_and_last_name_in_address? ? current_order.bill_address&.name : current_order.bill_address&.full_name
|
106
|
+
bill_address_name || form_data[:recipient]
|
106
107
|
end
|
107
108
|
|
108
109
|
def update_stripe_payment_description
|
@@ -61,20 +61,29 @@ module Spree
|
|
61
61
|
true
|
62
62
|
end
|
63
63
|
|
64
|
+
def non_fractional_money(money, currency)
|
65
|
+
amount = money.is_a?(Integer) ? money : money.cents
|
66
|
+
Spree::Money.new((amount * 100), { currency: currency })
|
67
|
+
end
|
68
|
+
|
69
|
+
def localize(money, currency)
|
70
|
+
ActiveMerchant::Billing::Gateway.currencies_without_fractions.include?(currency) ? non_fractional_money(money, currency) : money
|
71
|
+
end
|
72
|
+
|
64
73
|
def purchase(money, creditcard, transaction_options)
|
65
|
-
gateway.purchase(*options_for_purchase_or_auth(money, creditcard, transaction_options))
|
74
|
+
gateway.purchase(*options_for_purchase_or_auth(localize(money, transaction_options[:currency]), creditcard, transaction_options))
|
66
75
|
end
|
67
76
|
|
68
77
|
def authorize(money, creditcard, transaction_options)
|
69
|
-
gateway.authorize(*options_for_purchase_or_auth(money, creditcard, transaction_options))
|
78
|
+
gateway.authorize(*options_for_purchase_or_auth(localize(money, transaction_options[:currency]), creditcard, transaction_options))
|
70
79
|
end
|
71
80
|
|
72
81
|
def capture(money, response_code, transaction_options)
|
73
|
-
gateway.capture(money, response_code, transaction_options)
|
82
|
+
gateway.capture(localize(money, transaction_options[:currency]), response_code, transaction_options)
|
74
83
|
end
|
75
84
|
|
76
|
-
def credit(money, _creditcard, response_code,
|
77
|
-
gateway.refund(money, response_code, {})
|
85
|
+
def credit(money, _creditcard, response_code, transaction_options)
|
86
|
+
gateway.refund(localize(money, transaction_options[:currency]), response_code, {})
|
78
87
|
end
|
79
88
|
|
80
89
|
def void(response_code, _creditcard, _transaction_options)
|
@@ -87,10 +96,13 @@ module Spree
|
|
87
96
|
|
88
97
|
def try_void(payment)
|
89
98
|
if v3_intents? && payment.completed?
|
90
|
-
payment
|
91
|
-
|
92
|
-
|
93
|
-
|
99
|
+
refund = perform_refund(payment)
|
100
|
+
|
101
|
+
if refund.respond_to?(:perform_response)
|
102
|
+
refund.perform_response
|
103
|
+
else
|
104
|
+
refund.response
|
105
|
+
end
|
94
106
|
else
|
95
107
|
void(payment.response_code, nil, nil)
|
96
108
|
end
|
@@ -109,7 +121,7 @@ module Spree
|
|
109
121
|
}.merge! address_for(payment)
|
110
122
|
|
111
123
|
source = update_source!(payment.source)
|
112
|
-
if
|
124
|
+
if reuse_existing_source?(source)
|
113
125
|
if v3_intents?
|
114
126
|
creditcard = ActiveMerchant::Billing::StripeGateway::StripePaymentToken.new('id' => source.gateway_payment_profile_id)
|
115
127
|
else
|
@@ -121,7 +133,7 @@ module Spree
|
|
121
133
|
|
122
134
|
response = gateway.store(creditcard, options)
|
123
135
|
if response.success?
|
124
|
-
if v3_intents?
|
136
|
+
if v3_intents? && reuse_existing_source?(source)
|
125
137
|
payment.source.update!(
|
126
138
|
cc_type: payment.source.cc_type,
|
127
139
|
gateway_customer_profile_id: response.params['customer'],
|
@@ -152,6 +164,7 @@ module Spree
|
|
152
164
|
options[:description] = "Solidus Order ID: #{transaction_options[:order_id]}"
|
153
165
|
options[:currency] = transaction_options[:currency]
|
154
166
|
options[:off_session] = true if v3_intents?
|
167
|
+
options[:statement_descriptor_suffix] = transaction_options[:statement_descriptor_suffix] if transaction_options[:statement_descriptor_suffix]
|
155
168
|
|
156
169
|
if customer = creditcard.gateway_customer_profile_id
|
157
170
|
options[:customer] = customer
|
@@ -190,6 +203,28 @@ module Spree
|
|
190
203
|
source.cc_type = CARD_TYPE_MAPPING[source.cc_type] if CARD_TYPE_MAPPING.include?(source.cc_type)
|
191
204
|
source
|
192
205
|
end
|
206
|
+
|
207
|
+
def perform_refund(payment)
|
208
|
+
refund = payment.refunds.build(
|
209
|
+
amount: payment.credit_allowed,
|
210
|
+
reason: payment_intents_refund_reason
|
211
|
+
)
|
212
|
+
|
213
|
+
if refund.respond_to?(:perform_after_create)
|
214
|
+
refund.perform_after_create = false
|
215
|
+
refund.save!
|
216
|
+
refund.perform!
|
217
|
+
else
|
218
|
+
refund.save!
|
219
|
+
refund.perform! if Gem::Requirement.new('>= 3.0.0.alpha').satisfied_by?(Spree.solidus_gem_version)
|
220
|
+
end
|
221
|
+
|
222
|
+
refund
|
223
|
+
end
|
224
|
+
|
225
|
+
def reuse_existing_source?(source)
|
226
|
+
source.number.blank? && source.gateway_payment_profile_id.present?
|
227
|
+
end
|
193
228
|
end
|
194
229
|
end
|
195
230
|
end
|
data/bin/rails
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
unless File.exist? "#{app_root}/bin/rails"
|
8
|
-
system "bin/rake", app_root or begin # rubocop:disable Style/AndOr
|
9
|
-
warn "Automatic creation of the dummy app failed"
|
10
|
-
exit 1
|
11
|
-
end
|
3
|
+
if %w[g generate].include? ARGV.first
|
4
|
+
exec "#{__dir__}/rails-engine", *ARGV
|
5
|
+
else
|
6
|
+
exec "#{__dir__}/rails-sandbox", *ARGV
|
12
7
|
end
|
13
|
-
|
14
|
-
Dir.chdir app_root
|
15
|
-
exec 'bin/rails', *ARGV
|
data/bin/rails-engine
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails gems
|
3
|
+
# installed from the root of your application.
|
4
|
+
|
5
|
+
ENGINE_ROOT = File.expand_path('..', __dir__)
|
6
|
+
ENGINE_PATH = File.expand_path('../lib/solidus_stripe/engine', __dir__)
|
7
|
+
|
8
|
+
# Set up gems listed in the Gemfile.
|
9
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
10
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
11
|
+
|
12
|
+
require 'rails/all'
|
13
|
+
require 'rails/engine/commands'
|
data/bin/rails-sandbox
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
app_root = 'sandbox'
|
4
|
+
|
5
|
+
unless File.exist? "#{app_root}/bin/rails"
|
6
|
+
warn 'Creating the sandbox app...'
|
7
|
+
Dir.chdir "#{__dir__}/.." do
|
8
|
+
system "#{__dir__}/sandbox" or begin
|
9
|
+
warn 'Automatic creation of the sandbox app failed'
|
10
|
+
exit 1
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
Dir.chdir app_root
|
16
|
+
exec 'bin/rails', *ARGV
|
data/bin/sandbox
CHANGED
@@ -67,14 +67,16 @@ unbundled bundle install --gemfile Gemfile
|
|
67
67
|
|
68
68
|
unbundled bundle exec rake db:drop db:create
|
69
69
|
|
70
|
-
unbundled bundle exec rails generate
|
70
|
+
unbundled bundle exec rails generate solidus:install \
|
71
71
|
--auto-accept \
|
72
72
|
--user_class=Spree::User \
|
73
73
|
--enforce_available_locales=true \
|
74
74
|
--with-authentication=false \
|
75
|
+
--payment-method=none \
|
75
76
|
$@
|
76
77
|
|
77
78
|
unbundled bundle exec rails generate solidus:auth:install
|
79
|
+
unbundled bundle exec rails generate ${extension_name}:install
|
78
80
|
|
79
81
|
echo
|
80
82
|
echo "🚀 Sandbox app successfully created for $extension_name!"
|
@@ -9,16 +9,12 @@ module SolidusStripe
|
|
9
9
|
append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_stripe\n"
|
10
10
|
end
|
11
11
|
|
12
|
-
def add_migrations
|
13
|
-
run 'bundle exec rake railties:install:migrations FROM=solidus_stripe'
|
14
|
-
end
|
15
|
-
|
16
12
|
def add_migrations
|
17
13
|
run 'bin/rails railties:install:migrations FROM=solidus_stripe'
|
18
14
|
end
|
19
15
|
|
20
16
|
def run_migrations
|
21
|
-
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) # rubocop:disable
|
17
|
+
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) # rubocop:disable Layout/LineLength
|
22
18
|
if run_migrations
|
23
19
|
run 'bin/rails db:migrate'
|
24
20
|
else
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusStripe
|
4
|
+
class Configuration
|
5
|
+
# Define here the settings for this extension, e.g.:
|
6
|
+
#
|
7
|
+
# attr_accessor :my_setting
|
8
|
+
end
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def configuration
|
12
|
+
@configuration ||= Configuration.new
|
13
|
+
end
|
14
|
+
|
15
|
+
alias config configuration
|
16
|
+
|
17
|
+
def configure
|
18
|
+
yield configuration
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'solidus_core'
|
4
|
+
require 'solidus_support'
|
4
5
|
|
5
6
|
module SolidusStripe
|
6
7
|
class Engine < Rails::Engine
|
@@ -15,20 +16,8 @@ module SolidusStripe
|
|
15
16
|
g.test_framework :rspec
|
16
17
|
end
|
17
18
|
|
18
|
-
if SolidusSupport.backend_available?
|
19
|
-
paths["app/views"] << "lib/views/backend"
|
20
|
-
end
|
21
|
-
|
22
|
-
if SolidusSupport.frontend_available?
|
23
|
-
paths["app/views"] << "lib/views/frontend"
|
24
|
-
end
|
25
|
-
|
26
|
-
if SolidusSupport.api_available?
|
27
|
-
paths["app/views"] << "lib/views/api"
|
28
|
-
end
|
29
|
-
|
30
19
|
initializer "spree.payment_method.add_stripe_credit_card", after: "spree.register.payment_methods" do |app|
|
31
|
-
app.config.spree.payment_methods << Spree::PaymentMethod::StripeCreditCard
|
20
|
+
app.config.spree.payment_methods << "Spree::PaymentMethod::StripeCreditCard"
|
32
21
|
end
|
33
22
|
end
|
34
23
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusCardInputHelper
|
4
|
+
def fill_in_card(card = {})
|
5
|
+
card[:number] ||= "4242 4242 4242 4242"
|
6
|
+
card[:code] ||= "123"
|
7
|
+
card[:exp_month] ||= "01"
|
8
|
+
card[:exp_year] ||= "#{Time.zone.now.year + 1}"
|
9
|
+
|
10
|
+
if preferred_v3_elements || preferred_v3_intents
|
11
|
+
within_frame find('#card_number iframe') do
|
12
|
+
fill_in_number("cardnumber", card)
|
13
|
+
end
|
14
|
+
within_frame(find '#card_cvc iframe') { fill_in 'cvc', with: card[:code] }
|
15
|
+
within_frame(find '#card_expiry iframe') do
|
16
|
+
fill_in_expiration("exp-date", card)
|
17
|
+
end
|
18
|
+
else
|
19
|
+
fill_in_number("Card Number", card)
|
20
|
+
fill_in "Card Code", with: card[:code]
|
21
|
+
fill_in_expiration("Expiration", card)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def fill_in_number(field_name, card)
|
28
|
+
card[:number].split('').each { |n| find_field(field_name).native.send_keys(n) }
|
29
|
+
end
|
30
|
+
|
31
|
+
def fill_in_expiration(field_name, card)
|
32
|
+
"#{card[:exp_month]}#{card[:exp_year].last(2)}".split('').each { |n| find_field(field_name).native.send_keys(n) }
|
33
|
+
end
|
34
|
+
end
|
File without changes
|
data/lib/solidus_stripe.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
3
|
+
require 'active_merchant'
|
4
|
+
|
5
|
+
require 'solidus_stripe/configuration'
|
6
|
+
require 'solidus_stripe/version'
|
7
|
+
require 'solidus_stripe/engine'
|