Skip to main content

A simple library to manage Satispay payments following the Web-button flow.

Project description

satispaython

GitHub Workflow Status Codecov PyPI - Python Version

A simple library to manage Satispay payments following the Web-button flow.

Requirements

Installation

You can install this package with pip: pip install satispaython.

Usage

Type hints are available for all public functions.

Key generation

First of all you need a RSA private key. You may generate the key by yourself or you may use the provided utility functions:

from satispaython.utils.utils import generate_key, write_key

# Generate a key
rsa_key = generate_key()

# Write the key into a file
write_key(rsa_key, 'path/to/file.pem')

# You can also generate a key and save it directly to a provided path
rsa_key = generate_key('path/to/file.pem')

In order to load the key from a PEM encoded file you may use the utility function:

from satispaython.utils.utils import load_key

rsa_key = load_key('path/to/file.pem')

:information_source: The function write_key stores the key in the PEM format. If you generate the key with any other method and you would like to use the load_key function, please make sure the key is stored within a file in the PEM format.

:information_source: Satispaython key management is based on cryptography so all the functions which require an RSA key parameter expect an object of the class RSAPrivateKey. If you don't use the load_key function then make sure your key is an instance of RSAPrivateKey.

You may protect your key with a password simply adding the password parameter:

write_key(rsa_key, 'path/to/file.pem', 'mypassword')
rsa_key = load_key('path/to/file.pem', 'mypassword')
rsa_key = generate_key('path/to/file.pem', 'mypassword')

Both functions accept PathLike objects:

from pathlib import Path

path = Path('path/to/file.pem')

rsa_key = generate_key(path, 'mypassword')
write_key(rsa_key, path, 'mypassword')
rsa_key = load_key(path, 'mypassword')

Satispay API

Satispaython web requests are based on httpx so the following functions return an instance of Response. On success, the Satispay API responds with a JSON encoded body, so you can simply check for the response.status_code and eventually get the content with response.json().

:information_source: If you need to use the Sandbox endpoints be sure to read the proper section.

In order to use the Satispay API simply import satispaython:

import satispaython

Then you can:

Obtain a key-id using a token

response = satispaython.obtain_key_id(token, rsa_key)

:information_source: The token is the activation code that can be generated from the Satispay Dashboard (or provided manually for Sandbox account).

:warning: Tokens are disposable! The key-id should be saved right after its creation.

Make an authentication test

response = satispaython.test_authentication(key_id, rsa_key)

:information_source: Authentication tests work on Sandbox endpoints only.

Create a payment

response = satispaython.create_payment(key_id, rsa_key, amount_unit, currency, body_params=None, headers=None)

You may use the utility function format_datetime to get a correctly formatted expiration_date to supply to the request:

from datetime import datetime, timezone, timedelta
from satispaython.utils.utils import format_datetime

expiration_date = datetime.now(timezone.utc) + timedelta(hours=1)
expiration_date = format_datetime(expiration_date)

Get payment details

response = satispaythonsatispaython.get_payment_details(key_id, rsa_key, payment_id, headers=None)

Sandbox endpoints

By default satispaython points to the production Satispay API. If you need to use the Sandbox endpoints, simply set the staging parameter to True:

response = satispaython.obtain_key_id(rsa_key, token, staging=True)
response = satispaython.create_payment(key_id, rsa_key, amount_unit, currency, body_params=None, headers=None, staging=True)
response = satispaython.get_payment_details(key_id, rsa_key, payment_id, headers=None, staging=True)

Clients, AsyncClients and Auth

Satispaython offers specialized versions of httpx's Client, AsyncClient and Auth classes:

from satispaython import SatispayClient

with SatispayClient(key_id, rsa_key, staging=True) as client:
    response = client.create_payment(amount_unit, currency, body_params=None, headers=None)
    response = client.get_payment_details(payment_id, headers=None)
from satispaython import AsyncSatispayClient

async with AsyncSatispayClient(key_id, rsa_key, staging=True) as client:
    response = await client.create_payment(amount_unit, currency, body_params=None, headers=None)
    response = await client.get_payment_details(payment_id, headers=None)
import httpx
from satispaython import SatispayAuth

auth = SatispayAuth(key_id, rsa_key)
url = 'https://staging.authservices.satispay.com/wally-services/protocol/tests/signature'
response = httpx.post(url, auth=auth)

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

satispaython-0.4.0.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

satispaython-0.4.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file satispaython-0.4.0.tar.gz.

File metadata

  • Download URL: satispaython-0.4.0.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2

File hashes

Hashes for satispaython-0.4.0.tar.gz
Algorithm Hash digest
SHA256 b4587489ec5ce27f3bb9907835276e9513bb79f7d748ccc67ec2c3be57d48b2f
MD5 2b420b45c0ff8d7f5a0cb47e0abb678b
BLAKE2b-256 9644f3dd091a911e2ed21a075ab4c5a219ae1bcca36cb2ac1848742d2c955684

See more details on using hashes here.

File details

Details for the file satispaython-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: satispaython-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2

File hashes

Hashes for satispaython-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5216b2b3a573dff567144188747434a6f05eee53f90ecf084e935ea73df852d2
MD5 84622194dfa0e884dd6580f9582adc41
BLAKE2b-256 90f8d1056fe9a3bdaabf91f5d9ff09fd963b4361a169b4540a5f81aa33bfea48

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