我已成功整合paypal帐户.一切都很好.但我希望当付款成功转移然后重定向到我的网站.另一个问题如何从贝宝获得回应?这是我的贝宝形式.谢谢
`<form action="https://sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="business" value="savife_1314264698_biz@gmail.com ">
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<input type="hidden" name="item_name" value="Alice's Weekly Digest">
<input type="hidden" name="item_number" value="DIG Weekly">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="notify_url" value="http://localhost/check.php">
<input type="hidden" name="return" value="http://google.co.in">
<input type="hidden" name="a3" value="5.00">
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="M">
<!-- Display the payment button. -->
<input type="image" name="submit" border="0" src="btn_subscribe_LG.gif" alt="PayPal - The safer, easier way to pay online">
<img alt="" border="0" width="1" height="1" src="https://www.paypal.com/en_US/i/scr/pixel.gif" >
</form>
Run Code Online (Sandbox Code Playgroud)
请仔细阅读:
您想要的是PAYPAL IPN,即时付款通知,在付款完成后发送到用户的网站.
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_admin_IPNIntro
或者您也可以在购物车中设置IPN路径,paypal将发送通知,如下所示:
<input type="hidden" name="notify_url" value="site.com/ipn/index.php" />
<input type="hidden" name="return" value="site.com/ipn/index.php"/>
Run Code Online (Sandbox Code Playgroud)
但是您需要在paypal上登录您的商家帐户才能手动指定ipn和自动返回网址.在配置文件选项卡下的网站付款首选项和即时付款通知部分
我已经添加了成功付款后发送到您网站的示例ipn代码:
// 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.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
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
?>
Run Code Online (Sandbox Code Playgroud)
您需要在通知网址页面上添加此代码.您在购物车的通知网址字段中提到的返回页面即
<input type="hidden" name="notify_url" value="site.com/ipn/index.php" />
Run Code Online (Sandbox Code Playgroud)
把这段代码放进去 site.com/ipn/index.php
让我们举一个购物车的例子:
<form action="https://sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="business" value="savife_1314264698_biz@gmail.com ">
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<input type="hidden" name="item_name" value="Alice's Weekly Digest">
<input type="hidden" name="item_number" value="DIG Weekly">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="notify_url" value="http://localhost/check.php">
<input type="hidden" name="return" value="http://google.co.in">
<input type="hidden" name="a3" value="5.00">
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="M">
<!-- Display the payment button. -->
<input type="image" name="submit" border="0" src="btn_subscribe_LG.gif" alt="PayPal - The safer, easier way to pay online">
<img alt="" border="0" width="1" height="1" src="https://www.paypal.com/en_US/i/scr/pixel.gif" >
</form>
Run Code Online (Sandbox Code Playgroud)
在这种情况下,你的paypal将发送ipn的通知网址是http://localhost/check.php.
所以把代码放在check.php页面中.收到ipn后,您可以进一步使用它进入您的数据库等.
或者访问此链接以获取paypal ipn listener的概述:
希望这可以帮助.
| 归档时间: |
|
| 查看次数: |
4077 次 |
| 最近记录: |