开发者

Paypal Sandbox payment problem

开发者 https://www.devze.com 2023-03-21 20:21 出处:网络
I have the following post button that i use for paypal transactions: <form action=\"https://www.sandbox.paypal.com/cgi-bin/webscr\" method=\"post\">

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.


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!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号