Skip to content

Commit

Permalink
Merge pull request #3 from Chargily/chargily/2.0.1
Browse files Browse the repository at this point in the history
add missing attribute in checkout && fix makefile
  • Loading branch information
ChargilyDev authored Feb 14, 2024
2 parents 33dcbe3 + e3f5285 commit f7e9607
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 24 deletions.
3 changes: 1 addition & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
"test_*.py"
],
"python.testing.pytestEnabled": false,

"python.testing.unittestEnabled": true,
"python.testing.unittestEnabled": true
}
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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/*
10 changes: 0 additions & 10 deletions makefile

This file was deleted.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 1 addition & 7 deletions src/chargily_pay/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# ==================================
Expand Down Expand Up @@ -192,8 +192,6 @@ def list_prices(self, per_page: int = 10, page: int = 1):
response.raise_for_status()
return response.json()



# ==================================
# Checkouts
# ==================================
Expand Down Expand Up @@ -247,7 +245,6 @@ def expire_checkout(self, id):
response.raise_for_status()
return response.json()


# ==================================
# Payment Links
# ==================================
Expand Down Expand Up @@ -317,6 +314,3 @@ def validate_signature(self, signature: str, payload: str):
if hmac.compare_digest(signature, computed_signature):
return True
return False



5 changes: 4 additions & 1 deletion src/chargily_pay/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand All @@ -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")


Expand Down
57 changes: 54 additions & 3 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from itertools import product
import os
import unittest

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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(
Expand All @@ -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",
Expand Down

0 comments on commit f7e9607

Please sign in to comment.