billing: Create customer_has_credit_card_as_default_source function.

This commit is contained in:
Vishnu KS
2020-10-14 15:47:03 +05:30
committed by Tim Abbott
parent 6e3d4e7e75
commit cdf683e36f
7 changed files with 355 additions and 0 deletions

View File

@@ -338,6 +338,19 @@ def do_replace_payment_source(
return updated_stripe_customer
def stripe_customer_has_credit_card_as_default_source(stripe_customer: stripe.Customer) -> bool:
if not stripe_customer.default_source:
return False
return stripe_customer.default_source.object == "card"
def customer_has_credit_card_as_default_source(customer: Customer) -> bool:
if not customer.stripe_customer_id:
return False
stripe_customer = stripe_get_customer(customer.stripe_customer_id)
return stripe_customer_has_credit_card_as_default_source(stripe_customer)
# event_time should roughly be timezone_now(). Not designed to handle
# event_times in the past or future
@transaction.atomic