Created
May 16, 2022 17:40
-
-
Save erickdsama/9b3e4f14b071370e5880df6e1c60cd98 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
banks = ["ABC CAPITAL, S.A. INSTITUCISN DE BANCA MULTIPLE", | |
"AMERICAN EXPRESS", | |
"BANAMEX", | |
"BANCA AFIRME, S.A.", | |
"BANCA CREMI, S.A.", | |
"BANCA MIFEL, S.A.", | |
"BANCA SERFIN, S.A.", | |
"BANCO AUTOFIN MEXICO, S.A.", | |
"BANCO AZTECA S.A. INSTITUCION DE BANCA MULTIPLE", | |
"BANCO DEL AHORRO NACIONAL Y SERVICIOS FINANCIEROS S.N.C. - BANSEFI", | |
"BANCO DEL BAJIO, S.A.", | |
"BANCO DEL CENTRO, S.A.", | |
"BANCO DEL SURESTE, S.A.", | |
"BANCO FACIL, S.A. INSTITUCION DE BANCA MULTIPLE", | |
"BANCO INBURSA S.A. INSTITUCION DE BANCA MULTIPLE GRUPO FINAN", | |
"BANCO INBURSA, S.A.", | |
"BANCO INDUSTRIAL, S.A.", | |
"BANCO INTERACCIONES, S.A.", | |
"BANCO INVERLAT, S.A.", | |
"BANCO INVEX, S.A. INSTITUCION DE BANCA MULTIPLE, INVEX GRUPO", | |
"BANCO MONEX, S.A., INSTITUCION DE BANCA MULTIPLE, MONEX GRUP", | |
"BANCO NACIONAL DE MEXICO, S.A.", | |
"BANCO NACIONAL DE MEXICO, S.A. - AEROMEXICO", | |
"BANCO NACIONAL DEL EJERCITO, FUERZA AEREA Y ARMADA, S.N.C.", | |
"BANCO UNION, S.A.", | |
"BANCO WAL*MART DE MEXICO ADElanTE, S.A.", | |
"BANCOPPEL", | |
"BANCRECER, S.A.", | |
"BANORTE", | |
"BANREGIO", | |
"BANSI S.A. INSTITUCION DE BANCA MULTIPLE", | |
"BBVA BANCOMER", | |
"BNP PARIBAS PERSONAL FINANCE S.A. DE C.V., SOFOL FILIAL", | |
"CHASE MANHATTAN BANK MEXICO, S.A.", | |
"CITIBANK", | |
"CITICORP", | |
"COMMERCIAlanATIONAL BANK OF PENNSYLVANIA", | |
"CONFIA, S.A.", | |
"CREDOMATIC DE MEXICO S.A. DE C.V.", | |
"DISTRIBUIDORA LIVERPOOL S.A. DE C.V.", | |
"EUROPAY FRANCE, S.A.", | |
"FEDERACION UNISAP,S.C. DE R.L. DE C.V.", | |
"FICEN, SA DE CV SOCIEDAD FINANCIERA DE OJBETO LIMITADO", | |
"GE CAPITAL BANK S.A., INSTITUCION DE BANCA MULTIPLE-GE CAPITAL GRUPO FINANC.", | |
"GLOBAL CARD", | |
"GRCC", | |
"HSBC", | |
"IBI SERVICES S. DE R.L.", | |
"INTERPAYMENT SERVICES, LTD.", | |
"LIBERTAD SERVICIOS FINANCIEROS SA DE CV SFP", | |
"MULTIVA", | |
"Unknown Bank", | |
"OPERADORA DE RECURSOS REFORMA S.A. DE C.V.", | |
"PRESTACOMER S.A. DE C.V.", | |
"PROMOCION Y OPERACION, S.A. DE C.V.", | |
"SANTANDER", | |
"SCOTIABANK", | |
"SPIRA DE MEXICO S.A. DE C.V.", | |
"TARJETAS UNISOLUCIONES S.A. DE C.V.", | |
"TOTAL SYSTEM SERVICES, INC.", | |
"WIRECARD BANK AG"] | |
API_BINLIST = '' | |
API_GP = '' | |
token = '' | |
def search_in_banks(issuer: str): | |
for bank in banks: | |
if issuer in bank or bank in issuer: | |
return bank | |
def ask_binlist(bin_number: str): | |
binlist_response = requests.get(f'{API_BINLIST}{bin_number}') | |
bin_data = { | |
"payment_network": "visa", | |
"card_type": "debit", | |
"issuer": "UNKNOWN BANK", | |
"region": "MX", | |
"bin": bin_number | |
} | |
if binlist_response and binlist_response.status_code in range(200, 300): | |
response_json = binlist_response.json() | |
payment_network = response_json.get("scheme") | |
if payment_network == "AMERICAN EXPRESS": | |
payment_network = "amex" | |
bin_data["payment_network"] = payment_network | |
bin_data["card_type"] = response_json.get("type") | |
region = response_json.get("country", {}).get("alpha2", "MX") | |
if region == "MX": | |
issuer = response_json.get("bank", {}).get("name", "UNKWNON BANK") | |
issuer = search_in_banks(issuer=issuer) | |
if issuer: | |
bin_data["issuer"] = issuer | |
if not region or len(region) == 0: | |
region = "MX" | |
bin_data["region"] = region | |
return bin_data | |
def post_to_production(bin_data: dict): | |
headers = { | |
"content-type": "application/json", | |
"Authorization": f"Bearer {token}" | |
} | |
print(bin_data) | |
response = requests.post(f'{API_GP}/v1/bin/', data=json.dumps(bin_data), headers=headers) | |
if response.status_code == 409: | |
print("previously inserted") | |
if response.status_code == 201: | |
print("OK!") | |
if response.status_code == 400: | |
print(f"content: {response.content}") | |
with open('bins.txt', 'r') as bins: | |
bin_list = bins.readlines() | |
for bin_str in bin_list: | |
bin_str = bin_str.replace("\n", "") | |
print(f"bin: {bin_str}") | |
build_bin = ask_binlist(bin_number=bin_str) | |
post_to_production(bin_data=build_bin) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment