|
[x]
Posted via EE Mobile
|
||
Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
||
| 01/19/2009 at 08:35PM PST, ID: 24065929 |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: |
<?php
/*
Project: www.ad-hit.com
Purpose: Paypal IPN Script - Button (BUY NOW), Process (INCREASE CUSTOMERS AD-HIT POINTS)
Author: Ryan Bayne
Site: wwww.webtechglobal.co.uk
Date: 19th January 2009
*/
################# PART ONE - Write to log, format time, connect to database
$log = fopen("ipn.log", "a");
fwrite($log, "\n\nipn - " . gmstrftime ("%b %d %Y %H:%M:%S", time()) . "\n"); //gmstrftime formats system time to something readable
//$db = mysql_connect("localhost", "yourname", "yourpassword");
//mysql_select_db("yourdb",$db);
############## PART TWO - Create reply to return Paypals POST data, back to Paypal using PayPals standard code(this creates authorisation)
$postvars = array(); //create array to contain all values of POST from Paypal
while (list ($key, $value) = each ($HTTP_POST_VARS)) //read the posted vars from Paypal
{
$postvars[] = $key;
}
$req = 'cmd=_notify-validate'; //start reply with Paypals own command
for ($var = 0; $var < count ($postvars); $var++)
{ //for loop lists all POST variables in format: variable=value
$postvar_key = $postvars[$var];
$postvar_value = $$postvars[$var];
$req .= "&" . $postvar_key . "=" . urlencode ($postvar_value); //urlencode is the data format for POST transmission from a web page
}
/* Extra Reading
The function 'urlencode':
"Returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%)
sign followed by two hex digits and spaces encoded as plus (+) signs" (from the PHP manual).
This is basically a method of transmitting an 8-bit character set in just 7-bits.
*/
############## PART THREE - Create an HTTP header for the reply message, create the message, open a connection socket...
//$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";// Create message to post back to PayPal...
$header .= "https://www.sandbox.paypal.com/cgi-bin/webscr";// Create message to post back to PayPal...
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";//cont...
$header .= "Content-Length: " . strlen ($req) . "\r\n\r\n";//cont...
$fp = fsockopen ("www.paypal.com", 80, $errno, $errstr, 30);// Open a socket to the PayPal server...
//Write the transaction details to the log file - useful for debugging especially if database is down or has issues
//---------------------------------------------
fwrite($log, "Vals: ". $invoice." ". $receiver_email." ". $item_name." ". $item_ number." ". $quantity."
". $payment_status." ". $pending_reason." ".$payment_dat e." ". $payment_gross." ". $payment_fee."
". $txn_id." ". $txn_type." ". $first_ name." ". $last_name." ". $address_street." ". $address_city."
". $address_state . " ".$address_zip." ". $address_country." ". $address_status." ". $payer_email. "
". $payer_status." ". $payment_type." ". $notify_version." ". $verify_sign. "\ n");
############# PART FOUR - Check Connection socket to paypal is OK and perform Final Verification on string of POST vars ($req) by sending to Paypal
if (!$fp)
{ //connection has failed
echo "$errstr ($errno)"; //errstr and errno are system variables which report last error
fwrite($log, "Failed to open HTTP connection!");
$res = "FAILED";
}
else
{ //connection is OK
fputs ($fp, $header . $req);
while (!feof($fp)) //read the results of the verification...
{
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) // If VERIFIED = continue to process the TX...
{
//PERFORM ACTIONS UNIQUE TO YOUR APPLICATION - issue product basically (Excluding Main Database INSERT thats at end)
if (strcmp ($payment_status, "Completed") == 0) //if payment status = Completed then payment is not an eCheck
{
//for Ad-Hit.Com customer is buying POINTS and so this is when we increase their points total depending on payment amount
//email customer with
$message .= "Dear Customer,\n Thankyou for your order.\n\nIf you have any problems,
please contact us: \n\nsales\@webtechglobal.com";
mail($payer_email, "Your Book Password...", $message, "From: admin@ad-hit.com\nReply-To: admin@yourdomain.com");
}
else // If the payment_status is NOT Completed... You'll have to perform unique functions later (Dont issue product basically)
{
$message .= "Dear Customer,\n Thankyou for your order.\n\nSOME MESSAGE HERE FOR THE CUSTOMER ABOUT AWAITING PAYMENT COMPLETE.
\n\nThankyou \n\nsales\@yourdomain.com";
mail($payer_email, "Your Book Password...", $message, "From: admin@ad-hit.com\nReply-To: admin@ad-hit.com");
mail($receiver_email, "Incomplete PayPal TX...", "An incomplete transaction requires your attention.");
}
}
else //payment UNVERIFIED possibly attempted hack and should be checked by a human
{
mail($payer_email, "An Error Occurred...", "Dear Customer,\n an error occurred while PayPal was processing
your order. It will be investigated by a human at the earliest opportunity.\n\nWe apologise for any
inconvenience.", "From: admin@ad-hit.com\nReply-To: admin@ad-hit.com");
mail($receiver_email, "Invalid PayPal TX", "An invalid transaction on Ad-Hit.Com requires your attention. It should be checked for possible hacking
and other illegal activity.");
}
}
}
############### PART FIVE - Insert all data into database (you don't have to do this if you do not want to collect this data)
//The '\"' is placed around variable to ensure that they appear in double quotes in the query string.
//This ensures that whatever they contain, they'll get inserted.
/* $qry = "INSERT into paypal (
invoice, receiver_email, item_name, item_number, quantity, payment_status, pendi ng_reason, payment_date, payment_gross, payment_fee,
txn_id, txn_type, first_nam e, last_name, address_street, address_city, address_state, address_zip, address_ country, address_status, payer_email, payer_status, payment_type, notify_version , verify_sign )
VALUES
( \"$invoice\", \"$receiver_email\", \"$item_name\", \"$item_number\", \"$quanti ty\", \"$payment_status\", \"$pending_reason\",
\"$payment_date\", \"$payment_gr oss\", \"$payment_fee\", \"$txn_id\", \"$txn_type\", \"$first_name\", \"$last_na me\",
\"$address_street\", \"$address_city\", \"$address_state\", \"$address_zip \", \"$address_country\", \"$address_status\",
\"$payer_email\", \"$payer_status \", \"$payment_type\", \"$notify_version\", \"$verify_sign\" ) ";
$result = mysql_query($qry,$db);
// Close PayPal Connection, Log File and DB.
fclose ($fp);
fclose ($log);
mysql_close($db);
*/
?>
|
Advertisement