From e02248b12b00a2d18c90e2e76bb7494e81aff5af Mon Sep 17 00:00:00 2001 From: eadwinCode Date: Sat, 4 Sep 2021 20:25:12 +0100 Subject: [PATCH 1/2] Added transaction split --- README.md | 1 + paystackapi/paystack.py | 2 + paystackapi/tests/test_transaction_split.py | 97 +++++++++++++++++++ paystackapi/transaction_split.py | 101 ++++++++++++++++++++ 4 files changed, 201 insertions(+) create mode 100644 paystackapi/tests/test_transaction_split.py create mode 100644 paystackapi/transaction_split.py diff --git a/README.md b/README.md index 1e49069..b54cc00 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ Subscription Transaction TransferControl Transfer +TransferSplit TransferRecipient Verification diff --git a/paystackapi/paystack.py b/paystackapi/paystack.py index f2788ed..d291475 100644 --- a/paystackapi/paystack.py +++ b/paystackapi/paystack.py @@ -17,6 +17,7 @@ from paystackapi.transfer import Transfer from paystackapi.trecipient import TransferRecipient from paystackapi.verification import Verification +from paystackapi.transaction_split import TransactionSplit from paystackapi.base import PayStackBase @@ -41,6 +42,7 @@ def __init__(self, secret_key=None): self.subaccount = SubAccount self.subscription = Subscription self.transaction = Transaction + self.transactionSplit = TransactionSplit self.transferControl = TransferControl self.transfer = Transfer self.transferRecipient = TransferRecipient diff --git a/paystackapi/tests/test_transaction_split.py b/paystackapi/tests/test_transaction_split.py new file mode 100644 index 0000000..e652fb6 --- /dev/null +++ b/paystackapi/tests/test_transaction_split.py @@ -0,0 +1,97 @@ +"""Script defined to test the Customer class.""" + +import httpretty + +from paystackapi.transaction_split import TransactionSplit +from paystackapi.tests.base_test_case import BaseTestCase + + +class TestTransactionSplit(BaseTestCase): + """Method defined to test transaction split initialize.""" + + @httpretty.activate + def test_transaction_split_create(self): + """Method defined to test transaction split create.""" + httpretty.register_uri( + httpretty.POST, + self.endpoint_url("split"), + content_type='text/json', + body='{"status": true, "contributors": true}', + status=201, + ) + + response = TransactionSplit.create( + name='somes', type=12000, + currency='NGN', bearer_type='account' + ) + self.assertTrue(response['status']) + + @httpretty.activate + def test_transaction_split_list(self): + """Method defined to test transaction split list.""" + httpretty.register_uri( + httpretty.GET, + self.endpoint_url("split"), + content_type='text/json', + body='{"status": true, "contributors": true}', + status=201, + ) + + response = TransactionSplit.list() + self.assertTrue(response['status']) + + @httpretty.activate + def test_transaction_split_fetch(self): + """Method defined to test transaction split fetch.""" + httpretty.register_uri( + httpretty.GET, + self.endpoint_url("/split/1445"), + content_type='text/json', + body='{"status": true, "message": "Transaction Split Subaccount retrieved"}', + status=201, + ) + + response = TransactionSplit.fetch(split_id='1445') + self.assertEqual(response['status'], True) + + @httpretty.activate + def test_transaction_split_update(self): + """Method defined to test transaction split update.""" + httpretty.register_uri( + httpretty.PUT, + self.endpoint_url("/split/1445"), + content_type='text/json', + body='{"status": true, "message": "Transaction Split updated"}', + status=201, + ) + + response = TransactionSplit.update(split_id='1445') + self.assertEqual(response['status'], True) + + @httpretty.activate + def test_transaction_split_add_or_update_split_subaccount(self): + """Method defined to test transaction split add_or_update_split_subaccount.""" + httpretty.register_uri( + httpretty.POST, + self.endpoint_url("split/1445/subaccount/add"), + content_type='text/json', + body='{"status": true, "message": "Transaction Split Subaccount Updated"}', + status=201, + ) + + response = TransactionSplit.add_or_update_split_subaccount(split_id='1445') + self.assertEqual(response['status'], True) + + @httpretty.activate + def test_transaction_split_remove_split_subaccount(self): + """Method defined to test transaction split remove_split_subaccount.""" + httpretty.register_uri( + httpretty.POST, + self.endpoint_url("split/1445/subaccount/remove"), + content_type='text/json', + body='{"status": true, "message": "Transaction Split Subaccount Removed"}', + status=201, + ) + + response = TransactionSplit.remove_split_subaccount(split_id='1445') + self.assertEqual(response['status'], True) \ No newline at end of file diff --git a/paystackapi/transaction_split.py b/paystackapi/transaction_split.py new file mode 100644 index 0000000..2849934 --- /dev/null +++ b/paystackapi/transaction_split.py @@ -0,0 +1,101 @@ +"""Script used to define the paystack Plan class.""" +from paystackapi.base import PayStackBase + + + +class TransactionSplit(PayStackBase): + """docstring for Transaction Split.""" + + @classmethod + def create(cls, **kwargs): + """ + Create a split payment on your integration + + Args: + name: Name of the transaction split + type: The type of transaction split you want to create + currency: Any of NGN, GHS, ZAR, or USD + subaccounts: A list of object containing subaccount code and number of shares + bearer_type: Any of subaccount | account | all-proportional | all + bearer_subaccount: Subaccount code + **kwargs + + Returns: + Json data from paystack API. + """ + return cls().requests.post('split', data=kwargs) + + @classmethod + def list(cls, **kwargs): + """ + List/search for the transaction splits available on your integration. + + Args: + perPage: records you want to retrieve per page (Integer) + page: what page you want to retrieve (Integer) + + Returns: + JSON data from paystack's API. + """ + return cls().requests.get("split", qs=kwargs) + + @classmethod + def fetch(cls, split_id): + """ + Get details of a split on your integration. + + Args: + split_id: split ID + + Returns: + Json data from paystack API. + """ + return cls().requests.get(f"split/{split_id}") + + @classmethod + def update(cls, split_id, **kwargs): + """ + Update a transaction split details on your integration + + Args: + split_id: split ID + name: Name of the transaction split + active: True or False + subaccounts: A list of object containing subaccount code and number of shares + bearer_type: Any of subaccount | account | all-proportional | all + bearer_subaccount: Subaccount code + **kwargs + + Returns: + Json data from paystack API. + """ + return cls().requests.put(f"split/{split_id}", data=kwargs) + + @classmethod + def add_or_update_split_subaccount(cls, split_id, **kwargs): + """ + Add a Subaccount to a Transaction Split, or update the share of an existing Subaccount in a Transaction Split + + Args: + split_id: split ID + subaccount: This is the sub account code + share: This is the transaction share for the subaccount + + Returns: + Json data from paystack API. + """ + return cls().requests.post(f"split/{split_id}/subaccount/add", data=kwargs) + + @classmethod + def remove_split_subaccount(cls, split_id, **kwargs): + """ + Remove a subaccount from a transaction split + + Args: + split_id: split ID + subaccount: This is the sub account code + + Returns: + Json data from paystack API. + """ + return cls().requests.post(f"split/{split_id}/subaccount/remove", data=kwargs) From dde449e3c62d843d047ef99eb8eb4c8731cb88de Mon Sep 17 00:00:00 2001 From: eadwinCode Date: Sat, 4 Sep 2021 20:42:43 +0100 Subject: [PATCH 2/2] added transaction split doc --- docs/transaction_split.md | 137 +++++++++++++++++++++++++++++++ paystackapi/transaction_split.py | 2 +- 2 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 docs/transaction_split.md diff --git a/docs/transaction_split.md b/docs/transaction_split.md new file mode 100644 index 0000000..3070ae6 --- /dev/null +++ b/docs/transaction_split.md @@ -0,0 +1,137 @@ +## Transaction Split + +#### `TransactionSplit.create(**kwargs)` - Create a Transaction Split + +_Usage_ + +```python +from paystackapi.transaction_split import TransactionSplit +response = TransactionSplit.create( + name="Test Biz 123", + type="percentage", + currency="xxxxxxxxx", + subaccounts="[{'subaccount': 'ACCT_4hl4xenwpjy5wb', 'share':40 },...]", + bearer_type="account" + ) +``` + +_Arguments_ + +- `name`: Name of the transaction split +- `type`: The type of transaction split you want to create [ percentage | flat ] +- `currency`: Any of NGN, GHS, ZAR, or USD +- `subaccounts`: A list of object containing subaccount code and number of shares +- `bearer_type`: Any of subaccount | account | all-proportional | all +- `bearer_subaccount`: Subaccount code +- `**kwargs` + +_Returns_ + +JSON data from Paystack API. + +#### `TransactionSplit.list(perPage, page)` - List/search for the transaction splits available on your integration. + +_Usage_ + +```python +from paystackapi.transaction_split import TransactionSplit +response = TransactionSplit.list(perPage=3, page=1) +``` + +_Arguments_ + +- `perPage`: Records you want to retrieve per page (Integer) +- `page`: What page you want to retrieve (Integer) +- `**kwargs` + +_Returns_ + +JSON data from Paystack API. + +#### `TransactionSplit.fetch(split_id)` - Get details of a split on your integration. + +_Usage_ + +```python +from paystackapi.transaction_split import TransactionSplit +response = TransactionSplit.fetch(split_id=14551) +``` + +_Arguments_ + +- `split_id`: split ID + +_Returns_ + +JSON data from Paystack API. + +#### `TransactionSplit.update(split_id, **kwargs)` - Update a transaction split details on your integration + +_Usage_ + +```python +from paystackapi.transaction_split import TransactionSplit +response = TransactionSplit.update( + split_id=45411, + **kwargs + ) +``` + +_Arguments_ + +- `split_id`: split ID +- `name`: Name of the transaction split +- `active`: True or False +- `subaccounts`: A list of object containing subaccount code and number of shares +- `bearer_type`: Any of subaccount | account | all-proportional | all +- `bearer_subaccount`: Subaccount code +- `**kwargs` + +_Returns_ + +JSON data from Paystack API. + +#### `TransactionSplit.remove_split_subaccount(split_id, **kwargs)` - Remove a subaccount from a transaction split + +_Usage_ + +```python +from paystackapi.transaction_split import TransactionSplit +response = TransactionSplit.remove_split_subaccount( + split_id=45411, + **kwargs + ) +``` + +_Arguments_ + +- `split_id`: split ID +- `subaccount`: This is the sub account code +- `**kwargs` + +_Returns_ + +JSON data from Paystack API. + +#### `TransactionSplit.add_or_update_split_subaccount(split_id, **kwargs)` - Add a Subaccount to a Transaction Split, or update the share of an existing Subaccount in a Transaction Split + +_Usage_ + +```python +from paystackapi.transaction_split import TransactionSplit +response = TransactionSplit.add_or_update_split_subaccount( + split_id=45411, + **kwargs + ) +``` + +_Arguments_ + +- `split_id`: split ID +- `subaccount`: This is the sub account code +- `share`: This is the transaction share for the subaccount +- `**kwargs` + +_Returns_ + +JSON data from Paystack API. diff --git a/paystackapi/transaction_split.py b/paystackapi/transaction_split.py index 2849934..0b5eaeb 100644 --- a/paystackapi/transaction_split.py +++ b/paystackapi/transaction_split.py @@ -13,7 +13,7 @@ def create(cls, **kwargs): Args: name: Name of the transaction split - type: The type of transaction split you want to create + type: The type of transaction split you want to create [ percentage | flat ] currency: Any of NGN, GHS, ZAR, or USD subaccounts: A list of object containing subaccount code and number of shares bearer_type: Any of subaccount | account | all-proportional | all