// เช็คข้อมูลการชำระเงินจาก email // ipn message จากระบบของ paypal public function callback(){ // read the IPN msg from PayPal and add 'cmd' for your verification request $req = 'cmd=_notify-validate'; // append the IPN msg, in NVP format, to your verification request foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } // set up the headers for your verification request // POST your verification requests to PayPal (here, the Sandbox) $header = "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= "Host: www.sandbox.paypal.com:443\r\n"; // $header .= "Host: ipnpb.paypal.com:443\r\n"; // endpoint for Live apps $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; // open the socket $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30); // for live applications, use: // $fp = fsockopen ('ssl://ipnpb.paypal.com', 443, $errno, $errstr, 30); $ipn_response = ''; if (!$fp) { // HTTP error echo "HTTP socket error! Unable to open URL"; } else { // POST verification request fputs ($fp, $header . $req); while(!feof($fp)) { $ipn_response .= fgets($fp, 1024); } if( preg_match("/VERIFIED/", $ipn_response) ){ $msg = "ok"; $custom = isset($_POST['custom']) ? $_POST['custom'] : ''; // ยืนยันออเดอร์ ชำระเงินผ่านทาง paypal // $this->order_model->confirm_order( $order_id ); }else{ $msg = "not ok"; } } }