effective_orders 6.1.1 → 6.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9249f1d10040622da38e49058f9a644551208f8be9744e5444ce4288432f68ce
4
- data.tar.gz: bf7f2ca0477fbfedacf7034b2692d82dfc6fb915c6af66162b95aeab3ba1df3a
3
+ metadata.gz: d89c7eaee9322884706dfaacae71335ca4b8284b06ab69459194cb09b523eb53
4
+ data.tar.gz: 2c667a68c9e3e68fe764cd3386495698d55c8c86c7d213ce5691e0a35f37821c
5
5
  SHA512:
6
- metadata.gz: '08ba32390474ae77d738d6305845fd1b3797edc880d9a82ac1ac348abf1daf1a77ed6b196c04424ef9feff151fd3a5c8a3305953a91da34f77cfc97ead00d870'
7
- data.tar.gz: c817be2902218f0c7a7462859579c606e2905b17891e75f231c141f7902424761d06b715bcaf3c33fa76a4791bbae3c04e3f046be93ba66e39880e1b16af0a76
6
+ metadata.gz: cadaa028284a3ee34b1cdfefe2165722cec9edd5307771d8c2e7c5f5fa5afff5ccbd3926d0c6a535369b163dd3987eb4be4afef1572aafd5c6367268cb7e9591
7
+ data.tar.gz: c5cc2bee6db200d5ba490a61f987b5d00df5c7e7bc78c1bf7bfabb11e536ff2899c4fe1c8be3fef886fb62cfff266aa29b8164a0c3e864b8fa4800437e9ce923
@@ -17,8 +17,19 @@ this.StripeForm ||= class StripeForm
17
17
  @card = @stripe.elements().create('card', @style())
18
18
 
19
19
  @mount()
20
+ @form.find('.stripe-submit-button').show()
20
21
  @form.addClass('initialized')
21
22
 
23
+ destroy: ->
24
+ @form = $('form[data-stripe-form]').first()
25
+ return false unless @form.length > 0
26
+
27
+ @form.find("input[name$='[payment_intent_id]']").val('')
28
+ @form.find('#stripe-card-element').html('')
29
+
30
+ @form.find('.stripe-submit-button').hide()
31
+ @form.removeClass('initialized')
32
+
22
33
  style: ->
23
34
  style: {
24
35
  base: { color: '#32325d', fontSize: '16px', },
@@ -73,7 +84,8 @@ this.StripeForm ||= class StripeForm
73
84
 
74
85
  errorPayment: (error) ->
75
86
  $('#stripe-card-errors').text(error.message)
76
- EffectiveForm.invalidate(@form);
87
+ EffectiveForm.invalidate(@form)
77
88
 
78
89
  $ -> (new StripeForm()).initialize()
79
90
  $(document).on 'turbolinks:load', -> (new StripeForm()).initialize()
91
+ $(document).on 'turbolinks:before-cache', -> (new StripeForm()).destroy()
@@ -50,6 +50,17 @@ module Effective
50
50
  redirect_to declined_url.gsub(':id', @order.to_param.to_s)
51
51
  end
52
52
 
53
+ def order_not_processed(declined_url: nil)
54
+ # No change to the order
55
+
56
+ if flash[:danger].blank?
57
+ flash[:danger] = 'Payment was not processed. Please try again.'
58
+ end
59
+
60
+ declined_url = effective_orders.declined_order_path(':id') if declined_url.blank?
61
+ redirect_to declined_url.gsub(':id', @order.to_param.to_s)
62
+ end
63
+
53
64
  end
54
65
  end
55
66
  end
@@ -11,7 +11,14 @@ module Effective
11
11
 
12
12
  EffectiveResources.authorize!(self, :update, @order)
13
13
 
14
- payment = validate_stripe_payment(stripe_params[:payment_intent_id])
14
+ payment_intent_id = stripe_params[:payment_intent_id]
15
+
16
+ if payment_intent_id.blank?
17
+ flash[:danger] = 'Unable to process stripe order without payment. please try again.'
18
+ return order_not_processed(declined_url: stripe_params[:declined_url])
19
+ end
20
+
21
+ payment = validate_stripe_payment(payment_intent_id)
15
22
 
16
23
  if payment.blank?
17
24
  return order_declined(payment: payment, provider: 'stripe', declined_url: stripe_params[:declined_url])
@@ -37,6 +44,8 @@ module Effective
37
44
  end
38
45
 
39
46
  def validate_stripe_payment(payment_intent_id)
47
+ raise('expected stripe payment intent id to be present') if payment_intent_id.blank?
48
+
40
49
  intent = EffectiveOrders.with_stripe { ::Stripe::PaymentIntent.retrieve(payment_intent_id) }
41
50
  raise('expected stripe intent to be present') if intent.blank?
42
51
  return unless intent.status == 'succeeded'
@@ -60,17 +60,19 @@ module EffectiveStripeHelper
60
60
  customer.create_stripe_customer! # Only creates if customer not already present
61
61
 
62
62
  remember_card = EffectiveOrders.stripe[:remember_card]
63
+ token_required = customer.token_required?
63
64
 
64
65
  payment = {
65
66
  amount: order.total_with_surcharge,
66
67
  currency: EffectiveOrders.stripe[:currency],
67
68
  customer: customer.stripe_customer_id,
68
- payment_method: (customer.payment_method_id.presence if remember_card),
69
69
  description: stripe_order_description(order),
70
70
  metadata: { order_id: order.id }
71
71
  }
72
72
 
73
- token_required = customer.token_required?
73
+ if remember_card && customer.payment_method_id.present?
74
+ payment[:payment_method] = customer.payment_method_id
75
+ end
74
76
 
75
77
  # Always prompt them for a card unless remember card
76
78
  token_required = true unless remember_card
@@ -87,13 +89,18 @@ module EffectiveStripeHelper
87
89
  payload = {
88
90
  key: EffectiveOrders.stripe[:publishable_key],
89
91
  client_secret: intent.client_secret,
90
- payment_method: intent.payment_method,
91
-
92
- active_card: (customer.active_card if remember_card),
93
92
  email: customer.email,
94
93
  token_required: token_required
95
94
  }
96
95
 
96
+ if remember_card && customer.active_card.present? && intent.payment_method.present?
97
+ payload[:active_card] = customer.active_card
98
+ end
99
+
100
+ if intent.payment_method.present?
101
+ payload[:payment_method] = intent.payment_method
102
+ end
103
+
97
104
  payload
98
105
  end
99
106
 
@@ -4,5 +4,5 @@
4
4
  .col.text-right.mx-2
5
5
  %label Details
6
6
 
7
- #stripe-card-element
7
+ #stripe-card-element Loading...
8
8
  #stripe-card-errors
@@ -16,7 +16,7 @@
16
16
  = f.hidden_field :declined_url, value: declined_url
17
17
 
18
18
  -# This is set by the stripe.js javascript
19
- = f.hidden_field :payment_intent_id
19
+ = f.hidden_field :payment_intent_id, required: true
20
20
 
21
21
  - if stripe[:token_required]
22
22
  %p Please enter your credit card information.
@@ -27,5 +27,5 @@
27
27
  = collapse('Use this card instead...', class: 'update-stripe-payment-method') do
28
28
  = render('effective/orders/stripe/element')
29
29
 
30
- .mt-4
30
+ .mt-4.stripe-submit-button{style: 'display: none;'}
31
31
  = f.submit order_checkout_label(:stripe), center: true, border: false
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrders
2
- VERSION = '6.1.1'.freeze
2
+ VERSION = '6.1.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_orders
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.1.1
4
+ version: 6.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-22 00:00:00.000000000 Z
11
+ date: 2022-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails