Beispiel #1
0
 /**
  * Post back to PayPal to check whether this request is a valid one
  *
  * @param Zend_Http_Client_Adapter_Interface $httpAdapter
  */
 protected function _postBack(Zend_Http_Client_Adapter_Interface $httpAdapter)
 {
     $postbackQuery = http_build_query($this->_request) . '&cmd=_notify-validate';
     $postbackUrl = $this->_config->getPaypalUrl();
     $this->_debugData['postback_to'] = $postbackUrl;
     $httpAdapter->setConfig(array('verifypeer' => $this->_config->verifyPeer));
     $httpAdapter->write(Zend_Http_Client::POST, $postbackUrl, '1.1', array('Connection: close'), $postbackQuery);
     try {
         $postbackResult = $httpAdapter->read();
     } catch (Exception $e) {
         $this->_debugData['http_error'] = array('error' => $e->getMessage(), 'code' => $e->getCode());
         throw $e;
     }
     /*
      * Handle errors on PayPal side.
      */
     $responseCode = Zend_Http_Response::extractCode($postbackResult);
     if (empty($postbackResult) || in_array($responseCode, array('500', '502', '503'))) {
         if (empty($postbackResult)) {
             $reason = 'Empty response.';
         } else {
             $reason = 'Response code: ' . $responseCode . '.';
         }
         $this->_debugData['exception'] = 'PayPal IPN postback failure. ' . $reason;
         throw new Mage_Paypal_UnavailableException($reason);
     }
     $response = preg_split('/^\\r?$/m', $postbackResult, 2);
     $response = trim($response[1]);
     if ($response != 'VERIFIED') {
         $this->_debugData['postback'] = $postbackQuery;
         $this->_debugData['postback_result'] = $postbackResult;
         throw new Exception('PayPal IPN postback failure. See ' . self::DEFAULT_LOG_FILE . ' for details.');
     }
 }
Beispiel #2
0
 /**
  * Post back to PayPal to check whether this request is a valid one
  *
  * @param Zend_Http_Client_Adapter_Interface $httpAdapter
  */
 protected function _postBack(Zend_Http_Client_Adapter_Interface $httpAdapter)
 {
     $sReq = '';
     foreach ($this->_request as $k => $v) {
         $sReq .= '&' . $k . '=' . urlencode(stripslashes($v));
     }
     $sReq .= "&cmd=_notify-validate";
     $sReq = substr($sReq, 1);
     $this->_debugData['postback'] = $sReq;
     $this->_debugData['postback_to'] = $this->_config->getPaypalUrl();
     $httpAdapter->write(Zend_Http_Client::POST, $this->_config->getPaypalUrl(), '1.1', array(), $sReq);
     try {
         $response = $httpAdapter->read();
     } catch (Exception $e) {
         $this->_debugData['http_error'] = array('error' => $e->getMessage(), 'code' => $e->getCode());
         throw $e;
     }
     $this->_debugData['postback_result'] = $response;
     $response = preg_split('/^\\r?$/m', $response, 2);
     $response = trim($response[1]);
     if ($response != 'VERIFIED') {
         throw new Exception('PayPal IPN postback failure. See ' . self::DEFAULT_LOG_FILE . ' for details.');
     }
     unset($this->_debugData['postback'], $this->_debugData['postback_result']);
 }
Beispiel #3
0
 /**
  * Post back to PayPal to check whether this request is a valid one
  *
  * @param Zend_Http_Client_Adapter_Interface $httpAdapter
  */
 protected function _postBack(Zend_Http_Client_Adapter_Interface $httpAdapter)
 {
     $postbackQuery = http_build_query($this->_request) . '&cmd=_notify-validate';
     $postbackUrl = $this->_config->getPaypalUrl();
     $this->_debugData['postback_to'] = $postbackUrl;
     $httpAdapter->write(Zend_Http_Client::POST, $postbackUrl, '1.1', array(), $postbackQuery);
     try {
         $postbackResult = $httpAdapter->read();
     } catch (Exception $e) {
         $this->_debugData['http_error'] = array('error' => $e->getMessage(), 'code' => $e->getCode());
         throw $e;
     }
     $response = preg_split('/^\\r?$/m', $postbackResult, 2);
     $response = trim($response[1]);
     if ($response != 'VERIFIED') {
         $this->_debugData['postback'] = $postbackQuery;
         $this->_debugData['postback_result'] = $postbackResult;
         throw new Exception('PayPal IPN postback failure. See ' . self::DEFAULT_LOG_FILE . ' for details.');
     }
 }
 /**
  * Get ipn data, send verification to PayPal, run corresponding handler
  */
 public function processIpnRequest()
 {
     if (!$this->_ipnFormData) {
         return;
     }
     // debug requested
     if ($this->_config->debugFlag) {
         Mage::getModel('paypal/api_debug')->setApiEndpoint($this->_config->getPaypalUrl())->setRequestBody(var_export($this->_ipnFormData, 1))->save();
     }
     $sReq = '';
     $sReqDebug = '';
     foreach ($this->_ipnFormData as $k => $v) {
         $sReq .= '&' . $k . '=' . urlencode(stripslashes($v));
         $sReqDebug .= '&' . $k . '=';
     }
     // append ipn command
     $sReq .= "&cmd=_notify-validate";
     $sReq = substr($sReq, 1);
     $http = new Varien_Http_Adapter_Curl();
     $http->write(Zend_Http_Client::POST, $this->_config->getPaypalUrl(), '1.1', array(), $sReq);
     $response = $http->read();
     // debug postback request & response
     if ($this->_config->debugFlag) {
         Mage::getModel('paypal/api_debug')->setApiEndpoint($this->_config->getPaypalUrl())->setRequestBody($sReq)->setResponseBody($response)->save();
     }
     if ($error = $http->getError()) {
         $this->_notifyAdmin(Mage::helper('paypal')->__('PayPal IPN postback HTTP error: %s', $error));
         return;
     }
     $response = preg_split('/^\\r?$/m', $response, 2);
     $response = trim($response[1]);
     if ($response == 'VERIFIED') {
         $this->processIpnVerified();
     } else {
         // TODO: possible PCI compliance issue - the $sReq may contain data that is supposed to be encrypted
         $this->_notifyAdmin(Mage::helper('paypal')->__('PayPal IPN postback Validation error: %s', $sReq));
     }
 }