PayPal\Ipn\PPIPNMessage::validate PHP Method

validate() public method

Validates a IPN message
public validate ( ) : boolean
return boolean
    public function validate()
    {
        if (isset($this->isIpnVerified)) {
            return $this->isIpnVerified;
        } else {
            $request = self::IPN_CMD;
            if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc() == 1) {
                $get_magic_quotes_exists = true;
            } else {
                $get_magic_quotes_exists = false;
            }
            foreach ($this->ipnData as $key => $value) {
                if ($get_magic_quotes_exists) {
                    $value = urlencode(stripslashes($value));
                } else {
                    $value = urlencode($value);
                }
                $request .= "&{$key}={$value}";
            }
            $httpConfig = new PPHttpConfig($this->setEndpoint());
            $httpConfig->addCurlOption(CURLOPT_FORBID_REUSE, 1);
            $httpConfig->addCurlOption(CURLOPT_HTTPHEADER, array('Connection: Close'));
            $connection = PPConnectionManager::getInstance()->getConnection($httpConfig, $this->config);
            $response = $connection->execute($request);
            if ($response == 'VERIFIED') {
                $this->isIpnVerified = true;
                return true;
            }
            $this->isIpnVerified = false;
            return false;
            // value is 'INVALID'
        }
    }

Usage Example

Example #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');
 }
All Usage Examples Of PayPal\Ipn\PPIPNMessage::validate