From 72b8a31f2db1812a19c308fb9361168f4d044a71 Mon Sep 17 00:00:00 2001 From: Vishnu Narayanan Date: Thu, 16 Apr 2026 13:22:31 +0530 Subject: [PATCH] fix: handle users being stuck on is_creating billing flow (#12750) Fixes https://linear.app/chatwoot/issue/CW-5880/handle-customers-being-stuck-on-biling-page --- .../enterprise/create_stripe_customer_job.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/enterprise/app/jobs/enterprise/create_stripe_customer_job.rb b/enterprise/app/jobs/enterprise/create_stripe_customer_job.rb index 6b90cbec5..18223ae4b 100644 --- a/enterprise/app/jobs/enterprise/create_stripe_customer_job.rb +++ b/enterprise/app/jobs/enterprise/create_stripe_customer_job.rb @@ -3,5 +3,22 @@ class Enterprise::CreateStripeCustomerJob < ApplicationJob def perform(account) Enterprise::Billing::CreateStripeCustomerService.new(account: account).perform + ensure + # Always clear the is_creating_customer flag, even if the job fails + # This prevents users from getting stuck on the billing page + clear_creating_flag(account) + end + + private + + def clear_creating_flag(account) + # Atomic JSONB key removal — avoids clobbering concurrent writes to custom_attributes + # rubocop:disable Rails/SkipsModelValidations + Account.where(id: account.id).update_all( + "custom_attributes = custom_attributes - 'is_creating_customer'" + ) + # rubocop:enable Rails/SkipsModelValidations + rescue StandardError => e + Rails.logger.error("Failed to clear is_creating_customer flag for account=#{account.id}: #{e.full_message}") end end