Skip to content
zodiacfireworks edited this page Mar 7, 2021 · 1 revision

Cargos

Consulta la documentación de Culqi en https://apidocs.culqi.com/#/cargos

def get_charge_data(code, provider):
    token_data = deepcopy(Data.CARD[code][provider])
    token = culqi.token.create(data=token_data)

    charge_data = deepcopy(Data.CHARGE)
    charge_data["source_id"] = token["data"]["id"]

    return charge_data

Listar

charge_list = culqi.charge.list(
    data={
        "limit": 1,
    },
    headers={
        "Accept-Encoding": "identity",
    },
)

display(charge_list)
{
    "status": 200,
    "data": {
        "paging": {
            "previous": "https://api.culqi.com/v2/charges?limit=1&before=chr_test_XC0vjjYHs9PKwqKj",
            "next": "https://api.culqi.com/v2/charges?limit=1&after=chr_test_XC0vjjYHs9PKwqKj",
            "cursors": {
                "before": "chr_test_XC0vjjYHs9PKwqKj",
                "after": "chr_test_XC0vjjYHs9PKwqKj"
            },
            "remaining_items": 338
        },
        "items": [
            {
                "duplicated": null,
                "object": "charge",
                "id": "chr_test_XC0vjjYHs9PKwqKj",
                "creation_date": 1615131590000,
                "amount": 100,
                "amount_refunded": 0,
                "current_amount": 100,
                "installments": 0,
                "installments_amount": null,
                "currency_code": "PEN",
                "email": null,
                "description": "Validacion de tarjeta",
                "source": {
                    "object": "token",
                    "id": "tkn_test_8SSSqy9swCHbfZ1F",
                    "type": "card",
                    "creation_date": 1615131588000,
                    "email": "richardbfc3@piedpiper.com",
                    "card_number": "400002******0000",
                    "last_four": "0000",
                    "active": true,
                    "iin": {
                        "object": "iin",
                        "bin": "400002",
                        "card_brand": "Visa",
                        "card_type": "credito",
                        "card_category": null,
                        "issuer": {
                            "name": "RIVER VALLEY C.U.",
                            "country": "PERU",
                            "country_code": null,
                            "website": null,
                            "phone_number": null
                        },
                        "installments_allowed": null
                    },
                    "client": {
                        "ip": "191.98.182.73",
                        "ip_country": null,
                        "ip_country_code": "PE",
                        "browser": null,
                        "device_fingerprint": null,
                        "device_type": null
                    },
                    "metadata": {}
                },
                "outcome": {
                    "type": "card_error",
                    "code": "card_declined",
                    "decline_code": "stolen_card",
                    "merchant_message": "Tarjeta robada. La tarjeta fue bloqueada y reportada al banco emisor como una tarjeta robada.",
                    "user_message": "Su tarjeta está vencida. Verifica la fecha de vencimiento de tu tarjeta e ingrésalos correctamente. Si es denegada nuevamente, contáctate con el banco emisor de tu tarjeta."
                },
                "fraud_score": null,
                "antifraud_details": {
                    "first_name": "Richard",
                    "last_name": "Piedpiper",
                    "address": "Avenida Lima 123213",
                    "address_city": "LIMA",
                    "country_code": "PE",
                    "phone": "51998989789",
                    "object": "client"
                },
                "dispute": false,
                "capture": null,
                "reference_code": "LxqYIoLTFG",
                "authorization_code": "zdXUZU",
                "metadata": {},
                "total_fee": null,
                "fee_details": {
                    "fixed_fee": null,
                    "variable_fee": null
                },
                "total_fee_taxes": null,
                "transfer_amount": null,
                "paid": false,
                "statement_descriptor": null,
                "transfer_id": null,
                "operations": [],
                "capture_date": null
            }
        ]
    }
}

Crear

charge_data = get_charge_data("successful", "visa")
charge = culqi.charge.create(data=charge_data)

display(charge)
{
    "status": 201,
    "data": {
        "duplicated": false,
        "object": "charge",
        "id": "chr_test_M4efNkiZX9jszJQA",
        "creation_date": 1615131596000,
        "amount": 1000,
        "amount_refunded": 0,
        "current_amount": 1000,
        "installments": 1,
        "installments_amount": 1000,
        "currency_code": "PEN",
        "email": "richard@piedpiper.com",
        "description": "Venta de prueba",
        "source": {
            "object": "token",
            "id": "tkn_test_by2icDaZJGAAYY00",
            "type": "card",
            "creation_date": 1615131594000,
            "email": "richard@piedpiper.com",
            "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": {}
        },
        "outcome": {
            "type": "venta_exitosa",
            "code": "AUT0000",
            "merchant_message": "La operación de venta ha sido autorizada exitosamente",
            "user_message": "Su compra ha sido exitosa."
        },
        "fraud_score": 56.0,
        "dispute": false,
        "capture": false,
        "reference_code": "bYYXVQ7bfh",
        "authorization_code": "qnXJW5",
        "metadata": {},
        "total_fee": 47,
        "fee_details": {
            "fixed_fee": {},
            "variable_fee": {
                "currency_code": "PEN",
                "commision": 0.0399,
                "total": 40
            }
        },
        "total_fee_taxes": 7,
        "transfer_amount": 953,
        "paid": false,
        "statement_descriptor": "CULQI*",
        "transfer_id": null,
        "capture_date": null
    }
}

Capturar

charge_id = charge["data"]["id"]
captured_charge = culqi.charge.capture(id_=charge_id)

display(captured_charge)
{
    "status": 201,
    "data": {
        "duplicated": false,
        "object": "charge",
        "id": "chr_test_M4efNkiZX9jszJQA",
        "creation_date": 1615131596000,
        "amount": 1000,
        "amount_refunded": 0,
        "current_amount": 1000,
        "installments": 1,
        "installments_amount": 1000,
        "currency_code": "PEN",
        "email": "richard@piedpiper.com",
        "description": "Venta de prueba",
        "source": {
            "object": "token",
            "id": "tkn_test_by2icDaZJGAAYY00",
            "type": "card",
            "creation_date": 1615131594000,
            "email": "richard@piedpiper.com",
            "card_number": "411111******1111",
            "last_four": "1111",
            "active": true,
            "iin": {
                "object": "iin",
                "bin": "411111",
                "card_brand": "Visa",
                "card_type": "credito",
                "card_category": null,
                "issuer": {
                    "name": "BBVA",
                    "country": "PERU",
                    "country_code": null,
                    "website": null,
                    "phone_number": null
                },
                "installments_allowed": null
            },
            "client": {
                "ip": "191.98.182.73",
                "ip_country": null,
                "ip_country_code": null,
                "browser": null,
                "device_fingerprint": null,
                "device_type": null
            },
            "metadata": {}
        },
        "outcome": {
            "type": "venta_exitosa",
            "code": "AUT0000",
            "merchant_message": "La operación de venta ha sido autorizada exitosamente",
            "user_message": "Su compra ha sido exitosa."
        },
        "fraud_score": 56.0,
        "dispute": false,
        "capture": true,
        "reference_code": "bYYXVQ7bfh",
        "authorization_code": "qnXJW5",
        "metadata": {},
        "total_fee": 47,
        "fee_details": {
            "fixed_fee": {},
            "variable_fee": {
                "currency_code": "PEN",
                "commision": 0.0399,
                "total": 40
            }
        },
        "total_fee_taxes": 7,
        "transfer_amount": 953,
        "paid": false,
        "statement_descriptor": "CULQI*",
        "transfer_id": null,
        "operations": [],
        "capture_date": null
    }
}

Leer

charge_id = captured_charge["data"]["id"]
charge = culqi.charge.read(id_=charge_id)

display(charge)
{
    "status": 200,
    "data": {
        "duplicated": false,
        "object": "charge",
        "id": "chr_test_M4efNkiZX9jszJQA",
        "creation_date": 1615131596000,
        "amount": 1000,
        "amount_refunded": 0,
        "current_amount": 1000,
        "installments": 1,
        "installments_amount": 1000,
        "currency_code": "PEN",
        "email": "richard@piedpiper.com",
        "description": "Venta de prueba",
        "source": {
            "object": "token",
            "id": "tkn_test_by2icDaZJGAAYY00",
            "type": "card",
            "creation_date": 1615131594000,
            "email": "richard@piedpiper.com",
            "card_number": "411111******1111",
            "last_four": "1111",
            "active": true,
            "iin": {
                "object": "iin",
                "bin": "411111",
                "card_brand": "Visa",
                "card_type": "credito",
                "card_category": null,
                "issuer": {
                    "name": "BBVA",
                    "country": "PERU",
                    "country_code": null,
                    "website": null,
                    "phone_number": null
                },
                "installments_allowed": null
            },
            "client": {
                "ip": "191.98.182.73",
                "ip_country": null,
                "ip_country_code": null,
                "browser": null,
                "device_fingerprint": null,
                "device_type": null
            },
            "metadata": {}
        },
        "outcome": {
            "type": "venta_exitosa",
            "code": "AUT0000",
            "merchant_message": "La operación de venta ha sido autorizada exitosamente",
            "user_message": "Su compra ha sido exitosa."
        },
        "fraud_score": 56.0,
        "dispute": false,
        "capture": true,
        "reference_code": "bYYXVQ7bfh",
        "authorization_code": "qnXJW5",
        "metadata": {},
        "total_fee": 47,
        "fee_details": {
            "fixed_fee": {},
            "variable_fee": {
                "currency_code": "PEN",
                "commision": 0.0399,
                "total": 40
            }
        },
        "total_fee_taxes": 7,
        "transfer_amount": 953,
        "paid": false,
        "statement_descriptor": "CULQI*",
        "transfer_id": null,
        "operations": [],
        "capture_date": 1615131600000
    }
}

Actualizar

charge_id = charge["data"]["id"]
charge_metadata = {
    "metadata": {
        "orderId": 1234567890
    }
}
charge = culqi.charge.update(id_=charge_id, data=charge_metadata)

display(charge)
{
    "status": 200,
    "data": {
        "duplicated": false,
        "object": "charge",
        "id": "chr_test_M4efNkiZX9jszJQA",
        "creation_date": 1615131596000,
        "amount": 1000,
        "amount_refunded": 0,
        "current_amount": 1000,
        "installments": 1,
        "installments_amount": 1000,
        "currency_code": "PEN",
        "email": "richard@piedpiper.com",
        "description": "Venta de prueba",
        "source": {
            "object": "token",
            "id": "tkn_test_by2icDaZJGAAYY00",
            "type": "card",
            "creation_date": 1615131594000,
            "email": "richard@piedpiper.com",
            "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": {}
        },
        "outcome": {
            "type": "venta_exitosa",
            "code": "AUT0000",
            "merchant_message": "La operación de venta ha sido autorizada exitosamente",
            "user_message": "Su compra ha sido exitosa."
        },
        "fraud_score": 56.0,
        "dispute": false,
        "capture": true,
        "reference_code": "bYYXVQ7bfh",
        "authorization_code": "qnXJW5",
        "metadata": {
            "orderId": "1234567890"
        },
        "total_fee": 47,
        "fee_details": {
            "fixed_fee": {},
            "variable_fee": {
                "currency_code": "PEN",
                "commision": 0.0399,
                "total": 40
            }
        },
        "total_fee_taxes": 7,
        "transfer_amount": 953,
        "paid": false,
        "statement_descriptor": "CULQI*",
        "transfer_id": null,
        "capture_date": 1615131600000
    }
}

Clone this wiki locally