PayPal IPN 和更新数据库

发布于 2024-10-18 13:41:51 字数 509 浏览 4 评论 0原文

我了解 IPN 的工作原理,以及发送信息、验证等的基本思想。但我一生都无法让它工作!

这就是我正在尝试做的...

用户选择要购买的产品的某个部分,一旦他们单击它,它们就会链接到我添加了 2 个文本字段的 paypal 按钮。第一个是用户 ID,第二个是他们所选部分的名称 - 两者的值都会自动添加。一切都很好。

然后,他们按“立即购买”并填写卡详细信息,然后购买并重定向到成功页面。

但是,我想要它,因此它会更新我数据库中的个人资料,以显示他们已购买该产品。

我了解,使用 PayPal 的 IPN,我可以将信息发送到我网站上的页面进行检查,如果付款完成,则采取所需的任何操作。

我已经尝试过 PayPal 网站本身的脚本,但没有得到任何响应。有人能给我一个非常非常简单的方法来实现我所追求的目标吗?因为每个教程都过于复杂或不起作用,而且这些示例对我没有丝毫帮助,而且它们会告诉你,就好像你应该知道它是如何完成的一样。

我什至已经阅读了整个 PDF,但我仍然不知道如何让它工作。有什么帮助吗?

I understand how IPN works, and the basic idea of the sending of information, verifying etc. But for the life of me I cannot get it to work!!

This is what I'm trying to do...

A user selects a certain part of a product to purchase, once they click it, they are linked to a paypal button which I've added 2 text fields to. First is there User ID and the second the name of their selected part - both of which the value is added in automatically. That all works fine.

They then press Buy Now and fill out their card details and it is purchased and redirected to a success page.

However, I want it so it updates their profile in my database to show they have purchased that product.

I understand that using PayPal's IPN I can send information to a page on my site to check it, and if the payment is complete then take whatever action needed.

I have tried the scripts from the PayPal site itself and I get no response at all. Can someone give me a really, REALLY simple method of achieving what I'm after? Because every tutorial out there is overly complicated or doesn't work, and the examples don't help me in the slightest and they talk to you as if you should know how it's done already.

I've even read the whole PDF and still I'm clueless about how to get this working. Any help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

前事休说 2024-10-25 13:41:51

这实际上取决于您如何将用户存储在数据库中。

  1. 他们如何被识别,他们有用户名吗?
  2. 在将信息提交给 PayPal 之前,您是否将交易保存到数据库中?

基本上,您需要查看 IPN 变量 并查看当脚本收到 IPN 消息时可以使用什么将数据与数据库关联起来。

假设您有以下数据库:

Users: ID, email, etc.. etc..

Transactions: ID, emailofUser, invoiceID, Success/Fail(bool)

您希望在将数据发送到 PayPal 之前将信息存储到数据库 - “嘿,这个人被发送到 PayPal 来购买这个”。

然后,当您想要确保该商品确实是购买的时,IPN 就会派上用场。您不想为某人提供购买商品的好处只是为了发送到 PayPal,您希望确保他们实际完成付款。除了 IPN 变量之外,您还可以轻松使用“发票”变量(只要您在将数据发送到 PayPal 时正确定义它)。

假设您将买家发送到 PayPal,他完成结账,您的脚本会收到一条 IPN 消息。您需要执行以下操作:

  1. 验证 IPN
  2. 检查这适用于哪张发票

    mysql_query("SELECT * FROM Transactions WHEREinvoiceID=$_POST['invoice']");

  3. 查看交易是否成功。

    if ($_POST[' payment_status'] == '已完成')
    { 
    //更新你需要的任何信息
    }
    别的
    {
    //此交易发生了其他事情,在其上放置一个标志以供审核
    //管理员
    }
    

您应该查看下面的链接,其中详细介绍了有关管理订单的信息

订单管理自动化
订单管理指南

This really depends on how you have your users stored in a database.

  1. How are they identified, do they have a username?
  2. Are you saving transactions to a database before you submit the information to PayPal?

Basically, you would want to look at the IPN Variables and see what you could use to associate the data with your databases when the IPN message is received by your script.

Lets say you have the following Databases:

Users: ID, email, etc.. etc..

Transactions: ID, emailofUser, invoiceID, Success/Fail(bool)

You want to store information to the database before you send the data to PayPal - "Hey, this guy was sent to PayPal to purchase this".

Then, IPN comes in when you want to ensure that the item was actually purchased. You don't want to offer someone the benefits of purchasing an item just for being sent to PayPal, you want to make sure they actually completed payment. Going off of the IPN variables, you could easily use the 'invoice' variable (as long as you define it appropriately when you send the data to PayPal).

So lets say you send a buyer to PayPal, he completes checkout, and your script gets an IPN message. You'll want to do something like the following:

  1. Verify the IPN
  2. Check what invoice this is for

    mysql_query("SELECT * FROM Transactions WHERE invoiceID=$_POST['invoice']");

  3. See if the transaction is successful or not.

    if ($_POST['payment_status'] == 'completed')
    { 
    //update whatever information you need to
    }
    else
    {
    //something else happened with this transaction, put a flag on it for review by
    //an admin
    }
    

You should check out the links below which describe a little more about managing your orders

Order Management Automation
Order Management Guide

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文