effective_orders 5.9.2 → 5.9.4

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: 8207656323cf7dfe93656598ad79fec2db779f8879d1c89adce3d2c71f66b079
4
- data.tar.gz: 705cf2da66eee1acdaf88dd41061d517d7701ec5ff7aa66d0369d1324e177b3e
3
+ metadata.gz: 35bd45132852365a2cc570b4b6a7fbbf5cc62d42cd9f506710da80a0c77daf82
4
+ data.tar.gz: e97f9869c710bdfb91cfa35b6b0bc091b429b175cdc7af9b066283d02d90bac6
5
5
  SHA512:
6
- metadata.gz: 84102e16425ac192cf6f011ed9e10630971fb46beed5d16a433ae19e661e387e215d7242003e414ee76302cbe8c1913ccb86ada31a6caec9c86f32b3b6f0d083
7
- data.tar.gz: 44845062ecb7a093b1139d65a4912b6edbc2a261cb119663ea06456981ac4262b97e1e68989039684fcf201afa934b71a89ae8321da56faf6ec3fa5e1741d1c4
6
+ metadata.gz: 02036ff52d79eaa0c47e6f2353f23b33d6168222abe6337a77880fb7c48d0c7de7b1960235ed2b2dcb9e304aac36b8bddbbf0f1132fee7395bed3638be80c2bd
7
+ data.tar.gz: 1929601f0588f3cefde7eec8ceec3f796b03822406e9ae1533507a783c3f0867a5c408f21a9954c12eaa225c912817044102c869d1a334660f328a80a9381a2c
@@ -13,7 +13,7 @@ module Effective
13
13
 
14
14
  payment = validate_stripe_payment(stripe_params[:payment_intent_id])
15
15
 
16
- if payment.blank? || !payment.kind_of?(Hash)
16
+ if payment.blank?
17
17
  return order_declined(payment: payment, provider: 'stripe', declined_url: stripe_params[:declined_url])
18
18
  end
19
19
 
@@ -37,36 +37,35 @@ module Effective
37
37
  end
38
38
 
39
39
  def validate_stripe_payment(payment_intent_id)
40
- begin
41
- intent = EffectiveOrders.with_stripe { ::Stripe::PaymentIntent.retrieve(payment_intent_id) }
42
-
43
- raise('status is not succeeded') unless intent.status == 'succeeded'
44
- raise('charges are not present') unless intent.charges.present?
45
-
46
- charge = intent.charges.data.first
47
- raise('charge not succeeded') unless charge.status == 'succeeded'
48
-
49
- card = charge.payment_method_details.try(:card) || {}
50
- active_card = "**** **** **** #{card['last4']} #{card['brand']} #{card['exp_month']}/#{card['exp_year']}" if card.present?
51
-
52
- {
53
- charge_id: charge.id,
54
- payment_method_id: charge.payment_method,
55
- payment_intent_id: intent.id,
56
-
57
- active_card: active_card,
58
- card: card['brand'],
59
-
60
- amount: charge.amount,
61
- created: charge.created,
62
- currency: charge.currency,
63
- customer: charge.customer,
64
- status: charge.status
65
- }.compact
66
-
67
- rescue => e
68
- e.message
69
- end
40
+ intent = EffectiveOrders.with_stripe { ::Stripe::PaymentIntent.retrieve(payment_intent_id) }
41
+ raise('expected stripe intent to be present') if intent.blank?
42
+ return unless intent.status == 'succeeded'
43
+
44
+ # Stripe API version 2022-11-15 and 2022-08-01
45
+ charge_id = intent.try(:latest_charge) || (intent.charges.data.first.id rescue nil)
46
+ raise('expected stripe charge_id to be present') if charge_id.blank?
47
+
48
+ charge = EffectiveOrders.with_stripe { ::Stripe::Charge.retrieve(charge_id) }
49
+ raise('expected stripe charge to be present') if charge.blank?
50
+ return unless charge.status == 'succeeded'
51
+
52
+ card = charge.payment_method_details.try(:card) || {}
53
+ active_card = "**** **** **** #{card['last4']} #{card['brand']} #{card['exp_month']}/#{card['exp_year']}" if card.present?
54
+
55
+ {
56
+ charge_id: charge.id,
57
+ payment_method_id: charge.payment_method,
58
+ payment_intent_id: intent.id,
59
+
60
+ active_card: active_card,
61
+ card: card['brand'],
62
+
63
+ amount: charge.amount,
64
+ created: charge.created,
65
+ currency: charge.currency,
66
+ customer: charge.customer,
67
+ status: charge.status
68
+ }.compact
70
69
  end
71
70
 
72
71
  end
@@ -499,7 +499,10 @@ module Effective
499
499
  self.addresses.clear if addresses.any? { |address| address.valid? == false }
500
500
  save!
501
501
 
502
- send_payment_request_to_buyer! if send_payment_request_to_buyer?
502
+ if send_payment_request_to_buyer?
503
+ after_commit { send_payment_request_to_buyer! }
504
+ end
505
+
503
506
  true
504
507
  end
505
508
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrders
2
- VERSION = '5.9.2'.freeze
2
+ VERSION = '5.9.4'.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: 5.9.2
4
+ version: 5.9.4
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-11-29 00:00:00.000000000 Z
11
+ date: 2022-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails