payme-pkg 2.6.5__py3-none-any.whl → 3.0.17__py3-none-any.whl
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 payme-pkg might be problematic. Click here for more details.
- payme/__init__.py +1 -0
- payme/admin.py +12 -6
- payme/apps.py +0 -4
- payme/classes/cards.py +203 -0
- payme/classes/client.py +30 -0
- payme/classes/http.py +107 -0
- payme/classes/initializer.py +82 -0
- payme/classes/receipts.py +298 -0
- payme/const.py +12 -0
- payme/exceptions/__init__.py +5 -0
- payme/exceptions/general.py +275 -0
- payme/exceptions/webhook.py +125 -0
- payme/models.py +114 -40
- payme/types/response/__init__.py +4 -0
- payme/types/response/cards.py +110 -0
- payme/types/response/receipts.py +215 -0
- payme/types/response/webhook.py +136 -0
- payme/urls.py +2 -2
- payme/util.py +26 -0
- payme/views.py +287 -113
- payme_pkg-3.0.17.dist-info/METADATA +193 -0
- payme_pkg-3.0.17.dist-info/RECORD +29 -0
- {payme_pkg-2.6.5.dist-info → payme_pkg-3.0.17.dist-info}/WHEEL +1 -1
- payme/cards/__init__.py +0 -1
- payme/cards/subscribe_cards.py +0 -166
- payme/decorators/decorators.py +0 -34
- payme/errors/exceptions.py +0 -89
- payme/methods/cancel_transaction.py +0 -54
- payme/methods/check_perform_transaction.py +0 -26
- payme/methods/check_transaction.py +0 -43
- payme/methods/create_transaction.py +0 -68
- payme/methods/generate_link.py +0 -83
- payme/methods/get_statement.py +0 -65
- payme/methods/perform_transaction.py +0 -47
- payme/migrations/0001_initial.py +0 -48
- payme/receipts/__init__.py +0 -1
- payme/receipts/subscribe_receipts.py +0 -217
- payme/serializers.py +0 -86
- payme/utils/__init__.py +0 -0
- payme/utils/get_params.py +0 -24
- payme/utils/logging.py +0 -9
- payme/utils/make_aware_datetime.py +0 -21
- payme/utils/support.py +0 -8
- payme/utils/to_json.py +0 -13
- payme_pkg-2.6.5.dist-info/METADATA +0 -13
- payme_pkg-2.6.5.dist-info/RECORD +0 -36
- /payme/{decorators → classes}/__init__.py +0 -0
- /payme/{errors → types}/__init__.py +0 -0
- /payme/{methods → types/request}/__init__.py +0 -0
- {payme_pkg-2.6.5.dist-info → payme_pkg-3.0.17.dist-info}/LICENSE.txt +0 -0
- {payme_pkg-2.6.5.dist-info → payme_pkg-3.0.17.dist-info}/top_level.txt +0 -0
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import uuid
|
|
2
|
-
import time
|
|
3
|
-
import datetime
|
|
4
|
-
|
|
5
|
-
from payme.utils.logging import logger
|
|
6
|
-
from payme.utils.get_params import get_params
|
|
7
|
-
from payme.models import MerchantTransactionsModel
|
|
8
|
-
from payme.errors.exceptions import TooManyRequests
|
|
9
|
-
from payme.serializers import MerchantTransactionsModelSerializer
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class CreateTransaction:
|
|
13
|
-
"""
|
|
14
|
-
CreateTransaction class
|
|
15
|
-
That's used to create transaction
|
|
16
|
-
|
|
17
|
-
Full method documentation
|
|
18
|
-
-------------------------
|
|
19
|
-
https://developer.help.paycom.uz/metody-merchant-api/createtransaction
|
|
20
|
-
"""
|
|
21
|
-
def __call__(self, params: dict) -> tuple:
|
|
22
|
-
serializer = MerchantTransactionsModelSerializer(
|
|
23
|
-
data=get_params(params)
|
|
24
|
-
)
|
|
25
|
-
serializer.is_valid(raise_exception=True)
|
|
26
|
-
order_id = serializer.validated_data.get("order_id")
|
|
27
|
-
|
|
28
|
-
try:
|
|
29
|
-
transaction = MerchantTransactionsModel.objects.filter(
|
|
30
|
-
order_id=order_id
|
|
31
|
-
).last()
|
|
32
|
-
|
|
33
|
-
if transaction is not None:
|
|
34
|
-
if transaction._id != serializer.validated_data.get("_id"):
|
|
35
|
-
raise TooManyRequests()
|
|
36
|
-
|
|
37
|
-
except TooManyRequests as error:
|
|
38
|
-
logger.error("Too many requests for transaction %s", error)
|
|
39
|
-
raise TooManyRequests() from error
|
|
40
|
-
|
|
41
|
-
if transaction is None:
|
|
42
|
-
transaction, _ = \
|
|
43
|
-
MerchantTransactionsModel.objects.get_or_create(
|
|
44
|
-
_id=serializer.validated_data.get('_id'),
|
|
45
|
-
order_id=serializer.validated_data.get('order_id'),
|
|
46
|
-
transaction_id=uuid.uuid4(),
|
|
47
|
-
amount=serializer.validated_data.get('amount'),
|
|
48
|
-
created_at_ms=int(time.time() * 1000),
|
|
49
|
-
)
|
|
50
|
-
|
|
51
|
-
if transaction:
|
|
52
|
-
response: dict = {
|
|
53
|
-
"result": {
|
|
54
|
-
"create_time": int(transaction.created_at_ms),
|
|
55
|
-
"transaction": transaction.transaction_id,
|
|
56
|
-
"state": int(transaction.state),
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return order_id, response
|
|
61
|
-
|
|
62
|
-
@staticmethod
|
|
63
|
-
def _convert_ms_to_datetime(time_ms: int) -> datetime:
|
|
64
|
-
"""Use this format to convert from time ms to datetime format.
|
|
65
|
-
"""
|
|
66
|
-
readable_datetime = datetime.datetime.fromtimestamp(time_ms / 1000)
|
|
67
|
-
|
|
68
|
-
return readable_datetime
|
payme/methods/generate_link.py
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import base64
|
|
2
|
-
from decimal import Decimal
|
|
3
|
-
from dataclasses import dataclass
|
|
4
|
-
|
|
5
|
-
from django.conf import settings
|
|
6
|
-
|
|
7
|
-
PAYME_ID = settings.PAYME.get('PAYME_ID')
|
|
8
|
-
PAYME_ACCOUNT = settings.PAYME.get('PAYME_ACCOUNT')
|
|
9
|
-
PAYME_CALL_BACK_URL = settings.PAYME.get('PAYME_CALL_BACK_URL')
|
|
10
|
-
PAYME_URL = settings.PAYME.get("PAYME_URL")
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
@dataclass
|
|
14
|
-
class GeneratePayLink:
|
|
15
|
-
"""
|
|
16
|
-
GeneratePayLink dataclass
|
|
17
|
-
That's used to generate pay lint for each order.
|
|
18
|
-
|
|
19
|
-
Parameters
|
|
20
|
-
----------
|
|
21
|
-
order_id: int — The order_id for paying
|
|
22
|
-
amount: int — The amount belong to the order
|
|
23
|
-
callback_url: str \
|
|
24
|
-
The merchant api callback url to redirect after payment. Optional parameter.
|
|
25
|
-
By default, it takes PAYME_CALL_BACK_URL from your settings
|
|
26
|
-
|
|
27
|
-
Returns str — pay link
|
|
28
|
-
----------------------
|
|
29
|
-
|
|
30
|
-
Full method documentation
|
|
31
|
-
-------------------------
|
|
32
|
-
https://developer.help.paycom.uz/initsializatsiya-platezhey/
|
|
33
|
-
"""
|
|
34
|
-
order_id: str
|
|
35
|
-
amount: Decimal
|
|
36
|
-
callback_url: str = None
|
|
37
|
-
|
|
38
|
-
def generate_link(self) -> str:
|
|
39
|
-
"""
|
|
40
|
-
GeneratePayLink for each order.
|
|
41
|
-
"""
|
|
42
|
-
generated_pay_link: str = "{payme_url}/{encode_params}"
|
|
43
|
-
params: str = 'm={payme_id};ac.{payme_account}={order_id};a={amount};c={call_back_url}'
|
|
44
|
-
|
|
45
|
-
if self.callback_url:
|
|
46
|
-
redirect_url = self.callback_url
|
|
47
|
-
else:
|
|
48
|
-
redirect_url = PAYME_CALL_BACK_URL
|
|
49
|
-
|
|
50
|
-
params = params.format(
|
|
51
|
-
payme_id=PAYME_ID,
|
|
52
|
-
payme_account=PAYME_ACCOUNT,
|
|
53
|
-
order_id=self.order_id,
|
|
54
|
-
amount=self.amount,
|
|
55
|
-
call_back_url=redirect_url
|
|
56
|
-
)
|
|
57
|
-
encode_params = base64.b64encode(params.encode("utf-8"))
|
|
58
|
-
return generated_pay_link.format(
|
|
59
|
-
payme_url=PAYME_URL,
|
|
60
|
-
encode_params=str(encode_params, 'utf-8')
|
|
61
|
-
)
|
|
62
|
-
|
|
63
|
-
@staticmethod
|
|
64
|
-
def to_tiyin(amount: Decimal) -> Decimal:
|
|
65
|
-
"""
|
|
66
|
-
Convert from sum to tiyin.
|
|
67
|
-
|
|
68
|
-
Parameters
|
|
69
|
-
----------
|
|
70
|
-
amount: Decimal -> order amount
|
|
71
|
-
"""
|
|
72
|
-
return amount * 100
|
|
73
|
-
|
|
74
|
-
@staticmethod
|
|
75
|
-
def to_sum(amount: Decimal) -> Decimal:
|
|
76
|
-
"""
|
|
77
|
-
Convert from tiyin to sum.
|
|
78
|
-
|
|
79
|
-
Parameters
|
|
80
|
-
----------
|
|
81
|
-
amount: Decimal -> order amount
|
|
82
|
-
"""
|
|
83
|
-
return amount / 100
|
payme/methods/get_statement.py
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
from django.db import DatabaseError
|
|
2
|
-
|
|
3
|
-
from payme.utils.logging import logger
|
|
4
|
-
from payme.models import MerchantTransactionsModel
|
|
5
|
-
from payme.serializers import MerchantTransactionsModelSerializer as MTMS
|
|
6
|
-
from payme.utils.make_aware_datetime import make_aware_datetime as mad
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class GetStatement:
|
|
10
|
-
"""
|
|
11
|
-
GetStatement class
|
|
12
|
-
Transaction information is used for reconciliation
|
|
13
|
-
of merchant and Payme Business transactions.
|
|
14
|
-
|
|
15
|
-
Full method documentation
|
|
16
|
-
-------------------------
|
|
17
|
-
https://developer.help.paycom.uz/metody-merchant-api/getstatement
|
|
18
|
-
"""
|
|
19
|
-
|
|
20
|
-
def __call__(self, params: dict) -> tuple:
|
|
21
|
-
clean_data: dict = MTMS.get_validated_data(
|
|
22
|
-
params=params
|
|
23
|
-
)
|
|
24
|
-
|
|
25
|
-
start_date, end_date = mad(
|
|
26
|
-
int(clean_data.get("start_date")),
|
|
27
|
-
int(clean_data.get("end_date"))
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
try:
|
|
31
|
-
transactions = \
|
|
32
|
-
MerchantTransactionsModel.objects.filter(
|
|
33
|
-
created_at__gte=start_date,
|
|
34
|
-
created_at__lte=end_date
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
if not transactions: # no transactions found for the period
|
|
38
|
-
return None, {"result": {"transactions": []}}
|
|
39
|
-
|
|
40
|
-
statements = [
|
|
41
|
-
{
|
|
42
|
-
'id': t._id,
|
|
43
|
-
'time': int(t.created_at.timestamp()),
|
|
44
|
-
'amount': t.amount,
|
|
45
|
-
'account': {'order_id': t.order_id},
|
|
46
|
-
'create_time': int(t.created_at_ms),
|
|
47
|
-
'perform_time': t.perform_time,
|
|
48
|
-
'cancel_time': t.cancel_time,
|
|
49
|
-
'transaction': t.order_id,
|
|
50
|
-
'state': t.state,
|
|
51
|
-
'reason': int(t.reason) if t.reason is not None else None,
|
|
52
|
-
'receivers': [] # not implemented
|
|
53
|
-
} for t in transactions
|
|
54
|
-
]
|
|
55
|
-
|
|
56
|
-
response: dict = {
|
|
57
|
-
"result": {
|
|
58
|
-
"transactions": statements
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
except DatabaseError as error:
|
|
62
|
-
logger.error("Error getting transaction in database: %s", error)
|
|
63
|
-
response = {"result": {"transactions": []}}
|
|
64
|
-
|
|
65
|
-
return None, response
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import time
|
|
2
|
-
|
|
3
|
-
from django.db import DatabaseError
|
|
4
|
-
|
|
5
|
-
from payme.utils.logging import logger
|
|
6
|
-
from payme.utils.get_params import get_params
|
|
7
|
-
from payme.models import MerchantTransactionsModel
|
|
8
|
-
from payme.serializers import MerchantTransactionsModelSerializer
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class PerformTransaction:
|
|
12
|
-
"""
|
|
13
|
-
PerformTransaction class
|
|
14
|
-
That's used to perform a transaction.
|
|
15
|
-
|
|
16
|
-
Full method documentation
|
|
17
|
-
-------------------------
|
|
18
|
-
https://developer.help.paycom.uz/metody-merchant-api/performtransaction
|
|
19
|
-
"""
|
|
20
|
-
def __call__(self, params: dict) -> tuple:
|
|
21
|
-
serializer = MerchantTransactionsModelSerializer(
|
|
22
|
-
data=get_params(params)
|
|
23
|
-
)
|
|
24
|
-
serializer.is_valid(raise_exception=True)
|
|
25
|
-
clean_data: dict = serializer.validated_data
|
|
26
|
-
response: dict = None
|
|
27
|
-
try:
|
|
28
|
-
transaction = \
|
|
29
|
-
MerchantTransactionsModel.objects.get(
|
|
30
|
-
_id=clean_data.get("_id"),
|
|
31
|
-
)
|
|
32
|
-
transaction.state = 2
|
|
33
|
-
if transaction.perform_time == 0:
|
|
34
|
-
transaction.perform_time = int(time.time() * 1000)
|
|
35
|
-
|
|
36
|
-
transaction.save()
|
|
37
|
-
response: dict = {
|
|
38
|
-
"result": {
|
|
39
|
-
"perform_time": int(transaction.perform_time),
|
|
40
|
-
"transaction": transaction.transaction_id,
|
|
41
|
-
"state": int(transaction.state),
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
except DatabaseError as error:
|
|
45
|
-
logger.error("error while getting transaction in db: %s", error)
|
|
46
|
-
|
|
47
|
-
return transaction.order_id, response
|
payme/migrations/0001_initial.py
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
# pylint: disable=invalid-name
|
|
2
|
-
from django.db import migrations, models
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
class Migration(migrations.Migration):
|
|
6
|
-
# pylint: disable=missing-class-docstring
|
|
7
|
-
initial = True
|
|
8
|
-
dependencies = []
|
|
9
|
-
|
|
10
|
-
operations = [
|
|
11
|
-
migrations.CreateModel(
|
|
12
|
-
name='MerchantTransactionsModel',
|
|
13
|
-
fields=[
|
|
14
|
-
('id', models.BigAutoField(
|
|
15
|
-
auto_created=True,
|
|
16
|
-
primary_key=True,
|
|
17
|
-
serialize=False,
|
|
18
|
-
verbose_name='ID')
|
|
19
|
-
),
|
|
20
|
-
('_id', models.CharField(max_length=255, null=True)),
|
|
21
|
-
('transaction_id', models.CharField(max_length=255, null=True)),
|
|
22
|
-
('order_id', models.BigIntegerField(blank=True, null=True)),
|
|
23
|
-
('amount', models.FloatField(blank=True, null=True)),
|
|
24
|
-
('time', models.BigIntegerField(blank=True, null=True)),
|
|
25
|
-
('perform_time', models.BigIntegerField(default=0, null=True)),
|
|
26
|
-
('cancel_time', models.BigIntegerField(default=0, null=True)),
|
|
27
|
-
('state', models.IntegerField(default=1, null=True)),
|
|
28
|
-
('reason', models.CharField(blank=True, max_length=255, null=True)),
|
|
29
|
-
('created_at_ms', models.CharField(blank=True, max_length=255, null=True)),
|
|
30
|
-
('created_at', models.DateTimeField(auto_now_add=True)),
|
|
31
|
-
('updated_at', models.DateTimeField(auto_now=True)),
|
|
32
|
-
],
|
|
33
|
-
),
|
|
34
|
-
migrations.CreateModel(
|
|
35
|
-
name='Order',
|
|
36
|
-
fields=[
|
|
37
|
-
('id', models.BigAutoField(
|
|
38
|
-
auto_created=True,
|
|
39
|
-
primary_key=True,
|
|
40
|
-
serialize=False,
|
|
41
|
-
verbose_name='ID')
|
|
42
|
-
),
|
|
43
|
-
('amount', models.IntegerField(blank=True, null=True)),
|
|
44
|
-
('created_at', models.DateTimeField(auto_now_add=True)),
|
|
45
|
-
('updated_at', models.DateTimeField(auto_now=True)),
|
|
46
|
-
],
|
|
47
|
-
),
|
|
48
|
-
]
|
payme/receipts/__init__.py
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
from .import subscribe_receipts
|
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
from ..decorators.decorators import payme_request
|
|
2
|
-
from ..utils.to_json import to_json
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
class PaymeSubscribeReceipts:
|
|
6
|
-
"""
|
|
7
|
-
The PaymeSubscribeReceipts class includes
|
|
8
|
-
all paycom methods which are belongs receipts part.
|
|
9
|
-
|
|
10
|
-
Parameters
|
|
11
|
-
----------
|
|
12
|
-
base_url string: The base url of the paycom api
|
|
13
|
-
paycom_id string: The paycom_id uses to identify
|
|
14
|
-
paycom_key string: The paycom_key uses to identify too
|
|
15
|
-
|
|
16
|
-
Full method documentation
|
|
17
|
-
-------------------------
|
|
18
|
-
https://developer.help.paycom.uz/metody-subscribe-api/
|
|
19
|
-
"""
|
|
20
|
-
|
|
21
|
-
def __init__(
|
|
22
|
-
self,
|
|
23
|
-
base_url: str,
|
|
24
|
-
paycom_id: str,
|
|
25
|
-
paycom_key: str,
|
|
26
|
-
timeout: int = 5
|
|
27
|
-
) -> "PaymeSubscribeReceipts":
|
|
28
|
-
self.base_url: str = base_url
|
|
29
|
-
self.headers: dict = {
|
|
30
|
-
"X-Auth": f"{paycom_id}:{paycom_key}"
|
|
31
|
-
}
|
|
32
|
-
self.__methods: dict = {
|
|
33
|
-
"receipts_get": "receipts.get",
|
|
34
|
-
"receipts_pay": "receipts.pay",
|
|
35
|
-
"receipts_send": "receipts.send",
|
|
36
|
-
"receipts_check": "receipts.check",
|
|
37
|
-
"receipts_cancel": "receipts.cancel",
|
|
38
|
-
"receipts_create": "receipts.create",
|
|
39
|
-
"receipts_get_all": "receipts.get_all",
|
|
40
|
-
}
|
|
41
|
-
self.timeout = timeout
|
|
42
|
-
|
|
43
|
-
@payme_request
|
|
44
|
-
def __request(self, data) -> dict:
|
|
45
|
-
"""
|
|
46
|
-
Use this private method to request.
|
|
47
|
-
On success,response will be OK with format JSON.
|
|
48
|
-
|
|
49
|
-
Parameters
|
|
50
|
-
----------
|
|
51
|
-
data: dict — Includes request data.
|
|
52
|
-
|
|
53
|
-
Returns dictionary Payme Response
|
|
54
|
-
---------------------------------
|
|
55
|
-
"""
|
|
56
|
-
return data
|
|
57
|
-
|
|
58
|
-
def receipts_create(self, amount: float, order_id: int) -> dict:
|
|
59
|
-
"""
|
|
60
|
-
Use this method to create a new payment receipt.
|
|
61
|
-
|
|
62
|
-
Parameters
|
|
63
|
-
----------
|
|
64
|
-
amount: float — Payment amount in tiyins
|
|
65
|
-
order_id: int — Order object ID
|
|
66
|
-
|
|
67
|
-
Full method documentation
|
|
68
|
-
-------------------------
|
|
69
|
-
https://developer.help.paycom.uz/metody-subscribe-api/receipts.create
|
|
70
|
-
"""
|
|
71
|
-
data: dict = {
|
|
72
|
-
"method": self.__methods.get("receipts_create"),
|
|
73
|
-
"params": {
|
|
74
|
-
"amount": amount,
|
|
75
|
-
"account": {
|
|
76
|
-
"order_id": order_id,
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return self.__request(to_json(**data))
|
|
81
|
-
|
|
82
|
-
def receipts_pay(self, invoice_id: str, token: str, phone: str) -> dict:
|
|
83
|
-
"""
|
|
84
|
-
Use this method to pay for an exist receipt.
|
|
85
|
-
|
|
86
|
-
Parameters
|
|
87
|
-
----------
|
|
88
|
-
invoice_id: str — Invoice id for identity transaction
|
|
89
|
-
token: str — The card's active token
|
|
90
|
-
phone: str —The payer's phone number
|
|
91
|
-
|
|
92
|
-
Full method documentation
|
|
93
|
-
-------------------------
|
|
94
|
-
https://developer.help.paycom.uz/metody-subscribe-api/receipts.pay
|
|
95
|
-
"""
|
|
96
|
-
data: dict = {
|
|
97
|
-
"method": self.__methods.get("receipts_pay"),
|
|
98
|
-
"params": {
|
|
99
|
-
"id": invoice_id,
|
|
100
|
-
"token": token,
|
|
101
|
-
"payer": {
|
|
102
|
-
"phone": phone,
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return self.__request(to_json(**data))
|
|
107
|
-
|
|
108
|
-
def receipts_send(self, invoice_id: str, phone: str) -> dict:
|
|
109
|
-
"""
|
|
110
|
-
Use this method to send a receipt for payment in an SMS message.
|
|
111
|
-
|
|
112
|
-
Parameters
|
|
113
|
-
----------
|
|
114
|
-
invoice_id: str — The invoice id for identity transaction
|
|
115
|
-
phone: str — The payer's phone number
|
|
116
|
-
|
|
117
|
-
Full method documentation
|
|
118
|
-
-------------------------
|
|
119
|
-
https://developer.help.paycom.uz/metody-subscribe-api/receipts.send
|
|
120
|
-
"""
|
|
121
|
-
data: dict = {
|
|
122
|
-
"method": self.__methods.get('receipts_send'),
|
|
123
|
-
"params": {
|
|
124
|
-
"id": invoice_id,
|
|
125
|
-
"phone": phone
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
return self.__request(to_json(**data))
|
|
129
|
-
|
|
130
|
-
def receipts_cancel(self, invoice_id: str) -> dict:
|
|
131
|
-
"""
|
|
132
|
-
Use this method a paid check in the queue for cancellation.
|
|
133
|
-
|
|
134
|
-
Parameters
|
|
135
|
-
----------
|
|
136
|
-
invoice_id: str — The invoice id for identity transaction
|
|
137
|
-
|
|
138
|
-
Full method documentation
|
|
139
|
-
-------------------------
|
|
140
|
-
https://developer.help.paycom.uz/metody-subscribe-api/receipts.cancel
|
|
141
|
-
"""
|
|
142
|
-
data: dict = {
|
|
143
|
-
"method": self.__methods.get('receipts_cancel'),
|
|
144
|
-
"params": {
|
|
145
|
-
"id": invoice_id
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return self.__request(to_json(**data))
|
|
150
|
-
|
|
151
|
-
def receipts_check(self, invoice_id: str) -> dict:
|
|
152
|
-
"""
|
|
153
|
-
Use this method check for an exist receipt.
|
|
154
|
-
|
|
155
|
-
Parameters
|
|
156
|
-
----------
|
|
157
|
-
invoice_id: str — The invoice id for identity transaction
|
|
158
|
-
|
|
159
|
-
Full method documentation
|
|
160
|
-
-------------------------
|
|
161
|
-
https://developer.help.paycom.uz/metody-subscribe-api/receipts.check
|
|
162
|
-
"""
|
|
163
|
-
data: dict = {
|
|
164
|
-
"method": self.__methods.get('receipts_check'),
|
|
165
|
-
"params": {
|
|
166
|
-
"id": invoice_id
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
return self.__request(to_json(**data))
|
|
171
|
-
|
|
172
|
-
def receipts_get(self, invoice_id: str) -> dict:
|
|
173
|
-
"""
|
|
174
|
-
Use this method check status for an exist receipt.
|
|
175
|
-
|
|
176
|
-
Parameters
|
|
177
|
-
----------
|
|
178
|
-
invoice_id: str — The invoice id for identity transaction
|
|
179
|
-
|
|
180
|
-
Full method documentation
|
|
181
|
-
-------------------------
|
|
182
|
-
https://developer.help.paycom.uz/metody-subscribe-api/receipts.get
|
|
183
|
-
"""
|
|
184
|
-
data: dict = {
|
|
185
|
-
"method": self.__methods.get('receipts_get'),
|
|
186
|
-
"params": {
|
|
187
|
-
"id": invoice_id
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
return self.__request(to_json(**data))
|
|
192
|
-
|
|
193
|
-
def receipts_get_all(self, count: int, _from: int, _to: int, offset: int) -> dict:
|
|
194
|
-
"""
|
|
195
|
-
Use this method get all complete information, on checks for a certain period.
|
|
196
|
-
|
|
197
|
-
Parameters
|
|
198
|
-
----------
|
|
199
|
-
count: int — The number of checks. Maximum value - 50
|
|
200
|
-
_from: str — The date of the beginning
|
|
201
|
-
_to: int — The date of the ending
|
|
202
|
-
offset: str — The number of subsequent skipped checks.
|
|
203
|
-
|
|
204
|
-
Full method documentation
|
|
205
|
-
-------------------------
|
|
206
|
-
https://developer.help.paycom.uz/metody-subscribe-api/receipts.get_all
|
|
207
|
-
"""
|
|
208
|
-
data: dict = {
|
|
209
|
-
"method": self.__methods.get('receipts_get_all'),
|
|
210
|
-
"params": {
|
|
211
|
-
"count": count,
|
|
212
|
-
"from": _from,
|
|
213
|
-
"to": _to,
|
|
214
|
-
"offset": offset
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
return self.__request(to_json(**data))
|
payme/serializers.py
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
from django.conf import settings
|
|
2
|
-
|
|
3
|
-
from rest_framework import serializers
|
|
4
|
-
|
|
5
|
-
from payme.models import Order
|
|
6
|
-
from payme.utils.logging import logger
|
|
7
|
-
from payme.utils.get_params import get_params
|
|
8
|
-
from payme.models import MerchantTransactionsModel
|
|
9
|
-
from payme.errors.exceptions import IncorrectAmount
|
|
10
|
-
from payme.errors.exceptions import PerformTransactionDoesNotExist
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class MerchantTransactionsModelSerializer(serializers.ModelSerializer):
|
|
14
|
-
"""
|
|
15
|
-
MerchantTransactionsModelSerializer class \
|
|
16
|
-
That's used to serialize merchant transactions data.
|
|
17
|
-
"""
|
|
18
|
-
start_date = serializers.IntegerField(allow_null=True)
|
|
19
|
-
end_date = serializers.IntegerField(allow_null=True)
|
|
20
|
-
|
|
21
|
-
class Meta:
|
|
22
|
-
# pylint: disable=missing-class-docstring
|
|
23
|
-
model: MerchantTransactionsModel = MerchantTransactionsModel
|
|
24
|
-
fields: str = "__all__"
|
|
25
|
-
extra_fields = ['start_date', 'end_date']
|
|
26
|
-
|
|
27
|
-
def validate(self, attrs) -> dict:
|
|
28
|
-
"""
|
|
29
|
-
Validate the data given to the MerchantTransactionsModel.
|
|
30
|
-
"""
|
|
31
|
-
if attrs.get("order_id") is not None:
|
|
32
|
-
try:
|
|
33
|
-
order = Order.objects.get(
|
|
34
|
-
id=attrs['order_id']
|
|
35
|
-
)
|
|
36
|
-
if order.amount != int(attrs['amount']):
|
|
37
|
-
raise IncorrectAmount()
|
|
38
|
-
|
|
39
|
-
except IncorrectAmount as error:
|
|
40
|
-
logger.error("Invalid amount for order: %s", attrs['order_id'])
|
|
41
|
-
raise IncorrectAmount() from error
|
|
42
|
-
|
|
43
|
-
return attrs
|
|
44
|
-
|
|
45
|
-
def validate_amount(self, amount: int) -> int:
|
|
46
|
-
"""
|
|
47
|
-
Validator for Transactions Amount.
|
|
48
|
-
"""
|
|
49
|
-
if amount is not None:
|
|
50
|
-
if int(amount) <= int(settings.PAYME.get("PAYME_MIN_AMOUNT", 0)):
|
|
51
|
-
raise IncorrectAmount("Payment amount is less than allowed.")
|
|
52
|
-
|
|
53
|
-
return amount
|
|
54
|
-
|
|
55
|
-
def validate_order_id(self, order_id) -> int:
|
|
56
|
-
"""
|
|
57
|
-
Use this method to check if a transaction is allowed to be executed.
|
|
58
|
-
|
|
59
|
-
Parameters
|
|
60
|
-
----------
|
|
61
|
-
order_id: str -> Order Indentation.
|
|
62
|
-
"""
|
|
63
|
-
try:
|
|
64
|
-
Order.objects.get(id=order_id)
|
|
65
|
-
except Order.DoesNotExist as error:
|
|
66
|
-
logger.error("Order does not exist order_id: %s", order_id)
|
|
67
|
-
raise PerformTransactionDoesNotExist() from error
|
|
68
|
-
|
|
69
|
-
return order_id
|
|
70
|
-
|
|
71
|
-
@staticmethod
|
|
72
|
-
def get_validated_data(params: dict) -> dict:
|
|
73
|
-
"""
|
|
74
|
-
This static method helps to get validated data.
|
|
75
|
-
|
|
76
|
-
Parameters
|
|
77
|
-
----------
|
|
78
|
-
params: dict — Includes request params.
|
|
79
|
-
"""
|
|
80
|
-
serializer = MerchantTransactionsModelSerializer(
|
|
81
|
-
data=get_params(params)
|
|
82
|
-
)
|
|
83
|
-
serializer.is_valid(raise_exception=True)
|
|
84
|
-
clean_data: dict = serializer.validated_data
|
|
85
|
-
|
|
86
|
-
return clean_data
|
payme/utils/__init__.py
DELETED
|
File without changes
|
payme/utils/get_params.py
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
from django.conf import settings
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
def get_params(params: dict) -> dict:
|
|
5
|
-
"""
|
|
6
|
-
Use this function to get the parameters from the payme.
|
|
7
|
-
"""
|
|
8
|
-
account: dict = params.get("account")
|
|
9
|
-
|
|
10
|
-
clean_params: dict = {}
|
|
11
|
-
clean_params["_id"] = params.get("id")
|
|
12
|
-
clean_params["time"] = params.get("time")
|
|
13
|
-
clean_params["amount"] = params.get("amount")
|
|
14
|
-
clean_params["reason"] = params.get("reason")
|
|
15
|
-
|
|
16
|
-
# get statement method params
|
|
17
|
-
clean_params["start_date"] = params.get("from")
|
|
18
|
-
clean_params["end_date"] = params.get("to")
|
|
19
|
-
|
|
20
|
-
if account is not None:
|
|
21
|
-
account_name: str = settings.PAYME.get("PAYME_ACCOUNT")
|
|
22
|
-
clean_params["order_id"] = account[account_name]
|
|
23
|
-
|
|
24
|
-
return clean_params
|
payme/utils/logging.py
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
from django.utils.timezone import datetime as dt
|
|
2
|
-
from django.utils.timezone import make_aware
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
def make_aware_datetime(start_date: int, end_date: int):
|
|
6
|
-
"""
|
|
7
|
-
Convert Unix timestamps to aware datetimes.
|
|
8
|
-
|
|
9
|
-
:param start_date: Unix timestamp (milliseconds)
|
|
10
|
-
:param end_date: Unix timestamp (milliseconds)
|
|
11
|
-
|
|
12
|
-
:return: A tuple of two aware datetimes
|
|
13
|
-
"""
|
|
14
|
-
return map(
|
|
15
|
-
lambda timestamp: make_aware(
|
|
16
|
-
dt.fromtimestamp(
|
|
17
|
-
timestamp / 1000
|
|
18
|
-
)
|
|
19
|
-
),
|
|
20
|
-
[start_date, end_date]
|
|
21
|
-
)
|