diff --git a/app/code/core/Mage/Paypal/Model/Ipn.php b/app/code/core/Mage/Paypal/Model/Ipn.php index 974a7eb339f..2409986964b 100644 --- a/app/code/core/Mage/Paypal/Model/Ipn.php +++ b/app/code/core/Mage/Paypal/Model/Ipn.php @@ -36,6 +36,20 @@ class Mage_Paypal_Model_Ipn */ const DEFAULT_LOG_FILE = 'paypal_unknown_ipn.log'; + /** + * Default postback endpoint URL. + * + * @var string + */ + const DEFAULT_POSTBACK_URL = 'https://ipnpb.paypal.com/cgi-bin/webscr'; + + /** + * Sandbox postback endpoint URL. + * + * @var string + */ + const SANDBOX_POSTBACK_URL = 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr'; + /** * Store order instance * @@ -133,14 +147,15 @@ public function processIpnRequest(array $request, Zend_Http_Client_Adapter_Inter */ protected function _postBack(Zend_Http_Client_Adapter_Interface $httpAdapter) { + $url = $this->_getPostbackUrl(); + $postbackQuery = http_build_query($this->_request) . '&cmd=_notify-validate'; - $postbackUrl = $this->_config->getPostbackUrl(); - $this->_debugData['postback_to'] = $postbackUrl; + $this->_debugData['postback_to'] = $url; $httpAdapter->setConfig(array('verifypeer' => $this->_config->verifyPeer)); $httpAdapter->write( Zend_Http_Client::POST, - $postbackUrl, + $url, '1.1', array('Connection: close'), $postbackQuery @@ -176,6 +191,16 @@ protected function _postBack(Zend_Http_Client_Adapter_Interface $httpAdapter) } } + /** + * Get postback endpoint URL. + * + * @return string + */ + protected function _getPostbackUrl() + { + return $this->_config->sandboxFlag ? self::SANDBOX_POSTBACK_URL : self::DEFAULT_POSTBACK_URL; + } + /** * Load and validate order, instantiate proper configuration *