Skip to content

Commit

Permalink
v0.4.8
Browse files Browse the repository at this point in the history
- Added card details verification method
- Added tests that support the method
- No major/minor patch on any of the other methods
  • Loading branch information
WilliamOtieno committed Jan 3, 2022
1 parent 348e9d9 commit 7e3a3a1
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,11 @@ details = payment.initiate_ussd_payment(tx_ref="123erd", amount=100, email='john
phone_number='789456123', full_name='John Doe', account_bank='057')
print(details)
```

- For bank transactions, it is important to first verify the details given to you by the customer before granting incentives
according to the specifications of your application.
- To verify bank details call the function below that returns a Python dictionary with the data...
```
details = payment.verify_bank_account_details(account_number= "0690000032", account_bank= "044")
print(details)
```
24 changes: 23 additions & 1 deletion python_flutterwave/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def initiate_payment(tx_ref: str, amount: float, currency: Optional[str], redire
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.
Expand Down Expand Up @@ -109,3 +108,26 @@ def initiate_ussd_payment(tx_ref: str, account_bank: str, amount: float, email:
response = requests.request("POST", url, headers=headers, data=payload)

return dict(response.json())


def verify_bank_account_details(account_number: str, account_bank: str) -> dict:
"""
Takes the customer's account number and bank code as args and returns a dict with some data on the customer's account
:param account_number: str
:param account_bank: str
:return: dict
"""

url = "https://api.flutterwave.com/v3/accounts/resolve"

payload = json.dumps({
"account_number": f"{account_number}",
"account_bank": f"{account_bank}"
})
headers = {
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)
return dict(response.json())
36 changes: 36 additions & 0 deletions python_flutterwave/tests/test_verify_bank_account_details.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os
import unittest
from python_flutterwave import payment


class TestVerifyBankAccountDetails(unittest.TestCase):
def setUp(self) -> None:
self.token = os.environ.get("SECRET_KEY")
self.account_number = "0690000032"
self.account_bank = "044"

payment.token = self.token
self.details = payment.verify_bank_account_details(account_bank=self.account_bank,
account_number=self.account_number)

def tearDown(self) -> None:
pass

def test_argument_types(self):
self.assertIsInstance(self.token, str)
self.assertIsInstance(self.account_number, str)
self.assertIsInstance(self.account_bank, str)

def test_mandatory_args(self):
self.assertIsNot(self.token, "")
self.assertIsNot(self.account_bank, "")
self.assertIsNot(self.account_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.assertNotEqual(self.details["status"], "error")
self.assertNotEqual(self.details["data"], "null")
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = python-flutterwave
version = 0.3.8
version = 0.4.8
author = William Otieno
author_email = [email protected]
description = Python Wrapper for interacting with the Flutterwave Payments API
Expand Down

0 comments on commit 7e3a3a1

Please sign in to comment.