Skip to content

Instantly share code, notes, and snippets.

@yickson
Created May 2, 2019 16:05
Show Gist options
  • Save yickson/ffea5932f658a8a12156dd1407b5193c to your computer and use it in GitHub Desktop.
Save yickson/ffea5932f658a8a12156dd1407b5193c to your computer and use it in GitHub Desktop.
Notificación de pago conciliado
$receiver_id = obtener-al-crear-una-cuenta-de-cobro;
$secret = 'obtener-al-crear-una-cuenta-de-cobro';
$api_version = 'obtener-desde-los-parametros'; // Parámetro api_version
$notification_token = 'obtener-desde-los-parametros'; //Parámetro notification_token
$amount = monto-original-del-cobro;
try {
if ($api_version == '1.3') {
$configuration = new Khipu\Configuration();
$configuration->setSecret($secret);
$configuration->setReceiverId($receiver_id);
// $configuration->setDebug(true);
$client = new Khipu\ApiClient($configuration);
$payments = new Khipu\Client\PaymentsApi($client);
$response = $payments->paymentsGet($notification_token);
if ($response->getReceiverId() == $receiver_id) {
if ($response->getStatus() == 'done' && $response->getAmount() == $amount) {
// marcar el pago como completo y entregar el bien o servicio
}
} else {
// receiver_id no coincide
}
} else {
// Usar versión anterior de la API de notificación
}
} catch (\Khipu\ApiException $exception) {
print_r($exception->getResponseObject());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment