-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from eadwinCode/master
Added Transaction Split
- Loading branch information
Showing
5 changed files
with
338 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,7 @@ Subscription | |
Transaction | ||
TransferControl | ||
Transfer | ||
TransferSplit | ||
TransferRecipient | ||
Verification | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |