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

Commit 795e37f

Browse files
authored
chore: More logging to stripe update default method (#1288)
1 parent c2edbb3 commit 795e37f

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

services/billing.py

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -726,25 +726,65 @@ def update_billing_address(self, owner: Owner, name, billing_address):
726726
return None
727727

728728
try:
729-
default_payment_method = stripe.Customer.retrieve(
730-
owner.stripe_customer_id
731-
).invoice_settings.default_payment_method
729+
customer = stripe.Customer.retrieve(owner.stripe_customer_id)
730+
log.info("Retrieved customer", extra=dict(customer=customer))
731+
732+
default_payment_method = customer.invoice_settings.default_payment_method
733+
log.info(
734+
"Retrieved default payment method",
735+
extra=dict(payment_method=default_payment_method),
736+
)
732737

738+
if default_payment_method is None:
739+
log.warning(
740+
"Customer has no default payment method, skipping payment method update",
741+
extra=dict(
742+
stripe_customer_id=owner.stripe_customer_id,
743+
ownerid=owner.ownerid,
744+
),
745+
)
746+
# Still update the customer address even if there's no payment method
747+
stripe.Customer.modify(
748+
owner.stripe_customer_id, address=billing_address
749+
)
750+
log.info(
751+
"Stripe successfully updated customer address",
752+
extra=dict(
753+
ownerid=owner.ownerid,
754+
requesting_user_id=self.requesting_user.ownerid,
755+
),
756+
)
757+
return
758+
759+
log.info(
760+
"Modifying payment method billing details",
761+
extra=dict(stripe_customer_id=owner.stripe_customer_id),
762+
)
733763
stripe.PaymentMethod.modify(
734764
default_payment_method,
735765
billing_details={"name": name, "address": billing_address},
736766
)
737767

768+
log.info(
769+
"Modifying customer address",
770+
extra=dict(stripe_customer_id=owner.stripe_customer_id),
771+
)
738772
stripe.Customer.modify(owner.stripe_customer_id, address=billing_address)
739773
log.info(
740-
f"Stripe successfully updated billing address for owner {owner.ownerid} by user #{self.requesting_user.ownerid}"
774+
"Stripe successfully updated billing address",
775+
extra=dict(
776+
ownerid=owner.ownerid,
777+
requesting_user_id=self.requesting_user.ownerid,
778+
),
741779
)
742-
except Exception:
780+
except Exception as e:
743781
log.error(
744782
"Unable to update billing address for customer",
745783
extra=dict(
746784
customer_id=owner.stripe_customer_id,
747785
subscription_id=owner.stripe_subscription_id,
786+
error=str(e),
787+
error_type=type(e).__name__,
748788
),
749789
)
750790

services/tests/test_billing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,6 +1868,8 @@ def test_update_billing_address_with_invalid_address(self, log_error_mock):
18681868
extra={
18691869
"customer_id": "123",
18701870
"subscription_id": "123",
1871+
"error": "Invalid API Key provided: default",
1872+
"error_type": "AuthenticationError",
18711873
},
18721874
)
18731875

0 commit comments

Comments
 (0)