通过paypal重定向时无法通过POST数据

时间:2012-10-25 20:50:47

标签: php javascript html paypal

我建立了一个网站,客户可以在其中输入信息(姓名,地址等),并希望他们能够通过PayPal使用信用卡付款。这很好用。我已经设置了Paypal即时付款通知,并通过PayPal将其设置为客户被重定向到我的页面。这一切都正常工作,除了数据没有传递并保存到我的SQL数据库。我知道将数据插入数据库的代码可以正常工作。问题是数据没有被传递到该页面,因为paypal页面介于两者之间。

这是我的php

if (isset($_POST['child_name'])
    && isset($_POST['age'])
    && isset($_POST['hometown'])
    && isset($_POST['boy_girl'])
    && isset($_POST['email'])
    && isset($_POST['first_name'])
    && isset($_POST['last_name'])
    && isset($_POST['address1'])
    && isset($_POST['address2'])
    && isset($_POST['city'])
    && isset($_POST['state'])
    && isset($_POST['zip'])
    && isset($_POST['country']))  {
        $child_name = $_POST['child_name'];
        $age = $_POST['age'];
        $hometown = $_POST['hometown'];
        $boy_girl = $_POST['boy_girl'];
        $email = $_POST['email'];
        $first_name = $_POST['first_name'];
        $last_name = $_POST['last_name'];
        $address1 = $_POST['address1'];
        $address2 = $_POST['address2'];
        $city = $_POST['city'];
        $state = $_POST['state'];
        $zip = $_POST['zip'];
        $country = $_POST['country'];
}

这是HTML

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="NT2YC6LP7SWBE">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<input type="hidden" name="child_name" id="child_name" value ="<? echo $child_name; ?>" maxlength="20"/>
<input type="hidden" name="age" id="age" value ="<? echo $age; ?>" maxlength="4"/>
<input type="hidden" name="hometown" id="hometown" value ="<? echo $hometown; ?>" maxlength="32"/>
<input type="hidden" name="boy_girl" id="boy_girl" value ="<? echo $boy_girl; ?>" maxlength="4"/>
<input type="hidden" name="first_name" id="first_name" value ="<? echo $first_name; ?>" maxlength="32"/>
<input type="hidden" name="last_name" id="last_name" value ="<? echo $last_name; ?>" maxlength="32"/>
<input type="hidden" name="email" id="email" value ="<? echo $email; ?>" maxlength="64"/>
<input type="hidden" name="address1" id="address1" value ="<? echo $address1; ?>" maxlength="64"/>
<input type="hidden" name="address2" id="address2" value ="<? echo $address2; ?>" maxlength="32"/>
<input type="hidden" name="city" id="city" value ="<? echo $city; ?>" maxlength="32"/>
<input type="hidden" name="state" id="state" value ="<? echo $state; ?>" maxlength="20"/>
<input type="hidden" name="zip" id="zip" value ="<? echo $zip; ?>" maxlength="10"/>
<input type="hidden" name="country" id="country" value ="<? echo $country; ?>" maxlength="32"/>
<input type="hidden" name="payment_type" id="payment_type" value ="paypal" maxlength="6"/>
<input type="hidden" name="paid" id="paid" value ="yes" maxlength="3"/>
<input type="hidden" name="mailed" id="mailed" value ="no" maxlength="3"/>
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

我只是采用了paypal给我的形式并添加了隐藏的输入。这在另一个页面上完美地工作,但这是因为action属性直接指向将插入数据的页面。在这里,动作将它们发送到paypal的网站,数据永远不会发送到我的网站。我该如何调整呢?

2 个答案:

答案 0 :(得分:1)

由于流程,你不能这样做。两种解决方案:

  • 尝试使用分隔符将所有信息存储在Paypal的custom字段(255个字符)中

  • 使用唯一键将自定义信息存储在数据库中,并将唯一键存储在custom字段中,以便稍后使用IPN响应进行检索

在获得IPN响应之前,您不应该做任何与数据库相关的事情,这是IPN的重点。你在这里描述的是PDT,它依赖于客户在付款过程之后返回你的页面,而这种过程并不总是发生。

答案 1 :(得分:0)

正如kalpaitch建议的那样,您应该将数据保存到会话中,并在访问者从paypal页面返回时将其拉回。