3

I have the following post button that i use for paypal transactions:

    <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="my@email.com">
        <input type="hidden" name="item_name" value="Item description">
        <input type="hidden" name="item_number" value="1">
        <input type="hidden" name="amount" value="00.30">
        <input type="hidden" name="no_shipping" value="1">
        <input type="hidden" name="no_note" value="1">
        <input type="hidden" name="currency_code" value="USD">
        <input type="hidden" name="lc" value="US">
        <input type="hidden" name="bn" value="PP-BuyNowBF">
        <input type="hidden" name="return" value="website.com/index.php" />
        <input type="hidden" name="cancel_return" value="website.com/index.php" />
        <input type="hidden" name="rm" value="2">
        <input type="hidden" name="notify_url" value="website.com/ipn/ipn.php">
        <input type="hidden" name="custom" value="user_id">
        <input type="submit" value="upgrade" />
    </form>

and the following code in ipn.php

<?php
include_once 'config.php';
// 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 ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $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'];

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
            mysql_query("UPDATE table SET column='1' WHERE column2='13'");
        }
        else if (strcmp ($res, "INVALID") == 0) {
            // log for manual investigation
        }
    }
fclose ($fp);
}
?>

when i click the upgrade button and pay, it doesnt show me a go back to the website button... but there is a go back to my@email.com button, which has a 10 sec delay and takes me back to my website... although it popups a warning about encrypted data, which i dont know what it is.

Also the query i use in ipn.php does not execute.I dont even know if it goes to ipn.php.

stergosz
  • 5,754
  • 13
  • 62
  • 133

1 Answers1

0

Regarding go back to "my@email.com", this could happen if the email you specified doesn't map to an account in the PayPal sandbox. Perhaps you're using your real email in the button instead of a sandbox account email?

Another possibility is that your test account at "my@email.com" is not a business account. If you have a business account it should reflect your business name instead.

As for not receiving the IPNs, the sandbox doesn't always do a great job at delivering IPNs on time, if at all. I'd actually suggest that you try integrating using Express Checkout instead of Website Payments Standard. Express Checkout is a little bit of a confusing dance initially but it is easy to implement after you try to understand it. Here's what I think is the best doc explaining how Express Checkout works:

https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ECSimpleIntegration

And when you're ready to dive into the implementation you should look here:

https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/howto_api_reference

The nice thing about using Express Checkout instead of relying on IPN is that you get to figure out the payment status the moment your user returns to your site, and you don't have to sit around waiting for the IPN to show up.

With Express Checkout you also get to override your business name with a custom "brand name" so you can use the same receiving PayPal account on different sites with different "brands".

Good luck!

nioq
  • 3,215
  • 1
  • 23
  • 18
  • actually i used a non-sandbox account as my@email.com, i then changed it to my sandbox business email and created a new personal one as buyer... then i entered my buyer login details to buy the item, and still it doesnt execute the ipn.php page, it doesnt seem to go there... at the moment i wanna stick with IPN since it seems simple. thanks – stergosz Jul 21 '11 at 16:02
  • I see. If you want to stick with using IPN then you should probably take a look at their IPN tester at https://developer.paypal.com/cgi-bin/devscr?cmd=_ipn-link-session -- if that works then you can rule out your ipn.php as the source of the problem, but if it doesn't work then unfortunately you won't know whether the problem is with PayPal not sending the IPN – nioq Jul 22 '11 at 01:50
  • i selected express checkout, i dont know if this is the correct item i had to selected but it passed with the message: "IPN successfully sent.". – stergosz Jul 22 '11 at 05:39
  • You should probably select "web accept" instead if you're using buttons, but if your IPN.php succeeds even with "express checkout" then you're probably fine. The problem with the sandbox is sometimes automatic IPNs don't get sent. If you want additional assurance you can test with your live account. Don't worry, you can always refund any payment made - the fees will be reversed too. – nioq Jul 22 '11 at 05:48