pay 11.5.0 → 11.6.0
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/lib/pay/stripe/webhooks/invoice_updated.rb +34 -0
- data/lib/pay/stripe.rb +4 -0
- data/lib/pay/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 503a2d20ce3d8163cac35c916673cc1cc56d252fc895a292694eaba7dfab2924
|
|
4
|
+
data.tar.gz: 03630e69b4b412963703a8bc2649552867de46be58c394885868e330203ef723
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4dde8d6ebbbe1b4b212f971491843a3dce19f9335a47e9e3ad85364f1229c3cd93c1e148b36e3f3f37c634fae51212199ca1616619d1ed48fac4fdea9681bf51
|
|
7
|
+
data.tar.gz: 67a37ea6b91b289d9f11a1a1258c9e8715d2b80082605810bc48e710f3a0cf1f2e765de4e89b9e151c032094294b4e561ef4ce6d69ac45d7a3961cb18d7b7401
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module Pay
|
|
2
|
+
module Stripe
|
|
3
|
+
module Webhooks
|
|
4
|
+
class InvoiceUpdated
|
|
5
|
+
def call(event)
|
|
6
|
+
# Grab the invoice from the event
|
|
7
|
+
invoice = event.data.object
|
|
8
|
+
|
|
9
|
+
# Find the corresponding subscription_id
|
|
10
|
+
subscription_id = invoice.parent.try(:subscription_details).try(:subscription)
|
|
11
|
+
|
|
12
|
+
# Not all invoices have a subscription - could be a one-time or manual payment
|
|
13
|
+
return if subscription_id.blank?
|
|
14
|
+
|
|
15
|
+
# Grab the local subscription
|
|
16
|
+
subscription = Pay::Subscription.find_by_processor_and_id(:stripe, subscription_id)
|
|
17
|
+
|
|
18
|
+
# Return if we don't have a corresponding subscription
|
|
19
|
+
return unless subscription
|
|
20
|
+
|
|
21
|
+
# Grab the local latest_invoice from the subscription stripe_object
|
|
22
|
+
latest_invoice = subscription.stripe_object.try(:latest_invoice)
|
|
23
|
+
|
|
24
|
+
# Compare the local invoice id to the event invoice id and sync if they are the same
|
|
25
|
+
if latest_invoice.id.to_s == invoice.id.to_s
|
|
26
|
+
Pay::Stripe::Subscription.sync(subscription_id, stripe_account: event.try(:account))
|
|
27
|
+
end
|
|
28
|
+
rescue ::Stripe::StripeError => e
|
|
29
|
+
Rails.logger.error "Stripe Webhook Error (InvoiceUpdated): #{e.message}"
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
data/lib/pay/stripe.rb
CHANGED
|
@@ -12,6 +12,7 @@ module Pay
|
|
|
12
12
|
autoload :CheckoutSessionAsyncPaymentSucceeded, "pay/stripe/webhooks/checkout_session_async_payment_succeeded"
|
|
13
13
|
autoload :CustomerDeleted, "pay/stripe/webhooks/customer_deleted"
|
|
14
14
|
autoload :CustomerUpdated, "pay/stripe/webhooks/customer_updated"
|
|
15
|
+
autoload :InvoiceUpdated, "pay/stripe/webhooks/invoice_updated"
|
|
15
16
|
autoload :PaymentActionRequired, "pay/stripe/webhooks/payment_action_required"
|
|
16
17
|
autoload :PaymentFailed, "pay/stripe/webhooks/payment_failed"
|
|
17
18
|
autoload :PaymentIntentSucceeded, "pay/stripe/webhooks/payment_intent_succeeded"
|
|
@@ -84,6 +85,9 @@ module Pay
|
|
|
84
85
|
# This probably should be ignored for monthly subscriptions.
|
|
85
86
|
events.subscribe "stripe.invoice.upcoming", Pay::Stripe::Webhooks::SubscriptionRenewing.new
|
|
86
87
|
|
|
88
|
+
# Ensures the local stripe_object is up-to-date anytime the API's record is updated.
|
|
89
|
+
events.subscribe "stripe.invoice.updated", Pay::Stripe::Webhooks::InvoiceUpdated.new
|
|
90
|
+
|
|
87
91
|
# Payment action is required to process an invoice
|
|
88
92
|
events.subscribe "stripe.invoice.payment_action_required", Pay::Stripe::Webhooks::PaymentActionRequired.new
|
|
89
93
|
|
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.
|
|
4
|
+
version: 11.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jason Charnes
|
|
@@ -153,6 +153,7 @@ files:
|
|
|
153
153
|
- lib/pay/stripe/webhooks/checkout_session_completed.rb
|
|
154
154
|
- lib/pay/stripe/webhooks/customer_deleted.rb
|
|
155
155
|
- lib/pay/stripe/webhooks/customer_updated.rb
|
|
156
|
+
- lib/pay/stripe/webhooks/invoice_updated.rb
|
|
156
157
|
- lib/pay/stripe/webhooks/payment_action_required.rb
|
|
157
158
|
- lib/pay/stripe/webhooks/payment_failed.rb
|
|
158
159
|
- lib/pay/stripe/webhooks/payment_intent_succeeded.rb
|