paymentsgate 1.4.6__tar.gz → 1.4.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of paymentsgate might be problematic. Click here for more details.
- {paymentsgate-1.4.6 → paymentsgate-1.4.8}/PKG-INFO +1 -1
- {paymentsgate-1.4.6 → paymentsgate-1.4.8}/paymentsgate/client.py +34 -10
- {paymentsgate-1.4.6 → paymentsgate-1.4.8}/paymentsgate/models.py +17 -11
- {paymentsgate-1.4.6 → paymentsgate-1.4.8}/pyproject.toml +1 -1
- {paymentsgate-1.4.6 → paymentsgate-1.4.8}/setup.py +1 -1
- {paymentsgate-1.4.6 → paymentsgate-1.4.8}/LICENSE +0 -0
- {paymentsgate-1.4.6 → paymentsgate-1.4.8}/README.md +0 -0
- {paymentsgate-1.4.6 → paymentsgate-1.4.8}/paymentsgate/__init__.py +0 -0
- {paymentsgate-1.4.6 → paymentsgate-1.4.8}/paymentsgate/cache.py +0 -0
- {paymentsgate-1.4.6 → paymentsgate-1.4.8}/paymentsgate/enums.py +0 -0
- {paymentsgate-1.4.6 → paymentsgate-1.4.8}/paymentsgate/exceptions.py +0 -0
- {paymentsgate-1.4.6 → paymentsgate-1.4.8}/paymentsgate/logger.py +0 -0
- {paymentsgate-1.4.6 → paymentsgate-1.4.8}/paymentsgate/tokens.py +0 -0
- {paymentsgate-1.4.6 → paymentsgate-1.4.8}/paymentsgate/transport.py +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
|
-
|
|
2
|
+
import logging
|
|
3
|
+
from dataclasses import dataclass, is_dataclass, field, asdict
|
|
3
4
|
import json
|
|
4
5
|
from urllib.parse import urlencode
|
|
5
6
|
|
|
@@ -18,7 +19,8 @@ from paymentsgate.models import (
|
|
|
18
19
|
PayInModel,
|
|
19
20
|
PayInResponseModel,
|
|
20
21
|
PayOutModel,
|
|
21
|
-
PayOutResponseModel
|
|
22
|
+
PayOutResponseModel,
|
|
23
|
+
InvoiceModel
|
|
22
24
|
)
|
|
23
25
|
from paymentsgate.enums import ApiPaths
|
|
24
26
|
from paymentsgate.transport import (
|
|
@@ -44,10 +46,12 @@ class ApiClient:
|
|
|
44
46
|
REQUEST_DEBUG: bool = False
|
|
45
47
|
RESPONSE_DEBUG: bool = False
|
|
46
48
|
|
|
47
|
-
def __init__(self, config: Credentials, baseUrl: str):
|
|
49
|
+
def __init__(self, config: Credentials, baseUrl: str, debug: bool=False):
|
|
48
50
|
self.config = config
|
|
49
51
|
self.cache = DefaultCache()
|
|
50
|
-
self.baseUrl = baseUrl
|
|
52
|
+
self.baseUrl = baseUrl
|
|
53
|
+
if debug:
|
|
54
|
+
logging.basicConfig(level=logging.DEBUG)
|
|
51
55
|
|
|
52
56
|
def PayIn(self, request: PayInModel) -> PayInResponseModel:
|
|
53
57
|
# Prepare request
|
|
@@ -100,11 +104,30 @@ class ApiClient:
|
|
|
100
104
|
# Handle response
|
|
101
105
|
response = self._send_request(request)
|
|
102
106
|
self.logger(request, response)
|
|
103
|
-
if
|
|
104
|
-
return response.cast(GetQuoteResponseModel, APIResponseError)
|
|
105
|
-
else:
|
|
107
|
+
if not response.success:
|
|
106
108
|
raise APIResponseError(response)
|
|
107
109
|
|
|
110
|
+
return response.cast(GetQuoteResponseModel, APIResponseError)
|
|
111
|
+
|
|
112
|
+
def Status(self, query: str) -> InvoiceModel:
|
|
113
|
+
# Prepare request
|
|
114
|
+
request = Request(
|
|
115
|
+
method="get",
|
|
116
|
+
path=ApiPaths.invoices_info,
|
|
117
|
+
content_type='application/json',
|
|
118
|
+
noAuth=False,
|
|
119
|
+
signature=False,
|
|
120
|
+
body=request
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
# Handle response
|
|
124
|
+
response = self._send_request(request)
|
|
125
|
+
self.logger(request, response)
|
|
126
|
+
if not response.success:
|
|
127
|
+
raise APIResponseError(response)
|
|
128
|
+
|
|
129
|
+
return response.cast(InvoiceModel, APIResponseError)
|
|
130
|
+
|
|
108
131
|
@property
|
|
109
132
|
def token(self) -> AccessToken | None:
|
|
110
133
|
# First check if valid token is cached
|
|
@@ -152,7 +175,7 @@ class ApiClient:
|
|
|
152
175
|
"""
|
|
153
176
|
Send a specified Request to the GoPay REST API and process the response
|
|
154
177
|
"""
|
|
155
|
-
|
|
178
|
+
body = asdict(request.body) if is_dataclass(request.body) else request.body
|
|
156
179
|
# Add Bearer authentication to headers if needed
|
|
157
180
|
headers = request.headers or {}
|
|
158
181
|
if not request.noAuth:
|
|
@@ -161,9 +184,10 @@ class ApiClient:
|
|
|
161
184
|
headers["Authorization"] = f"Bearer {auth.token}"
|
|
162
185
|
|
|
163
186
|
if (request.method == 'get'):
|
|
187
|
+
params = urlencode(body)
|
|
164
188
|
r = requests.request(
|
|
165
189
|
method=request.method,
|
|
166
|
-
url=f"{self.baseUrl}{request.path}?{
|
|
190
|
+
url=f"{self.baseUrl}{request.path}?{params}",
|
|
167
191
|
headers=headers,
|
|
168
192
|
timeout=self.timeout
|
|
169
193
|
)
|
|
@@ -172,7 +196,7 @@ class ApiClient:
|
|
|
172
196
|
method=request.method,
|
|
173
197
|
url=f"{self.baseUrl}{request.path}",
|
|
174
198
|
headers=headers,
|
|
175
|
-
json=
|
|
199
|
+
json=body,
|
|
176
200
|
timeout=self.timeout
|
|
177
201
|
)
|
|
178
202
|
|
|
@@ -22,11 +22,11 @@ from pydantic import BaseModel, ConfigDict
|
|
|
22
22
|
class Credentials:
|
|
23
23
|
def __init__(
|
|
24
24
|
self,
|
|
25
|
-
account_id
|
|
26
|
-
merchant_id
|
|
27
|
-
project_id
|
|
28
|
-
private_key
|
|
29
|
-
public_key
|
|
25
|
+
account_id: str,
|
|
26
|
+
merchant_id: str,
|
|
27
|
+
project_id: str,
|
|
28
|
+
private_key: str,
|
|
29
|
+
public_key: str
|
|
30
30
|
):
|
|
31
31
|
self.account_id = account_id
|
|
32
32
|
self.merchant_id = merchant_id
|
|
@@ -34,14 +34,14 @@ class Credentials:
|
|
|
34
34
|
self.private_key = private_key
|
|
35
35
|
self.public_key = public_key
|
|
36
36
|
|
|
37
|
+
@classmethod
|
|
37
38
|
def fromFile(cls, filename):
|
|
38
39
|
data = json.load(open(filename))
|
|
39
|
-
cls
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return cls
|
|
40
|
+
return cls(data.get('account_id'),
|
|
41
|
+
data.get('merchant_id'),
|
|
42
|
+
data.get('project_id'),
|
|
43
|
+
data.get('private_key'),
|
|
44
|
+
data.get('public_key'))
|
|
45
45
|
|
|
46
46
|
|
|
47
47
|
@dataclass
|
|
@@ -148,6 +148,7 @@ class GetQuoteResponseModel:
|
|
|
148
148
|
fees: Optional[float] = None
|
|
149
149
|
fees_percent: Optional[float] = None
|
|
150
150
|
quotes: Optional[List[QuoteEntity]] = None
|
|
151
|
+
expiredAt: Optional[datetime.datetime] = None
|
|
151
152
|
|
|
152
153
|
#deprecated
|
|
153
154
|
currency_from: Optional[CurrencyModel] = None
|
|
@@ -199,9 +200,11 @@ class InvoiceAmountModel:
|
|
|
199
200
|
class InvoiceMetadataModel:
|
|
200
201
|
invoiceId: Optional[str]
|
|
201
202
|
clientId: Optional[str]
|
|
203
|
+
fiatAmount: Optional[float]
|
|
202
204
|
|
|
203
205
|
@dataclass
|
|
204
206
|
class InvoiceModel:
|
|
207
|
+
_id: str
|
|
205
208
|
orderId: str
|
|
206
209
|
projectId: str
|
|
207
210
|
currencyFrom: CurrencyModel
|
|
@@ -211,6 +214,8 @@ class InvoiceModel:
|
|
|
211
214
|
status: InvoiceStatusModel
|
|
212
215
|
amounts: InvoiceAmountModel
|
|
213
216
|
metadata: InvoiceMetadataModel
|
|
217
|
+
receiptUrls: List[str]
|
|
218
|
+
isExpired: bool
|
|
214
219
|
createdAt: datetime
|
|
215
220
|
updatedAt: datetime
|
|
216
221
|
expiredAt: datetime
|
|
@@ -225,3 +230,4 @@ class AssetsAccountModel:
|
|
|
225
230
|
@dataclass
|
|
226
231
|
class AssetsResponseModel:
|
|
227
232
|
assets: List[AssetsAccountModel]
|
|
233
|
+
|
|
@@ -15,7 +15,7 @@ install_requires = \
|
|
|
15
15
|
|
|
16
16
|
setup_kwargs = {
|
|
17
17
|
'name': 'paymentsgate',
|
|
18
|
-
'version': '1.4.
|
|
18
|
+
'version': '1.4.8',
|
|
19
19
|
'description': "PaymentsGate's Python SDK for REST API",
|
|
20
20
|
'long_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```',
|
|
21
21
|
'author': 'PaymentsGate',
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|