A simple library to manage Satispay payments following the Web-button flow.
Project description
satispaython
A simple library to manage Satispay payments following the Web-button flow.
Requirements
- python >= 3.6
cryptography
>= 3.1requests
>= 2.24
Installation
You can install this package with pip: pip install satispaython
.
Usage
Key generation
Firs 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 import generate_key, write_key
rsa_key = generate_key()
write_key(rsa_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 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 theload_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 classRSAPrivateKey
. If you don't use theload_key
function then make sure your key is an instance ofRSAPrivateKey
.
You may protect your key with a password simply adding the password
parameter:
write_key(rsa_key, 'path/to/file.pem', password='mypassword')
rsa_key = load_key('path/to/file.pem', password='mypassword')
Satispay API
In order to use the Satispay API simply import satispaython:
import satispaython as satispay
Then you can:
Obtain a key-id using a token
satispay.obtain_key_id(rsa_key, token)
: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
satispay.test_authentication(key_id, rsa_key)
:information_source: Authentication tests work on Sandbox endpoints only.
Create a payment
satispay.create_payment(key_id, rsa_key, amount_unit, currency, callback_url, expiration_date=None, external_code=None, metadata=None, idempotency_key=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 import format_datetime
expiration_date = datetime.now(timezone.utc) + timedelta(hours=1)
expiration_date = format_datetime(expiration_date)
Get payment details
satispay.get_payment_details(key_id, rsa_key, payment_id)
Satispaython web requests are based on requests
so those 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()
.
If you need to use the Sandbox endpoints, simply set the staging
parameter to True
:
satispay.obtain_key_id(rsa_key, token, staging=True)
satispay.create_payment(key_id, rsa_key, amount_unit, currency, callback_url, expiration_date=None, external_code=None, metadata=None, idempotency_key=None, staging=True)
satispay.get_payment_details(key_id, rsa_key, payment_id, staging=True)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for satispaython-0.2.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9eaeb7f61440f793382f6c0c0e04b12a68aa72d73e0a22098c24f7179722b1f5 |
|
MD5 | 068982e0f4de7002caa46abc8d0e0193 |
|
BLAKE2b-256 | b775b9a28510180e34755b7e5ed0c1c6e201db30fbbf9e2e47ace4897134b01c |