简体   繁体   English

贝宝支付回调

[英]PayPal Payment Callback

I have searched for more than 4 hours now on how to do callback with PayPal after a payment have been proceeded.我已经搜索了 4 个多小时,了解如何在付款后使用 PayPal 进行回调。

The thing is, I have a site the sells tickets to a LAN Party, and the only way to pay is with PayPal.问题是,我有一个网站出售 LAN 派对的门票,唯一的付款方式是使用 PayPal。
Here is my PayPal buy button code:这是我的 PayPal 购买按钮代码:

<form target="paypal" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="add" value="1">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="_MY_PAYPAL_EMAIL_">
<input type="hidden" name="item_number" value="<?php echo mktime(); ?>">
<input type="hidden" name="cn" value="<?php echo $_SESSION['userid']; ?>">
<input type="hidden" name="return" value="http://80.202.213.240/apps/tickets/buy/success/" />
<input type="hidden" name="cancel_return" value="http://80.202.213.240/apps/tickets/buy/cancelled/" />
<input type="hidden" name="notify_url" value="http://80.202.213.240/apps/tickets/buy/ipn/" />
<input type="hidden" name="lc" value="NO">
<input type="hidden" name="item_name" value="BitHack - Standard Ticket">
<input type="hidden" name="amount" value="100.00">
<input type="hidden" name="currency_code" value="NOK">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="button_subtype" value="Tickets">
<input type="hidden" name="add" value="1">
<input type="hidden" name="bn" value="PP-ShopCartBF:btn_cart_LG.gif:NonHostedGuest">
<input type="submit" value="Add to Cart" class="ticketShowButton submit" title="Payment via PayPal">

The info should then be inserted into a database, that part I have finished.然后应该将信息插入到数据库中,这部分我已经完成了。 Just need the callback system to work.只需要回调系统工作。 Anyone know any good callback script examples?任何人都知道任何好的回调脚本示例?

BTW, is it possible do use custom inputs?顺便说一句,是否可以使用自定义输入?

The callback function specified in the return and notify url variables are the programmer's responsibility. return 和 notify url 变量中指定的回调函数是程序员的责任。 Why?为什么? Because each website has it's own table structure for orders.因为每个网站都有自己的订单表结构。 Try this as a guide:试试这个作为指导:

On your Paypal profile set your preference to redirect automatically after an order.在您的 Paypal 个人资料中,将您的偏好设置为在下单后自动重定向。 You will also need to set a default return url.您还需要设置一个默认的返回 url。 this will be used if you forgot to specify a return url on your order form or query string sent to Paypal.如果您忘记在发送到 Paypal 的订单或查询字符串中指定返回 url,将使用此选项。

Next, set your rm field/variable to "2" (this will tell Paypal API to autoredirect to your return url after the order and pass the order info in POST format)接下来,将您的 rm 字段/变量设置为“2”(这将告诉 Paypal API 在订单后自动重定向到您的退货网址并以 POST 格式传递订单信息)

You can view the response from Paypal by doing a var_dump($_POST) or print_r($_POST).您可以通过执行 var_dump($_POST) 或 print_r($_POST) 查看来自 Paypal 的响应。

One of the important variables from the response is $_POST['payment_status'] which will tell you the outcome of the order.响应中的重要变量之一是 $_POST['payment_status'],它将告诉您订单的结果。 A successful transaction is 'Completed'.成功的交易是“已完成”。 A transaction that requires verification from Paypal or from the merchant's side is 'Pending'.需要从 Paypal 或商家方进行验证的交易是“待处理”。

Lastly, don't forget to specify 'invoice' on your Paypal field/request so you can update the status of your order.最后,不要忘记在您的 Paypal 字段/请求中指定“发票”,以便您可以更新订单状态。 Something like:类似的东西:

$status = $_POST['payment_status'];
$invoice = $_POST['invoice'];
mysql_query("UPDATE Orders SET status='$status' WHERE order_id='$invoice'");

I know this is bad and unsafe coding but at least you get the general idea in it's simplest form.我知道这是糟糕且不安全的编码,但至少您以最简单的形式获得了总体思路。

Again, don't rely on other's codes.同样,不要依赖他人的代码。 Codes in the net exists for reference purposes and not as God's handwork.网络中的代码仅供参考,并非上帝的杰作。 Only you have the power to create your own masterpiece :D只有你有能力创造自己的杰作 :D

I hope that helps.我希望这有帮助。 Vote up if you like it.喜欢就投上一票吧。 Ignore if not.如果没有,请忽略。

A commercial but low cost solution is the LinkLokIPN script at:一个商业但低成本的解决方案是 LinkLokIPN 脚本:

http://www.vibralogix.com/linklokipn/ http://www.vibralogix.com/linklokipn/

No connection other than as a satisfied customer of the PHP version.除了作为 PHP 版本的满意客户之外,没有任何联系。 Sometimes it is MUCH easier to buy (and perhaps adapt) a working solution than to reinvent the wheel.有时,购买(或许调整)一个可行的解决方案比重新发明轮子要容易得多。

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

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