Skip to content

Commit

Permalink
Merge pull request #80 from eadwinCode/master
Browse files Browse the repository at this point in the history
Added Transaction Split
  • Loading branch information
samuelvarejames authored Sep 30, 2021
2 parents f4b9082 + dde449e commit 84ce37b
Show file tree
Hide file tree
Showing 5 changed files with 338 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Subscription
Transaction
TransferControl
Transfer
TransferSplit
TransferRecipient
Verification

Expand Down
137 changes: 137 additions & 0 deletions docs/transaction_split.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 2 additions & 0 deletions paystackapi/paystack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
97 changes: 97 additions & 0 deletions paystackapi/tests/test_transaction_split.py
Original file line number Diff line number Diff line change
@@ -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)
101 changes: 101 additions & 0 deletions paystackapi/transaction_split.py
Original file line number Diff line number Diff line change
@@ -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 [ 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.
"""
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)

0 comments on commit 84ce37b

Please sign in to comment.