Official PHP SDK for the MonCashConnect payment platform.
Note: MonCashConnect is not affiliated with Digicel or the official MonCash service.
- PHP 7.4+
ext-curlext-json
composer require moncashconnect/php-sdkuse MonCashConnect\Client;
use MonCashConnect\Exception\MonCashException;
$client = new Client($_ENV['MCC_SECRET_KEY']);
try {
$payment = $client->createPayment(1500, 'ORDER-001', [
'return_url' => 'https://yoursite.com/payment/success',
'customer_name' => 'Jean Dupont',
]);
// Redirect the customer to MonCash
header('Location: ' . $payment['paymentUrl']);
exit;
} catch (MonCashException $e) {
echo 'Payment error: ' . $e->getMessage();
}Your secret key starts with sk_proj_ — get it from Developer → Projects in your dashboard.
$tx = $client->getPaymentStatus('ORDER-001');
echo $tx['status']; // "pending" | "completed" | "failed"
echo $tx['netAmount']; // Amount after commission deduction$balance = $client->getBalance();
echo $balance['balanceHtg']; // Total available
echo $balance['withdrawableHtg']; // Can withdraw nowConfigure a webhook URL in your project. MonCashConnect sends a signed POST when a payment is finalized.
Always read the raw body before any json_decode().
use MonCashConnect\Webhook;
use MonCashConnect\Exception\MonCashException;
$rawBody = file_get_contents('php://input');
$signature = $_SERVER['HTTP_X_MCC_SIGNATURE'] ?? '';
$timestamp = $_SERVER['HTTP_X_MCC_TIMESTAMP'] ?? '';
try {
$event = Webhook::constructEvent(
$rawBody,
$signature,
$timestamp,
$_ENV['MCC_WEBHOOK_SECRET']
);
} catch (MonCashException $e) {
http_response_code($e->getCode() ?: 400);
exit($e->getMessage());
}
switch ($event['event']) {
case 'payment.completed':
// Mark order as paid in your database
markOrderPaid($event['reference']);
break;
case 'payment.failed':
// Handle failure
markOrderFailed($event['reference']);
break;
}
http_response_code(200);
echo 'OK';// routes/api.php
Route::post('/webhooks/moncash', [MonCashWebhookController::class, 'handle']);
// app/Http/Controllers/MonCashWebhookController.php
public function handle(Request $request): Response
{
$event = Webhook::constructEvent(
$request->getContent(),
$request->header('X-MCC-Signature', ''),
$request->header('X-MCC-Timestamp', ''),
config('services.moncash.webhook_secret')
);
if ($event['event'] === 'payment.completed') {
Order::where('reference', $event['reference'])->update(['status' => 'paid']);
}
return response('OK');
}catch (MonCashException $e) {
$e->getMessage(); // "referenceId already exists for this project"
$e->getCode(); // HTTP status: 400, 401, 409, 429, 502…
$e->getContext(); // Full API response array, or null
}MIT