Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentacion #67

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build

if "%1" == "" goto help

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
25 changes: 25 additions & 0 deletions docs/source/apikey.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Api Keys
==============

Cuenca-python allows you to create, activate and deactivate api keys.
The example below shows you how to create an api key and how to disable the old one.

.. code-block:: python

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


Nota:
deactivate an ``ApiKey`` in a certain number of minutes. If minutes is
negative, the API will treat it the same as 0. You can't deactivate
the same key with which the client is configured, since that'd risk
locking you out. The deactivated key is returned so that you have the
exact deactivated_at time.
17 changes: 17 additions & 0 deletions docs/source/authentication.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Authentication
==============

Configure the client
--------------------

Cuenca-python has configurations values, with sensible defaults. The authentication has a configure the credentials for the
client, the way to configure is to set the :file:`CUENCA_API_KEY` and :file:`CUENCA_API_SECRET` environment variables.
The client library will automatically configure based on the values of those variables.

To configure manually:

.. code-block:: python

import cuenca

cuenca.configure(api_key='PKxxxx', api_secret='yyyyyy')
55 changes: 55 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))


# -- Project information -----------------------------------------------------

project = 'cuenca-python'
copyright = '2020, Cuenca'
author = 'Cuenca'

# The full version, including alpha/beta/rc tags
release = '0.3.2'


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
31 changes: 31 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.. cuenca-python documentation master file, created by
sphinx-quickstart on Wed Sep 30 13:11:39 2020.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.

Cuenca-python!
=========================================

Welcome to cuenca-python's documentation. Cuenca-python is a client library that allows connecting to different Cuenca's services.
Get started with :doc:`installation`


User's Guide
------------
.. toctree::
:maxdepth: 2


installation

Usage
------------
.. toctree::
:maxdepth: 2


authentication
transfers
retrieve
query
apikey
13 changes: 13 additions & 0 deletions docs/source/installation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Installation
============

Install Cuenca-python
---------------------

Use the following command to install cuenca-python:

.. code-block:: sh

$ pip install cuenca

cuenca-python is now installed.
35 changes: 35 additions & 0 deletions docs/source/query.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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.


You can use like this example:

.. code-block:: python

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)
9 changes: 9 additions & 0 deletions docs/source/retrieve.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Retrieve by id
-------------------
The way for retrieve a transfer is with the ``id``, like this:

.. code-block:: python

import cuenca

transfer = cuenca.Transfer.retrieve('tr_123')
48 changes: 48 additions & 0 deletions docs/source/transfers.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Transfers
==============

Create transfer
--------------------
In cuenca-python you can create transfers, something like this:

.. code-block:: python

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()


You can enable sandbox if you using this.

To create a transfer the following parameters are necessary:

===================== ==========================================
``account_number:`` CLABE
``amount:`` needs to be in centavos (not pesos)
``descriptor:`` how it'll appear for the recipient
``recipient_name:`` name of recipient
``idempotency_key:`` must be unique for each transfer to avoid duplicates
===================== ==========================================

The recommended idempotency_key scheme:

1. Create a transfer entry in your own database with the status created.


2. Call this method with the unique id from your database as the ``idempotency_key``.


3. Update your database with the status created or submitted after receiving a response from this method.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ requests==2.24.0
cuenca-validations==0.5.7
dataclasses>=0.7;python_version<"3.7"
aws-requests-auth==0.4.3
sphinx==3.2.1