Skip to content

Commit

Permalink
small fix and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammadali-Akbarov committed Nov 14, 2024
1 parent cd16b00 commit 2c7b54f
Show file tree
Hide file tree
Showing 8 changed files with 2 additions and 98 deletions.
9 changes: 0 additions & 9 deletions payme/classes/cards.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Optional

from payme.util import input_type_checker
from payme.classes.http import HttpClient
from payme.types.response import cards as response

Expand All @@ -20,8 +19,6 @@ class Cards:
services. It allows you to create new cards and retrieve verification
codes for existing cards.
"""

@input_type_checker
def __init__(self, url: str, payme_id: str) -> "Cards":
"""
Initialize the Cards client.
Expand All @@ -35,7 +32,6 @@ def __init__(self, url: str, payme_id: str) -> "Cards":
}
self.http = HttpClient(url, headers)

@input_type_checker
def create(self, number: str, expire: str, save: bool = False,
timeout: int = 10) -> response.CardsCreateResponse:
"""
Expand All @@ -53,7 +49,6 @@ def create(self, number: str, expire: str, save: bool = False,
params = {"card": {"number": number, "expire": expire}, "save": save}
return self._post_request(method, params, timeout)

@input_type_checker
def get_verify_code(self, token: str, timeout: int = 10) -> \
response.GetVerifyResponse:
"""
Expand All @@ -68,7 +63,6 @@ def get_verify_code(self, token: str, timeout: int = 10) -> \
params = {"token": token}
return self._post_request(method, params, timeout)

@input_type_checker
def verify(self, token: str, code: str, timeout: int = 10) -> \
response.VerifyResponse:
"""
Expand All @@ -84,7 +78,6 @@ def verify(self, token: str, code: str, timeout: int = 10) -> \
params = {"token": token, "code": code}
return self._post_request(method, params, timeout)

@input_type_checker
def remove(self, token: str, timeout: int = 10) -> response.RemoveResponse:
"""
Remove a card from the Paycom system.
Expand All @@ -98,7 +91,6 @@ def remove(self, token: str, timeout: int = 10) -> response.RemoveResponse:
params = {"token": token}
return self._post_request(method, params, timeout)

@input_type_checker
def check(self, token: str, timeout: int = 10) -> response.CheckResponse:
"""
Check the status of a card.
Expand All @@ -112,7 +104,6 @@ def check(self, token: str, timeout: int = 10) -> response.CheckResponse:
params = {"token": token}
return self._post_request(method, params, timeout)

@input_type_checker
def _post_request(self, method: str, params: dict,
timeout: int = 10) -> response.Common:
"""
Expand Down
4 changes: 1 addition & 3 deletions payme/classes/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from payme.const import Networks
from payme.classes.cards import Cards
from payme.util import input_type_checker
from payme.classes.receipts import Receipts
from payme.classes.initializer import Initializer

Expand All @@ -12,7 +11,6 @@ class Payme:
"""
The payme class provides a simple interface
"""
@input_type_checker
def __init__(
self,
payme_id: str,
Expand All @@ -24,7 +22,7 @@ def __init__(
url = Networks.PROD_NET

if is_test_mode is True:
url = Networks.TEST_NET
url = Networks.TEST_NET.value

self.cards = Cards(url=url, payme_id=payme_id)
self.initializer = Initializer(payme_id=payme_id)
Expand Down
20 changes: 0 additions & 20 deletions payme/classes/initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from django.conf import settings

from payme.util import input_type_checker


class Initializer:
"""
Expand All @@ -15,7 +13,6 @@ class Initializer:
The Payme ID associated with your account
"""

@input_type_checker
def __init__(self, payme_id: str = None):
self.payme_id = payme_id

Expand Down Expand Up @@ -58,20 +55,3 @@ def generate_pay_link(
)
params = base64.b64encode(params.encode("utf-8")).decode("utf-8")
return f"https://checkout.paycom.uz/{params}"

def test(self):
"""
Test method for the Initializer class.
This method generates a payment link for a sample order and checks
if the result is a valid string. If successful, it prints a
confirmation message.
"""
result = self.generate_pay_link(
id=12345,
amount=7000,
return_url="https://example.com"
)

assert isinstance(result, str), "Failed to generate payment link"
print("Success: Payment link generated successfully.")
9 changes: 0 additions & 9 deletions payme/classes/receipts.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Union, Optional

from payme.classes.cards import Cards
from payme.util import input_type_checker
from payme.classes.http import HttpClient
from payme.types.response import receipts as response

Expand Down Expand Up @@ -37,7 +36,6 @@ def __init__(self, payme_id: str, payme_key: str, url: str) -> "Receipts":
}
self.http = HttpClient(url, headers)

@input_type_checker
def create(
self,
account: dict,
Expand All @@ -64,7 +62,6 @@ def create(
}
return self._post_request(method, params, timeout)

@input_type_checker
def pay(
self, receipts_id: str, token: str, timeout: int = 10
) -> response.PayResponse:
Expand All @@ -83,7 +80,6 @@ def pay(
}
return self._post_request(method, params, timeout)

@input_type_checker
def send(
self, receipts_id: str, phone: str, timeout: int = 10
) -> response.SendResponse:
Expand All @@ -101,7 +97,6 @@ def send(
}
return self._post_request(method, params, timeout)

@input_type_checker
def cancel(
self, receipts_id: str, timeout: int = 10
) -> response.CancelResponse:
Expand All @@ -117,7 +112,6 @@ def cancel(
}
return self._post_request(method, params, timeout)

@input_type_checker
def check(
self, receipts_id: str, timeout: int = 10
) -> response.CheckResponse:
Expand All @@ -133,7 +127,6 @@ def check(
}
return self._post_request(method, params, timeout)

@input_type_checker
def get(
self, receipts_id: str, timeout: int = 10
) -> response.GetResponse:
Expand All @@ -149,7 +142,6 @@ def get(
}
return self._post_request(method, params, timeout)

@input_type_checker
def get_all(
self, count: int, from_: int, to: int, offset: int, timeout: int = 10
) -> response.GetAllResponse:
Expand All @@ -171,7 +163,6 @@ def get_all(
}
return self._post_request(method, params, timeout)

@input_type_checker
def _post_request(
self, method: str, params: dict, timeout: int = 10
) -> response.Common:
Expand Down
23 changes: 0 additions & 23 deletions payme/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,6 @@
from enum import Enum


class Methods(str, Enum):
"""
The enumeration of create transaction methods.
Available Methods:
- GET_STATEMENT: Fetches transaction statement.
- CHECK_TRANSACTION: Checks a transaction.
- CREATE_TRANSACTION: Creates a new transaction.
- CANCEL_TRANSACTION: Cancels an existing transaction.
- PERFORM_TRANSACTION: Performs a transaction.
- CHECK_PERFORM_TRANSACTION: Checks if the transaction can be performed.
"""
GET_STATEMENT = "GetStatement"
CHECK_TRANSACTION = "CheckTransaction"
CREATE_TRANSACTION = "CreateTransaction"
CANCEL_TRANSACTION = "CancelTransaction"
PERFORM_TRANSACTION = "PerformTransaction"
CHECK_PERFORM_TRANSACTION = "CheckPerformTransaction"

def __str__(self):
return str(self.value)


class Networks(str, Enum):
"""
Payme networks
Expand Down
27 changes: 0 additions & 27 deletions payme/util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from functools import wraps
from datetime import datetime
from typing import get_type_hints


def time_to_payme(datatime) -> int:
Expand All @@ -26,28 +24,3 @@ def time_to_service(milliseconds: int) -> datetime:
Converts milliseconds since the epoch to a datetime object.
"""
return datetime.fromtimestamp(milliseconds / 1000)


def input_type_checker(func):
"""
input type checker decorator helps to
validate the input types of the function before executing it.
"""
@wraps(func)
def wrapper(*args, **kwargs):
"""
Get the type hints of the function
"""
hints = get_type_hints(func)

all_args = kwargs.copy()
all_args.update(zip(func.__code__.co_varnames, args))

for arg_name, arg_type in hints.items():
if arg_name in all_args and not isinstance(all_args[arg_name], arg_type): # noqa
raise TypeError(
f"Argument '{arg_name}' in {func.__name__} must be of type {arg_type.__name__}, " # noqa
f"but got {type(all_args[arg_name]).__name__}."
)
return func(*args, **kwargs)
return wrapper
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='payme-pkg',
version='3.0.6',
version='3.0.7',
license='MIT',
author="Muhammadali Akbarov",
author_email='[email protected]',
Expand Down
6 changes: 0 additions & 6 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ def test_receipts_all_methods(self):
"""
return self.payme.receipts.test()

def test_initializer_all_methods(self):
"""
Verify that the initializer test method works without errors
"""
return self.payme.initializer.test()


if __name__ == '__main__':
unittest.main()

0 comments on commit 2c7b54f

Please sign in to comment.