effective_orders 6.1.1 → 6.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9249f1d10040622da38e49058f9a644551208f8be9744e5444ce4288432f68ce
4
- data.tar.gz: bf7f2ca0477fbfedacf7034b2692d82dfc6fb915c6af66162b95aeab3ba1df3a
3
+ metadata.gz: 819088f5b5cc1bd4d6965080f951be723aa5f0a10139ba7a724eae767e47b560
4
+ data.tar.gz: a2b5b57a2612d0b810b90e04481ad221c28335b8f0148e71de223180fa36525e
5
5
  SHA512:
6
- metadata.gz: '08ba32390474ae77d738d6305845fd1b3797edc880d9a82ac1ac348abf1daf1a77ed6b196c04424ef9feff151fd3a5c8a3305953a91da34f77cfc97ead00d870'
7
- data.tar.gz: c817be2902218f0c7a7462859579c606e2905b17891e75f231c141f7902424761d06b715bcaf3c33fa76a4791bbae3c04e3f046be93ba66e39880e1b16af0a76
6
+ metadata.gz: 31f30605ef8af6b7802264d741c7db94b434bd83ec8d917dbbe3f8e175fc516149806600b3237df2fc533fe486b419075f46a335dc6fdd0a43a993b9625a2ce2
7
+ data.tar.gz: 33652d1539fb9cc7ad2fbf53fa245272ddb6d17e75e3c2830c2292005169656704dbff0845b2cc1a5c14d93fd4492198dd82ec9fa88bf95274465a3ed995a77f
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrders
2
- VERSION = '6.1.1'.freeze
2
+ VERSION = '6.1.2'.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.2
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-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails