From 77c565c6c4974328fccb0ef722ce16153cdf155b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Thu, 7 Nov 2024 12:55:16 +0100 Subject: [PATCH] fix: use only supported languages for card payment Fixes #2322 --- weblate_web/payments/backends.py | 193 ++++++++++++++++++++++++++++++- 1 file changed, 192 insertions(+), 1 deletion(-) diff --git a/weblate_web/payments/backends.py b/weblate_web/payments/backends.py index 3e972e71f4..6f81c5e3c9 100644 --- a/weblate_web/payments/backends.py +++ b/weblate_web/payments/backends.py @@ -47,6 +47,191 @@ BACKENDS: dict[str, type[Backend]] = {} PROFORMA_RE = re.compile("50[0-9]{8}") +THEPAY_LANGUAGES = { + "ab", + "aa", + "af", + "ak", + "sq", + "am", + "ar", + "an", + "hy", + "as", + "av", + "ae", + "ay", + "az", + "bm", + "ba", + "eu", + "be", + "bn", + "bi", + "bs", + "br", + "bg", + "my", + "ca", + "km", + "ch", + "ce", + "ny", + "zh", + "cu", + "cv", + "kw", + "co", + "cr", + "hr", + "cs", + "da", + "dv", + "nl", + "dz", + "en", + "eo", + "et", + "ee", + "fo", + "fj", + "fi", + "fr", + "ff", + "gd", + "gl", + "lg", + "ka", + "de", + "el", + "gn", + "gu", + "ht", + "ha", + "he", + "hz", + "hi", + "ho", + "hu", + "is", + "io", + "ig", + "id", + "ia", + "ie", + "iu", + "ik", + "ga", + "it", + "ja", + "jv", + "kl", + "kn", + "kr", + "ks", + "kk", + "ki", + "rw", + "ky", + "kv", + "kg", + "ko", + "kj", + "ku", + "lo", + "la", + "lv", + "li", + "ln", + "lt", + "lu", + "lb", + "mk", + "mg", + "ms", + "ml", + "mt", + "gv", + "mi", + "mr", + "mh", + "mn", + "na", + "nv", + "ng", + "ne", + "nd", + "se", + "no", + "nb", + "nn", + "oc", + "oj", + "or", + "om", + "os", + "pi", + "ps", + "fa", + "pl", + "pt", + "pa", + "qu", + "ro", + "rm", + "rn", + "ru", + "sm", + "sg", + "sa", + "sc", + "sr", + "sn", + "ii", + "sd", + "si", + "sk", + "sl", + "so", + "nr", + "st", + "es", + "su", + "sw", + "ss", + "sv", + "tl", + "ty", + "tg", + "ta", + "tt", + "te", + "th", + "bo", + "ti", + "to", + "ts", + "tn", + "tr", + "tk", + "tw", + "ug", + "uk", + "ur", + "uz", + "ve", + "vi", + "vo", + "wa", + "cy", + "fy", + "wo", + "xh", + "yi", + "yo", + "za", + "zu", +} def get_backend(name): @@ -501,6 +686,12 @@ def request( return response.json() + def get_language(self): + language = get_language().lower().replace("_", "-").split("-")[0] + if language not in THEPAY_LANGUAGES: + return "en" + return language + def perform( self, request: HttpRequest | None, back_url: str, complete_url: str ) -> None | HttpResponseRedirect: @@ -536,7 +727,7 @@ def perform( "return_url": complete_url, "notif_url": complete_url, "save_authorization": bool(self.payment.recurring), - "language_code": get_language(), + "language_code": self.get_language(), "customer": { "name": self.payment.customer.name, "surname": "",