billing_page: Add capitalization format of various common cards.

This commit is contained in:
Aman Agrawal 2023-11-09 12:18:24 +00:00
parent f85bd0234a
commit 56eec2734c
2 changed files with 16 additions and 5 deletions

View File

@ -2550,7 +2550,7 @@ class StripeTest(StripeTestCase):
)
response = self.client_get("/billing/")
self.assert_in_success_response(["payment method: <strong>visa ending in 0341"], response)
self.assert_in_success_response(["Visa ending in 0341"], response)
assert RealmAuditLog.objects.filter(event_type=RealmAuditLog.STRIPE_CARD_CHANGED).exists()
stripe_payment_methods = stripe.PaymentMethod.list(customer=stripe_customer_id, type="card")
self.assert_length(stripe_payment_methods, 2)
@ -2590,9 +2590,7 @@ class StripeTest(StripeTestCase):
self.login_user(self.example_user("hamlet"))
response = self.client_get("/billing/")
self.assert_in_success_response(
["payment method: <strong>mastercard ending in 4444"], response
)
self.assert_in_success_response(["Mastercard ending in 4444"], response)
self.assert_length(stripe.PaymentMethod.list(customer=stripe_customer_id, type="card"), 1)
# Ideally we'd also test that we don't pay invoices with collection_method=='send_invoice'
for stripe_invoice in stripe.Invoice.list(customer=stripe_customer_id):

View File

@ -37,6 +37,16 @@ from zerver.models import Realm, UserProfile
billing_logger = logging.getLogger("corporate.stripe")
CARD_CAPITALIZATION = {
"amex": "American Express",
"diners": "Diners Club",
"discover": "Discover",
"jcb": "JCB",
"mastercard": "Mastercard",
"unionpay": "UnionPay",
"visa": "Visa",
}
# Should only be called if the customer is being charged automatically
def payment_method_string(stripe_customer: stripe.Customer) -> str:
@ -45,8 +55,11 @@ def payment_method_string(stripe_customer: stripe.Customer) -> str:
return _("No payment method on file.")
if default_payment_method.type == "card":
brand_name = default_payment_method.card.brand
if brand_name in CARD_CAPITALIZATION:
brand_name = CARD_CAPITALIZATION[default_payment_method.card.brand]
return _("{brand} ending in {last4}").format(
brand=default_payment_method.card.brand,
brand=brand_name,
last4=default_payment_method.card.last4,
)
# There might be one-off stuff we do for a particular customer that