Skip to content

Commit

Permalink
fix: use only supported languages for card payment
Browse files Browse the repository at this point in the history
Fixes #2322
  • Loading branch information
nijel committed Nov 7, 2024
1 parent 7ac4529 commit 77c565c
Showing 1 changed file with 192 additions and 1 deletion.
193 changes: 192 additions & 1 deletion weblate_web/payments/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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": "",
Expand Down

0 comments on commit 77c565c

Please sign in to comment.