Code Monkey home page Code Monkey logo

cuenca-python's Introduction

Cuenca – Python client library

test codecov PyPI

Installation

pip install cuenca

Authentication

The preferred way to configure the credentials for the client is to set the CUENCA_API_KEY and CUENCA_API_SECRET environment variables. The client library will automatically configure based on the values of those variables.

To configure manually:

import cuenca

cuenca.configure(api_key='PKxxxx', api_secret='yyyyyy')

Transfers

Create transfer

import cuenca

cuenca.configure(sandbox=True)  # if using sandbox

local_transfer_id = '078efdc20bab456285437309c4b75673'

transfer = cuenca.Transfer.create(
    recipient_name='Benito Juárez',
    account_number='646180157042875763',  # CLABE or card number
    amount=12345,  # Mx$123.45
    descriptor='sending money',  # As it'll appear for the customer
    idempotency_key=local_transfer_id
)

# To get updated status
transfer.refresh()

Retrieve by id

import cuenca

transfer = cuenca.Transfer.retrieve('tr_123')

Query by idempotency_key, account_number and status

Results are always returned in descending order of created_at

The methods that can be used:

  • one() - returns a single result. Raises NoResultFound if there are no results and MultipleResultsFound if there are more than one
  • first() - returns the first result or None if there aren't any
  • all() - returns a generator of all matching results. Pagination is handled automatically as you iterate over the response
  • count() - returns an integer with the count of the matching results
import cuenca
from cuenca.types import Status

# find the unique transfer using the idempotency key
local_transfer_id = '078efdc20bab456285437309c4b75673'
transfer = cuenca.Transfer.one(idempotency_key=local_transfer_id)

# returns a generator of all succeeded transfers to the specific account
transfers = cuenca.Transfer.all(
    account_number='646180157000000004',
    status=Status.succeeded
)

# the total number of succeeded transfers
count = cuenca.Transfer.count(status=Status.succeeded)

Api Keys

Create new ApiKey and deactivate old

import cuenca

# Create new ApiKey
new = cuenca.ApiKey.create()

# Have to use the new key to deactivate the old key
old_id = cuenca.session.auth[0]
cuenca.session.configure(new.id, new.secret)
cuenca.ApiKey.deactivate(old_id, 60)  # revoke prior API key in an hour

cuenca-python's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar felipao-mx avatar matin avatar rogeliolpz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.