Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit 60e5f1a

Browse files
committed
update code to better track if default method exists
1 parent 16501b2 commit 60e5f1a

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

services/billing.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,18 +728,30 @@ def update_billing_address(self, owner: Owner, name, billing_address):
728728
try:
729729
customer = stripe.Customer.retrieve(owner.stripe_customer_id)
730730
log.info(f"Retrieved customer: {customer}")
731+
731732
default_payment_method = customer.invoice_settings.default_payment_method
732733
log.info(f"Retrieved default payment method: {default_payment_method}")
734+
735+
if default_payment_method is None:
736+
log.warning(
737+
f"Customer {owner.stripe_customer_id} has no default payment method, skipping payment method update"
738+
)
739+
# Still update the customer address even if there's no payment method
740+
stripe.Customer.modify(owner.stripe_customer_id, address=billing_address)
741+
log.info(
742+
f"Stripe successfully updated customer address for owner {owner.ownerid} by user #{self.requesting_user.ownerid}"
743+
)
744+
return
733745

734746
log.info(
735-
f"Modifying payment method with billing details: name={name}, address={billing_address}"
747+
f"Modifying payment method billing details for customer {owner.stripe_customer_id}"
736748
)
737749
stripe.PaymentMethod.modify(
738750
default_payment_method,
739751
billing_details={"name": name, "address": billing_address},
740752
)
741753

742-
log.info(f"Modifying customer address: {billing_address}")
754+
log.info(f"Modifying customer address for customer {owner.stripe_customer_id}")
743755
stripe.Customer.modify(owner.stripe_customer_id, address=billing_address)
744756
log.info(
745757
f"Stripe successfully updated billing address for owner {owner.ownerid} by user #{self.requesting_user.ownerid}"

0 commit comments

Comments
 (0)