我有以下用于贝宝交易的发布按钮:

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


以及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);
}
?>


当我单击升级按钮并付款时,它没有显示返回网站按钮的信息……但是有一个返回到my@email.com按钮的信息,该按钮有10秒的延迟,将我带回到我的网站...尽管它弹出有关加密数据的警告,但我不知道它是什么。

我在ipn.php中使用的查询也不会执行。我什至不知道它是否进入ipn.php。

最佳答案

关于返回“ my@email.com”,如果您指定的电子邮件未映射到PayPal沙箱中的帐户,则可能会发生这种情况。也许您在按钮中使用的是真实电子邮件,而不是沙盒帐户电子邮件?

另一种可能是您位于“ my@email.com”的测试帐户不是企业帐户。如果您有公司帐户,则应改为显示您的公司名称。

至于不接收IPN,沙箱在按时交付IPN方面并不一定总是做得很好。实际上,我建议您尝试使用Express Checkout而不是Website Payments Standard进行集成。最初,Express Checkout有点让人困惑,但是在您理解它之后就很容易实现。我认为这是解释Express Checkout工作原理的最佳文档:

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

当您准备深入研究实现时,应该在这里查看:

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

使用Express Checkout而不是依赖IPN的好处是,您可以在用户返回站点时就知道付款状态,而不必坐等IPN出现。

借助Express Checkout,您还可以使用自定义的“品牌名称”覆盖您的公司名称,以便您可以在具有不同“品牌”的不同站点上使用同一收款贝宝帐户。

祝好运!

10-02 01:45
查看更多