【问题标题】:PayPal not returning variablesPayPal不返回变量
【发布时间】:2014-12-05 19:38:52
【问题描述】:

我正在将 PayPal 添加到我的结帐表单中。我没有使用 API,而是使用表单脚本。但是,付款后我没有从 PayPal 获得响应变量。我想确认我收到的金额,看看用户是否支付了他应该支付的金额。

由于我没有收到来自贝宝的响应变量,我无法看到用户是否确实支付了很多钱。难道我做错了什么?我看到很多人对此有疑问,但没有一个人有答案。

我的表格:

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" >
                        <input type="hidden" name="business" value="seller@seller.com">
                        <input type="hidden" name="cmd" value="_xclick">
                        <input type="hidden" name="upload" value="1" />
                        <input type="hidden" name="item_name" value="<?php echo $_amount_credits ?> credits">
                        <input type="hidden" name="item_number" value="<?php echo $_invoice_id ?>">
                        <input type="hidden" name="amount" value="<?php echo $_total_amount ?>">
                        <input type="hidden" name="lc" value="NL">
                        <input type="hidden" name="rm" value="2">
                        <input type="hidden" name="cbt" value="Go back to http://domain.com">
                        <input type="hidden" name="no_note" value="1" />
                        <input type="hidden" name="currency_code" value="EUR">
                        <input type="hidden" name="return" value="http://domain.com/index.php?payment=success&transaction_id=<?php echo $_GET['tx'] ?>"/>

                        <input type="hidden" name="cancel_return" value="http://domain.com/index.php?payment=canceled&transaction_id=<?php echo $_GET['tx'] ?>"/>
                        <input type="submit" class="button blue _quick_order_overview _payment_paypal" name="submit" value="Pay via PayPal">
                    </form>

【问题讨论】:

  • 接收页面的代码在哪里?
  • @Kkinsey 接收页面与表单所在页面相同。我正在检查是否设置了 $_GET 变量。如果是,则显示成功内容,如果不是,则显示 paypal 按钮。我正在考虑制作一个回调页面,我将在其中进行数据库操作。但是话又说回来,我无法验证是否已付款以及他们支付了多少钱。
  • 对。我不确定我是否解释得很好,但我认为你在错误的地方寻找“tx”。 您的用户提交上述表单后,该表单用于提交您的购物车,PayPal 将返回它们并自动将 tx=somevalue 附加到返回 URL。您不能向他们发送“tx”的值,因为您还没有应该拥有它。
  • PayPal 不返回任何东西,这就是重点。我添加变量只是为了检查我是否能得到答案。如果我删除变量,它只会将我重定向到没有变量的 index.php 。

标签: php paypal


【解决方案1】:

您应该使用Instant Payment Notification (IPN) 来处理这类事情。在 GitHub/Packagist 等上有很多很好的模板。

每当您的 PayPal 帐户发生交易时,IPN 都会将交易数据发布到您在服务器上设置的侦听器脚本。这将用于付款、退款、争议、清除电子支票等。您可以根据 IPN 发送给您的不同 txn_type 自动执行各种任务。

【讨论】:

    猜你喜欢
    • 2011-06-21
    • 2018-05-05
    • 2021-05-20
    • 2014-03-08
    • 2013-05-26
    • 1970-01-01
    • 2016-01-13
    • 1970-01-01
    相关资源
    最近更新 更多