Process payment
This is a placeholder integration to demonstrate how you might connect to a payment gateway such as MTN Mobile Money or any other provider.
Demo notice: Replace this block with real payment gateway logic. No funds are collected in this example.
Payment summary
- Unit: Serenity Wellness Salon Suite
- Type: Salon
- Amount due: RWF 920,000
Below is a simplified example of how you might initiate an MTN Mobile Money request using cURL in PHP. Be sure to:
- Store API keys and secrets securely (e.g., environment variables).
- Validate webhook callbacks and handle retries.
- Log transaction statuses for reconciliation.
<?php
// Example MTN MoMo collection request
$apiHost = 'https://sandbox.momodeveloper.mtn.com';
$subscriptionKey = 'REPLACE_WITH_COLLECTION_PRIMARY_KEY'; // Set via environment variable
$accessToken = 'REPLACE_WITH_ACCESS_TOKEN'; // Request via OAuth client credentials
$payload = [
'amount' => '920,000.00',
'currency' => 'RWF',
'externalId' => 'BID-' . time(),
'payer' => [
'partyIdType' => 'MSISDN',
'partyId' => '250700000000', // Customer phone number
],
'payerMessage' => 'Inshuti Residence reservation',
'payeeNote' => 'Reservation fee',
];
$ch = curl_init($apiHost . '/collection/v1_0/requesttopay');
curl_setopt_array($ch, [
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Authorization: Bearer ' . $accessToken,
'X-Reference-Id: ' . uuid_create(UUID_TYPE_RANDOM),
'X-Target-Environment: sandbox', // Switch to "production" in live mode
'Ocp-Apim-Subscription-Key: ' . $subscriptionKey,
],
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($payload),
CURLOPT_RETURNTRANSFER => true,
]);
$response = curl_exec($ch);
if (curl_errno($ch)) {
// Handle transport error
}
curl_close($ch);
?>
Once the payment API confirms a successful transaction, redirect the client to a receipt page and update your database with the payment reference.