Example 7: Multiple Payment Buttons
Creating multiple payment buttons on a single page (e.g., product catalog).
Important Note
The JavaScript script is loaded only once, even with multiple buttons. Each button has its own form with its own payment data.
Product Catalog
Premium Smartphone
High-end smartphone with AMOLED display
150 000 XOF
Laptop Computer
Professional 15-inch laptop
450 000 XOF
Tablet
10-inch tablet with stylus
80 000 XOF
Bluetooth Headphones
Wireless headphones with noise cancellation
25 000 XOF
Code Example
$products = [
["name" => "Premium Smartphone", "price" => 150000, ...],
["name" => "Laptop Computer", "price" => 450000, ...],
// ...
];
foreach ($products as $index => $product) {
$request = new AfribaPayRequest();
$request->description = $product["description"];
$request->amount = $product["price"];
// ... configure request
$buttonHtml = $sdk->createCheckoutButton($request, "Buy", "primary", "medium");
echo $buttonHtml;
}