Пример #1
0
 /**
  * @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');
 }
Пример #2
0
 /**
  * @test
  */
 public function processIPNWithSpecialCharacters()
 {
     $ipnData = "description=Jake's store";
     ini_set('get_magic_quotes_gpc', true);
     $ipn = new PPIPNMessage($ipnData);
     $rawData = $ipn->getRawData();
     $this->assertEquals($rawData['description'], "Jake's store");
     ini_set('get_magic_quotes_gpc', false);
     $ipn = new PPIPNMessage($ipnData);
     $rawData = $ipn->getRawData();
     $this->assertEquals($rawData['description'], "Jake's store");
     $this->assertEquals($rawData['description'], "Jake's store");
 }
Пример #3
0
 public function processIpn(PPIPNMessage $ipnMessage)
 {
     $data = $ipnMessage->getRawData();
     if ($ipnMessage->validate()) {
         //Log PayPal Notifications
         $payPalLog = new PayPalIpnLog();
         $payPalLog->setLog(serialize($data));
         $payPalLog->save();
         $custom = $data['custom'];
         $transactionId = $data['txn_id'];
         $transactionType = $data['txn_type'];
         $paymentStatus = $data['payment_status'];
         $paypalTransaction = PaypalTransactionQuery::create()->findOneByCustom($custom);
         $paypalTransaction->setTransactionId($transactionId)->setTransactionType($transactionType)->setStatus($paymentStatus);
         $paypalTransaction->save();
         $payment = $paypalTransaction->getPayment();
         if ($paymentStatus == 'Completed') {
             $this->paymentBus->getCompletedHandler($payment)->process();
         } elseif ($paymentStatus == 'Failed') {
             $this->paymentBus->getFailedHandler($payment)->process();
         }
     } else {
         \Log::error("Error: Got invalid IPN data");
         \Log::error($data);
     }
     return \Response::make('', 200);
 }
Пример #4
0
<?php

use PayPal\IPN\PPIPNMessage;
/**
 * This is a sample implementation of an IPN listener
 * that uses the SDK's PPIPNMessage class to process IPNs
 * 
 * This sample simply validates the incoming IPN message
 * and logs IPN variables. In a real application, you will
 * validate the IPN and initiate some action based on the 
 * incoming IPN variables.
 */
require_once '../PPBootStrap.php';
// first param takes ipn data to be validated. if null, raw POST data is read from input stream
$ipnMessage = new PPIPNMessage(null, Configuration::getConfig());
foreach ($ipnMessage->getRawData() as $key => $value) {
    error_log("IPN: {$key} => {$value}");
}
if ($ipnMessage->validate()) {
    error_log("Success: Got valid IPN data");
} else {
    error_log("Error: Got invalid IPN data");
}