dual BIN provider fallback
This commit is contained in:
17
app.py
17
app.py
@@ -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>'))
|
||||
brand = brand_of(num)
|
||||
bin8 = num[:8]
|
||||
st, b = http(f"https://lookup.binlist.net/{bin8}", headers={"Accept-Version": "3"})
|
||||
bl = jf(b) or {}
|
||||
bl = bin_lookup(bin8)
|
||||
bank = (bl.get("bank") or {}).get("name", "—")
|
||||
country = (bl.get("country") or {}).get("name", "—")
|
||||
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}"""
|
||||
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"])
|
||||
def api_card():
|
||||
num = re.sub(r"\D", "", param("num") or "")[:19]
|
||||
if not num: return jsonify({"ok": False, "error": "num required"})
|
||||
ok = luhn_ok(num)
|
||||
st, b = http(f"https://lookup.binlist.net/{num[:8]}", headers={"Accept-Version": "3"})
|
||||
bl = jf(b) or {}
|
||||
bl = bin_lookup(num[:8])
|
||||
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)),
|
||||
"bin": {"issuer": (bl.get("bank") or {}).get("name"), "country": (bl.get("country") or {}).get("name"),
|
||||
|
||||
Reference in New Issue
Block a user