pay 11.1.0 → 11.1.2

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: 82dd9dc3193e898e2fd8538148e9ff886b852506d80c768a26616921049fbd65
4
- data.tar.gz: 1b85c150235a1ae4531592b6d6c5cf577e126e693c1ce516ea2b01d8199f5276
3
+ metadata.gz: 65a518434cfa0042025a7d66ccaef83ab3057315d349988f3a6030ec58b55112
4
+ data.tar.gz: f92aada3064d15eb96d94cbb21dc3fce497176b4c09f514b0b7ed3f87c17fff2
5
5
  SHA512:
6
- metadata.gz: c0b450e4daa02317f33e74bc627728643157361f5d51d5748e37c5a372d94dabb41b28306b569f4e9c2fa4a0ca04e437f18e15007cac6ec3eb23a8a9ca190609
7
- data.tar.gz: 1964aabb5533aba8a248164ef01b7203bf450fed5dab23859c14a1cbbdf9f90a67ac29beeb8840decd0ec4e70bd4da0d252e668b1d5b6bcbb63b3214ad16d38b
6
+ metadata.gz: c1861d93f6e98f1d2c4e48a0449d55b1099c20a5c61191b9d6ee1398ed169c0b0ee514d3d45d2079b4e196c043bce5d4e25eb8d28c40831b0237bf950e4be27a
7
+ data.tar.gz: 8aa5427869f976334156b802d5ef6320c151860510f78b0855a1c335b7152b5dce3b604e9545e08474770d2e8a8b257bea40c5d27286ae7fe5fe784f2275177d
@@ -47,13 +47,15 @@ module Pay
47
47
  }
48
48
 
49
49
  # Associate charge with subscription if we can
50
- invoice_payments = ::Stripe::InvoicePayment.list({payment: {type: :payment_intent, payment_intent: object.payment_intent}, status: :paid, expand: ["data.invoice.total_discount_amounts.discount"]}, {stripe_account: stripe_account}.compact)
51
- if invoice_payments.any? && (invoice = invoice_payments.first.invoice)
52
- attrs[:stripe_invoice] = invoice.to_hash
53
- attrs[:subtotal] = invoice.subtotal
54
- attrs[:tax] = invoice.total - invoice.total_excluding_tax.to_i
55
- if (subscription = invoice.parent.try(:subscription_details).try(:subscription))
56
- attrs[:subscription] = pay_customer.subscriptions.find_by(processor_id: subscription)
50
+ if object.payment_intent.present?
51
+ invoice_payments = ::Stripe::InvoicePayment.list({payment: {type: :payment_intent, payment_intent: object.payment_intent}, status: :paid, expand: ["data.invoice.total_discount_amounts.discount"]}, {stripe_account: stripe_account}.compact)
52
+ if invoice_payments.any? && (invoice = invoice_payments.first.invoice)
53
+ attrs[:stripe_invoice] = invoice.to_hash
54
+ attrs[:subtotal] = invoice.subtotal
55
+ attrs[:tax] = invoice.total - invoice.total_excluding_tax.to_i
56
+ if (subscription = invoice.parent.try(:subscription_details).try(:subscription))
57
+ attrs[:subscription] = pay_customer.subscriptions.find_by(processor_id: subscription)
58
+ end
57
59
  end
58
60
  end
59
61
 
@@ -65,11 +67,13 @@ module Pay
65
67
  create!(attrs.merge(customer: pay_customer, processor_id: object.id))
66
68
  end
67
69
  rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotUnique
68
- try += 1
69
- raise unless try <= retries
70
-
71
- sleep 0.1
72
- retry
70
+ if try > retries
71
+ raise
72
+ else
73
+ try += 1
74
+ sleep 0.15**try
75
+ retry
76
+ end
73
77
  end
74
78
 
75
79
  def api_record
@@ -41,12 +41,12 @@ module Pay
41
41
  pay_payment_method.update!(attributes)
42
42
  pay_payment_method
43
43
  rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotUnique
44
- try += 1
45
- if try <= retries
46
- sleep 0.1
47
- retry
48
- else
44
+ if try > retries
49
45
  raise
46
+ else
47
+ try += 1
48
+ sleep 0.15**try
49
+ retry
50
50
  end
51
51
  end
52
52
 
@@ -103,7 +103,13 @@ module Pay
103
103
  if (invoice = object.try(:latest_invoice))
104
104
  Array(invoice.try(:payments)).each do |invoice_payment|
105
105
  next unless invoice_payment.status == "paid"
106
- Pay::Stripe::Charge.sync_payment_intent(invoice_payment.payment.payment_intent, stripe_account: pay_subscription.stripe_account)
106
+
107
+ case invoice_payment.payment.type
108
+ when "payment_intent"
109
+ Pay::Stripe::Charge.sync_payment_intent(invoice_payment.payment.payment_intent, stripe_account: pay_subscription.stripe_account)
110
+ when "charge"
111
+ Pay::Stripe::Charge.sync(invoice_payment.payment.charge, stripe_account: pay_subscription.stripe_account)
112
+ end
107
113
  end
108
114
  end
109
115
 
data/lib/pay/stripe.rb CHANGED
@@ -142,16 +142,25 @@ module Pay
142
142
  nil
143
143
  end
144
144
 
145
- def self.sync_checkout_session(session_id, stripe_account: nil)
145
+ # Subscriptions aren't always immediately associated, so we want to retry by default
146
+ def self.sync_checkout_session(session_id, stripe_account: nil, try: 0, retries: 5)
146
147
  checkout_session = ::Stripe::Checkout::Session.retrieve({id: session_id, expand: ["payment_intent.latest_charge"]}, {stripe_account: stripe_account}.compact)
147
148
  case checkout_session.mode
148
149
  when "payment"
149
150
  if (id = checkout_session.payment_intent.try(:latest_charge)&.id)
150
- Pay::Stripe::Charge.sync(id, stripe_account: stripe_account)
151
+ Pay::Stripe::Charge.sync(id, stripe_account: stripe_account, retries: 5)
151
152
  end
152
153
  when "subscription"
153
154
  Pay::Stripe::Subscription.sync(checkout_session.subscription, stripe_account: stripe_account)
154
155
  end
156
+ rescue ::Stripe::InvalidRequestError
157
+ if try > retries
158
+ raise
159
+ else
160
+ try += 1
161
+ sleep 0.15**try
162
+ retry
163
+ end
155
164
  end
156
165
  end
157
166
  end
data/lib/pay/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pay
2
- VERSION = "11.1.0"
2
+ VERSION = "11.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pay
3
3
  version: !ruby/object:Gem::Version
4
- version: 11.1.0
4
+ version: 11.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Charnes
@@ -187,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
187
187
  - !ruby/object:Gem::Version
188
188
  version: '0'
189
189
  requirements: []
190
- rubygems_version: 3.6.9
190
+ rubygems_version: 3.7.1
191
191
  specification_version: 4
192
192
  summary: Payments engine for Ruby on Rails
193
193
  test_files: []