stripe: Make newly added card default source.

This commit is contained in:
Vishnu Ks 2018-01-21 01:12:07 +05:30 committed by Greg Price
parent 2a59b2d2ac
commit b762b839d4
1 changed files with 3 additions and 1 deletions

View File

@ -158,7 +158,9 @@ def add_payment_method(request: HttpRequest) -> HttpResponse:
customer = stripe.Customer.retrieve(customer_obj.stripe_customer_id) customer = stripe.Customer.retrieve(customer_obj.stripe_customer_id)
billing_logger.info("Adding card on customer %s: source=%r, metadata=%r", billing_logger.info("Adding card on customer %s: source=%r, metadata=%r",
customer_obj.stripe_customer_id, token, card_metadata) customer_obj.stripe_customer_id, token, card_metadata)
customer.sources.create(source=token, metadata=card_metadata) card = customer.sources.create(source=token, metadata=card_metadata)
customer.default_source = card.id
customer.save()
ctx["num_cards"] = len(customer.sources.all(object="card")["data"]) ctx["num_cards"] = len(customer.sources.all(object="card")["data"])
except Customer.DoesNotExist: except Customer.DoesNotExist:
customer_metadata = {"string_id": user.realm.string_id} customer_metadata = {"string_id": user.realm.string_id}