简体   繁体   English

贝宝IPN-无法沙箱

[英]PayPal IPN - Cannot Sandbox

I am trying to code a simple PayPal purchase page with options on my site. 我正在尝试使用网站上的选项编写一个简单的PayPal购买页面代码。 However, I am having trouble testing it. 但是,我在测试时遇到了麻烦。 For some odd reason, when I use " http://paypal.com/cgi-bin/webscr " as the form URL, it seems to work, however I can't test the IPN without someone purchasing it. 出于某些奇怪的原因,当我使用“ http://paypal.com/cgi-bin/webscr ”作为表单URL时,它似乎可以工作,但是如果没有人购买,我将无法测试IPN。 If I leave it as " http://sandbox.paypal.com/cgi-bin/webscr ", it will pop up with this on the PayPal Sandbox site, 如果我将其保留为“ http://sandbox.paypal.com/cgi-bin/webscr ”,它将在PayPal沙箱网站上随其弹出,

PayPal cannot process this transaction because of a problem with the seller's website. 由于卖家网站存在问题,PayPal无法处理此交易。 Please contact the seller directly to resolve this problem. 请直接与卖家联系以解决此问题。

Below is my Form: 以下是我的表格:

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top">
    <input type="hidden" name="cmd" value="_s-xclick">
    <input type="hidden" name="hosted_button_id" value="YDPZBQ2LRBCSE">
    <table>
    <tr><td><input type="hidden" name="on0" value="Packages">Packages</td></tr><tr><td><select name="os0">
    <option value="Bronze">Bronze $10.00 USD</option>
    <option value="Silver">Silver $25.00 USD</option>
    <option value="Gold">Gold $50.00 USD</option>
    </select> </td></tr>
    <tr><td><input type="hidden" name="on1" value="Wubbo Username">Wubbo Username</td></tr><tr><td><input type="text" name="os1" maxlength="200"></td></tr>
    </table>
    <input type="hidden" name="currency_code" value="USD">
    <input type="image" src="http://wubbo.me/paypal/buynow.png" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
    <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

And here is my IPN Code: 这是我的IPN代码:

<?php
mysql_connect("localhost", "root", "PASSWORD") or die(mysql_error());
mysql_select_db("DATABASE") or die(mysql_error());

// STEP 1: read POST data
// Reading POSTed data directly from $_POST causes serialization issues with array data in the POST.
// Instead, read raw POST data from the input stream. 
$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();
foreach ($raw_post_array as $keyval) {
    $keyval = explode ('=', $keyval);
if (count($keyval) == 2)
 $myPost[$keyval[0]] = urldecode($keyval[1]);
}
// read the IPN message sent from PayPal and prepend 'cmd=_notify-validate'
$req = 'cmd=_notify-validate';
if(function_exists('get_magic_quotes_gpc')) {
    $get_magic_quotes_exists = true;
} 
foreach ($myPost as $key => $value) {        
    if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) { 
        $value = urlencode(stripslashes($value)); 
    } else {
        $value = urlencode($value);
    }
    $req .= "&$key=$value";
}

// Step 2: POST IPN data back to PayPal to validate
$ch = curl_init('https://www.sandbox.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
// In wamp-like environments that do not come bundled with root authority certificates,
// please download 'cacert.pem' from "http://curl.haxx.se/docs/caextract.html" and set 
// the directory path of the certificate as shown below:
// curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem');
if( !($res = curl_exec($ch)) ) {
    // error_log("Got " . curl_error($ch) . " when processing IPN data");
curl_close($ch);
exit;
}
curl_close($ch);

// inspect IPN validation result and act accordingly
if (strcmp ($res, "VERIFIED") == 0) {
    // The IPN is verified, process it:
    // check whether 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 the notification
    // assign posted variables to local variables
    $package = $_POST['os0'];
    $username = $_POST['os1'];

    if ($package == 'Bronze') {
        mysql_query("UPDATE `users` SET `vip_points` = (`vip_points` + 10) WHERE username = '" . $username . "'");
    } else if ($package == 'Silver') {
        mysql_query("UPDATE `users` SET `vip_points` = (`vip_points` + 30) WHERE username = '" . $username . "'");
    } else if ($package == 'Gold') {
        mysql_query("UPDATE `users` SET `vip_points` = (`vip_points` + 100) WHERE username = '" . $username . "'");
    }
}


} else if (strcmp ($res, "INVALID") == 0) {
// IPN invalid, log for manual investigation
echo "The response from IPN was: <b>" .$res ."</b>";
}
?>

Any assistance would be greatly appreciated! 任何帮助将不胜感激!

You should create a sandbox account and create a sandbox button to test. 您应该创建一个沙箱帐户并创建一个沙箱按钮进行测试。 To create a sandbox account, you should access developer.paypal.com, login with your live PayPal account, then follow up the link below to create a sandbox account(from step 2): https://ppmts.custhelp.com/app/answers/detail/a_id/744/kw/sandbox 要创建沙箱帐户,您应该访问developer.paypal.com,使用实际的PayPal帐户登录,然后按照下面的链接创建沙箱帐户(从第2步开始): https : //ppmts.custhelp.com/app /答案/细节/ A_ID / 744 /千瓦/沙箱

After created sandbox account, you can access www.sandbox.paypal.com and login with the sandbox account, then follow up the link below to create a button for sandbox environment: https://ppmts.custhelp.com/app/answers/detail/a_id/740/kw/create%20button 创建沙盒帐户后,您可以访问www.sandbox.paypal.com并使用沙盒帐户登录,然后按照下面的链接创建用于沙盒环境的按钮: https : //ppmts.custhelp.com/app/answers/细节/ A_ID / 740 /千瓦/创建%20button

You're getting that error message because you modified a hosted button. 您收到该错误消息是因为您修改了托管按钮。 If you create the button on PayPal then change the button code after you have copied it you get that error. 如果您在贝宝(PayPal)上创建按钮,则在复制按钮代码后对其进行更改,则会收到该错误。 You need to either make all modifications on PayPal or use an open source button. 您需要在PayPal上进行所有修改或使用开源按钮。

Here is an example of an open source button you will need to add your own email or merchant id from your PayPal Account for it to work: 这是一个开放源代码按钮的示例,您需要从PayPal帐户添加自己的电子邮件或商户ID才能起作用:

<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post" >
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="youremail@email.com">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="item_name" value="Sample Cart">
<input type="hidden" name="button_subtype" value="products">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="cn" value="Add special instructions to the seller:">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="add" value="1">
<input type="hidden" name="bn" value="PP-ShopCartBF:btn_cart_LG.gif:NonHosted">
<table>
<tr><td><input type="hidden" name="on0" value="Registration">Registration</td></tr><tr><td><select name="os0">
<option value="Bronze">Bronze $10.00 USD</option>
<option value="Silver">Silver $25.00 USD</option>
<option value="Gold">Gold $50.00 USD</option>
</select> </td></tr>
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="option_select0" value="Bronze">
<input type="hidden" name="option_amount0" value="10.00">
<input type="hidden" name="option_select1" value="Silver">
<input type="hidden" name="option_amount1" value="25.00">
<input type="hidden" name="option_select2" value="Gold">
<input type="hidden" name="option_amount2" value="50.00">
<input type="hidden" name="option_index" value="0">
</select> </td></tr>
<tr><td><input type="hidden" name="on1" value="Wubbo Username">Wubbo Username</td></tr><tr><td><input type="text" name="os1" maxlength="200">     </td></tr>
</table>

<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM