log_flg = 0;//0 : Not take log, 1 : take log /*********************************************************************************/ // Log-in Email $usces_paypal_business = "*********@********.***"; //PayPal URL $usces_paypal_url = "www.paypal.com"; /*********************************************************************************/ function paypal_check($usces_paypal_url) { /*********************************************************************************/ //Identity Token $auth_token = "**********************************************************"; /*********************************************************************************/ settlement_log('Start PDT'); // read the post from PayPal system and add 'cmd' $req = 'cmd=_notify-synch'; $tx_token = $_GET['tx']; $req .= '&tx=' . $tx_token . '&at=' . $auth_token; // post back to PayPal system to validate $header .= "POST /cgi-bin/webscr HTTP/1.1\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Host: " . $usces_paypal_url . "\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n"; $header .= "Connection: close\r\n\r\n"; $fp = fsockopen ('ssl://'.$usces_paypal_url, 443, $errno, $errstr, 30); $results = array(); if (!$fp) { $results[0] = false; settlement_log('connection error PDT'); } else { fputs ($fp, $header . $req); // read the body data $res = ''; $headerdone = false; while (!feof($fp)) { $line = fgets ($fp, 1024); if (strcmp($line, "\r\n") == 0) { // read the header $headerdone = true; }else if ($headerdone){ // header has been read. now read the contents $res .= $line; } } // parse the data $lines = explode("\n", $res); $keyarray = array(); if (strcmp ($lines[0], "SUCCESS") == 0) { $results[0] = true; for ($i=1; $i $value) { $value = urlencode(stripslashes($value)); $req .= '&' . $key . '=' . $value; } // post back to PayPal system to validate $header .= "POST /cgi-bin/webscr HTTP/1.1\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Host: " . $usces_paypal_url . "\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n"; $header .= "Connection: close\r\n\r\n"; $fp = fsockopen ('ssl://'.$usces_paypal_url, 443, $errno, $errstr, 30); $item_name = $_POST['item_name']; $item_number = $_POST['item_number']; $payment_status = $_POST['payment_status']; $payment_amount = $_POST['mc_gross']; $payment_currency = $_POST['mc_currency']; $txn_id = $_POST['txn_id']; $receiver_email = $_POST['receiver_email']; $payer_email = $_POST['payer_email']; $results = array(); if (!$fp) { $results[0] = false; settlement_log(__('IPN Connection Error', 'usces')); } else { fputs ($fp, $header . $req); // read the body data $res = ''; $headerdone = false; while (!feof($fp)) { $line = fgets ($fp, 1024); if (strcmp($line, "\r\n") == 0) { // read the header $headerdone = true; }else if ($headerdone){ // header has been read. now read the contents $res .= $line; } } // parse the data if (preg_match("/VERIFIED/mi", $res) == 1){ $results[0] = true; $results['payment_status'] = $payment_status; $ret = true; settlement_log('IPN[SUCCESS]'); }else{ $results[0] = false; settlement_log(__('IPN Refusal', 'usces') . "\n\t\t\t" . __("PayPal gives back 'FAIL'. Please confirm setting.", 'usces')); } // $lines = explode("\n", $res); // $keyarray = array(); // if (strcmp ($lines[0], "VERIFIED") == 0) { // $results[0] = true; // $results['payment_status'] = $payment_status; // $ret = true; // settlement_log('IPN[SUCCESS]'); // }else if (strcmp ($lines[0], "FAIL") == 0) { // $results[0] = false; // settlement_log(__('IPN Refusal', 'usces') . "\n\t\t\t" . __("PayPal gives back 'FAIL'. Please confirm setting.", 'usces')); // } fclose ($fp); } return $results; } function settlement_log($log){ global $usces; if(!$usces->log_flg) return; $log = date('[Y-m-d H:i:s]', current_time('timestamp')) . "\t" . $log . "\n"; $file = $usces->options['settlement_path'].'/paypal.log'; $fp = fopen($file, 'a'); fwrite($fp, $log); fclose($fp); } ?>