Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion gpwebpay/gpwebpay.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class GpwebpayClient:
def __init__(self):
self.data = None

def _create_payment_data(self, order_number: str = "", amount: int = 0) -> None:
def _create_payment_data(self, order_number: str = "", amount: int = 0, description: str | None = None) -> None:
"""To create the DIGEST we need to keep the order of the params"""
self.data = OrderedDict()
self.data["MERCHANTNUMBER"] = settings.merchant_id
Expand All @@ -31,6 +31,8 @@ def _create_payment_data(self, order_number: str = "", amount: int = 0) -> None:
self.data["CURRENCY"] = settings.currency
self.data["DEPOSITFLAG"] = settings.deposit_flag
self.data["URL"] = str(settings.merchant_callback_url)
if description is not None:
self.data["DESCRIPTION"] = description

def _create_message(self, data: dict, is_digest_1: bool = False) -> bytes:
# Create message according to GPWebPay documentation (4.1.1)
Expand Down
7 changes: 4 additions & 3 deletions tests/test_gpwebpay.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# CVC2: 200

# Example message = "<GPWEBPAY_MERCHANT_ID>|CREATE_ORDER|<order_number>|<amount>|
# <GPWEBPAY_CURRENCY>|<GPWEBPAY_DEPOSIT_FLAG>|<GPWEBPAY_RESPONSE_URL>"
# <GPWEBPAY_CURRENCY>|<GPWEBPAY_DEPOSIT_FLAG>|<GPWEBPAY_RESPONSE_URL>|[description]"


def test_init(gateway_client):
Expand All @@ -38,8 +38,9 @@ def test_create_data(gateway_client, monkeypatch):
CURRENCY="978",
DEPOSITFLAG="1",
URL="https://localhost:5000/payment_callback",
DESCRIPTION="Very important payment",
)
gateway_client._create_payment_data(order_number="123456", amount=10)
gateway_client._create_payment_data(order_number="123456", amount=10, description="Very important payment")
assert gateway_client.data == expected_data


Expand All @@ -50,7 +51,7 @@ def test_create_message(gateway_client, monkeypatch):
b"1234567890|CREATE_ORDER|123456|10|978|1|https://localhost:5000/"
b"payment_callback"
)
gateway_client._create_payment_data(order_number="123456", amount=10)
gateway_client._create_payment_data(order_number="123456", amount=10, description="Very important payment")
message = gateway_client._create_message(gateway_client.data)
assert message == expected_message

Expand Down