chore: Skip reprocessing invalid Stripe events (#5200)

This commit is contained in:
Sojan Jose 2022-08-04 13:51:11 +02:00 committed by GitHub
parent 7c5ee55d3e
commit 044692e475
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,18 +3,9 @@ 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'
plan = find_plan(subscription['plan']['product']) process_subscription_updated
account.update(
custom_attributes: {
stripe_customer_id: subscription.customer,
stripe_price_id: subscription['plan']['id'],
stripe_product_id: subscription['plan']['product'],
plan_name: plan['name'],
subscribed_quantity: subscription['quantity']
}
)
when 'customer.subscription.deleted' when 'customer.subscription.deleted'
Enterprise::Billing::CreateStripeCustomerService.new(account: account).perform process_subscription_deleted
else else
Rails.logger.debug { "Unhandled event type: #{event.type}" } Rails.logger.debug { "Unhandled event type: #{event.type}" }
end end
@ -22,6 +13,29 @@ class Enterprise::Billing::HandleStripeEventService
private private
def process_subscription_updated
plan = find_plan(subscription['plan']['product'])
# skipping self hosted plan events
return if plan.blank? || account.blank?
account.update(
custom_attributes: {
stripe_customer_id: subscription.customer,
stripe_price_id: subscription['plan']['id'],
stripe_product_id: subscription['plan']['product'],
plan_name: plan['name'],
subscribed_quantity: subscription['quantity']
}
)
end
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
end end