diff --git a/python_flutterwave/payment.py b/python_flutterwave/payment.py index a3ee1d7..d821bba 100644 --- a/python_flutterwave/payment.py +++ b/python_flutterwave/payment.py @@ -5,10 +5,9 @@ token = "" -def initiate_payment(tx_ref: str, amount: float, currency: str, redirect_url: str, payment_options: str, - customer_email: str, customer_phone_number: Optional[str], customer_name: str, - title: Optional[str], - description: Optional[str]) -> str: +def initiate_payment(tx_ref: str, amount: float, currency: Optional[str], redirect_url: str, customer_name: str, + payment_options: Optional[str], title: Optional[str], customer_email: str, + customer_phone_number: Optional[str], description: Optional[str]) -> str: """This is used to initiate standard payments. It takes in the arguments and returns the url to redirect users for payments """ payment_url = "https://api.flutterwave.com/v3/payments" @@ -38,6 +37,7 @@ def initiate_payment(tx_ref: str, amount: float, currency: str, redirect_url: st return link +# pragma: no cover def get_payment_details(trans_id: str) -> dict: """ Takes the transaction_id from the request and returns the status info in json. diff --git a/python_flutterwave/tests/__init__.py b/python_flutterwave/tests/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/python_flutterwave/tests/__init__.py @@ -0,0 +1 @@ + diff --git a/python_flutterwave/tests/test_initiate_payment.py b/python_flutterwave/tests/test_initiate_payment.py new file mode 100644 index 0000000..8a9c112 --- /dev/null +++ b/python_flutterwave/tests/test_initiate_payment.py @@ -0,0 +1,52 @@ +import random +import string + +from python_flutterwave import payment +import unittest + + +class TestStandardPayment(unittest.TestCase): + + def setUp(self) -> None: + self.token = "YOUR_SECRET_KEY" + self.tx_ref = f"{''.join(random.choice(string.ascii_letters) for i in range(10))}" + self.amount = 10.0 + self.currency = 'KES' + self.redirect_url = "https://example.com/" + self.payment_options = "mpesa" + self.customer_email = "johndoe@gmail.com" + self.customer_phone_number = "1234567890" + self.customer_name = "John Doe" + self.title = "Test Payment" + self.description = "Just pay me..." + payment.token = self.token + self.link = payment.initiate_payment(tx_ref=self.tx_ref, amount=self.amount, redirect_url=self.redirect_url, + payment_options=self.payment_options, customer_email=self.customer_email, + customer_phone_number=self.customer_phone_number, + customer_name=self.customer_name, title=self.title, + description=self.description, currency=self.currency) + + def tearDown(self) -> None: + pass + + def test_argument_types(self): + self.assertIsInstance(self.token, str) + self.assertIsInstance(self.tx_ref, str) + self.assertIsInstance(self.amount, float) + self.assertIsInstance(self.currency, str) + self.assertIsInstance(self.redirect_url, str) + self.assertIsInstance(self.payment_options, str) + self.assertIsInstance(self.customer_email, str) + self.assertIsInstance(self.customer_phone_number, str) + self.assertIsInstance(self.customer_name, str) + self.assertIsInstance(self.title, str) + self.assertIsInstance(self.description, str) + + def test_mandatory_args(self): + self.assertIsNot(self.token, "") + self.assertIsNot(self.amount, "") + self.assertIsNot(self.customer_email, "") + + def test_return_obj(self): + self.assertIsInstance(self.link, str) + self.assertIsNotNone(self.link) diff --git a/python_flutterwave/tests/test_initiate_ussd_payment.py b/python_flutterwave/tests/test_initiate_ussd_payment.py new file mode 100644 index 0000000..cc75bec --- /dev/null +++ b/python_flutterwave/tests/test_initiate_ussd_payment.py @@ -0,0 +1,45 @@ +import unittest +import random +import string + +from python_flutterwave import payment + + +class TestInitiateUSSDPayment(unittest.TestCase): + + def setUp(self) -> None: + self.token = "YOUR_SECRET_KEY" + self.tx_ref = f"{''.join(random.choice(string.ascii_letters) for i in range(10))}" + self.amount = 10.0 + self.account_bank = "044" + self.email = "johndoe@gmail.com" + self.phone_number = "1234567890" + self.full_name = "John Doe" + payment.token = self.token + self.details = payment.initiate_ussd_payment(tx_ref=self.tx_ref, amount=self.amount, + email=self.email, phone_number=self.phone_number, + full_name=self.full_name, account_bank=self.account_bank) + + def tearDown(self) -> None: + pass + + def test_argument_types(self): + self.assertIsInstance(self.token, str) + self.assertIsInstance(self.tx_ref, str) + self.assertIsInstance(self.amount, float) + self.assertIsInstance(self.account_bank, str) + + def test_mandatory_args(self): + self.assertIsNot(self.token, "") + self.assertIsNot(self.amount, "") + self.assertIsNot(self.email, "") + self.assertIsNot(self.account_bank, "") + self.assertIsNot(self.phone_number, "") + + def test_return_obj(self): + self.assertIsInstance(self.details, dict) + self.assertIsNotNone(self.details) + self.assertIn("status", self.details.keys()) + self.assertIn("message", self.details.keys()) + self.assertIn("data", self.details.keys()) + self.assertIn("meta", self.details.keys()) diff --git a/python_flutterwave/tests/test_trigger_mpesa_payment.py b/python_flutterwave/tests/test_trigger_mpesa_payment.py new file mode 100644 index 0000000..a8874c2 --- /dev/null +++ b/python_flutterwave/tests/test_trigger_mpesa_payment.py @@ -0,0 +1,42 @@ +import random +import string +import unittest + +from python_flutterwave import payment + + +class TestTriggerMpesaPayment(unittest.TestCase): + + def setUp(self) -> None: + self.token = "YOUR_SECRET_KEY" + self.tx_ref = f"{''.join(random.choice(string.ascii_letters) for i in range(10))}" + self.amount = 10.0 + self.currency = 'KES' + self.email = "johndoe@gmail.com" + self.phone_number = "1234567890" + self.full_name = "John Doe" + payment.token = self.token + self.details = payment.trigger_mpesa_payment(tx_ref=self.tx_ref, amount=self.amount, currency=self.currency, + email=self.email, phone_number=self.phone_number, + full_name=self.full_name) + + def tearDown(self) -> None: + pass + + def test_argument_types(self): + self.assertIsInstance(self.token, str) + self.assertIsInstance(self.tx_ref, str) + self.assertIsInstance(self.amount, float) + self.assertIsInstance(self.currency, str) + + def test_mandatory_args(self): + self.assertIsNot(self.token, "") + self.assertIsNot(self.amount, "") + self.assertIsNot(self.email, "") + + def test_return_obj(self): + self.assertIsInstance(self.details, dict) + self.assertIsNotNone(self.details) + self.assertIn("status", self.details.keys()) + self.assertIn("message", self.details.keys()) + self.assertIn("data", self.details.keys()) diff --git a/setup.cfg b/setup.cfg index 407b49d..f2dd4a8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = python-flutterwave -version = 0.2.6 +version = 0.2.7 author = William Otieno author_email = jimmywilliamotieno@gmail.com description = Python Wrapper for interacting with the Flutterwave Payments API