from djpaystack import PaystackClient
client = PaystackClient()response = client.transaction.initialize(
email='customer@example.com',
amount=50000, # in kobo
reference='unique-reference',
plan=None,
invoice_limit=None,
metadata=None,
subaccount=None,
currency=None,
split=None,
bearer=None
)response = client.transaction.verify(reference='unique-reference')
# or
response = client.transaction.verify(id=123456)response = client.transaction.list(
page=1,
per_page=50,
customer=None,
status=None,
from_date=None,
to_date=None
)response = client.transaction.fetch(id=123456)response = client.transaction.timeline(
reference='unique-reference',
id_type='reference' # or 'id'
)response = client.transaction.totals()response = client.transaction.export(
filename=None,
path=None
)response = client.customer.create(
email='customer@example.com',
first_name=None,
last_name=None,
phone=None
)response = client.customer.list(
page=1,
per_page=50
)response = client.customer.fetch(customer_code='CUS_xxxxx')
# or
response = client.customer.fetch(id=123)response = client.customer.update(
code='CUS_xxxxx',
first_name=None,
last_name=None,
email=None,
phone=None
)response = client.customer.whitelist(
action='whitelist', # or 'blacklist'
customer_code='CUS_xxxxx'
)response = client.plan.create(
name='Monthly Subscription',
description=None,
amount=500000, # in kobo
interval='monthly', # daily, weekly, monthly, quarterly, half-yearly, yearly
send_invoices=None,
send_sms=None,
hosted_invoice_url=None,
invoice_limit=None,
plan_code=None
)response = client.plan.list(
page=1,
per_page=50,
interval=None,
amount=None
)response = client.plan.fetch(plan_id=123)response = client.plan.update(
id=123,
name=None,
description=None,
amount=None,
interval=None,
send_invoices=None,
send_sms=None,
hosted_invoice_url=None,
invoice_limit=None
)response = client.subscription.create(
customer_code='CUS_xxxxx',
plan_code='PLN_xxxxx',
authorization_code='AUTH_xxxxx',
start_date=None
)response = client.subscription.list(
page=1,
per_page=50,
customer=None,
plan=None
)response = client.subscription.fetch(code='SUB_xxxxx')response = client.subscription.enable(
code='SUB_xxxxx',
token='tok_xxxxx'
)response = client.subscription.disable(code='SUB_xxxxx')response = client.transfer_recipient.create(
type='nuban', # or 'mobile_money', 'ghipss'
name='John Doe',
account_number='0000000000',
bank_code='001',
currency=None,
authorization_key=None
)response = client.transfer_recipient.list(
page=1,
per_page=50,
type=None
)response = client.transfer_recipient.fetch(recipient_code='RCP_xxxxx')response = client.transfer_recipient.update(
recipient_code='RCP_xxxxx',
name=None,
email=None,
description=None
)response = client.transfer_recipient.delete(recipient_code='RCP_xxxxx')response = client.transfer.initiate(
source='balance',
amount=50000,
recipient='RCP_xxxxx',
reference='transfer-ref-001',
reason=None,
currency=None
)response = client.transfer.finalize(
transfer_code='TRF_xxxxx',
otp='123456'
)response = client.transfer.list(
page=1,
per_page=50,
customer=None,
status=None
)response = client.transfer.fetch(transfer_code='TRF_xxxxx')response = client.transfer.verify(reference='transfer-ref-001')response = client.refund.create(
transaction=123456,
amount=None,
currency=None,
customer_note=None,
merchant_note=None
)response = client.refund.list(
page=1,
per_page=50,
reference=None,
currency=None
)response = client.refund.fetch(refund_id=123)response = client.verification.verify_account(
account_number='0000000000',
bank_code='001'
)response = client.verification.bvn(bvn='12345678901')response = client.verification.get_banks(
country=None,
use_cursor=None
)All endpoints return a dictionary:
{
'status': True, # or False
'message': 'Authorization URL generated',
'data': {
# Endpoint-specific data
}
}from djpaystack.exceptions import (
PaystackError,
PaystackAPIError,
PaystackValidationError,
PaystackAuthenticationError,
PaystackNetworkError,
)
try:
response = client.transaction.verify(reference='ref-123')
except PaystackAuthenticationError:
print('Invalid credentials')
except PaystackNetworkError:
print('Network error')
except PaystackAPIError as e:
print(f'API Error: {e}')PAYSTACK = {
# Required
'SECRET_KEY': 'sk_...',
'PUBLIC_KEY': 'pk_...',
# Optional - API
'BASE_URL': 'https://api.paystack.co',
'TIMEOUT': 30,
'MAX_RETRIES': 3,
'VERIFY_SSL': True,
# Optional - Webhooks
'WEBHOOK_SECRET': 'whsec_...',
'CALLBACK_URL': 'https://yoursite.com/callback/',
'ALLOWED_WEBHOOK_IPS': [],
# Optional - Environment
'ENVIRONMENT': 'production', # or 'test'
'CURRENCY': 'NGN',
# Optional - Features
'AUTO_VERIFY_TRANSACTIONS': True,
'CACHE_TIMEOUT': 300,
'LOG_REQUESTS': False,
'LOG_RESPONSES': False,
'ENABLE_SIGNALS': True,
'ENABLE_MODELS': True,
}from djpaystack import PaystackClient
client = PaystackClient()
# 1. Initialize transaction
init_response = client.transaction.initialize(
email='customer@example.com',
amount=100000, # 1000 NGN
reference='order-12345'
)
if init_response['status']:
auth_url = init_response['data']['authorization_url']
print(f"Redirect user to: {auth_url}")
# 2. After payment, verify transaction
verify_response = client.transaction.verify(reference='order-12345')
if verify_response['status'] and verify_response['data']['status'] == 'success':
print("Payment successful!")
amount = verify_response['data']['amount'] / 100
print(f"Amount paid: {amount} NGN")
else:
print("Payment failed!")# 1. Create customer
customer = client.customer.create(
email='recurring@example.com',
first_name='John'
)
# 2. Create plan
plan = client.plan.create(
name='Monthly Subscription',
amount=10000, # 100 NGN
interval='monthly',
plan_code='PLAN_MONTHLY'
)
# 3. Initialize transaction to get authorization
init = client.transaction.initialize(
email='recurring@example.com',
amount=10000,
reference='initial-transaction'
)
# User completes payment and returns
# 4. Get authorization
transaction = client.transaction.verify(reference='initial-transaction')
authorization = transaction['data']['authorization']
# 5. Create subscription
subscription = client.subscription.create(
customer_code=customer['data']['customer_code'],
plan_code='PLAN_MONTHLY',
authorization_code=authorization['authorization_code']
)For complete API documentation, visit Paystack API Docs