View Full Version : Testing PayPal Assistant is easy...


maxparker
01-12-2005, 09:14 PM
Hi, I downloaded this code from the Paypal developer's forums... It's pretty helpful:

Hello PayPal Developers,

Some of you may be familiar with www.paypaldev.org. This was the primary message board for PayPal Developers prior to the release of the Sandbox and this Developer Central Board.

The below is taken from paypaldev.org. Posted by the immortal paypal_pb, this is probably the easiest way I know of to test your IPN scripts without making an actual test payment through the Sandbox.

Of course, you will always want to do an "end-to-end" test within the Sandbox before going live but if you are experiencing unexpected behaviors with the IPN script, this should allow you to test the script itself to see if it runs as intended. Here's how it works:

Copy/paste the below into a web page, set the "action" to your script's URL and press the "Test IPN" button.

<!-- begin code-->

<form method="post" action="http://www.mysite.com/ipn.cfm" target="_blank">
<input type="hidden" name="mc_gross" value="0.01">
<input type="hidden" name="address_status" value="unconfirmed">
<input type="hidden" name="payer_id" value="QGVDAFGZ9XHLJ">
<input type="hidden" name="tax" value="0.00">
<input type="hidden" name="payment_date" value="20:50:26 May 20, 2004 PST">
<input type="hidden" name="address_street" value="12340 main st">
<input type="hidden" name="payment_status" value="Pending">
<input type="hidden" name="address_zip" value="94303">
<input type="hidden" name="first_name" value="firstname">
<input type="hidden" name="address_name" value="address_name">
<input type="hidden" name="notify_version" value="1.6">
<input type="hidden" name="custom" value="custom">
<input type="hidden" name="payer_status" value="unverified">
<input type="hidden" name="business" value="you@email.com">
<input type="hidden" name="address_country" value="United States">
<input type="hidden" name="address_city" value="Los Angeles">
<input type="hidden" name="quantity" value="1">
<input type="hidden" name="verify_sign" value="AkU-lzGsIkV0gazwa9nDVpmsx9X0AMF3KqbmhBuM8UTVNO5CFNAptk 78">
<input type="hidden" name="payer_email" value="buyer@email.com">
<input type="hidden" name="txn_id" value="4MX09190KB7728256">
<input type="hidden" name="payment_type" value="instant">
<input type="hidden" name="last_name" value="last_name">
<input type="hidden" name="address_state" value="CA">
<input type="hidden" name="receiver_email" value="test@test.com">
<input type="hidden" name="receiver_id" value="WAT63H8628SRN">
<input type="hidden" name="pending_reason" value="verify">
<input type="hidden" name="txn_type" value="web_accept">
<input type="hidden" name="item_name" value="Test">
<input type="hidden" name="mc_currency" value="USD">
<input type="hidden" name="item_number" value="">
<input type="hidden" name="payment_gross" value="0.01">
<input type="submit" value="Test IPN">
</form>
<!-- end code -->

The above code will show up as a button on a page. That button will say "Test IPN". Clicking the button will essentially send a dummy POST to your IPN script. This should allow you to easily test to see if your script runs as intended.

For example, if your script is supposed to write to a database, you can use this to simulate a POST to your script to see if the script will insert a record.

Or, if your script generates a webpage, you can use this to simulate a POST to see if the script is pulling the correct variables out of the POST and displaying the page as intended.

Important Note: Because this is dummy data, PayPal will always return 'INVALID' back to the script. This means you would need to "adjust" your script in the testing phase to run if the POST from PayPal is 'INVALID'. Again, the idea is to test the script to see if it will run as intended and to eliminate the possibility of any syntax or logic errors within the script itself.

The names of the hidden input types are the names of the IPN variables. A list of these variables can be found within the PayPal Integration Guide (link below). Happy Testing!!

https://www.paypal.com/en_US/pdf/integration_guide.pdf

Message was edited by PayPal_PatrickO at Jul 28, 2004 12:45 PM

Jafo
01-13-2005, 03:22 AM
Yes you can do that, but why you would not use the Paypal Sandbox is beyond me. It emulates the real Paypal 100% and is the closest you can actually get to testing any IPN script in realtime.

maxparker
01-13-2005, 01:42 PM
Yes that may be the case, however it's not clear on exactly how to use the Sandbox to test the script.

I went into sandbox and generated a Buy it Now button for an item I created in PayPal assistant. Strangely, when I use this button it does not log it into the activity/history of the PayPal Assistant. First I used the code that Sandbox supplied:

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="manish@globalnowconsulting.com">
<input type="hidden" name="item_name" value="Widget">
<input type="hidden" name="item_number" value="001">
<input type="hidden" name="amount" value="0.01">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/x-click-but23.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>

and nothing happened with the PayPal Assistant.

Next, I changed the target POST URL and business value as follows:

<form method="post" action="http://www.roadstoprosperity.com/paypal/index.php" target="_blank">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="manish@gn-a.com">
<input type="hidden" name="item_name" value="Widget">
<input type="hidden" name="item_number" value="001">
<input type="hidden" name="amount" value="0.01">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/x-click-but23.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form></p>

Again nothing happened.

So if I am not doing this right, i.e., not using Sandbox properly to test the script, can you please clarify exactly how to do that?

Thank you for your help.

Jafo
01-13-2005, 01:55 PM
Well, you have the READ the ReadMe.htm file that comes with the script :) :

Quote:

The best way to test this script is to get a free developers account from Paypal. You can get an account (termed Sandbox) at http://developer.paypal.com (http://developer.paypal.com/) and sign up. Here you can create two test accounts that have no real purchase power. You create one business and one personal. Keep in mind that the accounts do NOT send email to your email addresses, there is a separate folder tab that contains your email in your sandbox account. This is to eliminate confusion.


You will have to alter the script slightly to take advantage of their test environment. Find this line:

$fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);

Just change the URL to the sandbox URL like so:

$fp = fsockopen ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);


That's it! Now you can test your script. As a part of our license, you can only run one instance of the Paypal Assistant, however, we do allow a separate test instance. This way you can have two scripts, one for live, and one for testing.

maxparker
01-13-2005, 02:28 PM
Yes, fine point. I forgot to mention that I already did that modification to the PHP code.

OK I think I have officially tried every permutation possible with no luck.:

I set up an item called Widget, item number 001, at a cost of $0.01.
Next, I set up 2 actions, both similar to the "mailer" action described earlier, but the 2nd action was for an Invalid transaction. In other words, I took your advice to set up 2 actions, one valid and one invalid.

1. I went into Sandbox - > Account > Profile > IPN and put in
http://www.roadstoprosperity.com/paypal/index.php as the target.

Next, I did the buy it now button again and no activity was logged into the script, nor was any action taken.

2. I went back into Sandbox - > Account > Profile > IPN and put in
http://www.roadstoprosperity.com/paypal/paypal.php as the target.

I tried the Buy It Now button again and yet again nothing happened. No activity was logged and no action was taken.


It's getting to the point where I'm getting worn out by trying to get this to work. I've invested over 6 hours total thus far -- it shouldn't be this hard!

What can I try next?

Jafo
01-13-2005, 02:39 PM
You have to point the IPN URL to the paypal script. This is located in the profile tab -> Instant Payment Notification Preferences

maxparker
01-13-2005, 02:52 PM
Yes, I did that already. Please read the thread above your last response, I edited and supplied a great deal of more detail on what is and is not happening.

meucat
05-11-2005, 04:33 PM
mmmmm! I have same problems to test my script ( newer in this business)

I made exactly what sandbox and paypal manuals say, that is: I copied paypal PHP template to create my processipn.php script, then I pointed www.mysite.../processipn.php into IPN target at sandbox->profile->ipn->URL

I created a buy now button and then performed a single trasaction between two users in sandbox. Transact was processed OK, debs and credits appeared on both accounts with no errors.

BUT the processing.php script was not executed. I echo variables to see what is happening there but the only error I got was 'Warning: fsockopen(): unable to connect to www.paypal.com:80 in ..'

Then I changed paypal server to www.sandbox.paypal.com (I invented this url, since sandbox manual doesn't say which server you shoul use to test ipns), but I got the same fsockopen error this time with www.sandobox.paypal.com server

I even doubt what time my script was called because I point it with 'return' field, so I don't know if it was executed at right time.

this a copy of processipn.php I use as listed in paypal templates

// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);

// 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'];
$first_name = $_POST['first_name']; // nome do assinante

if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
?>


Thanks for any explanations, I am really lost into this jungle

Miguel

(i would appreciate response copies to m02041952@yahoo.com thanks!)

fishfish
05-11-2005, 06:17 PM
Just to comment.

I have found that for testing, the sandbox works well. By changing the scripts reference URL to sandbox.paypal.com, setting up your Paypal Developer account properly, and then creating and using a button for a test purchase, you can get the script to run under test conditions.

My initial testing with with the PHP version and used a test item called Widget with an associated IPN action simply e-mailing myself the information of the completed transaction. I received the e-mail each time.

There was a problem, however, which I have addressed in previous threads. In the PHP version, the transaction history does not show up for the completed transactions when trying to search transactions from the home page of paypal assistant. If you search with criteria set blank and with search set to ALL you will see no results although if you look in paypal assistants activity log file on your server, the transactions are there.

This transaction listing issue seems evident be comparing the two demo versions on the worldwidecreations website. Try the two versions (cgi and php) and you will see that the cgi version shows all the the transactions (including wildcards) but the PHP version shows nothing (although there are wildcards if you check).

In fact, in the PHP version, even if you enter a transaction id from the list of wildcards you will get no search results.

Secondly, in the PHP version, there seems to be a problem with IPN's that send POST or GET variables to secondary scripts. This issue has also been addressed in another thread but has not yet been solved. The PHP version of the paypal assistant does not correctly send these variables and as such, if you have a secondary script waiting to analyse transaction data, it will not be called correctly and will not run. You will not notice this failing while testing and may feel your secondary script is not getting called, however, a quick look at your http logs will uncover the problem.

My guess is you are having probems with the PHP version of the assistant.
• if you are simply sending an e-mail with the details of the completed transaction, the script works fine.
• If you are trying to get a transaction listing, you will not be able to find it.
• If you are trying to send variables to another script, the ipn script will run but your variables will not get to your second script properly.

These issues have not been completely solved as far as I am concerned as I am still waiting for a solution to these problems.
Patiently, :cool: