Skip to content

Commit f7e9607

Browse files
authored
Merge pull request #3 from Chargily/chargily/2.0.1
add missing attribute in checkout && fix makefile
2 parents 33dcbe3 + e3f5285 commit f7e9607

File tree

7 files changed

+71
-24
lines changed

7 files changed

+71
-24
lines changed

.vscode/settings.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@
88
"test_*.py"
99
],
1010
"python.testing.pytestEnabled": false,
11-
12-
"python.testing.unittestEnabled": true,
11+
"python.testing.unittestEnabled": true
1312
}

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.PHONY: test
2+
3+
test:
4+
python -m unittest discover -s tests -p 'test_*.py'
5+
6+
build:
7+
python -m build
8+
9+
publish:
10+
python -m twine upload dist/*

makefile

Lines changed: 0 additions & 10 deletions
This file was deleted.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "chargily_pay"
7-
version = "2.0.0"
7+
version = "2.0.1"
88
authors = [{ name = "Berkane Tarek", email = "tarekg320@gmail.com" }]
99
description = "This Plugin is to integrate ePayment gateway with Chargily V2 easily."
1010
readme = "README.md"

src/chargily_pay/api.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def retrieve_product_prices(self, id, per_page: int = 10, page: int = 1):
149149
)
150150
response.raise_for_status()
151151
return response.json()
152-
152+
153153
# ==================================
154154
# Prices
155155
# ==================================
@@ -192,8 +192,6 @@ def list_prices(self, per_page: int = 10, page: int = 1):
192192
response.raise_for_status()
193193
return response.json()
194194

195-
196-
197195
# ==================================
198196
# Checkouts
199197
# ==================================
@@ -247,7 +245,6 @@ def expire_checkout(self, id):
247245
response.raise_for_status()
248246
return response.json()
249247

250-
251248
# ==================================
252249
# Payment Links
253250
# ==================================
@@ -317,6 +314,3 @@ def validate_signature(self, signature: str, payload: str):
317314
if hmac.compare_digest(signature, computed_signature):
318315
return True
319316
return False
320-
321-
322-

src/chargily_pay/entity.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class Address:
1313
class Customer:
1414
name: str
1515
email: str
16+
phone: Optional[str] = None
1617
address: Address = None
1718
metadata: list = field(default_factory=list)
1819

@@ -49,6 +50,8 @@ class Checkout:
4950
customer_id: str = None
5051
description: str = None
5152
locale: str = None
53+
payment_method: str = None
54+
webhook_endpoint: str = None
5255
pass_fees_to_customer: bool = None
5356
metadata: list[dict] = field(default_factory=list)
5457

@@ -59,7 +62,7 @@ def __post_init__(self):
5962
if self.amount:
6063
if self.amount <= 10:
6164
raise Exception("amount should be great than 10 dzd")
62-
if not self.currency:
65+
if not self.currency:
6366
raise Exception("Currency must be provided when amount is provided")
6467

6568

tests/test_api.py

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from itertools import product
21
import os
32
import unittest
43

@@ -38,6 +37,17 @@ def test_create_customer(self):
3837
response = self.chargily.create_customer(customer)
3938
self.assertEqual(type(response), dict)
4039

40+
def test_create_customer_with_phone(self):
41+
customer = Customer(
42+
name="Username",
43+
email="example@gmail.com",
44+
phone="12345678",
45+
address=Address(address="Address", state="State", country="dz"),
46+
)
47+
response = self.chargily.create_customer(customer)
48+
self.assertEqual(type(response), dict)
49+
self.assertEqual(response["phone"], "12345678")
50+
4151
def test_create_customer_without_address(self):
4252
customer = Customer(
4353
name="Username",
@@ -235,6 +245,49 @@ def test_create_checkout(self):
235245
)
236246
self.assertEqual(type(checkout), dict)
237247

248+
def test_create_checkout_with_webhook(self):
249+
product = Product(
250+
name="Product name",
251+
description="Product description",
252+
)
253+
response = self.chargily.create_product(product)
254+
product_id = response["id"]
255+
price = self.chargily.create_price(
256+
Price(amount=100, currency="dzd", product_id=product_id)
257+
)
258+
price_id = price["id"]
259+
checkout = self.chargily.create_checkout(
260+
Checkout(
261+
items=[{"price": price_id, "quantity": 1}],
262+
success_url="https://example.com/success",
263+
failure_url="https://example.com/failure",
264+
webhook_endpoint="https://example.com/webhook",
265+
)
266+
)
267+
self.assertEqual(type(checkout), dict)
268+
self.assertEqual(checkout["webhook_endpoint"], "https://example.com/webhook")
269+
270+
def test_create_checkout_with_payment_method(self):
271+
product = Product(
272+
name="Product name",
273+
description="Product description",
274+
)
275+
response = self.chargily.create_product(product)
276+
product_id = response["id"]
277+
price = self.chargily.create_price(
278+
Price(amount=100, currency="dzd", product_id=product_id)
279+
)
280+
price_id = price["id"]
281+
checkout = self.chargily.create_checkout(
282+
Checkout(
283+
items=[{"price": price_id, "quantity": 1}],
284+
success_url="https://example.com/success",
285+
payment_method="cib",
286+
)
287+
)
288+
self.assertEqual(type(checkout), dict)
289+
self.assertEqual(checkout["payment_method"], "cib")
290+
238291
def test_create_checkout_with_amount(self):
239292
checkout = self.chargily.create_checkout(
240293
Checkout(
@@ -245,8 +298,6 @@ def test_create_checkout_with_amount(self):
245298
)
246299
self.assertEqual(type(checkout), dict)
247300

248-
249-
250301
def test_create_checkout_with_customer(self):
251302
product = Product(
252303
name="Product name",

0 commit comments

Comments
 (0)