Skip to content

Commit d15fc87

Browse files
committed
add schedule payout
1 parent 8c3de20 commit d15fc87

File tree

3 files changed

+55
-7
lines changed

3 files changed

+55
-7
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
test.py
44
kkiapay.egg-info
55
dist
6-
build
6+
build
7+
venv
8+
.idea

kkiapay/core.py

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
import json
2-
import requests
32
from collections import namedtuple
43

4+
import requests
55

6-
class Kkiapay:
6+
from kkiapay.exceptions import KKiapayAlogrithmException, KKiapayDestinationTypeException
77

8+
9+
class Kkiapay:
810
BASE_URL = "https://api.kkiapay.me"
911
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+
}
1020

1121
def __init__(self, public_key, private_key, secret, sandbox=False):
1222
self.secret = secret
@@ -45,7 +55,29 @@ def refund_transaction(self, transaction_id):
4555
),
4656
)
4757

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+
}

kkiapay/exceptions.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,16 @@
11
class KkiapayException(Exception):
22
pass
3+
4+
5+
class KKiapayAlogrithmException(Exception):
6+
def __init__(self, algorithms):
7+
Exception.__init__(self,
8+
"algorithm must be {}".format(
9+
" or ".join(" if it's ".join(algorithm) for algorithm in algorithms.items())))
10+
11+
12+
class KKiapayDestinationTypeException(Exception):
13+
def __init__(self, algorithms):
14+
Exception.__init__(self,
15+
"destination_type must be {}".format(
16+
" or ".join(" if it's ".join(algorithm) for algorithm in algorithms.items())))

0 commit comments

Comments
 (0)