<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.notchpay.co/payments');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'amount' => 5000,
'currency' => 'XAF',
'customer' => [
'email' => 'customer@example.com'
]
]));
$headers = [
'Authorization: YOUR_PUBLIC_KEY',
'Content-Type: application/json'
];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
if ($data['code'] >= 200 && $data['code'] < 300) {
// Success
echo "Success: " . $data['message'] . "\n";
echo "Payment ID: " . $data['data']['id'] . "\n";
echo "Authorization URL: " . $data['data']['authorization_url'] . "\n";
} else {
// Error
echo "Error: " . $data['message'] . "\n";
if (isset($data['errors'])) {
echo "Validation errors:\n";
foreach ($data['errors'] as $field => $errors) {
echo "- $field: " . implode(', ', $errors) . "\n";
}
}
}