/**
* @Route ("/ipn")
* @Transactional
*
* Handles the incoming HTTP request
* @param array $params
*/
public function ipn(array $params)
{
$log = Application::instance()->getLogger();
try {
$ipnMessage = new PPIPNMessage();
if (!$ipnMessage->validate()) {
$log->error('Got a invalid IPN ' . json_encode($ipnMessage->getRawData()));
return new Response(Http::STATUS_ERROR, 'Got a invalid IPN');
}
$data = $ipnMessage->getRawData();
$log->info(sprintf('Got a valid IPN [txn_id: %s, txn_type: %s]', $ipnMessage->getTransactionId(), $data['txn_type']));
$orderService = OrdersService::instance();
$orderService->addIPNRecord(array('ipnTrackId' => $data['ipn_track_id'], 'ipnTransactionId' => $data['txn_id'], 'ipnTransactionType' => $data['txn_type'], 'ipnData' => json_encode($data, JSON_UNESCAPED_UNICODE)));
// Make sure this IPN is for the merchant
if (strcasecmp(Config::$a['commerce']['receiver_email'], $data['receiver_email']) !== 0) {
$log->critical(sprintf('IPN originated with incorrect receiver_email [%s]', $data['ipn_track_id']));
return new Response(Http::STATUS_ERROR, 'Invalid IPN');
}
// Handle the IPN
$this->handleIPNTransaction($data['txn_id'], $data['txn_type'], $data);
// Return success response
return new Response(Http::STATUS_OK);
} catch (\Exception $e) {
$log->critical($e->getMessage());
return new Response(Http::STATUS_ERROR, 'Error');
}
$log->critical('Unhandled IPN');
return new Response(Http::STATUS_ERROR, 'Unhandled IPN');
}