# Paymentsgate Python SDK for Payments REST API
## Requirements
- Python >= 3.8.1
- dependencies:
- [`requests`](https://github.com/kennethreitz/requests)
- [`pydantic`](https://docs.pydantic.dev/latest/)
- [`jwt`](https://pyjwt.readthedocs.io/en/stable/)
## Installation
The simplest way to install SDK is to use [PIP](https://docs.python.org/3/installing/):
```bash
pip install paymentsgate
```
## Basic usage
```python
from paymentsgate import ApiClient, Credentials, Currencies
# minimal configuration
config = Credentials().fromFile('/path/to/credentials.json');
# create ApiClient
client = ApiClient(config, baseUrl='https://api.example.com');
# request quote
res = cli.Quote(
{
"amount": 10.10,
"currency_from": Currencies.EUR,
"currency_to": Currencies.AZN,
}
)
print(res);
```
The `credentials.json` file is used to connect to the client and contains all necessary data to use the API. This file can be obtained in your personal cabinet, in the service accounts section. Follow the instructions in the documentation to issue new keys. If you already have keys, but you don't feel comfortable storing them in a file, you can use client initialization via variables. In this case, the key data can be stored in external storage instead of on the file system:
```python
from paymentsgate import ApiClient, Credentials
config = Credentials(
account_id="00000000-4000-4000-0000-00000000000a"
public_key="LS0tLS1CRUdJTiBSU0EgUFJJVkFUNSUlFb3dJQk..."
)
client = ApiClient(config, baseUrl='https://api.example.com');
...
```
*It is important to note that the data format for key transfer is base46.
## Examples
### create PayIn
```python
res = cli.PayIn(
{
"amount": 10.10,
"currency": Currencies.AZN,
"invoiceId": "INVOICE-112123124",
"clientId": "",
"successUrl": "https://example.com/success",
"failUrl": "https://example.com/fail",
"type": InvoiceTypes.m10
}
)
print(res);
```
### create PayOut
```python
res = cli.PayOut(
{
"amount": 5.12,
"currencyTo": Currencies.EUR,
"invoiceId": "INVOICE-112123124",
"clientId": "CLIENT-003010023004",
"baseCurrency": CurrencyTypes.fiat,
"feesStrategy": FeesStrategy.add,
"recipient": {
"account_number": "4000000000000012",
"account_owner": "CARD HOLDER",
"type": CredentialsTypes.card
}
}
)
print(res);
```
### Error handling
```python
try:
res = cli.PayOut(
{
"amount": 5.12,
"currencyTo": Currencies.EUR,
"invoiceId": "INVOICE-112123124",
"clientId": "CLIENT-003010023004",
"baseCurrency": CurrencyTypes.fiat,
"feesStrategy": FeesStrategy.add,
"recipient": {
"account_number": "4000000000000012",
"account_owner": "CARD HOLDER",
"type": CredentialsTypes.card
}
}
)
print(res);
except APIAuthenticationError as err:
print(f"Authentication fail: {err.message}")
except APIResponseError as err:
print(f"Exception: {err.error}; Message: {err.message}")
```
Raw data
{
"_id": null,
"home_page": "https://github.com/paymentsgate/python-secure-api",
"name": "paymentsgate",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": "paymentsgate, payments, sdk, api",
"author": "PaymentsGate",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/ec/32/6141a880156bfb2bf4de3fce4f785f1f044b5cc154d749c8bc32e6663ee9/paymentsgate-1.4.4.tar.gz",
"platform": null,
"description": "\n# Paymentsgate Python SDK for Payments REST API\n\n\n## Requirements\n\n- Python >= 3.8.1\n- dependencies:\n - [`requests`](https://github.com/kennethreitz/requests)\n - [`pydantic`](https://docs.pydantic.dev/latest/)\n - [`jwt`](https://pyjwt.readthedocs.io/en/stable/)\n \n## Installation\n\nThe simplest way to install SDK is to use [PIP](https://docs.python.org/3/installing/):\n\n```bash\npip install paymentsgate\n```\n\n## Basic usage\n\n```python\nfrom paymentsgate import ApiClient, Credentials, Currencies\n\n\n# minimal configuration\nconfig = Credentials().fromFile('/path/to/credentials.json');\n\n# create ApiClient\nclient = ApiClient(config, baseUrl='https://api.example.com');\n\n# request quote\nres = cli.Quote(\n {\n \"amount\": 10.10,\n \"currency_from\": Currencies.EUR,\n \"currency_to\": Currencies.AZN,\n }\n)\nprint(res);\n```\n\nThe `credentials.json` file is used to connect to the client and contains all necessary data to use the API. This file can be obtained in your personal cabinet, in the service accounts section. Follow the instructions in the documentation to issue new keys. If you already have keys, but you don't feel comfortable storing them in a file, you can use client initialization via variables. In this case, the key data can be stored in external storage instead of on the file system:\n\n```python\nfrom paymentsgate import ApiClient, Credentials\n\nconfig = Credentials(\n account_id=\"00000000-4000-4000-0000-00000000000a\" \n public_key=\"LS0tLS1CRUdJTiBSU0EgUFJJVkFUNSUlFb3dJQk...\"\n)\n\nclient = ApiClient(config, baseUrl='https://api.example.com');\n\n...\n```\n*It is important to note that the data format for key transfer is base46.\n\n## Examples\n\n### create PayIn\n\n```python\nres = cli.PayIn(\n {\n \"amount\": 10.10,\n \"currency\": Currencies.AZN,\n \"invoiceId\": \"INVOICE-112123124\",\n \"clientId\": \"\",\n \"successUrl\": \"https://example.com/success\",\n \"failUrl\": \"https://example.com/fail\",\n \"type\": InvoiceTypes.m10\n }\n)\nprint(res);\n```\n\n### create PayOut\n\n```python\nres = cli.PayOut(\n {\n \"amount\": 5.12,\n \"currencyTo\": Currencies.EUR,\n \"invoiceId\": \"INVOICE-112123124\",\n \"clientId\": \"CLIENT-003010023004\",\n \"baseCurrency\": CurrencyTypes.fiat,\n \"feesStrategy\": FeesStrategy.add,\n \"recipient\": {\n \"account_number\": \"4000000000000012\",\n \"account_owner\": \"CARD HOLDER\",\n \"type\": CredentialsTypes.card\n }\n }\n)\nprint(res);\n```\n\n### Error handling\n\n```python\ntry:\n res = cli.PayOut(\n {\n \"amount\": 5.12,\n \"currencyTo\": Currencies.EUR,\n \"invoiceId\": \"INVOICE-112123124\",\n \"clientId\": \"CLIENT-003010023004\",\n \"baseCurrency\": CurrencyTypes.fiat,\n \"feesStrategy\": FeesStrategy.add,\n \"recipient\": {\n \"account_number\": \"4000000000000012\",\n \"account_owner\": \"CARD HOLDER\",\n \"type\": CredentialsTypes.card\n }\n }\n )\n print(res);\nexcept APIAuthenticationError as err:\n print(f\"Authentication fail: {err.message}\")\nexcept APIResponseError as err:\n print(f\"Exception: {err.error}; Message: {err.message}\")\n```",
"bugtrack_url": null,
"license": "MIT",
"summary": "PaymentsGate's Python SDK for REST API",
"version": "1.4.4",
"project_urls": {
"Documentation": "https://github.com/paymentsgate/python-secure-api",
"Homepage": "https://github.com/paymentsgate/python-secure-api",
"Repository": "https://github.com/paymentsgate/python-secure-api"
},
"split_keywords": [
"paymentsgate",
" payments",
" sdk",
" api"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "5b842a8bf95303d24393f17241c642353b522d01db306ca9a70271eb0b0fc682",
"md5": "f0559cec72fb2eaca88fd03d558a7946",
"sha256": "a3dc4bdc23d0b15c144d1b323e2a371fb1cda8effbfd375f8a9777ab407cec85"
},
"downloads": -1,
"filename": "paymentsgate-1.4.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f0559cec72fb2eaca88fd03d558a7946",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 10405,
"upload_time": "2024-12-21T16:20:56",
"upload_time_iso_8601": "2024-12-21T16:20:56.654467Z",
"url": "https://files.pythonhosted.org/packages/5b/84/2a8bf95303d24393f17241c642353b522d01db306ca9a70271eb0b0fc682/paymentsgate-1.4.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ec326141a880156bfb2bf4de3fce4f785f1f044b5cc154d749c8bc32e6663ee9",
"md5": "a96fe2f2990ebcccdabe9802ce18a796",
"sha256": "c19f9472ff883347bd5c4cd1c193a867539ec3931241ec8161c8c12b6a9aae95"
},
"downloads": -1,
"filename": "paymentsgate-1.4.4.tar.gz",
"has_sig": false,
"md5_digest": "a96fe2f2990ebcccdabe9802ce18a796",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 9935,
"upload_time": "2024-12-21T16:20:58",
"upload_time_iso_8601": "2024-12-21T16:20:58.983178Z",
"url": "https://files.pythonhosted.org/packages/ec/32/6141a880156bfb2bf4de3fce4f785f1f044b5cc154d749c8bc32e6663ee9/paymentsgate-1.4.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-21 16:20:58",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "paymentsgate",
"github_project": "python-secure-api",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "paymentsgate"
}