[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.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

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!

7.8

Please look over Paypal IPN Script

Asked by TycoonMillion in PHP Scripting Language, Payment Processing Recommendation and Integrating, Miscellaneous Web Development

Tags: paypal, IPN

Hey

I've not finished my IPN script however I believe I should be at a point where I can test it and get something happening, only nothing happens. This is the 2nd time I attempted the IPN and the first I felt like I was walking into walls.

I have sent an IPN test from Sandbox and I get a success returned but it appears to mean nothing but the fact that it has found the IPN script.

I'm getting no emails in any inbox I test, paypals sandbox or my own inboxes. So if the success on the IPN test means it is working to a point but not the whole script then could you possible suggest where I may be going wrong.

Cheers for any help
Ryan

I commeted out any DB activity by way until I get the basics happening
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);
	*/
?>
[+][-]01/19/09 09:25 PM, ID: 23417435

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/19/09 09:32 PM, ID: 23417473

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/19/09 09:36 PM, ID: 23417489

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/19/09 09:39 PM, ID: 23417501

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/19/09 09:43 PM, ID: 23417518

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/19/09 09:44 PM, ID: 23417521

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/19/09 09:51 PM, ID: 23417550

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/19/09 09:57 PM, ID: 23417567

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/19/09 10:00 PM, ID: 23417579

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/19/09 10:05 PM, ID: 23417600

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/19/09 10:12 PM, ID: 23417629

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/19/09 10:12 PM, ID: 23417630

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/19/09 10:21 PM, ID: 23417655

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/19/09 10:31 PM, ID: 23417688

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/19/09 10:46 PM, ID: 23417729

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/19/09 10:47 PM, ID: 23417739

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/19/09 10:49 PM, ID: 23417747

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/19/09 10:51 PM, ID: 23417751

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/19/09 10:52 PM, ID: 23417758

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/19/09 11:02 PM, ID: 23417790

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/19/09 11:03 PM, ID: 23417795

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/19/09 11:11 PM, ID: 23417826

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/19/09 11:13 PM, ID: 23417832

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/19/09 11:17 PM, ID: 23417842

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/19/09 11:19 PM, ID: 23417855

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/19/09 11:24 PM, ID: 23417873

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/19/09 11:30 PM, ID: 23417904

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/19/09 11:35 PM, ID: 23417920

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: PHP Scripting Language, Payment Processing Recommendation and Integrating, Miscellaneous Web Development
Tags: paypal, IPN
Sign Up Now!
Solution Provided By: mrcoffee365
Participating Experts: 1
Solution Grade: A
 
 
[+][-]01/19/09 11:37 PM, ID: 23417931

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20090824-EE-VQP-74 - Hierarchy / EE_QW_3_20080625