Skip to main content

Biblioteca de Culqi en Python

Project description

Culqi Python

GitHub PyPI Travis (.org) branch

Biblioteca de CULQI para el lenguaje Python, pagos simples en tu sitio web. Consume el Culqi API.

Versión actual Culqi API
0.2.6 (2017-02-27) v2

Requisitos

  • Python 2.7, 3.5, 3.6, 3.7, 3.8-dev
  • Credenciales de comercio en Culqi.

Instalación

pip install culqi

Ejemplo

Inicialización

from uuid import uuid4
import culqi

public_key = '{LLAVE PUBLICA}'
private_key = '{LLAVE SECRETA}'

client = Client(public_key=public_key, private_key=private_key)

Token

Crear
token_data = {
      "cvv": "123",
      "card_number": "4111111111111111",
      "expiration_year": "2020",
      "expiration_month": "09",
      "email": "richard@piedpiper.com",
}

token = client.token.create(data=token_data)
print(token["data"])
Leer
retrieved_token = client.token.read(token["data"]["id"])
print(retrieved_token["data"])
Actualizar
metadatada = {
      "metadata": {
            "order_id": "0001"
      }
}
updated_token = client.token.update(id_=token["data"]["id"], data=metadatada)
print(updated_token["data"])
Listar
retrieved_token_list = client.token.list()
assert "items" in retrieved_token_list["data"]

Cargo

Crear
charge_data = {
      "amount": 10000,
      "capture": False,
      "currency_code": "PEN",
      "description": "Venta de prueba",
      "email": "richard@piedpiper.com",
      "installments": 0,
      "source_id": token["data"]["id"],
}

charge = client.charge.create(data=charge_data)
print(charge["data"])
Capturar
captured_charge = client.charge.capture(charge["data"]["id"])
print(captured_charge["data"])
Leer
retrieved_charge = client.charge.read(charge["data"]["id"])
print(retrieved_charge["data"])
Actualizar
metadatada = {
      "metadata": {
            "order_id": "0001"
      }
}
updated_charge = client.charge.update(id_=charge["data"]["id"], data=metadatada)
print(updated_charge["data"])
Listar
retrieved_charge_list = client.charge.list()
assert "items" in retrieved_charge_list["data"]

Reembolso

Crear
refund_data = {
      "amount": 100,
      "reason": "solicitud_comprador",
      "charge_id": charge["data"]["id"],
}

refund = client.refund.create(data=refund_data)
print(refund["data"])
Leer
retrieved_refund = client.refund.read(refund["data"]["id"])
print(retrieved_refund["data"])
Actualizar
metadatada = {
      "metadata": {
            "order_id": "0001"
      }
}
updated_refund = client.refund.update(id_=refund["data"]["id"], data=metadatada)
print(updated_refund["data"])
Listar
retrieved_refund_list = client.refund.list()
assert "items" in retrieved_refund_list["data"]

Cliente

Crear
customer_data = {
      "address": "Avenida Lima 123213",
      "address_city": "LIMA",
      "country_code": "PE",
      "email": "richard@piedpiper.com",
      "first_name": "Richard",
      "last_name": "Piedpiper",
      "phone_number": "+51998989789",
}

customer = client.customer.create(data=customer_data)
print(customer["data"])
Leer
retrieved_customer = client.customer.read(customer["data"]["id"])
print(retrieved_customer["data"])
Actualizar
metadatada = {
      "metadata": {
            "order_id": "0001"
      }
}
updated_customer = client.customer.update(id_=customer["data"]["id"], data=metadatada)
print(updated_customer["data"])
Eliminar
deleted_customer = client.customer.delete(id_=customer["data"]["id"])
print(deleted_customer["data"])
Listar
retrieved_customer_list = client.customer.list()
assert "items" in retrieved_customer_list["data"]

Tarjeta

Crear
card_data = {
      "token_id": token["data"]["id"],
      "customer_id": customer["data"]["id"],
}

card = client.card.create(data=card_data)
print(card["data"])
Leer
retrieved_card = client.card.read(card["data"]["id"])
print(retrieved_card["data"])
Actualizar
metadatada = {
      "metadata": {
            "order_id": "0001"
      }
}
updated_card = client.card.update(id_=card["data"]["id"], data=metadatada)
print(updated_card["data"])
Eliminar
deleted_card = client.card.delete(id_=card["data"]["id"])
print(deleted_card["data"])
Listar
retrieved_card_list = client.card.list()
assert "items" in retrieved_card_list["data"]

Plan

Crear
plan_data = {
      "amount": 1000,
      "currency_code": "PEN",
      "interval": "dias",
      "interval_count": 2,
      "limit": 10,
      "name": "plan-{0}".format(uuid4().hex[:4]),
      "trial_days": 30,
}

plan = client.plan.create(data=plan_data)
print(plan["data"])
Leer
retrieved_plan = client.plan.read(plan["data"]["id"])
print(retrieved_plan["data"])
Actualizar
metadatada = {
      "metadata": {
            "order_id": "0001"
      }
}
updated_plan = client.plan.update(id_=plan["data"]["id"], data=metadatada)
print(updated_plan["data"])
Eliminar
deleted_plan = client.plan.delete(id_=plan["data"]["id"])
print(deleted_plan["data"])
Listar
retrieved_plan_list = client.plan.list()
assert "items" in retrieved_plan_list["data"]

Suscripción

Crear
subscription_data = {
      "card_id": card["data"]["id"],
      "plan_id": plan["data"]["id"],
}

subscription = client.subscription.create(data=subscription_data)
print(subscription["data"])
Leer
retrieved_subscription = client.subscription.read(subscription["data"]["id"])
print(retrieved_subscription["data"])
Actualizar
metadatada = {
      "metadata": {
            "order_id": "0001"
      }
}
updated_subscription = client.subscription.update(id_=subscription["data"]["id"], data=metadatada)
print(updated_subscription["data"])
Eliminar
deleted_subscription = client.subscription.delete(id_=subscription["data"]["id"])
print(deleted_subscription["data"])
Listar
retrieved_subscription_list = client.subscription.list()
assert "items" in retrieved_subscription_list["data"]

Orden

Crear
order_data = {
      "amount": 1000,
      "currency_code": "PEN",
      "description": "Venta de prueba",
      "order_number": "order-{0}".format(uuid4().hex[:4]),
      "client_details": {
            "first_name": "Richard",
            "last_name": "Piedpiper",
            "email": "richard@piedpiper.com",
            "phone_number": "+51998989789",
      },
      "expiration_date": 1893474000,
      "confirm": False,
}

order = client.order.create(data=order_data)
print(order["data"])
Confirmar
confirmed_order = client.order.confirm(order["data"]["id"])
print(confirmed_order["data"])
Leer
retrieved_order = client.order.read(order["data"]["id"])
print(retrieved_order["data"])
Actualizar
metadatada = {
      "metadata": {
            "order_id": "0001"
      }
}
updated_order = client.order.update(id_=order["data"]["id"], data=metadatada)
print(updated_order["data"])
Eliminar
deleted_order = client.order.delete(order["data"]["id"])
print(deleted_order["data"])
Listar
retrieved_order_list = client.order.list()
assert "items" in retrieved_order_list["data"]

Evento

Leer
retrieved_event = client.event.read(event_id)
print(retrieved_event["data"])
Listar
retrieved_event_list = client.event.list()
assert "items" in retrieved_event_list["data"]

Iin

Leer
retrieved_iin = client.iin.read(iin_id)
print(retrieved_iin["data"])
Listar
retrieved_iin_list = client.iin.list()
assert "items" in retrieved_iin_list["data"]

Transferencia

Leer
retrieved_transfer = client.transfer.read(transfer_id)
print(retrieved_transfer["data"])
Listar
retrieved_transfer_list = client.transfer.list()
assert "items" in retrieved_transfer_list["data"]

Nota

Cada metodo retona un diccionario con la estructura

{
      "status": status_code,
      "data": data
}

El status_code es el estatus HTTP numérico devuelto por la solicitud HTTP que se realiza al API de Culqi, y data contiene el cuerpo de la respuesta obtenida.

Documentación

Changelog

Todos los cambios en las versiones de esta biblioteca están listados en CHANGELOG.md.

Desarrollo

Si estas interesado en contribuir con el desarrollo y mantenimiento de este paquete es recomendable que emplees poetry para la gestión de dependencias.

Entorno

Clona el proyecto

$ git clone https://github.com/culqi/culqi.git
$ cd culqi

Instala las dependencias

$ poetry install

Testing and coverage

Puedes ejecutar los tests con poetry

poetry run pytest --cov --cov-report=
poetry run coverage report

¿Quieres enviar un PR?

Antes de hacer tu primer commit y enviar tu pull request ejecuta

$ poetry run pre-commit install

Luego relaiza tu commits de forma habitual.

Autor

Willy Aguirre (@marti1125 - Team Culqi)

Nuestros Contribuidores

Licencia

El código fuente de culqi está distribuido bajo MIT License, revisar el archivo LICENSE.txt.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

culqi-1.0.1.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

culqi-1.0.1-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file culqi-1.0.1.tar.gz.

File metadata

  • Download URL: culqi-1.0.1.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.7.5

File hashes

Hashes for culqi-1.0.1.tar.gz
Algorithm Hash digest
SHA256 991372929054d4777f22d77e8100cb7ede49fb680d6ec057c6b17574dfdf8204
MD5 9c2e1c3d2ed072dfbbf085794913beed
BLAKE2b-256 cdcfcefcddc1585ba20501f57ebbca7fd1d4f25a18725923699e148951ce76a5

See more details on using hashes here.

File details

Details for the file culqi-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: culqi-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.7.5

File hashes

Hashes for culqi-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 949e938c04ae00d94405a2e4bcf5bfd452b53918438c621da6e19ff413e4b582
MD5 9b4145114654e4a3f8715f778867b15f
BLAKE2b-256 ecc760c348ab7ea733943d62385b0948d38fdcd9179da50b62bd2e7df93c25d0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page