PAR — Payment And Redirection
The PAR API is PayDunya's primary payment flow, recommended for 99% of use cases. You create an invoice, redirect the customer to PayDunya's payment page, and confirm the result afterward.
Workflow
- Build an invoice with items, taxes, customer info (optional)
- Set the total amount (PayDunya bills this exact amount)
- Call
invoice.create()— get atokenand a payment page URL (response_text) - Redirect the customer to the URL
- After payment, confirm via
invoice.confirm(token)or handle the IPN callback
Example
from paydunya import Invoice, InvoiceItem, PaydunyaClient, Store
client = PaydunyaClient(
master_key="your-master-key",
private_key="test_private_...",
token="your-token",
mode="test",
)
store = Store(name="My Shop")
items = [
InvoiceItem(
name="Croco shoes",
quantity=3,
unit_price="10000",
total_price="30000",
description="Genuine crocodile skin",
),
InvoiceItem(
name="Ice Shirt",
quantity=1,
unit_price="5000",
total_price="5000",
),
]
invoice = Invoice(client, store)
invoice.add_items(items)
invoice.add_tax("TVA (18%)", 6300)
invoice.add_tax("Delivery", 1000)
invoice.set_total_amount(42300)
invoice.set_description("Payment for items from My Shop")
response = invoice.create()
# response["response_text"] contains the payment page URL
# response["token"] is the invoice token for confirmation
# After the customer pays, confirm:
status = invoice.confirm(response["token"])
print(status["status"]) # pending, completed, cancelled, or failed
Customer Pre-fill
Pre-fill the name, email, and phone on the payment page:
invoice.set_customer(
name="John Doe",
email="john@example.com",
phone="771111111",
)
Restricting Payment Channels
invoice.add_channels(["card", "wave-senegal", "orange-money-senegal"])
Available channel slugs are in the introduction documentation.
Redirect URLs
invoice.set_cancel_url("https://my-shop.com/cancelled")
invoice.set_return_url("https://my-shop.com/thanks") # token appended as ?token=...
invoice.set_callback_url("https://my-shop.com/ipn") # IPN endpoint
Custom Data
Store extra data that is returned on confirmation but never displayed to the customer:
invoice.add_custom_data({
"cart_id": 97628,
"coupon": "SUMMER25",
})
Confirming an Invoice
result = invoice.confirm(token)
print(result["status"]) # pending, completed, cancelled, failed
print(result["customer"]) # customer info filled during payment
print(result["receipt_url"]) # PDF receipt URL
print(result["invoice"]) # full invoice data
print(result["custom_data"]) # your stored custom data
print(result["hash"]) # SHA-512 of your master key — verify via verify_ipn_hash()