首页 文章

PayPal立即购买按钮自定义变量不起作用

提问于
浏览
0

我正在尝试通过3个经典步骤执行付款:

1)带有PayNow按钮的订单页面

2)PayPal付款

3)重定向到“付款已完成页面”

我想要实现的是从第1步到第3步 . 我尝试做的是将此字段插入“自定义”变量,如:

<input type="hidden" name="custom" value="--Server Code--">

PayPal付款后,PayPal会将我重定向到我的页面:

http://www.mysite.cm/tx=blalba?aaaa

在此URL中没有自定义字段 . 如果,从API,我联系PayPal获取销售详细信息,我得到的任何与我的自定义字段无关 .

我做错了什么?我正在考虑使用cookie,但我更喜欢以标准方式进行 .

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
        <input type="hidden" name="cmd" value="_s-xclick">
        <input type="hidden" name="return" value="testestest">
        <input type="image" src="https://www.paypalobjects.com/it_IT/IT/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal è il metodo rapido e sicuro per pagare e farsi pagare online.">
        <img alt="" border="0" src="https://www.paypalobjects.com/it_IT/i/scr/pixel.gif" width="1" height="1">
    </form>

2 回答

  • 2

    PayPal自定义变量在IPN(Instante付款通知)中返回,而不是在用户在完成付款后返回到您的网站时返回 .

    在你的情况下,只需一个会话变量即可 .

    编辑:

    另一种方法可能是在“返回”字段中添加正确的url值 . 例:

    <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
        <input type="hidden" name="cmd" value="_xclick">
        <input type="hidden" name="return" value="http://www.website.com?pram=value">
        <input type="hidden" name="cancel" value="http://www.website.com?param=value">
        <input type="hidden" name="business" value="yourpaypal@email.com">
        <input type="hidden" name="item_name" value="Test">
        <input type="hidden" name="amount" value="9.00">
        <input type="hidden" name="currency_code" value="EUR">
    
        <input type="image" src="https://www.paypalobjects.com/it_IT/IT/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal è il metodo rapido e sicuro per pagare e farsi pagare online.">
       <img alt="" border="0" src="https://www.paypalobjects.com/it_IT/i/scr/pixel.gif" width="1" height="1">
    </form>
    
  • 0

    现有的答案已经提到IPN是要走的路,但缺少的是如何实际实现这一点的更多信息 .

    我最近自己必须这样做,所以这里的解决方案对我有用:

    首先,您需要将您的ID添加到“立即付款”按钮的HTML中,例如添加到“自定义”变量中,如问题中所示 .

    在我自己的实现中,我在使用"custom"变量时遇到了一些问题(不再记得细节了),所以我将我的ID作为URL参数传递到IPN "notify" URL中:

    <input type="hidden" name="notify_url" value="https://example.com/notify/?id=xyz">
    

    这是我的按钮的完整HTML代码:

    <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
        <input type="hidden" name="cmd" value="_s-xclick">
        <input type="hidden" name="hosted_button_id" value="ABCDEFGHILJKLM">
        <table>
        <tr><td><input type="hidden" name="on0" value="Betrag">Betrag</td></tr><tr><td><select name="os0">
            <option value="Gebuehr">Gebuehr €3,50 EUR</option>
            <option value="Gebuehr und Spende">Gebuehr und Spende €5,00 EUR</option>
        </select> </td></tr>
        </table>
        <input type="hidden" name="currency_code" value="EUR">
        <input type="image" src="https://www.paypalobjects.com/de_DE/DE/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="Jetzt einfach, schnell und sicher online bezahlen – mit PayPal.">
        <img alt="" border="0" src="https://www.paypalobjects.com/de_DE/i/scr/pixel.gif" width="1" height="1">
        <input type="hidden" name="notify_url" value="https://example.com/notify/?id=xyz">
    </form>
    

    付款流程完成后,PayPal会将IPN message发布到我的通知URL,其中包含大量有关交易的信息(有关详细信息,请参阅链接) .

    我的ID是通过URL参数传递的,所以我可以这样得到它(在PHP中):

    $uid = "";
    if (!empty($_GET['id'])) {
        $uid = $_GET['id'];
    }
    

    当然,你需要check whether the IPN call is actually coming from PayPal .

相关问题