PSR — Payment Without Redirection
The PSR API enables customers to pay directly on your website without being redirected to PayDunya's payment page, using a JavaScript popup.
How It Works
- Your server creates a checkout invoice (same as PAR) and exposes an endpoint that returns the payment token as JSON
- Your frontend includes PayDunya's JavaScript library and a "Pay" button
- When clicked, the JS fetches the token from your endpoint and opens a payment popup on your site
Server-Side (Flask/Django/FastAPI Example)
from flask import Flask, jsonify
from paydunya import Invoice, InvoiceItem, PaydunyaClient, Store
app = Flask(__name__)
client = PaydunyaClient(
master_key="your-master-key",
private_key="test_private_...",
token="your-token",
mode="test",
)
@app.route("/paydunya-api")
def paydunya_api():
store = Store(name="My Shop")
invoice = Invoice(client, store)
invoice.set_total_amount(5000)
invoice.set_description("MacBook Pro")
result = invoice.create()
return jsonify({
"success": True,
"mode": "test", # only in test mode
"token": result["token"],
})
The endpoint must return JSON with success, token, and (in test mode) mode.
Client-Side (HTML/JS)
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/venobox/1.8.2/venobox.min.css">
<button class="pay" onclick="payWithPaydunya(this)"
data-ref="102"
data-fullname="Alioune Faye"
data-email="alioune@example.com"
data-phone="774563209">
Buy MacBook Pro (2,000,000 FCFA)
</button>
<script src="https://code.jquery.com/jquery.min.js"></script>
<script src="https://paydunya.com/js/paydunya2.min.js"></script>
<script>
function payWithPaydunya(btn) {
PayDunya.setup({
selector: $(btn),
url: "https://your-domain.com/paydunya-api",
method: "GET",
displayMode: PayDunya.DISPLAY_IN_POPUP,
onTerminate: function(ref, token, status) {
console.log("Ref:", ref, "Token:", token, "Status:", status);
// status: pending, completed, failed, cancelled
},
onError: function(error) {
console.error("Error:", error);
},
}).requestToken();
}
</script>
Attributes (Optional)
On the button element:
- data-ref — your reference identifier for this payment
- data-fullname — pre-fill the payer's name
- data-email — pre-fill the payer's email
- data-phone — pre-fill the payer's phone
Reference
See the full PSR API documentation for all options.