Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.
Merged
50 changes: 45 additions & 5 deletions services/billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,25 +726,65 @@
return None

try:
default_payment_method = stripe.Customer.retrieve(
owner.stripe_customer_id
).invoice_settings.default_payment_method
customer = stripe.Customer.retrieve(owner.stripe_customer_id)
log.info("Retrieved customer", extra=dict(customer=customer))

default_payment_method = customer.invoice_settings.default_payment_method
log.info(
"Retrieved default payment method",
extra=dict(payment_method=default_payment_method),
)

if default_payment_method is None:
log.warning(

Check warning on line 739 in services/billing.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/billing.py#L739

Added line #L739 was not covered by tests
"Customer has no default payment method, skipping payment method update",
extra=dict(
stripe_customer_id=owner.stripe_customer_id,
ownerid=owner.ownerid,
),
)
# Still update the customer address even if there's no payment method
stripe.Customer.modify(

Check warning on line 747 in services/billing.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/billing.py#L747

Added line #L747 was not covered by tests
owner.stripe_customer_id, address=billing_address
)
log.info(

Check warning on line 750 in services/billing.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/billing.py#L750

Added line #L750 was not covered by tests
"Stripe successfully updated customer address",
extra=dict(
ownerid=owner.ownerid,
requesting_user_id=self.requesting_user.ownerid,
),
)
return

Check warning on line 757 in services/billing.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/billing.py#L757

Added line #L757 was not covered by tests

log.info(
"Modifying payment method billing details",
extra=dict(stripe_customer_id=owner.stripe_customer_id),
)
stripe.PaymentMethod.modify(
default_payment_method,
billing_details={"name": name, "address": billing_address},
)

log.info(
"Modifying customer address",
extra=dict(stripe_customer_id=owner.stripe_customer_id),
)
stripe.Customer.modify(owner.stripe_customer_id, address=billing_address)
log.info(
f"Stripe successfully updated billing address for owner {owner.ownerid} by user #{self.requesting_user.ownerid}"
"Stripe successfully updated billing address",
extra=dict(
ownerid=owner.ownerid,
requesting_user_id=self.requesting_user.ownerid,
),
)
except Exception:
except Exception as e:
log.error(
"Unable to update billing address for customer",
extra=dict(
customer_id=owner.stripe_customer_id,
subscription_id=owner.stripe_subscription_id,
error=str(e),
error_type=type(e).__name__,
),
)

Expand Down
2 changes: 2 additions & 0 deletions services/tests/test_billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1868,6 +1868,8 @@ def test_update_billing_address_with_invalid_address(self, log_error_mock):
extra={
"customer_id": "123",
"subscription_id": "123",
"error": "Invalid API Key provided: default",
"error_type": "AuthenticationError",
},
)

Expand Down
Loading