Metadata-Version: 2.1
Name: paymentsgate
Version: 1.5.10
Summary: PaymentsGate's Python SDK for REST API
Home-page: https://github.com/paymentsgate/python-secure-api
License: MIT
Keywords: paymentsgate,payments,sdk,api
Author: PaymentsGate
Requires-Python: >=3.10,<4.0
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Dist: cryptography (>=44.0.2,<45.0.0)
Requires-Dist: httpx (>=0.28.1,<0.29.0)
Requires-Dist: jwt (>=1.3.1,<2.0.0)
Requires-Dist: pydantic (>=2.8.2,<3.0.0)
Requires-Dist: ruff (>=0.11.7,<0.12.0)
Requires-Dist: tomli (>=2.0.1,<3.0.0)
Project-URL: Documentation, https://github.com/paymentsgate/python-secure-api
Project-URL: Repository, https://github.com/paymentsgate/python-secure-api
Description-Content-Type: text/markdown


# 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}")
```
