首页 文章

Paypal Sandbox付款问题

提问于
浏览
3

我有以下用于paypal交易的帖子按钮:

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

1 回答

  • 0

    关于返回“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显示 .

    使用快速结账时,您还可以使用自定义“品牌名称”覆盖您的公司名称,这样您就可以在具有不同“品牌”的不同网站上使用相同的接收PayPal帐户 .

    祝好运!

相关问题