集成贝宝 [英] Integrate PayPal

查看:18
本文介绍了集成贝宝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已成功集成 PayPal.一切正常.但我希望我的表单在成功付款后重定向到我的网站.另一个问题:如何获得 PayPal 的回复?这是我的 PayPal 表格.谢谢.

I have successfully integrated PayPal. All is working fine. But I want my form to redirect to my site after a successful payment. Another question: how to get response from PayPal? Here is my PayPal form. Thanks.

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

推荐答案

只需通过这个:

您想要的是 PAYPAL IPN,即付款完成后发送到用户网站的即时付款通知.

What you want is PAYPAL IPN, INSTANT PAYMENT NOTIFICATION which is sent to user's website after payment is completed.

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

或者您也可以在您的购物车中设置 IPN 的路径,paypal 将在其中发送这样的通知:

or you can also set path to IPN in your cart where paypal will send notification like this:

<input type="hidden" name="notify_url" value="site.com/ipn/index.php" />
<input type="hidden" name="return"     value="site.com/ipn/index.php"/>

但是您需要在 paypal 上登录您的商家帐户以手动指定 IPn 和自动返回 url.在个人资料选项卡下的网站付款首选项和即时付款通知部分.

But you'll need to login to your merchant account on paypal to manually specify the ipn and auto return url. in website payment preferences and instant payment notifications section under profile tab.

以下我添加了成功付款后发送到您网站的示例 ipn 代码:

Following i've added the sample ipn code which is sent to your website after successfull payment:

// 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
";
$header .= "Content-Type: application/x-www-form-urlencoded
";
$header .= "Content-Length: " . strlen($req) . "

";
$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);
}
?>

您需要在您的通知网址页面上添加此代码.您在购物车的通知 url 字段中提到的返回页面,即

You need to add this code on your notify url page. the return page you mention in notify url field of shopping cart i.e.

<input type="hidden" name="notify_url" value="site.com/ipn/index.php" />

把这段代码放在site.com/ipn/index.php

让我们以您的购物车为例:

Lets take an example of your shopping cart:

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

在这种情况下,paypal 将发送 ipn 的通知 url 是 http://localhost/check.php.

In this case your notify url where paypal will send ipn is http://localhost/check.php.

所以把这段代码放在 check.php 页面中.收到ipn后,您可以进一步使用它输入您的数据库等.

So put that code in check.php page. After recieving the ipn you can further use it to enter in your database etc.

或访问此链接以获取有关 paypal ipn 侦听器的概述:

or visit this link to get an overview of paypal ipn listener:

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

希望这会有所帮助.

这篇关于集成贝宝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆