|
1 | 1 | import json |
2 | | -import requests |
3 | 2 | from collections import namedtuple |
4 | 3 |
|
| 4 | +import requests |
5 | 5 |
|
6 | | -class Kkiapay: |
| 6 | +from kkiapay.exceptions import KKiapayAlogrithmException, KKiapayDestinationTypeException |
7 | 7 |
|
| 8 | + |
| 9 | +class Kkiapay: |
8 | 10 | BASE_URL = "https://api.kkiapay.me" |
9 | 11 | SANDBOX_URL = "https://api-sandbox.kkiapay.me" |
| 12 | + ALGORITHMS = {"1": 'rate', "2": 'roof'} |
| 13 | + |
| 14 | + RATE_FREQUENCIES = {"1": '3d', "2": '1w', "3": '1m'} |
| 15 | + default_roof_amount = "50000" |
| 16 | + DESTINATION_TYPES = { |
| 17 | + "1": 'MOBILE_MONEY', |
| 18 | + "2": 'BANK_ACCOUNT', |
| 19 | + } |
10 | 20 |
|
11 | 21 | def __init__(self, public_key, private_key, secret, sandbox=False): |
12 | 22 | self.secret = secret |
@@ -45,7 +55,29 @@ def refund_transaction(self, transaction_id): |
45 | 55 | ), |
46 | 56 | ) |
47 | 57 |
|
48 | | - def setup_payout(self, options): |
49 | | - self.url += "/merchant/payouts/schedule" |
50 | | - r = requests.post(self.url, data=options, headers=self.headers) |
51 | | - return r.text |
| 58 | + def setup_payout(self, algorithm: str, destination: str, destination_type: str, roof_amount: str = None, |
| 59 | + send_notification: bool = True, rate_frequency: str = None, country_code: str = "229"): |
| 60 | + options = { |
| 61 | + "destination": country_code + destination if destination_type == "1" else destination, |
| 62 | + "send_notification": 1 if send_notification else 0, |
| 63 | + } |
| 64 | + |
| 65 | + if destination_type in self.DESTINATION_TYPES.keys(): |
| 66 | + options["destination_type"] = self.DESTINATION_TYPES[destination_type] |
| 67 | + else: |
| 68 | + raise KKiapayDestinationTypeException(self.DESTINATION_TYPES) |
| 69 | + |
| 70 | + if algorithm in self.ALGORITHMS.keys(): |
| 71 | + options['algorithm'] = self.ALGORITHMS[algorithm] |
| 72 | + else: |
| 73 | + raise KKiapayAlogrithmException(self.ALGORITHMS) |
| 74 | + if algorithm == "2": |
| 75 | + options["roof_amount"] = roof_amount if roof_amount is not None else self.default_roof_amount |
| 76 | + else: |
| 77 | + options["rate_frequency"] = rate_frequency if rate_frequency in self.RATE_FREQUENCIES.values() else \ |
| 78 | + self.RATE_FREQUENCIES["1"] |
| 79 | + r = requests.post(self.url + '/merchant/payouts/schedule', data=options, headers=self.headers) |
| 80 | + return { |
| 81 | + 'response': r.json(), |
| 82 | + 'status_code': r.status_code |
| 83 | + } |
0 commit comments