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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +5 -0
  4. data/CHANGELOG.md +58 -2
  5. data/Gemfile +7 -0
  6. data/LICENSE +2 -2
  7. data/README.md +26 -8
  8. data/Rakefile +1 -1
  9. data/app/assets/javascripts/spree/frontend/solidus_stripe/stripe-cart-page-checkout.js +42 -9
  10. data/app/assets/javascripts/spree/frontend/solidus_stripe/stripe-payment-intents.js +3 -2
  11. data/app/assets/javascripts/spree/frontend/solidus_stripe/stripe-payment-request-button-shared.js +56 -20
  12. data/app/controllers/solidus_stripe/intents_controller.rb +23 -18
  13. data/app/decorators/models/spree/refund_decorator.rb +9 -0
  14. data/app/models/solidus_stripe/address_from_params_service.rb +5 -2
  15. data/app/models/solidus_stripe/create_intents_payment_service.rb +113 -0
  16. data/app/models/spree/payment_method/stripe_credit_card.rb +16 -1
  17. data/bin/r +13 -0
  18. data/bin/rake +7 -0
  19. data/bin/sandbox +84 -0
  20. data/bin/sandbox_rails +18 -0
  21. data/bin/setup +1 -1
  22. data/config/routes.rb +4 -1
  23. data/lib/generators/solidus_stripe/install/install_generator.rb +7 -3
  24. data/lib/solidus_stripe/engine.rb +2 -2
  25. data/lib/solidus_stripe/factories.rb +4 -0
  26. data/lib/solidus_stripe/version.rb +1 -1
  27. data/lib/views/frontend/spree/checkout/payment/v3/_form_elements.html.erb +0 -1
  28. data/solidus_stripe.gemspec +34 -37
  29. data/spec/features/stripe_checkout_spec.rb +101 -48
  30. data/spec/models/solidus_stripe/address_from_params_service_spec.rb +19 -5
  31. data/spec/models/solidus_stripe/create_intents_payment_service_spec.rb +127 -0
  32. data/spec/models/spree/payment_method/stripe_credit_card_spec.rb +44 -1
  33. data/spec/spec_helper.rb +4 -1
  34. metadata +23 -16
  35. data/LICENSE.md +0 -26
  36. 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: 929c7fff2fc949fe3979ae7a9403903b563a3ef67c5c8588f171c9bf42181ce6
4
- data.tar.gz: a00f65c3222947871e6a97e5fd3e7d72eb7e5edc134128e300578ff68b13f876
3
+ metadata.gz: fbb4f65f220249d05424544fea63ae4b7ee065a735d9ad75d30212f90f11c2e9
4
+ data.tar.gz: 0167d591c1bad084130963d11dc0d823d51e9fb7b26d04964634ba87d79f7a8f
5
5
  SHA512:
6
- metadata.gz: 8090f338dfefc83e121000e88d467eabc6631e6501eea750b2103c31d285a1a28364e01968c0586f564099780d69bde29f736cc2bf4b34f9456b7bf02ea84501
7
- data.tar.gz: d7e5b50dd60a80c74754acd3bbcc0552af926c04d05f380995319a0336daf2aa37f8c127966d68dcecf8bb308d7ef6607ff5d948bc2e23a1544179a41c93fac5
6
+ metadata.gz: 5006bc7738c469e4d00f0f709c51691f56dad323a418283b0d361d04728140a4bf1069be861ff5d08df98b06e3147d0fa91ea004fe741e5c8229e720702b6c8a
7
+ data.tar.gz: 2dfea9b20b5dabc2f1199256fb04a3911e811f62d97de95e07cb5f675ba3c70105c81ff8b6ea8fb34f6cf19eb4b1e380a0ae8fd28acccad715c45f8cd9064b56
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ pkg
16
16
  *.swp
17
17
  spec/dummy
18
18
  spec/examples.txt
19
+ /sandbox
@@ -1,2 +1,7 @@
1
1
  require:
2
2
  - solidus_dev_support/rubocop
3
+
4
+ AllCops:
5
+ Exclude:
6
+ - sandbox/**/*
7
+ - spec/dummy/**/*
@@ -1,12 +1,68 @@
1
1
  # Changelog
2
2
 
3
- ## [Unreleased](https://github.com/solidusio/solidus_stripe/tree/HEAD)
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/v3.0.0...HEAD)
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) 2020 Solidus Team
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 Solidus nor the names of its contributors may be used to
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 load that partial in the `orders#edit` frontend page, and pass it the
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`, for example using `deface`:
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
@@ -3,4 +3,4 @@
3
3
  require 'solidus_dev_support/rake_tasks'
4
4
  SolidusDevSupport::RakeTasks.install
5
5
 
6
- task default: %w[extension:test_app extension:specs]
6
+ task default: 'extension:specs'
@@ -16,11 +16,14 @@ SolidusStripe.CartPageCheckout.prototype.init = function() {
16
16
  };
17
17
 
18
18
  SolidusStripe.CartPageCheckout.prototype.showError = function(error) {
19
- this.errorElement.text(error).show();
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(this.prTokenHandler(payment.paymentMethod)),
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(result) {
43
- var handleServerResponse = this.handleServerResponse.bind(this);
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: result.shippingAddress,
50
- shipping_option: result.shippingOption,
51
- email: result.payerEmail,
52
- name: result.payerName,
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
- handleServerResponse(json, result);
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/confirm_payment', {
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/confirm_intents', {
67
+ fetch('/stripe/create_intent', {
67
68
  method: 'POST',
68
69
  headers: {
69
70
  'Content-Type': 'application/json'
@@ -83,37 +83,73 @@
83
83
  this.showError(response.error);
84
84
  this.completePaymentRequest(payment, 'fail');
85
85
  } else if (response.requires_action) {
86
- this.stripe.handleCardAction(
87
- response.stripe_payment_intent_client_secret
88
- ).then(this.onIntentsClientSecret.bind(this));
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.completePaymentRequest(payment, 'success');
91
- this.submitPayment(payment);
97
+ this.completePayment(payment, response.stripe_payment_intent_id)
92
98
  }
93
99
  },
94
100
 
95
- onIntentsClientSecret: function(result) {
96
- if (result.error) {
97
- this.showError(result.error);
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
- fetch('/stripe/confirm_intents', {
100
- method: 'POST',
101
- headers: { 'Content-Type': 'application/json' },
102
- body: JSON.stringify({
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 confirm
8
- begin
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
- SolidusStripe::CreateIntentsOrderService.new(@intent, stripe, self).call
41
- render json: { success: true }
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 create_intent
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: 'manual',
58
+ confirmation_method: 'automatic',
54
59
  capture_method: 'manual',
55
60
  confirm: true,
56
61
  setup_future_usage: 'off_session',