solidus_stripe 3.1.0 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +5 -0
- data/CHANGELOG.md +58 -2
- data/Gemfile +7 -0
- data/LICENSE +2 -2
- data/README.md +26 -8
- 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-payment-intents.js +3 -2
- data/app/assets/javascripts/spree/frontend/solidus_stripe/stripe-payment-request-button-shared.js +56 -20
- data/app/controllers/solidus_stripe/intents_controller.rb +23 -18
- 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 +16 -1
- 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 +101 -48
- 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 +23 -16
- data/LICENSE.md +0 -26
- data/app/models/solidus_stripe/create_intents_order_service.rb +0 -70
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbb4f65f220249d05424544fea63ae4b7ee065a735d9ad75d30212f90f11c2e9
|
4
|
+
data.tar.gz: 0167d591c1bad084130963d11dc0d823d51e9fb7b26d04964634ba87d79f7a8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5006bc7738c469e4d00f0f709c51691f56dad323a418283b0d361d04728140a4bf1069be861ff5d08df98b06e3147d0fa91ea004fe741e5c8229e720702b6c8a
|
7
|
+
data.tar.gz: 2dfea9b20b5dabc2f1199256fb04a3911e811f62d97de95e07cb5f675ba3c70105c81ff8b6ea8fb34f6cf19eb4b1e380a0ae8fd28acccad715c45f8cd9064b56
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,12 +1,68 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## [
|
3
|
+
## [v4.1.0](https://github.com/solidusio/solidus_stripe/tree/v4.1.0) (2020-07-01)
|
4
4
|
|
5
|
-
[Full Changelog](https://github.com/solidusio/solidus_stripe/compare/
|
5
|
+
[Full Changelog](https://github.com/solidusio/solidus_stripe/compare/v4.0.0...v4.1.0)
|
6
|
+
|
7
|
+
**Fixed bugs:**
|
8
|
+
|
9
|
+
- Card name ignored when adding new card to an order during checkout [\#68](https://github.com/solidusio/solidus_stripe/issues/68)
|
10
|
+
- Try to find address state also by name [\#65](https://github.com/solidusio/solidus_stripe/pull/65) ([spaghetticode](https://github.com/spaghetticode))
|
11
|
+
- Fix order cancel with Payment Intents captured payment [\#57](https://github.com/solidusio/solidus_stripe/pull/57) ([spaghetticode](https://github.com/spaghetticode))
|
12
|
+
- \[ADMIN\] Order cancel doen't work with Payment Intents captured payments [\#56](https://github.com/solidusio/solidus_stripe/issues/56)
|
13
|
+
|
14
|
+
**Merged pull requests:**
|
15
|
+
|
16
|
+
- Save correct cardholder name in Spree::CreditCard [\#69](https://github.com/solidusio/solidus_stripe/pull/69) ([spaghetticode](https://github.com/spaghetticode))
|
17
|
+
- Update Readme [\#63](https://github.com/solidusio/solidus_stripe/pull/63) ([aleph1ow](https://github.com/aleph1ow))
|
18
|
+
- Remove credit cards image [\#62](https://github.com/solidusio/solidus_stripe/pull/62) ([aleph1ow](https://github.com/aleph1ow))
|
19
|
+
- Remove Stripe::CardError leftover [\#58](https://github.com/solidusio/solidus_stripe/pull/58) ([spaghetticode](https://github.com/spaghetticode))
|
20
|
+
- Update gemspec URLs [\#54](https://github.com/solidusio/solidus_stripe/pull/54) ([elia](https://github.com/elia))
|
21
|
+
- fix typo [\#51](https://github.com/solidusio/solidus_stripe/pull/51) ([ccarruitero](https://github.com/ccarruitero))
|
22
|
+
|
23
|
+
**Closed issues:**
|
24
|
+
|
25
|
+
- Could not find generator 'solidus\_stripe:install' [\#60](https://github.com/solidusio/solidus_stripe/issues/60)
|
26
|
+
- Payment Intent creation exception handling with class not present in the gem [\#55](https://github.com/solidusio/solidus_stripe/issues/55)
|
27
|
+
- Using static credentials [\#52](https://github.com/solidusio/solidus_stripe/issues/52)
|
28
|
+
- Auto capture behavior in v4.0.0 [\#50](https://github.com/solidusio/solidus_stripe/issues/50)
|
29
|
+
|
30
|
+
## [v4.0.0](https://github.com/solidusio/solidus_stripe/tree/v4.0.0) (2020-04-29)
|
31
|
+
|
32
|
+
[Full Changelog](https://github.com/solidusio/solidus_stripe/compare/v3.0.0...v4.0.0)
|
33
|
+
|
34
|
+
**Fixed bugs:**
|
35
|
+
|
36
|
+
- Duplicates charges with Payment Intents [\#44](https://github.com/solidusio/solidus_stripe/issues/44)
|
37
|
+
- Fix for 3D-Secure payments on cart page checkout [\#49](https://github.com/solidusio/solidus_stripe/pull/49) ([spaghetticode](https://github.com/spaghetticode))
|
38
|
+
- Send form data also when paying with payment request button [\#47](https://github.com/solidusio/solidus_stripe/pull/47) ([spaghetticode](https://github.com/spaghetticode))
|
39
|
+
- Create a single charge when using Stripe Payment Intents [\#45](https://github.com/solidusio/solidus_stripe/pull/45) ([spaghetticode](https://github.com/spaghetticode))
|
6
40
|
|
7
41
|
**Closed issues:**
|
8
42
|
|
43
|
+
- Custom stripe element field options \(e.g for showing a credit card icon\) [\#41](https://github.com/solidusio/solidus_stripe/issues/41)
|
44
|
+
- Stripe Elements submit button stuck in disabled state. [\#39](https://github.com/solidusio/solidus_stripe/issues/39)
|
45
|
+
- Visa credit card type is blank [\#36](https://github.com/solidusio/solidus_stripe/issues/36)
|
9
46
|
- Pay with Apple Pay from cart page [\#23](https://github.com/solidusio/solidus_stripe/issues/23)
|
47
|
+
- Clearer documentation on how to implement [\#15](https://github.com/solidusio/solidus_stripe/issues/15)
|
48
|
+
|
49
|
+
**Merged pull requests:**
|
50
|
+
|
51
|
+
- Relax solidus\_support dependency [\#48](https://github.com/solidusio/solidus_stripe/pull/48) ([kennyadsl](https://github.com/kennyadsl))
|
52
|
+
- Replace deprecated route `/stripe/confirm\_payment` [\#46](https://github.com/solidusio/solidus_stripe/pull/46) ([spaghetticode](https://github.com/spaghetticode))
|
53
|
+
- Custom Stripe Elements field options [\#42](https://github.com/solidusio/solidus_stripe/pull/42) ([stuffmatic](https://github.com/stuffmatic))
|
54
|
+
- Improve the way Stripe Elements validation errors are displayed [\#40](https://github.com/solidusio/solidus_stripe/pull/40) ([stuffmatic](https://github.com/stuffmatic))
|
55
|
+
- Fix stripe-to-solidus card type mapping [\#38](https://github.com/solidusio/solidus_stripe/pull/38) ([stuffmatic](https://github.com/stuffmatic))
|
56
|
+
- Add hook to provide custom Stripe Elements options [\#37](https://github.com/solidusio/solidus_stripe/pull/37) ([stuffmatic](https://github.com/stuffmatic))
|
57
|
+
- Change order description that we pass to Stripe [\#35](https://github.com/solidusio/solidus_stripe/pull/35) ([kennyadsl](https://github.com/kennyadsl))
|
58
|
+
|
59
|
+
## [v3.2.1](https://github.com/solidusio/solidus_stripe/tree/v3.2.1) (2020-06-29)
|
60
|
+
|
61
|
+
[Full Changelog](https://github.com/solidusio/solidus_stripe/compare/v3.2.0...v3.2.1)
|
62
|
+
|
63
|
+
**Merged pull requests:**
|
64
|
+
|
65
|
+
- Relax solidus\_support version dependency [\#70](https://github.com/solidusio/solidus_stripe/pull/70) ([spaghetticode](https://github.com/spaghetticode))
|
10
66
|
|
11
67
|
## [v3.0.0](https://github.com/solidusio/solidus_stripe/tree/v3.0.0) (2020-03-11)
|
12
68
|
|
data/Gemfile
CHANGED
@@ -30,3 +30,10 @@ group :development, :test do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
gemspec
|
33
|
+
|
34
|
+
# Use a local Gemfile to include development dependencies that might not be
|
35
|
+
# relevant for the project or for other contributors, e.g. pry-byebug.
|
36
|
+
#
|
37
|
+
# We use `send` instead of calling `eval_gemfile` to work around an issue with
|
38
|
+
# how Dependabot parses projects: https://github.com/dependabot/dependabot-core/issues/1658.
|
39
|
+
send(:eval_gemfile, 'Gemfile-local') if File.exist? 'Gemfile-local'
|
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c)
|
1
|
+
Copyright (c) 2014 Spree Commerce Inc. and other contributors.
|
2
2
|
All rights reserved.
|
3
3
|
|
4
4
|
Redistribution and use in source and binary forms, with or without modification,
|
@@ -9,7 +9,7 @@ are permitted provided that the following conditions are met:
|
|
9
9
|
* Redistributions in binary form must reproduce the above copyright notice,
|
10
10
|
this list of conditions and the following disclaimer in the documentation
|
11
11
|
and/or other materials provided with the distribution.
|
12
|
-
* Neither the name
|
12
|
+
* Neither the name Spree nor the names of its contributors may be used to
|
13
13
|
endorse or promote products derived from this software without specific
|
14
14
|
prior written permission.
|
15
15
|
|
data/README.md
CHANGED
@@ -107,6 +107,25 @@ Spree.config do |config|
|
|
107
107
|
end
|
108
108
|
```
|
109
109
|
|
110
|
+
When using the Payment Intents API, be aware that the charge flow will be a bit
|
111
|
+
different than when using the old V2 API or Elements. It's advisable that all
|
112
|
+
Payment Intents charges are captured only by using the Solidus backend, as it is
|
113
|
+
the final source of truth in regards of Solidus orders payments.
|
114
|
+
|
115
|
+
A Payment Intent is created as soon as the customer enters their credit card
|
116
|
+
data. A tentative charge will be created on Stripe, easily recognizable by its
|
117
|
+
description: `Solidus Order ID: R987654321 (pending)`. As soon as the credit
|
118
|
+
card is confirmed (ie. when the customer passes the 3DSecure authorization, when
|
119
|
+
required) then the charge description gets updated to include the Solidus payment
|
120
|
+
number: `Solidus Order ID: R987654321-Z4VYUDB3`.
|
121
|
+
|
122
|
+
These charges are created `uncaptured` and will need to be captured in Solidus
|
123
|
+
backend later, after the customer confirms the order. If the customer never
|
124
|
+
completes the checkout, that charge must remain uncaptured. If the customer
|
125
|
+
decides to change their payment method after creating a Payment Request, then
|
126
|
+
that Payment Request charge will be canceled.
|
127
|
+
|
128
|
+
|
110
129
|
Apple Pay and Google Pay
|
111
130
|
-----------------------
|
112
131
|
|
@@ -119,14 +138,11 @@ Stripe account to receive payments via Apple Pay.
|
|
119
138
|
It's possible to pay with Apple Pay and Google Pay directly from the cart
|
120
139
|
page. The functionality is self-contained in the view partial
|
121
140
|
`_stripe_payment_request_button.html.erb`. In order to use it, you need
|
122
|
-
to
|
141
|
+
to render that partial in the `orders#edit` frontend page, and pass it the
|
123
142
|
payment method configured for Stripe via the local variable
|
124
|
-
`cart_checkout_payment_method
|
143
|
+
`cart_checkout_payment_method`:
|
125
144
|
|
126
145
|
```ruby
|
127
|
-
# app/overrides/spree/orders/edit/add_payment_request_button.html.erb.deface
|
128
|
-
|
129
|
-
<!-- insert_after '[data-hook="cart_container"]' -->
|
130
146
|
<%= render 'stripe_payment_request_button', cart_checkout_payment_method: Spree::PaymentMethod::StripeCreditCard.first %>
|
131
147
|
```
|
132
148
|
|
@@ -210,13 +226,13 @@ You can also style your element containers directly by using CSS rules like this
|
|
210
226
|
|
211
227
|
### Customizing individual input fields
|
212
228
|
|
213
|
-
If you want to customize individual input fields, you can override these methods
|
229
|
+
If you want to customize individual input fields, you can override these methods
|
214
230
|
|
215
231
|
* `SolidusStripe.Elements.prototype.cardNumberElementOptions`
|
216
232
|
* `SolidusStripe.Elements.prototype.cardExpiryElementOptions`
|
217
233
|
* `SolidusStripe.Elements.prototype.cardCvcElementOptions`
|
218
234
|
|
219
|
-
and return a valid [options object](https://stripe.com/docs/js/elements_object/create_element?type=cardNumber) for the corresponding field type. For example, this code sets a custom placeholder and enables the credit card icon for the card number field
|
235
|
+
and return a valid [options object](https://stripe.com/docs/js/elements_object/create_element?type=cardNumber) for the corresponding field type. For example, this code sets a custom placeholder and enables the credit card icon for the card number field
|
220
236
|
|
221
237
|
```js
|
222
238
|
SolidusStripe.Elements.prototype.cardNumberElementOptions = function () {
|
@@ -230,7 +246,7 @@ SolidusStripe.Elements.prototype.cardNumberElementOptions = function () {
|
|
230
246
|
|
231
247
|
### Passing options to the Stripe Elements instance
|
232
248
|
|
233
|
-
By overriding the `SolidusStripe.Payment.prototype.elementsBaseOptions` method and returning a [valid options object](https://stripe.com/docs/js/elements_object/create), you can pass custom options to the Stripe Elements instance.
|
249
|
+
By overriding the `SolidusStripe.Payment.prototype.elementsBaseOptions` method and returning a [valid options object](https://stripe.com/docs/js/elements_object/create), you can pass custom options to the Stripe Elements instance.
|
234
250
|
|
235
251
|
Note that in order to use web fonts with Stripe Elements, you must specify the fonts when creating the Stripe Elements instance. Here's an example specifying a custom web font and locale:
|
236
252
|
|
@@ -294,3 +310,5 @@ gem bump --version minor --remote upstream
|
|
294
310
|
gem tag --remote upstream
|
295
311
|
gem release
|
296
312
|
```
|
313
|
+
|
314
|
+
Copyright (c) 2020 Spree Commerce Inc., released under the New BSD License
|
data/Rakefile
CHANGED
@@ -16,11 +16,14 @@ SolidusStripe.CartPageCheckout.prototype.init = function() {
|
|
16
16
|
};
|
17
17
|
|
18
18
|
SolidusStripe.CartPageCheckout.prototype.showError = function(error) {
|
19
|
-
|
19
|
+
var message = error.message || error;
|
20
|
+
|
21
|
+
this.errorElement.text(message).show();
|
20
22
|
};
|
21
23
|
|
22
24
|
SolidusStripe.CartPageCheckout.prototype.submitPayment = function(payment) {
|
23
25
|
var showError = this.showError.bind(this);
|
26
|
+
var prTokenHandler = this.prTokenHandler.bind(this);
|
24
27
|
|
25
28
|
$.ajax({
|
26
29
|
url: $('[data-submit-url]').data('submit-url'),
|
@@ -29,7 +32,7 @@ SolidusStripe.CartPageCheckout.prototype.submitPayment = function(payment) {
|
|
29
32
|
},
|
30
33
|
type: 'PATCH',
|
31
34
|
contentType: 'application/json',
|
32
|
-
data: JSON.stringify(
|
35
|
+
data: JSON.stringify(prTokenHandler(payment.paymentMethod)),
|
33
36
|
success: function() {
|
34
37
|
window.location = $('[data-complete-url]').data('complete-url');
|
35
38
|
},
|
@@ -39,26 +42,56 @@ SolidusStripe.CartPageCheckout.prototype.submitPayment = function(payment) {
|
|
39
42
|
});
|
40
43
|
};
|
41
44
|
|
42
|
-
SolidusStripe.CartPageCheckout.prototype.onPrPayment = function(
|
43
|
-
var
|
45
|
+
SolidusStripe.CartPageCheckout.prototype.onPrPayment = function(payment) {
|
46
|
+
var createIntent = this.createIntent.bind(this);
|
44
47
|
|
45
48
|
fetch('/stripe/update_order', {
|
46
49
|
method: 'POST',
|
47
50
|
headers: { 'Content-Type': 'application/json' },
|
48
51
|
body: JSON.stringify({
|
49
|
-
shipping_address:
|
50
|
-
shipping_option:
|
51
|
-
email:
|
52
|
-
name:
|
52
|
+
shipping_address: payment.shippingAddress,
|
53
|
+
shipping_option: payment.shippingOption,
|
54
|
+
email: payment.payerEmail,
|
55
|
+
name: payment.payerName,
|
53
56
|
authenticity_token: this.authToken
|
54
57
|
})
|
55
58
|
}).then(function(response) {
|
56
59
|
response.json().then(function(json) {
|
57
|
-
|
60
|
+
createIntent(json, payment);
|
58
61
|
})
|
59
62
|
});
|
60
63
|
};
|
61
64
|
|
65
|
+
SolidusStripe.CartPageCheckout.prototype.createIntent = function(result, payment) {
|
66
|
+
var handleServerResponse = this.handleServerResponse.bind(this);
|
67
|
+
|
68
|
+
if (result.error) {
|
69
|
+
this.completePaymentRequest(payment, 'fail');
|
70
|
+
this.showError(result.error);
|
71
|
+
} else {
|
72
|
+
if (payment.error) {
|
73
|
+
this.showError(payment.error.message);
|
74
|
+
} else {
|
75
|
+
fetch('/stripe/create_intent', {
|
76
|
+
method: 'POST',
|
77
|
+
headers: {
|
78
|
+
'Content-Type': 'application/json'
|
79
|
+
},
|
80
|
+
body: JSON.stringify({
|
81
|
+
form_data: payment.shippingAddress,
|
82
|
+
spree_payment_method_id: this.config.id,
|
83
|
+
stripe_payment_method_id: payment.paymentMethod.id,
|
84
|
+
authenticity_token: this.authToken
|
85
|
+
})
|
86
|
+
}).then(function(response) {
|
87
|
+
response.json().then(function(result) {
|
88
|
+
handleServerResponse(result, payment)
|
89
|
+
})
|
90
|
+
});
|
91
|
+
}
|
92
|
+
}
|
93
|
+
};
|
94
|
+
|
62
95
|
SolidusStripe.CartPageCheckout.prototype.onPrButtonMounted = function(buttonId, success) {
|
63
96
|
var container = document.getElementById(buttonId).parentElement;
|
64
97
|
|
@@ -21,12 +21,13 @@ SolidusStripe.PaymentIntents.prototype.onPrPayment = function(payment) {
|
|
21
21
|
var that = this;
|
22
22
|
|
23
23
|
this.elementsTokenHandler(payment.paymentMethod);
|
24
|
-
fetch('/stripe/
|
24
|
+
fetch('/stripe/create_intent', {
|
25
25
|
method: 'POST',
|
26
26
|
headers: {
|
27
27
|
'Content-Type': 'application/json'
|
28
28
|
},
|
29
29
|
body: JSON.stringify({
|
30
|
+
form_data: this.form.serialize(),
|
30
31
|
spree_payment_method_id: this.config.id,
|
31
32
|
stripe_payment_method_id: payment.paymentMethod.id,
|
32
33
|
authenticity_token: this.authToken
|
@@ -63,7 +64,7 @@ SolidusStripe.PaymentIntents.prototype.onIntentsPayment = function(payment) {
|
|
63
64
|
var that = this;
|
64
65
|
|
65
66
|
this.elementsTokenHandler(payment.paymentMethod);
|
66
|
-
fetch('/stripe/
|
67
|
+
fetch('/stripe/create_intent', {
|
67
68
|
method: 'POST',
|
68
69
|
headers: {
|
69
70
|
'Content-Type': 'application/json'
|
data/app/assets/javascripts/spree/frontend/solidus_stripe/stripe-payment-request-button-shared.js
CHANGED
@@ -83,37 +83,73 @@
|
|
83
83
|
this.showError(response.error);
|
84
84
|
this.completePaymentRequest(payment, 'fail');
|
85
85
|
} else if (response.requires_action) {
|
86
|
-
|
87
|
-
|
88
|
-
|
86
|
+
var clientSecret = response.stripe_payment_intent_client_secret;
|
87
|
+
var onConfirmCardPayment = this.onConfirmCardPayment.bind(this);
|
88
|
+
|
89
|
+
this.stripe.confirmCardPayment(
|
90
|
+
clientSecret,
|
91
|
+
{payment_method: payment.paymentMethod.id},
|
92
|
+
{handleActions: false}
|
93
|
+
).then(function(confirmResult) {
|
94
|
+
onConfirmCardPayment(confirmResult, payment, clientSecret)
|
95
|
+
});
|
89
96
|
} else {
|
90
|
-
this.
|
91
|
-
this.submitPayment(payment);
|
97
|
+
this.completePayment(payment, response.stripe_payment_intent_id)
|
92
98
|
}
|
93
99
|
},
|
94
100
|
|
95
|
-
|
96
|
-
|
97
|
-
|
101
|
+
onConfirmCardPayment: function(confirmResult, payment, clientSecret) {
|
102
|
+
onStripeResponse = function(response, payment) {
|
103
|
+
if (response.error) {
|
104
|
+
this.showError(response.error);
|
105
|
+
} else {
|
106
|
+
this.completePayment(payment, response.paymentIntent.id)
|
107
|
+
}
|
108
|
+
}.bind(this);
|
109
|
+
|
110
|
+
if (confirmResult.error) {
|
111
|
+
this.completePaymentRequest(payment, 'fail');
|
112
|
+
this.showError(confirmResult.error);
|
98
113
|
} else {
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
form_data: this.form.serialize(),
|
104
|
-
spree_payment_method_id: this.config.id,
|
105
|
-
stripe_payment_intent_id: result.paymentIntent.id,
|
106
|
-
authenticity_token: this.authToken
|
107
|
-
})
|
108
|
-
}).then(function(confirmResult) {
|
109
|
-
return confirmResult.json();
|
110
|
-
}).then(this.handleServerResponse.bind(this));
|
114
|
+
this.completePaymentRequest(payment, 'success');
|
115
|
+
this.stripe.confirmCardPayment(clientSecret).then(function(response) {
|
116
|
+
onStripeResponse(response, payment);
|
117
|
+
});
|
111
118
|
}
|
112
119
|
},
|
113
120
|
|
121
|
+
completePayment: function(payment, stripePaymentIntentId) {
|
122
|
+
var onCreateBackendPayment = function (response) {
|
123
|
+
if (response.error) {
|
124
|
+
this.completePaymentRequest(payment, 'fail');
|
125
|
+
this.showError(response.error);
|
126
|
+
} else {
|
127
|
+
this.completePaymentRequest(payment, 'success');
|
128
|
+
this.submitPayment(payment);
|
129
|
+
}
|
130
|
+
}.bind(this);
|
131
|
+
|
132
|
+
fetch('/stripe/create_payment', {
|
133
|
+
method: 'POST',
|
134
|
+
headers: { 'Content-Type': 'application/json' },
|
135
|
+
body: JSON.stringify({
|
136
|
+
form_data: this.form ? this.form.serialize() : payment.shippingAddress,
|
137
|
+
spree_payment_method_id: this.config.id,
|
138
|
+
stripe_payment_intent_id: stripePaymentIntentId,
|
139
|
+
authenticity_token: this.authToken
|
140
|
+
})
|
141
|
+
}).then(function(solidusPaymentResponse) {
|
142
|
+
return solidusPaymentResponse.json();
|
143
|
+
}).then(onCreateBackendPayment)
|
144
|
+
},
|
145
|
+
|
114
146
|
completePaymentRequest: function(payment, state) {
|
115
147
|
if (payment && typeof payment.complete === 'function') {
|
116
148
|
payment.complete(state);
|
149
|
+
if (state === 'fail') {
|
150
|
+
// restart the button (required in order to force address choice)
|
151
|
+
new SolidusStripe.CartPageCheckout().init();
|
152
|
+
}
|
117
153
|
}
|
118
154
|
}
|
119
155
|
};
|
@@ -4,23 +4,25 @@ module SolidusStripe
|
|
4
4
|
class IntentsController < Spree::BaseController
|
5
5
|
include Spree::Core::ControllerHelpers::Order
|
6
6
|
|
7
|
-
def
|
8
|
-
|
9
|
-
@intent = begin
|
10
|
-
if params[:stripe_payment_method_id].present?
|
11
|
-
create_intent
|
12
|
-
elsif params[:stripe_payment_intent_id].present?
|
13
|
-
stripe.confirm_intent(params[:stripe_payment_intent_id], nil)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
rescue Stripe::CardError => e
|
17
|
-
render json: { error: e.message }, status: 500
|
18
|
-
return
|
19
|
-
end
|
20
|
-
|
7
|
+
def create_intent
|
8
|
+
@intent = create_payment_intent
|
21
9
|
generate_payment_response
|
22
10
|
end
|
23
11
|
|
12
|
+
def create_payment
|
13
|
+
create_payment_service = SolidusStripe::CreateIntentsPaymentService.new(
|
14
|
+
params[:stripe_payment_intent_id],
|
15
|
+
stripe,
|
16
|
+
self
|
17
|
+
)
|
18
|
+
|
19
|
+
if create_payment_service.call
|
20
|
+
render json: { success: true }
|
21
|
+
else
|
22
|
+
render json: { error: "Could not create payment" }, status: 500
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
24
26
|
private
|
25
27
|
|
26
28
|
def stripe
|
@@ -37,20 +39,23 @@ module SolidusStripe
|
|
37
39
|
stripe_payment_intent_client_secret: response['client_secret']
|
38
40
|
}
|
39
41
|
elsif response['status'] == 'requires_capture'
|
40
|
-
|
41
|
-
|
42
|
+
render json: {
|
43
|
+
success: true,
|
44
|
+
requires_capture: true,
|
45
|
+
stripe_payment_intent_id: response['id']
|
46
|
+
}
|
42
47
|
else
|
43
48
|
render json: { error: response['error']['message'] }, status: 500
|
44
49
|
end
|
45
50
|
end
|
46
51
|
|
47
|
-
def
|
52
|
+
def create_payment_intent
|
48
53
|
stripe.create_intent(
|
49
54
|
(current_order.total * 100).to_i,
|
50
55
|
params[:stripe_payment_method_id],
|
51
56
|
description: "Solidus Order ID: #{current_order.number} (pending)",
|
52
57
|
currency: current_order.currency,
|
53
|
-
confirmation_method: '
|
58
|
+
confirmation_method: 'automatic',
|
54
59
|
capture_method: 'manual',
|
55
60
|
confirm: true,
|
56
61
|
setup_future_usage: 'off_session',
|