Tarjetas - softbutterfly/culqi-api-python GitHub Wiki
Tarjetas
Consulta la documentación de Culqi en https://apidocs.culqi.com/#/tarjetas
def get_card_data(code, provider):
email = "richard{0}@piedpiper.com".format(uuid4().hex[:4])
token_data = deepcopy(Data.CARD[code][provider])
token_data["email"] = email
token = culqi.token.create(data=token_data)
customer_data = deepcopy(Data.CUSTOMER)
customer_data["email"] = email
customer = culqi.customer.create(data=customer_data)
return {
"token_id": token["data"]["id"],
"customer_id": customer["data"]["id"],
}
Listar
card_list = culqi.card.list(
data={
"limit": 1,
},
headers={
"Accept-Encoding": "identity",
},
)
display(card_list)
{
"status": 200,
"data": {
"paging": {
"previous": "https://api.culqi.com/v2/cards?limit=1&before=crd_test_yAPm5rwlF3aTGVHa",
"next": "https://api.culqi.com/v2/cards?limit=1&after=crd_test_yAPm5rwlF3aTGVHa",
"cursors": {
"before": "crd_test_yAPm5rwlF3aTGVHa",
"after": "crd_test_yAPm5rwlF3aTGVHa"
},
"remaining_items": 83
},
"items": [
{
"object": "card",
"id": "crd_test_yAPm5rwlF3aTGVHa",
"active": true,
"creation_date": 1615131614000,
"customer_id": "cus_test_f4l7UKPuYrORPvyP",
"source": {
"object": "token",
"id": "tkn_test_mw7AQicjlOII6Y5u",
"type": "card",
"creation_date": 1615131608000,
"email": "[email protected]",
"card_number": "511111******1118",
"last_four": "1118",
"active": true,
"iin": {
"object": "iin",
"bin": "511111",
"card_brand": "MasterCard",
"card_type": "debito",
"card_category": "Clásica",
"issuer": {
"name": "INTERBANK",
"country": "PERU",
"country_code": "PE",
"website": null,
"phone_number": null
},
"installments_allowed": [
24,
2,
3,
4,
5,
6,
7,
8,
9,
12,
48
]
},
"client": {
"ip": "191.98.182.73",
"ip_country": "Peru",
"ip_country_code": "PE",
"browser": "UNKNOWN",
"device_fingerprint": null,
"device_type": "Escritorio"
},
"metadata": {}
},
"metadata": {}
}
]
}
}
Crear
card_data = get_card_data("successful", "visa")
card = culqi.card.create(data=card_data)
display(card)
{
"status": 201,
"data": {
"object": "card",
"id": "crd_test_3HS06nwaWNH7GJv9",
"active": true,
"creation_date": 1615131630282,
"customer_id": "cus_test_357GTykK2sAJymJB",
"source": {
"object": "token",
"id": "tkn_test_46FxFV1t3eF7anVP",
"type": "card",
"creation_date": 1615131624000,
"email": "[email protected]",
"card_number": "411111******1111",
"last_four": "1111",
"active": true,
"iin": {
"object": "iin",
"bin": "411111",
"card_brand": "Visa",
"card_type": "credito",
"card_category": "Clásica",
"issuer": {
"name": "BBVA",
"country": "PERU",
"country_code": "PE",
"website": null,
"phone_number": null
},
"installments_allowed": [
2,
4,
6,
8,
10,
12,
3,
5,
7,
9,
24,
48
]
},
"client": {
"ip": "191.98.182.73",
"ip_country": "Peru",
"ip_country_code": "PE",
"browser": "UNKNOWN",
"device_fingerprint": null,
"device_type": "Escritorio"
},
"metadata": {}
},
"metadata": {
"ZDA": true
}
}
}
Leer
card_id = card["data"]["id"]
card = culqi.card.read(id_=card_id)
display(card)
{
"status": 200,
"data": {
"object": "card",
"id": "crd_test_3HS06nwaWNH7GJv9",
"active": true,
"creation_date": 1615131630000,
"customer_id": "cus_test_357GTykK2sAJymJB",
"source": {
"object": "token",
"id": "tkn_test_46FxFV1t3eF7anVP",
"type": "card",
"creation_date": 1615131624000,
"email": "[email protected]",
"card_number": "411111******1111",
"last_four": "1111",
"active": true,
"iin": {
"object": "iin",
"bin": "411111",
"card_brand": "Visa",
"card_type": "credito",
"card_category": "Clásica",
"issuer": {
"name": "BBVA",
"country": "PERU",
"country_code": "PE",
"website": null,
"phone_number": null
},
"installments_allowed": [
2,
4,
6,
8,
10,
12,
3,
5,
7,
9,
24,
48
]
},
"client": {
"ip": "191.98.182.73",
"ip_country": "Peru",
"ip_country_code": "PE",
"browser": "UNKNOWN",
"device_fingerprint": null,
"device_type": "Escritorio"
},
"metadata": {}
},
"metadata": {}
}
}
Actualizar
card_id = card["data"]["id"]
card_metadata = {
"metadata": {
"orderId": 1234567890
}
}
card = culqi.card.update(
id_=card_id, data=card_metadata
)
display(card)
{
"status": 200,
"data": {
"object": "card",
"id": "crd_test_3HS06nwaWNH7GJv9",
"active": true,
"creation_date": 1615131630000,
"customer_id": "cus_test_357GTykK2sAJymJB",
"source": {
"object": "token",
"id": "tkn_test_46FxFV1t3eF7anVP",
"type": "card",
"creation_date": 1615131624000,
"email": "[email protected]",
"card_number": "411111******1111",
"last_four": "1111",
"active": true,
"iin": {
"object": "iin",
"bin": "411111",
"card_brand": "Visa",
"card_type": "credito",
"card_category": "Clásica",
"issuer": {
"name": "BBVA",
"country": "PERU",
"country_code": "PE",
"website": null,
"phone_number": null
},
"installments_allowed": [
2,
4,
6,
8,
10,
12,
3,
5,
7,
9,
24,
48
]
},
"client": {
"ip": "191.98.182.73",
"ip_country": "Peru",
"ip_country_code": "PE",
"browser": "UNKNOWN",
"device_fingerprint": null,
"device_type": "Escritorio"
},
"metadata": {}
},
"metadata": {
"orderId": "1234567890"
}
}
}
Eliminar
card_id = card["data"]["id"]
deleted_card = culqi.card.delete(id_=card_id)
display(deleted_card)
{
"status": 200,
"data": {
"id": "crd_test_3HS06nwaWNH7GJv9",
"deleted": true,
"merchant_message": "Se eliminó la tarjeta con ID crd_test_3HS06nwaWNH7GJv9 exitosamente."
}
}