Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

billing_page: Add capitalization format of various common cards.

Aman Agrawal56eec2734c7a
diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py
index 177444e098f..f88ab93a999 100644
--- a/corporate/tests/test_stripe.py
+++ b/corporate/tests/test_stripe.py
@@ -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):
diff --git a/corporate/views/billing_page.py b/corporate/views/billing_page.py
index 0724f5cade4..23da665d3e9 100644
--- a/corporate/views/billing_page.py
+++ b/corporate/views/billing_page.py
@@ -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