Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // CONFIG: Enable debug mode. This means we'll log requests into 'ipn.log' in the same directory.
- // Especially useful if you encounter network errors or other intermittent problems with IPN (validation).
- // Set this to 0 once you go live or don't require logging.
- define("DEBUG", 1);
- // Set to 0 once you're ready to go live
- define("USE_SANDBOX", 0);
- define("LOG_FILE", "./ipn.log");
- define("LOG_FILE_ERRORS", "./errors.log");
- define("LOG_FILE_ATF", "./errorsatf.log");
- //init vars
- //$receiver_email = "paypal@nutrio2.com";
- $receiver_id = "AZHAU5PH9YUA2";
- // Read POST data
- // reading posted data directly from $_POST causes serialization
- // issues with array data in POST. Reading raw POST data from input stream instead.
- $raw_post_data = file_get_contents('php://input');
- $raw_post_array = explode('&', $raw_post_data);
- $myPost = array();
- foreach ($raw_post_array as $keyval) {
- $keyval = explode ('=', $keyval);
- if (count($keyval) == 2)
- $myPost[$keyval[0]] = urldecode($keyval[1]);
- }
- // read the post from PayPal system and add 'cmd'
- $req = 'cmd=_notify-validate';
- if(function_exists('get_magic_quotes_gpc')) {
- $get_magic_quotes_exists = true;
- }
- foreach ($myPost as $key => $value) {
- if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
- $value = urlencode(stripslashes($value));
- } else {
- $value = urlencode($value);
- }
- $req .= "&$key=$value";
- }
- error_log(date('[Y-m-d H:i e] '). "IPN fired: $req" . PHP_EOL, 3, LOG_FILE);
- // Post IPN data back to PayPal to validate the IPN data is genuine
- // Without this step anyone can fake IPN data
- if(USE_SANDBOX == true) {
- $paypal_url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
- } else {
- $paypal_url = "https://www.paypal.com/cgi-bin/webscr";
- }
- $ch = curl_init($paypal_url);
- if ($ch == FALSE) {
- //LOGS all FALSE IPNs
- error_log(date('[Y-m-d H:i e] '). "FALSE IPN: $req" . PHP_EOL, 3, LOG_FILE);
- return FALSE;
- }
- curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
- curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
- if(DEBUG == true) {
- curl_setopt($ch, CURLOPT_HEADER, 1);
- curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
- }
- // CONFIG: Optional proxy configuration
- //curl_setopt($ch, CURLOPT_PROXY, $proxy);
- //curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
- // Set TCP timeout to 30 seconds
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
- // CONFIG: Please download 'cacert.pem' from "http://curl.haxx.se/docs/caextract.html" and set the directory path
- // of the certificate as shown below. Ensure the file is readable by the webserver.
- // This is mandatory for some environments.
- //$cert = __DIR__ . "./cacert.pem";
- //curl_setopt($ch, CURLOPT_CAINFO, $cert);
- $res = curl_exec($ch);
- if (curl_errno($ch) != 0) // cURL error
- {
- if(DEBUG == true) {
- error_log(date('[Y-m-d H:i e] '). "Can't connect to PayPal to validate IPN message: " . curl_error($ch) . PHP_EOL, 3, LOG_FILE);
- }
- curl_close($ch);
- exit;
- } else {
- // Log the entire HTTP response if debug is switched on.
- if(DEBUG == true) {
- error_log(date('[Y-m-d H:i e] '). "HTTP request of validation request:". curl_getinfo($ch, CURLINFO_HEADER_OUT) ." for IPN payload: $req" . PHP_EOL, 3, LOG_FILE);
- error_log(date('[Y-m-d H:i e] '). "HTTP response of validation request: $res" . PHP_EOL, 3, LOG_FILE);
- }
- curl_close($ch);
- }
- // Inspect IPN validation result and act accordingly
- // Split response headers and payload, a better way for strcmp
- $tokens = explode("\r\n\r\n", trim($res));
- $res = trim(end($tokens));
- if (strcmp ($res, "VERIFIED") == 0) {
- // check whether the payment_status is Completed
- // check that txn_id has not been previously processed
- // check that receiver_email is your PayPal email
- // check that payment_amount/payment_currency are correct
- // process payment and mark item as paid.
- //check based on secure merchant id (receiver_id)
- //error_log(date('[Y-m-d H:i e] '). "receiver email ".$_POST['receiver_email']. PHP_EOL, 3, LOG_FILE);
- // assign posted variables to local variables
- //$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'];
- //$transaction_id = $_POST['txn_id'];
- //$payerid = $_POST['payer_id'];
- //$firstname = $_POST['first_name'];
- //$lastname = $_POST['last_name'];
- //$payeremail = $_POST['payer_email'];
- $paymentstatus = $_POST['payment_status'];
- $mdate= date('Y-m-d h:i:s',strtotime($paymentdate));
- $otherstuff = json_encode($_POST);
- $path = $_SERVER['DOCUMENT_ROOT'] . "/scripts/lib/includes.php";
- require_once($path);
- //this is a recurring_payment_profile txn
- if (strpos($_POST["txn_type"],'recurring_payment_profile') !== false) {
- $txn_id = $_POST["initial_payment_txn_id"];
- $mc_gross = $_POST['initial_payment_amount'];
- $payment_status = $_POST["initial_payment_status"];
- $paymentdate = "0000-00-00 00:00:00";
- $nextpaymentdate = $_POST['next_payment_date'];
- $thispaymentdate = date("F j, Y, g:i a", strtotime($nextpaymentdate));
- $profileId = $_POST["recurring_payment_id"];
- $path = $_SERVER['DOCUMENT_ROOT'] . "/scripts/lib/Lionite/Paypal.php";
- require_once($path);
- $paypal = new Lionite_Paypal();
- //Set sandbox mode
- if(USE_SANDBOX == true) {
- $paypal_sb = true;
- } else {
- $paypal_sb = false;
- }
- Lionite_Paypal::sandbox($paypal_sb);
- $details = $paypal -> getRecurringProfile($profileId);
- // Details found
- if(is_array($details)) {
- $ship_fname = $details["name"];
- $ship_lname = "-";
- $ship_address1 = $details["shipping_street"];
- $ship_address2 = "";
- $ship_city = $details["shipping_city"];
- $ship_zip = $details["shipping_zip"];
- $ship_state = $details["shipping_state"];
- $ship_country = $details["shipping_country_name"];
- $ship_country_code = $details["shipping_country_code"];
- $ship_phone = '00000000';
- $ship_email = $_POST["payer_email"];
- $currency = $_POST["currency_code"];
- $amount = 1;
- //uses rp_invoice_id or profile_reference because recurring profiles have no other fields
- //$ip = $_POST["rp_invoice_id"];
- //parse custom to get things like IP
- parse_str($_POST["rp_invoice_id"]);
- $ip = $ip;
- }
- //this is a regular txn
- } else {
- $txn_id = $_POST["txn_id"];
- $payment_status = $_POST["payment_status"];
- $mc_gross = $_POST['mc_gross'];
- $paymentdate = $_POST['payment_date'];
- $product_name = isset($_POST['product_name'])?$_POST['product_name']:'';
- $nextpaymentdate = "0000-00-00 00:00:00";
- $thispaymentdate = date("F j, Y, g:i a", strtotime($paymentdate));
- //parse custom to get things like IP
- parse_str($_POST["custom"]);
- // Prepare variables (for fulfillment)
- $ship_fname = $_POST["address_name"];
- $ship_lname = "-";
- $ship_address1 = $_POST["address_street"];
- $ship_address2 = "";
- $ship_city = $_POST["address_city"];
- $ship_zip = $_POST["address_zip"];
- $ship_state = $_POST["address_state"];
- $ship_country = $_POST["address_country"];
- $ship_country_code = $_POST["address_country_code"];
- $ship_phone = '8888888';
- $ship_email = $_POST["payer_email"];
- $currency = $_POST["mc_currency"];
- $amount = 1;
- $ip = $ip;
- }
- $parent_txn_id = '';
- if (isset($_POST['parent_txn_id'])){
- $parent_txn_id = $_POST['parent_txn_id'];
- }
- $sql = "INSERT INTO ipns (
- parent_txn_id,
- txn_id,
- recurring_payment_id,
- txn_type,
- custom,
- payment_type,
- payment_date,
- next_payment_date,
- payment_status,
- profile_status,
- product_name,
- first_name,
- last_name,
- payer_email,
- payer_id,
- address_name,
- address_country,
- address_country_code,
- address_zip,
- address_state,
- address_city,
- address_street,
- business,
- receiver_email,
- receiver_id,
- residence_country,
- item_name1,
- item_number1,
- quantity,
- shipping,
- tax,
- mc_currency,
- mc_fee,
- mc_gross,
- mc_gross1,
- invoice,
- ip,
- ieverything_else)
- VALUES (
- '".trim($parent_txn_id)."',
- '".trim($txn_id)."',
- '".trim($_POST["recurring_payment_id"])."',
- '".trim($_POST["txn_type"])."',
- '".trim($_POST["custom"])."',
- '".trim($_POST["payment_type"])."',
- '".trim(date('Y-m-d H:i:s', strtotime($paymentdate)))."',
- '".trim(date('Y-m-d H:i:s', strtotime($nextpaymentdate)))."',
- '".trim($payment_status)."',
- '".trim($_POST["profile_status"])."',
- '".trim($_POST["product_name"])."',
- '".trim($_POST["first_name"])."',
- '".trim($_POST["last_name"])."',
- '".trim($_POST["payer_email"])."',
- '".trim($_POST["payer_id"])."',
- '".trim($ship_fname)."',
- '".trim($ship_country)."',
- '".trim($ship_country_code)."',
- '".trim($ship_zip)."',
- '".trim($ship_state)."',
- '".trim($ship_city)."',
- '".addslashes($ship_address1)."',
- '".trim($_POST["business"])."',
- '".trim($_POST["receiver_email"])."',
- '".trim($_POST["receiver_id"])."',
- '".trim($_POST["residence_country"])."',
- '".trim($_POST["item_name1"])."',
- '".trim($_POST["item_number1"])."',
- '".trim($_POST["quantity"])."',
- '".trim($_POST["shipping"])."',
- '".trim($_POST["tax"])."',
- '".trim($currency)."',
- '".trim($_POST["mc_fee"])."',
- '".trim($mc_gross)."',
- '".trim($_POST["mc_gross1"])."',
- '".trim($_POST["invoice"])."',
- '".trim($ip)."',
- '".addslashes(print_r($otherstuff,true))."')";
- //debug sql
- //error_log(date('[Y-m-d H:i e] '). "SQL: " . $sql . PHP_EOL, 3, LOG_FILE);
- $result = mysql_query($sql);
- //only post shipment when payment is completed (for creation of recurring billing profile, or for recurring/instant payments)
- if ( trim($payment_status)=="Completed" ) {
- $path = $_SERVER['DOCUMENT_ROOT'] . "/scripts/lib/ATF/ATF.php";
- require_once($path);
- // Create the client instance
- $atf = new atf();
- $date = date("m/d/Y"); //'02/22/2012'
- $time = date("h:ia"); //'02:01am'
- $orderID = $txn_id;
- $total = $mc_gross;
- //gets the pname depending on the transaction
- if ($_POST["item_name1"]!="") {
- //this is for all instant payments
- $pname = $_POST["item_name1"];
- } else if ($_POST["product_name"]!="") {
- //this is likely for recurring profile CREATED
- $pname = $_POST["product_name"];
- } else if ($details["desc"]!="") {
- //this grabs desc from the recurring profile
- $pname = $details["desc"];
- }
- //from the pname, extract the sku
- preg_match("/\(([^\)]*)\)/", $pname, $aMatches);
- $psku = $aMatches[1];
- error_log(date('[Y-m-d H:i e] '). "ATF vars: ". $orderID."|".
- $date."|".
- $time."|".
- $total."|".
- $ship_fname."|".
- $ship_lname."|".
- $ship_address1."|".
- $ship_address2."|".
- $ship_city."|".
- $ship_zip."|".
- $ship_state."|".
- $ship_country."|".
- $ship_phone."|".
- $ship_email."|".
- $psku."|".
- $amount."|".
- $ip. PHP_EOL, 3, LOG_FILE_ATF);
- // Sets city, state, zip to the country if they are unset
- if ($ship_city =="") { $ship_city = $ship_country; }
- if ($ship_zip =="") { $ship_zip = $ship_country; }
- if ($ship_state =="") { $ship_state = $ship_country; }
- // Post shipment
- $callresult = $atf->postShipment(
- cleanText($orderID),
- cleanText($date),
- cleanText($time),
- cleanText($total),
- cleanText($ship_fname),
- cleanText($ship_lname),
- cleanText($ship_address1),
- cleanText($ship_address2),
- cleanText($ship_city),
- cleanText($ship_zip),
- cleanText($ship_state),
- cleanText($ship_country),
- cleanText($ship_phone),
- cleanText($ship_email),
- cleanText($psku),
- cleanText($amount),
- cleanText($ip)
- );
- error_log(date('[Y-m-d H:i e] '). "ATF call: ". print_r($callresult,true). PHP_EOL, 3, LOG_FILE_ATF);
- /*******************************************
- Process ad tracking pixels
- ********************************************/
- //do this for monthly recurring payments
- if ($psku==$SKU_NUTRI1Monthly) {
- $adURL = "http://www.nutrifrontier.net/track/a.php?type=sale&value=129.95&id=10&name=Nutrio2+Re-engage+6+bottles&description=";
- } else {
- $adURL = "";
- }
- if ($adURL!="") {
- doCURL($adURL);
- }
- /*******************************************
- Emails the customer
- ********************************************/
- $path = $_SERVER['DOCUMENT_ROOT'] . "/scripts/lib/PHPMailer/PHPMailerAutoload.php";
- require_once($path);
- //this includes the email body
- $path = $_SERVER['DOCUMENT_ROOT'] . "/scripts/lib/include-email.php";
- require_once($path);
- $mail = new PHPMailer;
- //$mail->SMTPDebug = 3; // Enable verbose debug output
- $mail->isSMTP(); // Set mailer to use SMTP
- $mail->Host = 'host.successvantage.com'; // Specify main and backup SMTP servers
- $mail->SMTPAuth = true; // Enable SMTP authentication
- $mail->Username = 'noreply@realhealthsciences.com'; // SMTP username
- $mail->Password = ',5iXeF.9J,4u'; // SMTP password
- $mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
- $mail->Port = 465; // TCP port to connect to
- $mail->From = 'noreply@realhealthsciences.com';
- $mail->FromName = 'Real Health Sciences';
- //$mail->addAddress('joe@example.net', 'Joe User'); // Add a recipient
- $mail->addAddress($_POST["payer_email"]); // Name is optional
- //$mail->addReplyTo('info@example.com', 'Information');
- //$mail->addCC('cc@example.com');
- $mail->addBCC('mentismarketing.support@gmail.com');
- //***************
- $mail->isHTML(true); // Set email format to HTML
- $mail->Subject = 'Renew Order '.$txn_id;
- $mail->Body = getEmail( $txn_id,
- $thispaymentdate,
- $_POST["first_name"],
- $_POST["last_name"],
- $ship_fname,
- $ship_address1,
- $ship_city,
- $ship_state,
- $ship_zip,
- $ship_country,
- $psku,
- $pname,
- $mc_gross,
- $currency );
- //$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
- /********************
- * hasoffers postback
- ********************/
- if( isset($hasoffers_cookie) ){
- $hasOffersURL = "http://tracking.gomagnesium-at.com/aff_goal?a=lsr";
- //Add goal id is there is one
- isset($hasoffers_goal) ? $hasOffersURL .= "&goal_id=".$hasoffers_goal : '';
- //Add transaction ID
- $hasOffersURL .= "&transaction_id=".$hasoffers_cookie;
- //Add Advertiser Sub IDs
- $hasOffersURL .= "";
- $hasOffersURL .= (isset($aff_sub1) && $aff_sub1 != '')?"&adv_sub=".$aff_sub1:'';
- $hasOffersURL .= (isset($aff_sub2) && $aff_sub2 != '')?"&adv_sub2=".$aff_sub2:'';
- $hasOffersURL .= (isset($aff_sub3) && $aff_sub3 != '')?"&adv_sub3=".$aff_sub3:'';
- $hasOffersURL .= (isset($aff_sub4) && $aff_sub4 != '')?"&adv_sub4=".$aff_sub4:'';
- $hasOffersURL .= (isset($aff_sub5) && $aff_sub5 != '')?"&adv_sub5=".$aff_sub5:'';
- $hasoffers_result = doCURL($hasOffersURL);
- $ho_fh = fopen("holog.txt","a");
- fwrite($ho_fh, $hasoffers_result.' '.$hasOffersURL.' '.$_POST["custom"]);
- fclose($ho_fh);
- if(strpos( $hasoffers_result, 'success=true;') === false ){
- error_log(date('[Y-m-d H:i e] '). "HasOffers postback failed for txn: $hasoffers_cookie\nData:$hasoffers_result\n\n". PHP_EOL, 3, LOG_FILE_ERRORS);
- }
- }else{
- preg_match("/\((.*)\)/",$product_name,$matches);
- $conversionSKU = $matches[1];
- $sub_id = (isset($aff_sub1) && $aff_sub1 != '')?$aff_sub1:'';
- $sub_id2 = (isset($aff_sub2) && $aff_sub2 != '')?$aff_sub2:'';
- $sub_id3 = (isset($aff_sub3) && $aff_sub3 != '')?$aff_sub3:'';
- $sub_id4 = (isset($aff_sub4) && $aff_sub4 != '')?$aff_sub4:'';
- $sub_id5 = (isset($aff_sub5) && $aff_sub5 != '')?$aff_sub5:'';
- $args = array(
- 'NetworkId' => 'hvaffiliates',
- 'Target' => 'Conversion',
- 'Method' => 'create',
- 'NetworkToken' => 'NETj0R7lVEL8BJ35JdY5lv5jtZM89M',
- 'data' => array(
- 'ip' => $ip,
- 'offer_id' => '29',
- 'status' => 'approved',
- 'revenue' => $_POST['mc_gross'],
- 'goal_id' => $hasoffers_goal,
- 'payout' => $_POST['mc_gross'],
- 'affiliate_info1' => $sub_id,
- 'affiliate_info2' => $sub_id2,
- 'affiliate_info3' => $sub_id3,
- 'affiliate_info4' => $sub_id4,
- 'affiliate_info5' => $sub_id5,
- 'affiliate_id' => '1'
- ),
- 'return_object' => '1'
- );
- // Initialize cURL
- $curlHandle = curl_init();
- // Configure cURL request
- curl_setopt($curlHandle, CURLOPT_URL, "https://api.hasoffers.com/Apiv3/json");
- // Configure POST
- curl_setopt($curlHandle, CURLOPT_POST, 1);
- curl_setopt($curlHandle, CURLOPT_POSTFIELDS, http_build_query($args));
- // Make sure we can access the response when we execute the call
- curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
- // Execute the API call
- $jsonEncodedApiResponse = curl_exec($curlHandle);
- // Ensure HTTP call was successful
- if($jsonEncodedApiResponse === false) {
- $ho_fh = fopen("holog.txt","a");
- fwrite($ho_fh, $jsonEncodedApiResponse."WOOT\n");
- fclose($ho_fh);
- }
- else{
- // Decode the response from a JSON string to a PHP associative array
- $apiResponse = json_decode($jsonEncodedApiResponse, true);
- // Make sure we got back a well-formed JSON string and that there were no
- // errors when decoding it
- $jsonErrorCode = json_last_error();
- if($jsonErrorCode !== JSON_ERROR_NONE) {
- $ho_fh = fopen("holog.txt","a");
- fwrite($ho_fh, $jsonErrorCode);
- fclose($ho_fh);
- }
- // Print out the response details
- if($apiResponse['response']['status'] === 1) {
- // No errors encountered
- file_put_contents('hosuccess.txt', print_r($apiResponse['response']['data'], true));
- }
- else {
- file_put_contents('hoerrors.txt', print_r($apiResponse['response']['errors'], true));
- }
- $query = "UPDATE ipns SET hasOffersId='".$apiResponse['response']['data']['Conversion']['id']."' WHERE txn_id='".trim($txn_id)."'";
- }
- // Clean up the resource now that we're done with cURL
- curl_close($curlHandle);
- }
- if(!$mail->send()) {
- echo 'Message could not be sent.';
- error_log(date('[Y-m-d H:i e] '). "Mailer Error: " . $mail->ErrorInfo . PHP_EOL, 3, LOG_FILE_ERRORS);
- } else {
- echo 'Message has been sent';
- }
- }
- else if(trim($payment_status)=="Refunded"){
- $ho_fh = fopen("holog.txt","a");
- fwrite($ho_fh, $raw_post_data." ".$hasoffers_cookie);
- fclose($ho_fh);
- if(isset($hasoffers_cookie)){
- $args = array(
- 'NetworkId' => 'hvaffiliates',
- 'Target' => 'Conversion',
- 'Method' => 'update',
- 'NetworkToken' => 'NETj0R7lVEL8BJ35JdY5lv5jtZM89M',
- 'data' => array(
- 'revenue' => '0.00'
- ),
- 'transaction_id' => $hasoffers_cookie
- );
- }else{
- $query = "SELECT hasOffersId FROM ipns WHERE txn_id='".trim($txn_id)."' ORDER BY id ASC LIMIT 1";
- $result = mysql_query($query);
- if($result){
- $row = mysql_fetch_assoc($result);
- $conversionId = $row["hasOffersId"];
- }else{
- error_log(date('[Y-m-d H:i e] '). "MySQL Refund Error: " . trim($txn_id) . PHP_EOL, 3, LOG_FILE_ERRORS);
- }
- $args = array(
- 'NetworkId' => 'hvaffiliates',
- 'Target' => 'Conversion',
- 'Method' => 'update',
- 'NetworkToken' => 'NETj0R7lVEL8BJ35JdY5lv5jtZM89M',
- 'id' => $conversionId,
- 'data' => array(
- 'status' => 'rejected'
- )
- );
- }
- // Initialize cURL
- $curlHandle = curl_init();
- // Configure cURL request
- curl_setopt($curlHandle, CURLOPT_URL, "https://api.hasoffers.com/Apiv3/json");
- // Configure POST
- curl_setopt($curlHandle, CURLOPT_POST, 1);
- curl_setopt($curlHandle, CURLOPT_POSTFIELDS, http_build_query($args));
- // Make sure we can access the response when we execute the call
- curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
- // Execute the API call
- $jsonEncodedApiResponse = curl_exec($curlHandle);
- // Ensure HTTP call was successful
- if($jsonEncodedApiResponse === false) {
- $ho_fh = fopen("holog.txt","a");
- fwrite($ho_fh, $jsonEncodedApiResponse."WOOT");
- fclose($ho_fh);
- }
- // Clean up the resource now that we're done with cURL
- curl_close($curlHandle);
- // Decode the response from a JSON string to a PHP associative array
- $apiResponse = json_decode($jsonEncodedApiResponse, true);
- // Make sure we got back a well-formed JSON string and that there were no
- // errors when decoding it
- $jsonErrorCode = json_last_error();
- if($jsonErrorCode !== JSON_ERROR_NONE) {
- $ho_fh = fopen("holog.txt","a");
- fwrite($ho_fh, $jsonErrorCode);
- fclose($ho_fh);
- }
- // Print out the response details
- if($apiResponse['response']['status'] === 1) {
- // No errors encountered
- file_put_contents('hosuccess.txt', print_r($apiResponse['response']['data'], true));
- }
- else {
- file_put_contents('hoerrors.txt', print_r($apiResponse['response']['errors'], true));
- }
- }
- if(DEBUG == true) {
- error_log(date('[Y-m-d H:i e] '). "Verified IPN: $req ". PHP_EOL, 3, LOG_FILE);
- }
- } else if (strcmp ($res, "INVALID") == 0) {
- // log for manual investigation
- // Add business logic here which deals with invalid IPN messages
- if(DEBUG == true) {
- error_log(date('[Y-m-d H:i e] '). "Invalid IPN: $req" . PHP_EOL, 3, LOG_FILE);
- }
- }
- //save a copy of IPN into tracker DB
- require_once('ipn-track.php');
- function doCURL($url) {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- //return the transfer as a string
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- // $output contains the output string
- $output = curl_exec($ch);
- curl_close($ch);
- return $output;
- }
- function cleanText($text) {
- // Remove all none utf-8 symbols
- $text = htmlspecialchars_decode(htmlspecialchars($text, ENT_IGNORE, 'UTF-8'));
- // remove non-breaking spaces and other non-standart spaces
- $text = preg_replace('~\s+~u', ' ', $text);
- // replace controls symbols with "?"
- $text = preg_replace('~\p{C}+~u', '?', $text);
- return $text;
- }
- /********
- Example of Paypal Profile
- Recurring profile details
- array(50) {
- ["ACK"]=>
- string(7) "Success"
- ["VERSION"]=>
- string(4) "82.0"
- ["BUILD"]=>
- string(8) "17098556"
- ["profile_id"]=>
- string(14) "I-HY9V9MY0PE4W"
- ["status"]=>
- string(6) "Active"
- ["autobill"]=>
- string(10) "NoAutoBill"
- ["desc"]=>
- string(89) "Time magazine monthly subscription for 1 year. 1 month free trial, then 29.99 GBP monthly"
- ["max_failed"]=>
- string(1) "0"
- ["name"]=>
- string(10) "buyer test"
- ["start_date"]=>
- string(20) "2015-06-30T16:00:00Z"
- ["next_billing_date"]=>
- string(20) "2015-07-01T10:00:00Z"
- ["num_cycles_completed"]=>
- string(1) "0"
- ["num_cycles_remaining"]=>
- string(1) "1"
- ["outstanding_balance"]=>
- string(4) "0.00"
- ["failed_payments"]=>
- string(1) "0"
- ["trial_amount_paid"]=>
- string(4) "0.00"
- ["regular_amount_paid"]=>
- string(4) "0.00"
- ["aggregate_amount"]=>
- string(4) "0.00"
- ["aggregate_optional_amount"]=>
- string(4) "0.00"
- ["final_payment_date"]=>
- string(20) "2016-07-01T10:00:00Z"
- ["timestamp"]=>
- string(20) "2015-06-28T07:00:50Z"
- ["correlation_id"]=>
- string(13) "a1fa47056c5c7"
- ["shipping_street"]=>
- string(16) "123 Thomson Rd. "
- ["shipping_city"]=>
- string(9) "Singapore"
- ["shipping_zip"]=>
- string(6) "308123"
- ["shipping_country_code"]=>
- string(2) "SG"
- ["shipping_country"]=>
- string(2) "SG"
- ["shipping_country_name"]=>
- string(9) "Singapore"
- ["shipping_address_owner"]=>
- string(6) "PayPal"
- ["shipping_address_status"]=>
- string(11) "Unconfirmed"
- ["period"]=>
- string(5) "Month"
- ["frequency"]=>
- string(1) "1"
- ["total_cycles"]=>
- string(1) "1"
- ["currency"]=>
- string(3) "GBP"
- ["cost"]=>
- string(5) "29.99"
- ["shipping"]=>
- string(4) "0.00"
- ["tax"]=>
- string(4) "0.00"
- ["trial_period"]=>
- string(5) "Month"
- ["trial_frequency"]=>
- string(1) "1"
- ["trial_total_cycles"]=>
- string(1) "1"
- ["trial_currency_code"]=>
- string(3) "GBP"
- ["trial_cost"]=>
- string(4) "0.00"
- ["trial_shipping_amount"]=>
- string(4) "0.00"
- ["trial_tax_amount"]=>
- string(4) "0.00"
- ["regular_billing_period"]=>
- string(5) "Month"
- ["regular_billing_frequency"]=>
- string(1) "1"
- ["regular_total_billing_cycles"]=>
- string(2) "12"
- ["regular_currency_code"]=>
- string(3) "GBP"
- ["regular_shipping_amount"]=>
- string(4) "0.00"
- ["regular_tax_amount"]=>
- string(4) "0.00"
- }
- Recurring profile created::::
- {"payment_cycle":"Daily","txn_type":"recurring_payment_profile_created","last_name":"buyer","initial_payment_status":"Completed","next_payment_date":"03:00:00 Jul 01, 2015 PDT","residence_country":"SG","initial_payment_amount":"1.00","rp_invoice_id":"103.245.95.50","currency_code":"USD","time_created":"00:24:47 Jul 01, 2015 PDT","verify_sign":"AN9zikv75AwD7FSABy-2H9RV1ETNAKBIFCX-19lgfr5pRs7dp0BR3jNQ","period_type":" Regular","payer_status":"verified","test_ipn":"1","tax":"0.00","payer_email":"paypal-buyer@brainmaxima.com","first_name":"test","receiver_email":"paypal-facilitator@brainmaxima.com","payer_id":"GPACWYCF3836U","product_type":"1","initial_payment_txn_id":"2HW30276WH825815R","shipping":"0.00","amount_per_cycle":"9.99","profile_status":"Active","charset":"gb2312","notify_version":"3.8","amount":"9.99","outstanding_balance":"0.00","recurring_payment_id":"I-KA4L0YUC1H9T","product_name":"Time magazine monthly subscription for 1 year. 1 month free trial, then 29.99 USD daily","ipn_track_id":"4b27a7e4c1e9"}
- Recurring payment::::
- {"mc_gross":"9.99","period_type":" Regular","outstanding_balance":"0.00","next_payment_date":"03:00:00 Jun 29, 2015 PDT","protection_eligibility":"Eligible","payment_cycle":"Daily","address_status":"unconfirmed","tax":"0.00","payer_id":"GPACWYCF3836U","address_street":"123 Thomson Rd.","payment_date":"03:41:09 Jun 28, 2015 PDT","payment_status":"Completed","product_name":"Time magazine monthly subscription for 1 year. 1 month free trial, then 29.99 USD daily","charset":"gb2312","rp_invoice_id":"132.147.72.52","recurring_payment_id":"I-4EB8UFKB2LL5","address_zip":"308123","first_name":"test","mc_fee":"0.64","address_country_code":"SG","address_name":"buyer test","notify_version":"3.8","amount_per_cycle":"9.99","payer_status":"verified","currency_code":"USD","business":"paypal-facilitator@brainmaxima.com","address_country":"Singapore","address_city":"Singapore","verify_sign":"Agfb8DnF8gs6j4EwIwFPjQ7Rt9a.At5RBxymPJ.fwSjS0mt91UNJdiL1","payer_email":"paypal-buyer@brainmaxima.com","initial_payment_amount":"1.00","profile_status":"Active","amount":"9.99","txn_id":"71S220809S1846841","payment_type":"instant","last_name":"buyer","address_state":"","receiver_email":"paypal-facilitator@brainmaxima.com","payment_fee":"0.64","receiver_id":"FZBJUFBDMSBZJ","txn_type":"recurring_payment","mc_currency":"USD","residence_country":"SG","test_ipn":"1","transaction_subject":"Time magazine monthly subscription for 1 year. 1 month free trial, then 29.99 USD daily","payment_gross":"9.99","shipping":"0.00","product_type":"1","time_created":"00:32:46 Jun 28, 2015 PDT","ipn_track_id":"88e6336ee79"}
- One time payment::::
- {"mc_gross":"69.97","protection_eligibility":"Eligible","address_status":"unconfirmed","item_number1":"1984","payer_id":"GPACWYCF3836U","tax":"0.00","address_street":"123 Thomson Rd.","payment_date":"08:56:44 Jun 24, 2015 PDT","payment_status":"Completed","charset":"gb2312","address_zip":"308123","mc_shipping":"0.00","mc_handling":"0.00","first_name":"test","mc_fee":"2.68","address_country_code":"SG","address_name":"buyer test","notify_version":"3.8","custom":"5","payer_status":"verified","address_country":"Singapore","num_cart_items":"1","mc_handling1":"0.00","address_city":"Singapore","verify_sign":"AMbszvxvYSF5dhC2-PBwiJRHzT8yALLUM2kWqwI-m6msJ0OyQ2NlvySO","payer_email":"paypal-buyer@brainmaxima.com","mc_shipping1":"0.00","tax1":"0.00","txn_id":"3G580325DH949014M","payment_type":"instant","last_name":"buyer","address_state":"","item_name1":"Product ABC","receiver_email":"paypal-facilitator@brainmaxima.com","payment_fee":"2.68","quantity1":"1","receiver_id":"FZBJUFBDMSBZJ","txn_type":"cart","mc_gross_1":"69.97","mc_currency":"USD","residence_country":"SG","test_ipn":"1","transaction_subject":"","payment_gross":"69.97","ipn_track_id":"20bae702572a5"}
- ********/
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement