solidus_stripe 3.0.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +5 -0
- data/CHANGELOG.md +55 -0
- data/Gemfile +7 -0
- data/LICENSE +2 -2
- data/README.md +69 -11
- data/Rakefile +1 -1
- data/app/assets/javascripts/spree/frontend/solidus_stripe/stripe-cart-page-checkout.js +42 -9
- data/app/assets/javascripts/spree/frontend/solidus_stripe/stripe-elements.js +61 -25
- data/app/assets/javascripts/spree/frontend/solidus_stripe/stripe-payment-intents.js +4 -2
- data/app/assets/javascripts/spree/frontend/solidus_stripe/stripe-payment-request-button-shared.js +56 -19
- data/app/assets/javascripts/spree/frontend/solidus_stripe/stripe-payment.js +7 -1
- data/app/controllers/solidus_stripe/intents_controller.rb +42 -28
- data/app/decorators/models/spree/order_update_attributes_decorator.rb +39 -0
- data/app/decorators/models/spree/payment_decorator.rb +11 -0
- data/app/decorators/models/spree/refund_decorator.rb +9 -0
- data/app/models/solidus_stripe/address_from_params_service.rb +5 -2
- data/app/models/solidus_stripe/create_intents_payment_service.rb +113 -0
- data/app/models/spree/payment_method/stripe_credit_card.rb +19 -9
- data/bin/r +13 -0
- data/bin/rake +7 -0
- data/bin/sandbox +84 -0
- data/bin/sandbox_rails +18 -0
- data/bin/setup +1 -1
- data/config/routes.rb +4 -1
- data/lib/generators/solidus_stripe/install/install_generator.rb +7 -3
- data/lib/solidus_stripe/engine.rb +2 -2
- data/lib/solidus_stripe/factories.rb +4 -0
- data/lib/solidus_stripe/version.rb +1 -1
- data/lib/views/frontend/spree/checkout/payment/v3/_form_elements.html.erb +0 -1
- data/solidus_stripe.gemspec +34 -37
- data/spec/features/stripe_checkout_spec.rb +159 -64
- data/spec/models/solidus_stripe/address_from_params_service_spec.rb +19 -5
- data/spec/models/solidus_stripe/create_intents_payment_service_spec.rb +127 -0
- data/spec/models/spree/payment_method/stripe_credit_card_spec.rb +44 -1
- data/spec/spec_helper.rb +4 -1
- metadata +22 -12
- data/LICENSE.md +0 -26
@@ -14,7 +14,8 @@ RSpec.describe SolidusStripe::AddressFromParamsService do
|
|
14
14
|
recipient: 'Clark Kent',
|
15
15
|
city: 'Metropolis',
|
16
16
|
postalCode: '12345',
|
17
|
-
addressLine: [ '12, Lincoln Rd']
|
17
|
+
addressLine: [ '12, Lincoln Rd'],
|
18
|
+
phone: '555-555-0199'
|
18
19
|
}
|
19
20
|
end
|
20
21
|
|
@@ -39,7 +40,8 @@ RSpec.describe SolidusStripe::AddressFromParamsService do
|
|
39
40
|
firstname: 'Clark',
|
40
41
|
lastname: 'Kent',
|
41
42
|
address1: params[:addressLine].first,
|
42
|
-
address2: nil
|
43
|
+
address2: nil,
|
44
|
+
phone: '555-555-0199'
|
43
45
|
)
|
44
46
|
end
|
45
47
|
|
@@ -50,11 +52,23 @@ RSpec.describe SolidusStripe::AddressFromParamsService do
|
|
50
52
|
|
51
53
|
context "when no user's address is compatible with the params" do
|
52
54
|
before do
|
53
|
-
user.addresses << create(:address)
|
55
|
+
user.addresses << create(:address, state: state)
|
54
56
|
end
|
55
57
|
|
56
|
-
it "returns a non-persisted address
|
57
|
-
|
58
|
+
it "returns a non-persisted valid address" do
|
59
|
+
aggregate_failures do
|
60
|
+
expect(subject).to be_new_record
|
61
|
+
expect(subject).to be_valid
|
62
|
+
expect(subject.state).to eq state
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "when the region is the state name" do
|
67
|
+
before { params[:region] = state.name }
|
68
|
+
|
69
|
+
it "still can set the address state attribute" do
|
70
|
+
expect(subject.state).to eq state
|
71
|
+
end
|
58
72
|
end
|
59
73
|
end
|
60
74
|
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusStripe::CreateIntentsPaymentService do
|
6
|
+
let(:service) { described_class.new(intent_id, stripe, controller) }
|
7
|
+
|
8
|
+
let(:stripe) {
|
9
|
+
Spree::PaymentMethod::StripeCreditCard.create!(
|
10
|
+
name: "Stripe",
|
11
|
+
preferred_secret_key: "sk_test_VCZnDv3GLU15TRvn8i2EsaAN",
|
12
|
+
preferred_publishable_key: "pk_test_Cuf0PNtiAkkMpTVC2gwYDMIg",
|
13
|
+
preferred_v3_elements: false,
|
14
|
+
preferred_v3_intents: true
|
15
|
+
)
|
16
|
+
}
|
17
|
+
|
18
|
+
let(:order) { create :order, state: :payment, total: 19.99 }
|
19
|
+
|
20
|
+
let(:intent_id) { "pi_123123ABC" }
|
21
|
+
let(:controller) { double(current_order: order.reload, params: params, request: spy) }
|
22
|
+
|
23
|
+
let(:params) do
|
24
|
+
{
|
25
|
+
spree_payment_method_id: stripe.id,
|
26
|
+
stripe_payment_intent_id: intent_id,
|
27
|
+
form_data: {
|
28
|
+
addressLine: ["31 Cotton Rd"],
|
29
|
+
city: "San Diego",
|
30
|
+
country: "US",
|
31
|
+
phone: "+188836412312",
|
32
|
+
postalCode: "12345",
|
33
|
+
recipient: "James Edwards",
|
34
|
+
region: "CA"
|
35
|
+
}
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
let(:intent) do
|
40
|
+
double(params: {
|
41
|
+
"id" => intent_id,
|
42
|
+
"charges" => {
|
43
|
+
"data" => [{
|
44
|
+
"billing_details" => {
|
45
|
+
"name" => "John Doe"
|
46
|
+
},
|
47
|
+
"payment_method_details" => {
|
48
|
+
"card" => {
|
49
|
+
"brand" => "visa",
|
50
|
+
"exp_month" => 1,
|
51
|
+
"exp_year" => 2022,
|
52
|
+
"last4" => "4242"
|
53
|
+
},
|
54
|
+
}
|
55
|
+
}]
|
56
|
+
}
|
57
|
+
})
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '#call' do
|
61
|
+
subject { service.call }
|
62
|
+
|
63
|
+
before do
|
64
|
+
allow(stripe).to receive(:show_intent) { intent }
|
65
|
+
allow_any_instance_of(Spree::CreditCard).to receive(:require_card_numbers?) { false }
|
66
|
+
allow_any_instance_of(Spree::PaymentMethod::StripeCreditCard).to receive(:create_profile) { true }
|
67
|
+
end
|
68
|
+
|
69
|
+
it { expect(subject).to be true }
|
70
|
+
|
71
|
+
it "creates a new pending payment" do
|
72
|
+
expect { subject }.to change { order.payments.count }
|
73
|
+
expect(order.payments.last.reload).to be_pending
|
74
|
+
end
|
75
|
+
|
76
|
+
it "creates a credit card with the correct information" do
|
77
|
+
expect { subject }.to change { Spree::CreditCard.count }
|
78
|
+
card = Spree::CreditCard.last
|
79
|
+
|
80
|
+
aggregate_failures do
|
81
|
+
expect(card.name).to eq "John Doe"
|
82
|
+
expect(card.cc_type).to eq "visa"
|
83
|
+
expect(card.month).to eq "1"
|
84
|
+
expect(card.year).to eq "2022"
|
85
|
+
expect(card.last_digits).to eq "4242"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context "when for any reason the payment could not be created" do
|
90
|
+
before { params[:form_data].delete(:city) }
|
91
|
+
|
92
|
+
it "returns false" do
|
93
|
+
expect(subject).to be false
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context "when there are previous pending payments" do
|
98
|
+
let!(:payment) do
|
99
|
+
create(:payment, order: order).tap do |payment|
|
100
|
+
payment.update!(state: :pending)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
before do
|
105
|
+
response = double(success?: true, authorization: payment.response_code)
|
106
|
+
allow_any_instance_of(Spree::PaymentMethod::StripeCreditCard).to receive(:void) { response }
|
107
|
+
end
|
108
|
+
|
109
|
+
context "when one of them is a Payment Intent" do
|
110
|
+
before do
|
111
|
+
payment.update!(payment_method: stripe)
|
112
|
+
payment.source.update!(payment_method: stripe)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "invalidates it" do
|
116
|
+
expect { subject }.to change { payment.reload.state }.to 'void'
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context "when none is a Payment Intent" do
|
121
|
+
it "does not invalidate them" do
|
122
|
+
expect { subject }.not_to change { payment.reload.state }
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -22,7 +22,8 @@ describe Spree::PaymentMethod::StripeCreditCard do
|
|
22
22
|
let(:payment) {
|
23
23
|
double('Spree::Payment',
|
24
24
|
source: source,
|
25
|
-
order: order
|
25
|
+
order: order,
|
26
|
+
amount: order.total
|
26
27
|
)
|
27
28
|
}
|
28
29
|
|
@@ -241,4 +242,46 @@ describe Spree::PaymentMethod::StripeCreditCard do
|
|
241
242
|
expect(gateway).to receive(:capture).with(9855, '12345', anything).and_return(success_response)
|
242
243
|
end
|
243
244
|
end
|
245
|
+
|
246
|
+
describe '#try_void' do
|
247
|
+
let(:payment) { create :payment, amount: order.total }
|
248
|
+
|
249
|
+
shared_examples 'voids the payment transaction' do
|
250
|
+
it 'voids the payment transaction' do
|
251
|
+
expect(payment).to receive(:void_transaction!)
|
252
|
+
|
253
|
+
subject.try_void(payment)
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
context 'when using Payment Intents' do
|
258
|
+
before { subject.preferred_v3_intents = true }
|
259
|
+
|
260
|
+
context 'when the payment is completed' do
|
261
|
+
before do
|
262
|
+
allow(payment).to receive(:completed?) { true }
|
263
|
+
end
|
264
|
+
|
265
|
+
it 'creates a refund' do
|
266
|
+
expect { subject.try_void(payment) }.to change { Spree::Refund.count }.by(1)
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
context 'when the payment is not completed' do
|
271
|
+
it_behaves_like 'voids the payment transaction'
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
context 'when not using Payment Intents' do
|
276
|
+
before { subject.preferred_v3_intents = false }
|
277
|
+
|
278
|
+
context 'when the payment is completed' do
|
279
|
+
it_behaves_like 'voids the payment transaction'
|
280
|
+
end
|
281
|
+
|
282
|
+
context 'when the payment is not completed' do
|
283
|
+
it_behaves_like 'voids the payment transaction'
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
244
287
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -13,7 +13,10 @@ require 'solidus_dev_support/rspec/feature_helper'
|
|
13
13
|
|
14
14
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
15
15
|
# in spec/support/ and its subdirectories.
|
16
|
-
Dir[File.join(File.dirname(__FILE__),
|
16
|
+
Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
|
17
|
+
|
18
|
+
# Requires factories defined in lib/solidus_stripe/factories.rb
|
19
|
+
require 'solidus_stripe/factories'
|
17
20
|
|
18
21
|
RSpec.configure do |config|
|
19
22
|
config.infer_spec_type_from_file_location!
|
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
|
+
version: 4.1.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-
|
11
|
+
date: 2020-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: solidus_core
|
@@ -36,14 +36,14 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: 0.
|
39
|
+
version: '0.5'
|
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.
|
46
|
+
version: '0.5'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: activemerchant
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -88,7 +88,6 @@ files:
|
|
88
88
|
- CHANGELOG.md
|
89
89
|
- Gemfile
|
90
90
|
- LICENSE
|
91
|
-
- LICENSE.md
|
92
91
|
- README.md
|
93
92
|
- Rakefile
|
94
93
|
- app/assets/javascripts/spree/frontend/solidus_stripe.js
|
@@ -101,12 +100,20 @@ files:
|
|
101
100
|
- app/controllers/solidus_stripe/intents_controller.rb
|
102
101
|
- app/controllers/solidus_stripe/payment_request_controller.rb
|
103
102
|
- app/controllers/spree/stripe_controller.rb
|
103
|
+
- app/decorators/models/spree/order_update_attributes_decorator.rb
|
104
|
+
- app/decorators/models/spree/payment_decorator.rb
|
105
|
+
- app/decorators/models/spree/refund_decorator.rb
|
104
106
|
- app/models/solidus_stripe/address_from_params_service.rb
|
107
|
+
- app/models/solidus_stripe/create_intents_payment_service.rb
|
105
108
|
- app/models/solidus_stripe/prepare_order_for_payment_service.rb
|
106
109
|
- app/models/solidus_stripe/shipping_rates_service.rb
|
107
110
|
- app/models/spree/payment_method/stripe_credit_card.rb
|
108
111
|
- bin/console
|
112
|
+
- bin/r
|
109
113
|
- bin/rails
|
114
|
+
- bin/rake
|
115
|
+
- bin/sandbox
|
116
|
+
- bin/sandbox_rails
|
110
117
|
- bin/setup
|
111
118
|
- config/routes.rb
|
112
119
|
- db/migrate/20181010123508_update_stripe_payment_method_type_to_credit_card.rb
|
@@ -115,6 +122,7 @@ files:
|
|
115
122
|
- lib/generators/solidus_stripe/install/install_generator.rb
|
116
123
|
- lib/solidus_stripe.rb
|
117
124
|
- lib/solidus_stripe/engine.rb
|
125
|
+
- lib/solidus_stripe/factories.rb
|
118
126
|
- lib/solidus_stripe/version.rb
|
119
127
|
- lib/tasks/solidus_stripe/db/seed.rake
|
120
128
|
- lib/views/api/spree/api/payments/source_views/_stripe.json.jbuilder
|
@@ -132,33 +140,34 @@ files:
|
|
132
140
|
- solidus_stripe.gemspec
|
133
141
|
- spec/features/stripe_checkout_spec.rb
|
134
142
|
- spec/models/solidus_stripe/address_from_params_service_spec.rb
|
143
|
+
- spec/models/solidus_stripe/create_intents_payment_service_spec.rb
|
135
144
|
- spec/models/solidus_stripe/prepare_order_for_payment_service_spec.rb
|
136
145
|
- spec/models/solidus_stripe/shipping_rates_service_spec.rb
|
137
146
|
- spec/models/spree/payment_method/stripe_credit_card_spec.rb
|
138
147
|
- spec/spec_helper.rb
|
139
148
|
- spec/support/solidus_address_helper.rb
|
140
|
-
homepage: https://
|
149
|
+
homepage: https://github.com/solidusio/solidus_stripe#readme
|
141
150
|
licenses:
|
142
151
|
- BSD-3
|
143
152
|
metadata:
|
144
|
-
homepage_uri: https://
|
145
|
-
source_code_uri: https://
|
153
|
+
homepage_uri: https://github.com/solidusio/solidus_stripe#readme
|
154
|
+
source_code_uri: https://github.com/solidusio/solidus_stripe
|
155
|
+
changelog_uri: https://github.com/solidusio/solidus_stripe/blob/master/CHANGELOG.md
|
146
156
|
post_install_message:
|
147
157
|
rdoc_options: []
|
148
158
|
require_paths:
|
149
159
|
- lib
|
150
160
|
required_ruby_version: !ruby/object:Gem::Requirement
|
151
161
|
requirements:
|
152
|
-
- - "
|
162
|
+
- - "~>"
|
153
163
|
- !ruby/object:Gem::Version
|
154
|
-
version: '2.
|
164
|
+
version: '2.4'
|
155
165
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
166
|
requirements:
|
157
167
|
- - ">="
|
158
168
|
- !ruby/object:Gem::Version
|
159
169
|
version: '0'
|
160
|
-
requirements:
|
161
|
-
- none
|
170
|
+
requirements: []
|
162
171
|
rubygems_version: 3.0.3
|
163
172
|
signing_key:
|
164
173
|
specification_version: 4
|
@@ -166,6 +175,7 @@ summary: Stripe Payment Method for Solidus
|
|
166
175
|
test_files:
|
167
176
|
- spec/features/stripe_checkout_spec.rb
|
168
177
|
- spec/models/solidus_stripe/address_from_params_service_spec.rb
|
178
|
+
- spec/models/solidus_stripe/create_intents_payment_service_spec.rb
|
169
179
|
- spec/models/solidus_stripe/prepare_order_for_payment_service_spec.rb
|
170
180
|
- spec/models/solidus_stripe/shipping_rates_service_spec.rb
|
171
181
|
- spec/models/spree/payment_method/stripe_credit_card_spec.rb
|
data/LICENSE.md
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
Copyright (c) 2014 Spree Commerce Inc. and other contributors.
|
2
|
-
All rights reserved.
|
3
|
-
|
4
|
-
Redistribution and use in source and binary forms, with or without modification,
|
5
|
-
are permitted provided that the following conditions are met:
|
6
|
-
|
7
|
-
* Redistributions of source code must retain the above copyright notice,
|
8
|
-
this list of conditions and the following disclaimer.
|
9
|
-
* Redistributions in binary form must reproduce the above copyright notice,
|
10
|
-
this list of conditions and the following disclaimer in the documentation
|
11
|
-
and/or other materials provided with the distribution.
|
12
|
-
* Neither the name Spree nor the names of its contributors may be used to
|
13
|
-
endorse or promote products derived from this software without specific
|
14
|
-
prior written permission.
|
15
|
-
|
16
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
17
|
-
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
18
|
-
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
19
|
-
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
20
|
-
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
21
|
-
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
22
|
-
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
23
|
-
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
24
|
-
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
25
|
-
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26
|
-
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|