Created
June 18, 2020 07:37
-
-
Save LordGhostX/0ac6d73d4e13d8e2c89bf0cb213479c7 to your computer and use it in GitHub Desktop.
Withdraw From Paystack
This file contains hidden or 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
from paystackapi.paystack import Paystack | |
from paystackapi.trecipient import TransferRecipient | |
from paystackapi.tcontrol import TransferControl | |
from paystackapi.verification import Verification | |
from paystackapi.transfer import Transfer | |
paystack_secret_key = "" | |
paystack = Paystack(secret_key=paystack_secret_key) | |
def get_balance(): | |
response = TransferControl.check_balance() | |
return response["data"][0]["balance"] / 100 | |
def withdraw(name, account_number, bank_code, amount): | |
response = TransferRecipient.create( | |
type="nuban", | |
name=name, | |
description="Paystack Withdrawal", | |
account_number=account_number, | |
bank_code=bank_code, | |
) | |
recipient_code = response["data"]["recipient_code"] | |
response = Transfer.initiate_bulk_transfer( | |
source="balance", | |
currency="NGN", | |
transfers=[ | |
{ | |
"amount": str(amount * 100), | |
"recipient": recipient_code | |
} | |
] | |
) | |
return response | |
def get_banks(): | |
bank_data = { | |
"Access Bank": "044", | |
"Citibank Nigeria": "023", | |
"Diamond Bank": "063", | |
"Ecobank Nigeria": "050", | |
"Enterprise Bank": "084", | |
"Fidelity Bank": "070", | |
"First Bank of Nigeria": "011", | |
"First City Monument Bank": "214", | |
"Guaranty Trust Bank": "058", | |
"Heritage Bank": "030", | |
"Keystone Bank": "082", | |
"MainStreet Bank": "014", | |
"Skye Bank": "076", | |
"Stanbic IBTC Bank": "221", | |
"Standard Chartered Bank": "068", | |
"Sterling Bank": "232", | |
"Union Bank of Nigeria": "032", | |
"United Bank For Africa": "033", | |
"Unity Bank": "215", | |
"Wema Bank": "035", | |
"Zenith Bank": "057" | |
} | |
return bank_data | |
# get balance | |
balance = get_balance() | |
print("Account Balance: ₦{:,.2f}".format(balance)) | |
amount = int(input("Enter amount to withdraw: ")) | |
# get bank code | |
bank_data = get_banks() | |
banks = [] | |
for i, j in enumerate(bank_data): | |
print("{} - {}".format(i, j)) | |
banks.append(bank_data[j]) | |
bank = int(input("Choose a bank to withdraw to: ")) | |
bank_code = banks[bank] | |
# verify account number | |
while True: | |
account_number = input("Enter account number: ") | |
response = Verification.verify_account( | |
account_number=account_number, bank_code=bank_code) | |
if response["status"]: | |
break | |
print("Invalid Account Number, please confirm the digits") | |
name = response["data"]["account_name"] | |
# finalize withdraw | |
confirm = input( | |
"Confirm transfer of #{:,.2f} to {} (y/N)? ".format(amount, name)) | |
if confirm.lower() in ["y", "yes"]: | |
response = withdraw(name, account_number, bank_code, amount) | |
print(response) | |
else: | |
print("Transfer Cancelled") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment