1
0
mirror of https://github.com/quay/quay.git synced 2025-04-18 10:44:06 +03:00

marketplace: handle exception thrown by stripe when customer has no subscription (PROJQUAY-8431) (#3603)

* handle exception thrown by stripe when customer has no subscription
This commit is contained in:
Marcus Kok 2025-02-03 14:36:27 -05:00 committed by GitHub
parent b48e1b47ad
commit 52f3e38413
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 2 deletions

View File

@ -87,8 +87,12 @@ class ReconciliationWorker(Worker):
except stripe.error.InvalidRequestError:
logger.warn("Invalid request for stripe_id %s", user.stripe_id)
continue
try:
subscription = stripe_customer.subscription
except AttributeError:
subscription = None
for sku_id in RECONCILER_SKUS:
if stripe_customer.subscription:
if subscription is not None:
plan = get_plan(stripe_customer.subscription.plan.id)
if plan is None:
continue

View File

@ -34,7 +34,7 @@ def test_reconcile_org_user(initialized_db):
mock.assert_called_with(org_user.email)
def test_exception_handling(initialized_db):
def test_exception_handling(initialized_db, caplog):
with patch("data.billing.FakeStripe.Customer.retrieve") as mock:
mock.side_effect = stripe.error.InvalidRequestException
worker._perform_reconciliation(marketplace_users, marketplace_subscriptions)
@ -43,6 +43,22 @@ def test_exception_handling(initialized_db):
worker._perform_reconciliation(marketplace_users, marketplace_subscriptions)
def test_attribute_error(initialized_db, caplog):
test_user = model.user.create_user("stripe_user", "password", "stripe_user@test.com")
test_user.stripe_id = "cus_" + "".join(random.choices(string.ascii_lowercase, k=14))
test_user.save()
with patch("data.billing.FakeStripe.Customer.retrieve") as mock:
class MockCustomer:
@property
def subscription(self):
raise AttributeError
mock.return_value = MockCustomer()
worker._perform_reconciliation(marketplace_users, marketplace_subscriptions)
def test_create_for_stripe_user(initialized_db):
test_user = model.user.create_user("stripe_user", "password", "stripe_user@test.com")