Skip to content

Commit 6a05c0b

Browse files
add new payment methods
1 parent d0a97ae commit 6a05c0b

15 files changed

+827
-782
lines changed

.DS_Store

4 KB
Binary file not shown.

README.md

Lines changed: 418 additions & 76 deletions
Large diffs are not rendered by default.

example.py

Lines changed: 74 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,77 @@
44

55
rave = Rave(PublicKey, SecretKey, production=True, usingEnv=False)
66

7-
accountDetails = {
8-
"email": "cornelius.ashley@outlook.com",
9-
"seckey": SecretKey,
10-
"is_permanent": True,
11-
"narration": "Yaovi Test",
12-
"bvn": "22169541783",
13-
"txRef": "sample1234"
14-
}
15-
print(rave.VirtualAccount.create(accountDetails))
7+
payload = {
8+
"amount": 30,
9+
"PBFPubKey": PublicKey,
10+
"currency": "NGN",
11+
"email": "user@example.com",
12+
"meta": [{"metaname": "test", "metavalue": "12383"}],
13+
"ip": "123.0.1.3",
14+
"firstname": "Flutterwave",
15+
"lastname": "Tester",
16+
"is_token": False
17+
}
18+
19+
payload_2 = {
20+
"currency": "TZS",
21+
"country": "TZ",
22+
"amount": 1000,
23+
"email": "user@example.com",
24+
"firstname": "John",
25+
"lastname": "Doe",
26+
"phonenumber": "255123456789",
27+
}
28+
29+
payload_3 = {
30+
"cardno": "4187451811620618",
31+
"cvv": "306",
32+
"expirymonth": "05",
33+
"expiryyear": "25",
34+
"amount": "100",
35+
"email": "korneliosyaovi@gmail.com",
36+
"phonenumber": "08109328188",
37+
"firstname": "Cornelius",
38+
"lastname": "Ashley",
39+
"IP": "355426087298442",
40+
"pin": "7991",
41+
"currency": "NGN"
42+
}
43+
44+
payload_4 = {
45+
"token": "flw-t1nf-45a7a6bfbe2fb30a70c1d974d84e31c5-k3n",
46+
"amount": "100",
47+
"email": "korneliosyaovi@gmail.com",
48+
"phonenumber": "08109328188",
49+
"firstname": "Cornelius",
50+
"lastname": "Ashley",
51+
"IP": "355426087298442",
52+
"currency": "NGN",
53+
"country": "NG"
54+
}
55+
56+
payload_5 = {
57+
"amount": 30,
58+
"PBFPubKey": PublicKey,
59+
"currency": "NGN",
60+
"email": "user@example.com",
61+
"meta": [{"metaname": "test", "metavalue": "12383"}],
62+
"ip": "123.0.1.3",
63+
"firstname": "Flutterwave",
64+
"lastname": "Tester",
65+
}
66+
67+
payload_6 = {
68+
"amount": 2,
69+
"PBFPubKey": PublicKey,
70+
"currency": "GBP",
71+
"email": "user@example.com",
72+
"meta": [{"metaname": "test", "metavalue": "12383"}],
73+
"ip": "123.0.1.3",
74+
"firstname": "Flutterwave",
75+
"lastname": "Tester"
76+
}
77+
78+
79+
# print(rave.Enaira.charge(payload))
80+
print(rave.Enaira.charge(payload))

rave_python/.DS_Store

6 KB
Binary file not shown.

rave_python/__pycache__/.DS_Store

6 KB
Binary file not shown.

rave_python/rave.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,20 @@
2020
from rave_python.rave_virtualaccount import VirtualAccount
2121
from rave_python.rave_virtualcard import VirtualCard
2222
from rave_python.rave_zbmobile import ZBMobile
23+
from rave_python.rave_banktransfer import BankTransfer
24+
from rave_python.rave_enaira import Enaira
25+
from rave_python.rave_tzmobile import TZSMobile
2326

2427

2528
class Rave:
2629

2730
def __init__(self, publicKey, secretKey, production=False, usingEnv=True):
2831
""" This is main organizing object. It contains the following:\n
2932
rave.Account -- For bank account transactions\n
33+
rave.BankTransfer -- For pay with bank transfer transaction\n
3034
rave.Bills -- For Bills payments\n
3135
rave.Card -- For card transactions\n
36+
rave.Enaira -- For enaira wallet payments\n
3237
rave.Francophone -- For West African Francophone mobile money transactions\n
3338
rave.GhMobile -- For Ghana mobile money transactions\n
3439
rave.Mpesa -- For mpesa transactions\n
@@ -37,6 +42,7 @@ def __init__(self, publicKey, secretKey, production=False, usingEnv=True):
3742
rave.RWMobile -- For Rwanda mobile money transactions\n
3843
rave.Settlement -- For settled transactions\n
3944
rave.SubAccount -- For creation of subaccounts for split payment operations\n
45+
rave.TZSMobile -- For Tanzania mobile money transactions\n
4046
rave.Transfer -- For Payouts and transfers\n
4147
rave.UGMobile -- For Uganda mobile money transactions\n
4248
rave.Ussd -- For ussd transactions\n
@@ -48,9 +54,11 @@ def __init__(self, publicKey, secretKey, production=False, usingEnv=True):
4854

4955
classes = (
5056
Account,
57+
BankTransfer,
5158
Bills,
5259
Card,
5360
Ebills,
61+
Enaira,
5462
Francophone,
5563
GhMobile,
5664
Mpesa,
@@ -62,6 +70,7 @@ def __init__(self, publicKey, secretKey, production=False, usingEnv=True):
6270
SubAccount,
6371
Subscriptions,
6472
Transfer,
73+
TZSMobile,
6574
UGMobile,
6675
Ussd,
6776
Verify,

rave_python/rave_account.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from rave_python.rave_misc import generateTransactionReference
33
from rave_python.rave_payment import Payment
44

5-
65
class Account(Payment):
76
""" This is the rave object for account transactions. It contains the following public functions:\n
87
.charge -- This is for making an account charge\n
@@ -46,37 +45,35 @@ def charge(self, accountDetails, hasFailed=False):
4645

4746
# setting the endpoint
4847
endpoint = self._baseUrl + self._endpointMap['account']['charge']
49-
feature_name = "Initiate-Account-charge"
48+
feature_name = "Pay with Bank"
5049

5150
# It is faster to just update rather than check if it is already
5251
# present
53-
accountDetails.update({'payment_type': 'account'})
52+
if accountDetails.get("currency") == "NGN":
53+
accountDetails.update({'payment_type': 'account', 'is_mono': '1', 'country': 'NG'})
54+
else:
55+
accountDetails.update({'payment_type': 'token_io', 'is_token_io': '1', 'country': 'NG'})
5456

5557
# Generate transaction reference if txRef doesn't exist
5658
accountDetails.setdefault('txRef', generateTransactionReference())
5759

5860
# Checking for required account components
5961
requiredParameters = [
60-
'accountbank',
61-
'accountnumber',
62+
'currency',
6263
'amount',
6364
'email',
64-
'phonenumber',
65-
'IP']
66-
67-
return super().charge(feature_name, accountDetails, requiredParameters, endpoint)
65+
'firstname',
66+
'lastname'
67+
]
6868

69-
def validate(self, flwRef, otp):
70-
endpoint = self._baseUrl + self._endpointMap['account']['validate']
71-
feature_name = "Account-charge-validate"
72-
return super().validate(feature_name, flwRef, endpoint)
69+
return super(Account, self).charge(feature_name, accountDetails, requiredParameters, endpoint)
7370

7471
def verify(self, txRef):
7572
endpoint = self._baseUrl + self._endpointMap['account']['verify']
76-
feature_name = "Account-charge-verify"
77-
return super().verify(feature_name, txRef, endpoint)
73+
feature_name = "Verify PWB"
74+
return super(Account, self).verify(feature_name, txRef, endpoint)
7875

7976
def refund(self, flwRef, amount):
80-
feature_name = "Account-charge-refund"
77+
feature_name = "Refund PWB"
8178
endpoint = self._baseUrl + self._endpointMap["account"]["refund"]
82-
return super().refund(feature_name, flwRef, amount)
79+
return super(Account, self).refund(feature_name, flwRef, amount)

rave_python/rave_banktransfer.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
from rave_python.rave_payment import Payment
2+
from rave_python.rave_exceptions import AccountChargeError
3+
from rave_python.rave_misc import generateTransactionReference
4+
5+
class BankTransfer(Payment):
6+
""" This is the rave object for pay with bank transfer transactions. It contains the following public functions:\n
7+
.charge -- This is for making a pay with bank transfer charge\n
8+
.verify -- This checks the status of your transaction\n
9+
.refunds -- This initiates the refund for a PWBT transaction\n
10+
"""
11+
12+
def _handleChargeResponse(self, response, txRef, request=None):
13+
""" This handles account charge responses """
14+
# This checks if we can parse the json successfully
15+
res = self._preliminaryResponseChecks(
16+
response, AccountChargeError, txRef=txRef)
17+
18+
response_json = res['json']
19+
# change - added data before flwRef
20+
response_data = response_json['data']
21+
flw_ref = response_data['flw_reference']
22+
bank_name = response_data['bankname']
23+
account_number = response_data['accountnumber']
24+
expiry = response_data['expiry_date']
25+
desc = response_data['note']
26+
27+
# If all preliminary checks are passed
28+
data = {
29+
'error': False,
30+
'validationRequired': False,
31+
'txRef': txRef,
32+
'flwRef': flw_ref,
33+
'bankName': bank_name,
34+
'accountNumber': account_number,
35+
'expiresIn': expiry,
36+
'transferNote': desc
37+
}
38+
return data
39+
40+
# Charge account function
41+
def charge(self, accountDetails, hasFailed=False):
42+
""" This is the direct account charge call.\n
43+
Parameters include:\n
44+
accountDetails (dict) -- These are the parameters passed to the function for processing\n
45+
hasFailed (boolean) -- This is a flag to determine if the attempt had previously failed due to a timeout\n
46+
"""
47+
48+
# setting the endpoint
49+
endpoint = self._baseUrl + self._endpointMap['account']['charge']
50+
feature_name = "Pay with Bank Transfer"
51+
52+
# It is faster to just update rather than check if it is already
53+
# present
54+
accountDetails.update({
55+
'payment_type': 'banktransfer',
56+
'is_bank_transfer': True,
57+
'country': 'NG'
58+
})
59+
60+
# Generate transaction reference if txRef doesn't exist
61+
accountDetails.setdefault('txRef', generateTransactionReference())
62+
63+
# Checking for required account components
64+
requiredParameters = [
65+
'amount',
66+
'email',
67+
'firstname',
68+
'lastname'
69+
]
70+
71+
return super(BankTransfer, self).charge(feature_name, accountDetails, requiredParameters, endpoint)
72+
73+
def verify(self, txRef):
74+
endpoint = self._baseUrl + self._endpointMap['account']['verify']
75+
feature_name = "Verify PWBT"
76+
return super(BankTransfer, self).verify(feature_name, txRef, endpoint)
77+
78+
def refund(self, flwRef, amount):
79+
feature_name = "Refund PWBT"
80+
endpoint = self._baseUrl + self._endpointMap["account"]["refund"]
81+
return super(BankTransfer, self).refund(feature_name, flwRef, amount)
82+

rave_python/rave_card.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,4 @@ def refund(self, flwRef, amount):
204204
feature_name = "Card-refund"
205205
endpoint = self._baseUrl + self._endpointMap["card"]["refund"]
206206
return super(Card, self).refund(feature_name, flwRef, amount)
207+

rave_python/rave_enaira.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
from rave_python.rave_payment import Payment
2+
from rave_python.rave_exceptions import AccountChargeError
3+
from rave_python.rave_misc import generateTransactionReference
4+
5+
class Enaira(Payment):
6+
""" This is the rave object for eNaira wallet transactions. It contains the following public functions:\n
7+
.charge -- This is for charging the eNaira wallet\n
8+
.verify -- This checks the status of your transaction\n
9+
.refunds -- This initiates the refund for the transaction\n
10+
"""
11+
12+
def _handleChargeResponse(self, response, txRef, request=None):
13+
""" This handles account charge responses """
14+
# This checks if we can parse the json successfully
15+
res = self._preliminaryResponseChecks(
16+
response, AccountChargeError, txRef=txRef)
17+
18+
response_json = res['json']
19+
# change - added data before flwRef
20+
response_data = response_json['data']
21+
flw_ref = response_data['flwRef']
22+
23+
data = {
24+
'error': False,
25+
'validationRequired': True,
26+
'txRef': txRef,
27+
'flwref': flw_ref
28+
}
29+
30+
if 'qr_image' in response_data:
31+
data.update({
32+
'validateInstructions': "Please scan the qr image in your eNaira app.",
33+
'image': response_data['qr_image']
34+
})
35+
else:
36+
data.update({
37+
'validateInstructions': response_data['validate_instructions'],
38+
'image': None
39+
})
40+
41+
# If all preliminary checks are passed
42+
return data
43+
44+
# Charge account function
45+
def charge(self, accountDetails, hasFailed=False):
46+
""" This is the direct account charge call.\n
47+
Parameters include:\n
48+
accountDetails (dict) -- These are the parameters passed to the function for processing\n
49+
hasFailed (boolean) -- This is a flag to determine if the attempt had previously failed due to a timeout\n
50+
"""
51+
52+
# setting the endpoint
53+
endpoint = self._baseUrl + self._endpointMap['account']['charge']
54+
feature_name = "eNaira Payments"
55+
56+
# It is faster to just update rather than check if it is already
57+
# present
58+
59+
if accountDetails.get("is_token") == True:
60+
accountDetails.update({'payment_type': 'enaira', 'is_token': True, 'country': 'NG'})
61+
else:
62+
accountDetails.update({'payment_type': 'enaira', 'is_qr': True, 'country': 'NG'})
63+
64+
# Generate transaction reference if txRef doesn't exist
65+
accountDetails.setdefault('txRef', generateTransactionReference())
66+
67+
# Checking for required account components
68+
requiredParameters = [
69+
'amount',
70+
'email',
71+
'firstname',
72+
'lastname'
73+
]
74+
75+
return super(Enaira, self).charge(feature_name, accountDetails, requiredParameters, endpoint)
76+
77+
def validate(self, flwRef, otp):
78+
endpoint = self._baseUrl + self._endpointMap['account']['validate']
79+
feature_name = "Account-charge-validate"
80+
return super().validate(feature_name, flwRef, endpoint)
81+
82+
def verify(self, txRef):
83+
endpoint = self._baseUrl + self._endpointMap['account']['verify']
84+
feature_name = "Verify eNaira"
85+
return super(Enaira, self).verify(feature_name, txRef, endpoint)
86+
87+
def refund(self, flwRef, amount):
88+
feature_name = "Refund eNaira"
89+
endpoint = self._baseUrl + self._endpointMap["account"]["refund"]
90+
return super(Enaira, self).refund(feature_name, flwRef, amount)
91+

0 commit comments

Comments
 (0)