diff --git a/.vscode/settings.json b/.vscode/settings.json index 512fe28..665ba9e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,6 +8,5 @@ "test_*.py" ], "python.testing.pytestEnabled": false, - - "python.testing.unittestEnabled": true, + "python.testing.unittestEnabled": true } \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..793fb11 --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +.PHONY: test + +test: + python -m unittest discover -s tests -p 'test_*.py' + +build: + python -m build + +publish: + python -m twine upload dist/* \ No newline at end of file diff --git a/makefile b/makefile deleted file mode 100644 index 615c93a..0000000 --- a/makefile +++ /dev/null @@ -1,10 +0,0 @@ -.PHONY: test - -test: - python -m unittest discover -s tests -p 'test_*.py' - -build: - python -m build - -publish: - python -m twine upload dist/* \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 1abb81e..ca62d00 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "chargily_pay" -version = "2.0.0" +version = "2.0.1" authors = [{ name = "Berkane Tarek", email = "tarekg320@gmail.com" }] description = "This Plugin is to integrate ePayment gateway with Chargily V2 easily." readme = "README.md" diff --git a/src/chargily_pay/api.py b/src/chargily_pay/api.py index e22d004..6e60962 100644 --- a/src/chargily_pay/api.py +++ b/src/chargily_pay/api.py @@ -149,7 +149,7 @@ def retrieve_product_prices(self, id, per_page: int = 10, page: int = 1): ) response.raise_for_status() return response.json() - + # ================================== # Prices # ================================== @@ -192,8 +192,6 @@ def list_prices(self, per_page: int = 10, page: int = 1): response.raise_for_status() return response.json() - - # ================================== # Checkouts # ================================== @@ -247,7 +245,6 @@ def expire_checkout(self, id): response.raise_for_status() return response.json() - # ================================== # Payment Links # ================================== @@ -317,6 +314,3 @@ def validate_signature(self, signature: str, payload: str): if hmac.compare_digest(signature, computed_signature): return True return False - - - \ No newline at end of file diff --git a/src/chargily_pay/entity.py b/src/chargily_pay/entity.py index 35ab87c..1bf0698 100644 --- a/src/chargily_pay/entity.py +++ b/src/chargily_pay/entity.py @@ -13,6 +13,7 @@ class Address: class Customer: name: str email: str + phone: Optional[str] = None address: Address = None metadata: list = field(default_factory=list) @@ -49,6 +50,8 @@ class Checkout: customer_id: str = None description: str = None locale: str = None + payment_method: str = None + webhook_endpoint: str = None pass_fees_to_customer: bool = None metadata: list[dict] = field(default_factory=list) @@ -59,7 +62,7 @@ def __post_init__(self): if self.amount: if self.amount <= 10: raise Exception("amount should be great than 10 dzd") - if not self.currency: + if not self.currency: raise Exception("Currency must be provided when amount is provided") diff --git a/tests/test_api.py b/tests/test_api.py index fb4d031..2690d74 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -1,4 +1,3 @@ -from itertools import product import os import unittest @@ -38,6 +37,17 @@ def test_create_customer(self): response = self.chargily.create_customer(customer) self.assertEqual(type(response), dict) + def test_create_customer_with_phone(self): + customer = Customer( + name="Username", + email="example@gmail.com", + phone="12345678", + address=Address(address="Address", state="State", country="dz"), + ) + response = self.chargily.create_customer(customer) + self.assertEqual(type(response), dict) + self.assertEqual(response["phone"], "12345678") + def test_create_customer_without_address(self): customer = Customer( name="Username", @@ -235,6 +245,49 @@ def test_create_checkout(self): ) self.assertEqual(type(checkout), dict) + def test_create_checkout_with_webhook(self): + product = Product( + name="Product name", + description="Product description", + ) + response = self.chargily.create_product(product) + product_id = response["id"] + price = self.chargily.create_price( + Price(amount=100, currency="dzd", product_id=product_id) + ) + price_id = price["id"] + checkout = self.chargily.create_checkout( + Checkout( + items=[{"price": price_id, "quantity": 1}], + success_url="https://example.com/success", + failure_url="https://example.com/failure", + webhook_endpoint="https://example.com/webhook", + ) + ) + self.assertEqual(type(checkout), dict) + self.assertEqual(checkout["webhook_endpoint"], "https://example.com/webhook") + + def test_create_checkout_with_payment_method(self): + product = Product( + name="Product name", + description="Product description", + ) + response = self.chargily.create_product(product) + product_id = response["id"] + price = self.chargily.create_price( + Price(amount=100, currency="dzd", product_id=product_id) + ) + price_id = price["id"] + checkout = self.chargily.create_checkout( + Checkout( + items=[{"price": price_id, "quantity": 1}], + success_url="https://example.com/success", + payment_method="cib", + ) + ) + self.assertEqual(type(checkout), dict) + self.assertEqual(checkout["payment_method"], "cib") + def test_create_checkout_with_amount(self): checkout = self.chargily.create_checkout( Checkout( @@ -245,8 +298,6 @@ def test_create_checkout_with_amount(self): ) self.assertEqual(type(checkout), dict) - - def test_create_checkout_with_customer(self): product = Product( name="Product name",