chore: Skip reprocessing invalid Stripe events (#5200)
This commit is contained in:
parent
7c5ee55d3e
commit
044692e475
1 changed files with 25 additions and 11 deletions
|
@ -3,7 +3,21 @@ class Enterprise::Billing::HandleStripeEventService
|
||||||
ensure_event_context(event)
|
ensure_event_context(event)
|
||||||
case @event.type
|
case @event.type
|
||||||
when 'customer.subscription.updated'
|
when 'customer.subscription.updated'
|
||||||
|
process_subscription_updated
|
||||||
|
when 'customer.subscription.deleted'
|
||||||
|
process_subscription_deleted
|
||||||
|
else
|
||||||
|
Rails.logger.debug { "Unhandled event type: #{event.type}" }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def process_subscription_updated
|
||||||
plan = find_plan(subscription['plan']['product'])
|
plan = find_plan(subscription['plan']['product'])
|
||||||
|
# skipping self hosted plan events
|
||||||
|
return if plan.blank? || account.blank?
|
||||||
|
|
||||||
account.update(
|
account.update(
|
||||||
custom_attributes: {
|
custom_attributes: {
|
||||||
stripe_customer_id: subscription.customer,
|
stripe_customer_id: subscription.customer,
|
||||||
|
@ -13,14 +27,14 @@ class Enterprise::Billing::HandleStripeEventService
|
||||||
subscribed_quantity: subscription['quantity']
|
subscribed_quantity: subscription['quantity']
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
when 'customer.subscription.deleted'
|
|
||||||
Enterprise::Billing::CreateStripeCustomerService.new(account: account).perform
|
|
||||||
else
|
|
||||||
Rails.logger.debug { "Unhandled event type: #{event.type}" }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
def process_subscription_deleted
|
||||||
|
# skipping self hosted plan events
|
||||||
|
return if account.blank?
|
||||||
|
|
||||||
|
Enterprise::Billing::CreateStripeCustomerService.new(account: account).perform
|
||||||
|
end
|
||||||
|
|
||||||
def ensure_event_context(event)
|
def ensure_event_context(event)
|
||||||
@event = event
|
@event = event
|
||||||
|
|
Loading…
Reference in a new issue