From 1623f9d58bcc70451843262686eb454a77c9b74a Mon Sep 17 00:00:00 2001 From: drjones Date: Tue, 29 Sep 2026 18:22:13 -0700 Subject: [PATCH] dual BIN provider fallback --- app.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index 04e5c6e..979b298 100644 --- a/app.py +++ b/app.py @@ -221,8 +221,7 @@ def card(): tags.append(('LUHN VALID' if ok else 'LUHN INVALID — fake/dead number')) 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"),