【问题标题】:Paypal Sandbox payment problemPaypal沙盒支付问题
【发布时间】:2011-10-10 08:15:03
【问题描述】:

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

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

【问题讨论】:

    标签: paypal sandbox paypal-ipn paypal-sandbox


    【解决方案1】:

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

    另一种可能是您在“my@email.com”上的测试帐户不是企业帐户。如果您有企业帐户,则它应该反映您的企业名称。

    至于不接收 IPN,沙盒在按时交付 IPN 方面并不总是做得很好,如果有的话。我实际上建议您尝试使用 Express Checkout 而不是网站付款标准进行集成。 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,您还可以使用自定义“品牌名称”覆盖您的公司名称,这样您就可以在具有不同“品牌”的不同网站上使用相同的 PayPal 收款帐户。

    祝你好运!

    【讨论】:

    • 实际上我使用了一个非沙盒帐户作为 my@email.com,然后我将其更改为我的沙盒业务电子邮件并创建了一个新的个人作为买家...然后我输入了我的买家登录详细信息购买该项目,但它仍然没有执行 ipn.php 页面,它似乎没有去那里......目前我想坚持使用 IPN,因为它看起来很简单。谢谢
    • 我明白了。如果您想坚持使用 IPN,那么您可能应该在developer.paypal.com/cgi-bin/devscr?cmd=_ipn-link-session 上查看他们的 IPN 测试仪——如果可行,那么您可以排除您的 ipn.php 作为问题的根源,但如果不是工作然后不幸的是,您将不知道问题是否在于 PayPal 没有发送 IPN
    • 我选择了快速结帐,我不知道这是否是我必须选择的正确项目,但它通过了以下消息:“IPN 成功发送。”。
    • 如果您使用按钮,您可能应该选择“网络接受”,但如果您的 IPN.php 即使使用“快速结帐”也成功,那么您可能没问题。沙盒的问题是有时不会发送自动 IPN。如果您需要额外的保证,您可以使用您的真实账户进行测试。不用担心,您可以随时退还任何付款 - 费用也会被退回。
    猜你喜欢
    • 2017-08-16
    • 2015-07-11
    • 2021-01-30
    • 2017-06-10
    • 2018-03-26
    • 2015-03-08
    • 2011-08-07
    • 2013-08-14
    • 2018-07-31
    相关资源
    最近更新 更多