dual BIN provider fallback

This commit is contained in:
2026-09-29 18:22:13 -07:00
parent a12b202f60
commit 1623f9d58b

17
app.py
View File

@@ -221,8 +221,7 @@ def card():
tags.append(('<span class="tag ok">LUHN VALID</span>' if ok else '<span class="tag bad">LUHN INVALID — fake/dead number</span>')) tags.append(('<span class="tag ok">LUHN VALID</span>' if ok else '<span class="tag bad">LUHN INVALID — fake/dead number</span>'))
brand = brand_of(num) brand = brand_of(num)
bin8 = num[:8] bin8 = num[:8]
st, b = http(f"https://lookup.binlist.net/{bin8}", headers={"Accept-Version": "3"}) bl = bin_lookup(bin8)
bl = jf(b) or {}
bank = (bl.get("bank") or {}).get("name", "—") bank = (bl.get("bank") or {}).get("name", "—")
country = (bl.get("country") or {}).get("name", "—") country = (bl.get("country") or {}).get("name", "—")
ctype = bl.get("type", "—") ctype = bl.get("type", "—")
@@ -254,13 +253,23 @@ var v=this.value.replace(/\\D/g,'').slice(0,19);this.value=v.replace(/(.{{4}})/g
{result}""" {result}"""
return page("card", body) return page("card", body)
def bin_lookup(bin8):
st, b = http(f"https://lookup.binlist.net/{bin8}", headers={"Accept-Version": "3"})
bl = jf(b) or {}
if not bl.get("bank") and not bl.get("type") and not bl.get("scheme"):
st, b = http(f"https://data.handyapi.com/bin/{bin8}")
h = jf(b) or {}
if h.get("Status") == "SUCCESS":
return {"bank": {"name": h.get("Issuer")}, "country": {"name": h.get("Country", {}).get("Name") if isinstance(h.get("Country"), dict) else h.get("Country")},
"type": str(h.get("Type", "")).lower() or None, "prepaid": "prepaid" in str(h.get("Type","")).lower() or None, "scheme": h.get("Scheme")}
return bl
@app.route("/api/card", methods=["POST"]) @app.route("/api/card", methods=["POST"])
def api_card(): def api_card():
num = re.sub(r"\D", "", param("num") or "")[:19] num = re.sub(r"\D", "", param("num") or "")[:19]
if not num: return jsonify({"ok": False, "error": "num required"}) if not num: return jsonify({"ok": False, "error": "num required"})
ok = luhn_ok(num) ok = luhn_ok(num)
st, b = http(f"https://lookup.binlist.net/{num[:8]}", headers={"Accept-Version": "3"}) bl = bin_lookup(num[:8])
bl = jf(b) or {}
return jsonify({"ok": True, "luhn": ok, "brand": brand_of(num), "length_ok": len(num) in return jsonify({"ok": True, "luhn": ok, "brand": brand_of(num), "length_ok": len(num) in
{"Visa":(13,16,19),"Mastercard":(16,),"Amex":(15,)}.get(brand_of(num),(13,15,16,19)), {"Visa":(13,16,19),"Mastercard":(16,),"Amex":(15,)}.get(brand_of(num),(13,15,16,19)),
"bin": {"issuer": (bl.get("bank") or {}).get("name"), "country": (bl.get("country") or {}).get("name"), "bin": {"issuer": (bl.get("bank") or {}).get("name"), "country": (bl.get("country") or {}).get("name"),