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 +4 -4
- data/app/models/pay/stripe/charge.rb +16 -12
- data/app/models/pay/stripe/payment_method.rb +5 -5
- data/app/models/pay/stripe/subscription.rb +7 -1
- data/lib/pay/stripe.rb +11 -2
- data/lib/pay/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65a518434cfa0042025a7d66ccaef83ab3057315d349988f3a6030ec58b55112
|
4
|
+
data.tar.gz: f92aada3064d15eb96d94cbb21dc3fce497176b4c09f514b0b7ed3f87c17fff2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
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
|
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
|
-
|
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
|
-
|
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
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.
|
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.
|
190
|
+
rubygems_version: 3.7.1
|
191
191
|
specification_version: 4
|
192
192
|
summary: Payments engine for Ruby on Rails
|
193
193
|
test_files: []
|