Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.
27 changes: 23 additions & 4 deletions services/billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,25 +726,44 @@ def update_billing_address(self, owner: Owner, name, billing_address):
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(f"Retrieved customer: {customer}")

default_payment_method = customer.invoice_settings.default_payment_method
log.info(f"Retrieved default payment method: {default_payment_method}")

if default_payment_method is None:
log.warning(
f"Customer {owner.stripe_customer_id} has no default payment method, skipping payment method update"
)
# Still update the customer address even if there's no payment method
stripe.Customer.modify(owner.stripe_customer_id, address=billing_address)
log.info(
f"Stripe successfully updated customer address for owner {owner.ownerid} by user #{self.requesting_user.ownerid}"
)
return

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

log.info(f"Modifying customer address for customer {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}"
)
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
Loading