solidus_stripe 3.1.0 → 4.2.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.
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
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.
@@ -1,70 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SolidusStripe
4
- class CreateIntentsOrderService
5
- attr_reader :intent, :stripe, :controller
6
-
7
- delegate :request, :current_order, :params, to: :controller
8
-
9
- def initialize(intent, stripe, controller)
10
- @intent, @stripe, @controller = intent, stripe, controller
11
- end
12
-
13
- def call
14
- invalidate_previous_payment_intents_payments
15
- payment = create_payment
16
- description = "Solidus Order ID: #{payment.gateway_order_identifier}"
17
- stripe.update_intent(nil, response['id'], nil, description: description)
18
- end
19
-
20
- private
21
-
22
- def invalidate_previous_payment_intents_payments
23
- if stripe.v3_intents?
24
- current_order.payments.pending.where(payment_method: stripe).each(&:void_transaction!)
25
- end
26
- end
27
-
28
- def create_payment
29
- Spree::OrderUpdateAttributes.new(
30
- current_order,
31
- payment_params,
32
- request_env: request.headers.env
33
- ).apply
34
-
35
- Spree::Payment.find_by(response_code: response['id']).tap do |payment|
36
- payment.update!(state: :pending)
37
- end
38
- end
39
-
40
- def payment_params
41
- card = response['charges']['data'][0]['payment_method_details']['card']
42
- address_attributes = form_data['payment_source'][stripe.id.to_s]['address_attributes']
43
-
44
- {
45
- payments_attributes: [{
46
- payment_method_id: stripe.id,
47
- amount: current_order.total,
48
- response_code: response['id'],
49
- source_attributes: {
50
- month: card['exp_month'],
51
- year: card['exp_year'],
52
- cc_type: card['brand'],
53
- gateway_payment_profile_id: response['payment_method'],
54
- last_digits: card['last4'],
55
- name: current_order.bill_address.full_name,
56
- address_attributes: address_attributes
57
- }
58
- }]
59
- }
60
- end
61
-
62
- def response
63
- intent.params
64
- end
65
-
66
- def form_data
67
- Rack::Utils.parse_nested_query(params[:form_data])
68
- end
69
- end
70
- end