NabooPay Python SDK
Project description
NabooPay Python SDK Workshop
Hey there! Welcome to this fun and practical workshop on using the NabooPay Python SDK. Whether you're syncing up synchronously or diving into async adventures, this guide has got you covered. We'll walk through installing the SDK, setting up clients, and performing some cool operations like retrieving account details, managing transactions, and handling cashouts. I’ve added a sprinkle of humor to keep things light because who said coding can’t be fun, right? Let’s dive in!
Table of Contents
- Installation
- Client Initialization
- 2.1 Token Loading
- 2.2 Synchronous Client
- 2.3 Asynchronous Client
- Operations
- 3.1 Retrieve Account Details
- 3.1.1 Synchronous
- 3.1.2 Asynchronous
- 3.2 Transactions
- 3.2.1 Create Transaction
- 3.2.1.1 Synchronous
- 3.2.1.2 Asynchronous
- 3.2.2 Delete Transaction
- 3.2.2.1 Synchronous
- 3.2.2.2 Asynchronous
- 3.2.3 Get Transactions
- 3.2.3.1 Synchronous
- 3.2.3.2 Asynchronous
- 3.2.1 Create Transaction
- 3.3 Cashout
- 3.3.1 Cashout with Wave
- 3.3.1.1 Synchronous
- 3.3.1.2 Asynchronous
- 3.3.2 Cashout with Orange Money
- 3.3.2.1 Synchronous
- 3.3.2.2 Asynchronous
- 3.3.1 Cashout with Wave
- 3.1 Retrieve Account Details
Installation
Let’s kick things off by installing the NabooPay Python SDK with this magical command. Run it in your terminal, and you’re good to go! with pip
pip install naboopay
for development :
pip install git+https://github.com/naboopay/naboopay-python-sdk.git
with uv (faster)
uv pip install git+https://github.com/naboopay/naboopay-python-sdk.git
Client Initialization
Before we can do anything fancy, we need to set up our clients. This involves loading our API token and initializing both synchronous and asynchronous clients. Here’s how:
Token Loading
First, grab your API token from a .env file—it’s the safest way to keep your secrets, well, secret! If you don’t have one yet, head to the NabooPay dashboard and conjure one up.
from dotenv import load_dotenv
import os
load_dotenv()
token = os.environ.get("NABOO_API_KEY")
# Alternatively: token = "your_token_here" (but shh, that’s not safe!)
# You wanna know my phone number 😂, no bro you can't 🙃 let's load them as env var
phone_number_1 = os.environ.get("TEST_NUMBER_1")
phone_number_2 = os.environ.get("TEST_NUMBER_2")
Synchronous Client
For those who like to take things one step at a time, here’s how to set up the synchronous client:
from naboopay import NabooPay
naboopay_client = NabooPay(token=token)
Asynchronous Client
If you’re ready to live on the async edge, initialize the asynchronous client like this:
from naboopay import NabooPayAsync
naboopay_async_client = NabooPayAsync(token=token)
Operations
Now for the fun part let’s do stuff with the NabooPay API! We’ll cover retrieving account details, managing transactions, and cashing out, with examples for both synchronous and asynchronous approaches.
Retrieve Account Details
Let’s peek at your account info.
Synchronous
Simple and straightforward get your account details and print them:
account_info_sync = naboopay_client.account.get_info()
print(account_info_sync)
Asynchronous
For the async fans, here’s how to fetch account details. Don’t forget to run it with asyncio:
import asyncio
async def account_test():
account_info_async = await naboopay_async_client.account.get_info()
print(account_info_async)
asyncio.run(account_test())
Transactions
Time to play with transactions, create them, delete them, and fetch them!
Create Transaction
Let’s whip up a transaction with some payment methods and a snazzy T-shirt product. Feel free to add more items (maybe a “Unicorn Horn”?) as long as it’s legal!
from naboopay.models import TransactionRequest, ProductModel, Wallet
request = TransactionRequest(
method_of_payment=[Wallet.WAVE, Wallet.ORANGE_MONEY, Wallet.FREE_MONEY],
products=[
ProductModel(
name="T-shirt",
category="clothing",
amount=10000,
quantity=1,
description="test description",
),
# Add more products here if you’re feeling fancy!
],
)
Synchronous
Create that transaction and see what you get:
from naboopay.models import TransactionResponse
response_sync: TransactionResponse = naboopay_client.transaction.create(request=request)
print(response_sync)
Asynchronous
Async creation because why wait around?
async def create_transaction_async():
response_async: TransactionResponse = await naboopay_async_client.transaction.create(request=request)
print(response_async)
return response_async
response_async = asyncio.run(create_transaction_async())
Delete Transaction
Got a transaction you don’t like? Let’s delete it using the order_id from the creation step.
Synchronous
Using the response_sync from above:
from naboopay.models import DeleteTransactionRequest
request_sync_delete = DeleteTransactionRequest(order_id=response_sync.order_id)
response_sync_delete = naboopay_client.transaction.delete(request=request_sync_delete)
print(response_sync_delete)
Asynchronous
Using the response_async from the async creation:
request_async_delete = DeleteTransactionRequest(order_id=response_async.order_id)
async def delete_transaction_async():
response_async_delete = await naboopay_async_client.transaction.delete(request=request_async_delete)
print(response_async_delete)
asyncio.run(delete_transaction_async())
Get Transactions
Want to see all your transactions or just one? Here’s how:
Synchronous
Fetch all transactions:
all_transactions_sync = naboopay_client.transaction.get_all()
print(all_transactions_sync)
Grab a single transaction using an order_id (we’ll use the first one from the list):
transaction_id = all_transactions_sync.transactions[0].order_id
one_transaction_sync = naboopay_client.transaction.get_one(order_id=transaction_id)
print(one_transaction_sync)
Asynchronous
All transactions, async style:
async def get_all_transactions_async():
all_transactions_async = await naboopay_async_client.transaction.get_all()
print(all_transactions_async)
asyncio.run(get_all_transactions_async())
One transaction, async style:
async def get_one_transaction_async():
one_transaction_async = await naboopay_async_client.transaction.get_one(order_id=transaction_id)
print(one_transaction_async)
asyncio.run(get_one_transaction_async())
Cashout
Let’s move some money with Wave and Orange Money. Pro tip: use your own phone number for testing unless you want to surprise sudoping01!
Cashout with Wave
Set up your cashout request:
from naboopay.models import CashOutRequest
request_wave: CashOutRequest = CashOutRequest(
full_name="sudoping01",
amount=10000,
phone_number=phone_number_1, # Don’t change this unless you’re testing sudoping01 likes it this way! 😂
)
Synchronous
Cash out and handle any hiccups:
try:
response_wave_sync = naboopay_client.cashout.wave(request=request_wave)
print(response_wave_sync)
except Exception as e:
print(f"Exception: {e}")
Asynchronous
Async cashout with error handling:
async def cashout_wave_async():
try:
response_wave_async = await naboopay_async_client.cashout.wave(request=request_wave)
print(response_wave_async)
except Exception as e:
print(f"Exception: {e}")
asyncio.run(cashout_wave_async())
Cashout with Orange Money
Another cashout, this time with Orange Money:
request_orange: CashOutRequest = CashOutRequest(
full_name="Djim Patrick Lo", # Hi Patrick! 😂
amount=100,
phone_number=phone_number_2, # Swap this out for testing, or Patrick might cash in!
)
Synchronous
try:
response_orange_sync = naboopay_client.cashout.orange_money(request=request_orange)
print(response_orange_sync)
except Exception as e:
print(f"Exception: {e}")
Asynchronous
async def cashout_orange_async():
try:
response_orange_async = await naboopay_async_client.cashout.orange_money(request=request_orange)
print(response_orange_async)
except Exception as e:
print(f"Exception: {e}")
asyncio.run(cashout_orange_async())
Wrapping Up
And there you have it a full workshop on using the NabooPay Python SDK! You’ve installed it, set up clients, and mastered account details, transactions, and cashouts both synchronously and asynchronously. Pretty cool, right? Feel free to tweak the code, explore more features, and keep the good vibes going. Good Integration 🫂!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file naboopay-1.0.2.tar.gz.
File metadata
- Download URL: naboopay-1.0.2.tar.gz
- Upload date:
- Size: 15.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c75033918a89fd8195f5e770e6e378f8a7ea3e87074bbf2e212e99d09279b94b
|
|
| MD5 |
0c48380f2cea6fd5b5f38be7817c2037
|
|
| BLAKE2b-256 |
d47f8a8c6078e44f976893d178648b6c3ced0b873226a704cd199c444616e244
|
File details
Details for the file naboopay-1.0.2-py3-none-any.whl.
File metadata
- Download URL: naboopay-1.0.2-py3-none-any.whl
- Upload date:
- Size: 14.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d39b74d654054c3a80877165552dab8a331b715a294bc82a40172307434d193
|
|
| MD5 |
9f4466e2fbaa679fba4d38898ea59d88
|
|
| BLAKE2b-256 |
ea78799c54d9d2919b2387c0d68ba3a1a4abd82dc5d7ecc212a5d66fe1bcce58
|