Safepay's python SDK for checkout integration
Project description
Safepay Python SDK
Official python library for Safepay API.
Installation
With Pip
pip install safepay-python
Usage
Import and create a Safepay client by passing your config;
from safepay_python.safepay import *
env = Safepay(
{
"environment": "sandbox",
"apiKey": "sec_asd12-2342s-1231s",
"v1Secret": "bar",
"webhookSecret": "foo",
}
)
You can now create payments and checkout links.
Payments
Create payment
| Parameter | Type | Required |
|---|---|---|
amount |
number |
Yes |
currency |
PKR, USD |
Yes |
payment_response = env.set_payment_details({"amount": 10000, "currency": "PKR"})
token = (payment_response['data'])['token']
# Pass `token` to create checkout link
Checkout
Create checkout link
| Parameter | Type | Description | Required |
|---|---|---|---|
token |
string |
Token from env.set_payment_details |
Yes |
orderId |
string |
Your internal invoice / order id | No |
cancelUrl |
string |
Url to redirect to if user cancels the flow | Yes |
redirectUrl |
string |
Url to redirect to if user completes the flow | Yes |
source |
string |
Optional, defaults to custom |
No |
webhooks |
boolean |
Optional, defaults to false |
No |
checkout_url = env.get_checkout_url(
{
"beacon": token,
"cancelUrl": "http://example.com/cancel",
"orderId": "T800",
"redirectUrl": "http://example.com/success",
"source": "custom",
"webhooks": True,
}
)
# set webhooks = True if want to subscribe to webhooks
# redirect user to `url`
Verification
Signature
| Parameter | Type | Description | Required |
|---|---|---|---|
sig |
string |
The signature string from your server |
Yes |
tracker |
string |
The tracker string from your server |
Yes |
signature_verification = env.is_signature_valid({"sig": "abcd", "tracker": token})
# mark the invoice as paid if valid
# show an error if invalid
Webhook
| Parameter | Type | Description | Required |
|---|---|---|---|
x-sfpy-signature |
string |
The signature string from your server |
Yes |
data |
object |
The data object from your server |
Yes |
webhook_verification = env.is_webhook_valid(
{"x-sfpy-signature": "abcd"}, {"data": data}
)
# mark the invoice as paid if valid
# show an error if invalid
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
safepay_python-0.0.4.tar.gz
(4.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file safepay_python-0.0.4.tar.gz.
File metadata
- Download URL: safepay_python-0.0.4.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1050d92d8c9fca46d6dfe6b1577fc68123c1f8ef498ad96b50bb32d9b36f9adb
|
|
| MD5 |
ec0eda1c3e8df804d51bdd77798cc09a
|
|
| BLAKE2b-256 |
df69d6157c5d872a294f2db95e56f9ea4d3330867781b96539a1b4ea54a006b4
|
File details
Details for the file safepay_python-0.0.4-py3-none-any.whl.
File metadata
- Download URL: safepay_python-0.0.4-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b540be16c7489fb2b66fea8be031dea6aea340bd6f726c19b4aef2330ad6f753
|
|
| MD5 |
4dcf5251c2c74a5f4fb7f1966ac85f2a
|
|
| BLAKE2b-256 |
397fc5afb93b1db3082b72155cfa7c30e0804ad0c1acdc638929e0cafe14025b
|