首次通过Paypal重定向用户时,如何传递发布的数据? [英] How can I get posted data passed along when the user is first redirected through Paypal?

查看:80
本文介绍了首次通过Paypal重定向用户时,如何传递发布的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试解决了一段时间.我有一个订单页面,客户必须在其中输入信息,例如姓名,地址等,以及一些其他唯一字段.我已经使用Paypal设置了IPN,并将客户重定向到我指定的页面.但是数据并没有随之而来.我希望我能正确地问我的问题,以免我被关闭".这是贝宝(Paypal)提交按钮中的HTML,该HTML重定向到他们的页面.

I've been trying to tackle this for some time now. I have an order page where the customer must enter information like name, address, etc. and some more unique fields. I have set up IPN with Paypal and the customer is redirected to the page I specified. But the data does not come along with it. I hope I'm asking my question properly so that I don't get "closed." Here is the HTML in the Paypal submit button that redirects to their page.

<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变量",我以后可以修复,但是访问Paypal后,我的数据都无法返回到我的指定页面,即使是Paypal支持城市".这是我在页面上将其重定向到的PHP.

It has been pointed out to me that some of the variables are not "Paypal variables" and I can fix that later, but none of my data is making it back to my specified page after visiting Paypal, even the variables that Paypal supports like "city." Here is the PHP that I have on the page that they get redirected to.

$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();
foreach ($raw_post_array as $keyval) {
  $keyval = explode ('=', $keyval);
  if (count($keyval) == 2)
     $myPost[$keyval[0]] = urldecode($keyval[1]);
}
$req = 'cmd=_notify-validate';
if(function_exists('get_magic_quotes_gpc')) {
   $get_magic_quotes_exists = true;
} 
foreach ($myPost as $key => $value) {        
   if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) { 
        $value = urlencode(stripslashes($value)); 
   } else {
        $value = urlencode($value);
   }
   $req .= "&$key=$value";
}

$ch = curl_init('https://www.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));

if( !($res = curl_exec($ch)) ) {
    // error_log("Got " . curl_error($ch) . " when processing IPN data");
    curl_close($ch);
    exit;
}
curl_close($ch);

if (strcmp ($res, "VERIFIED") == 0) {
        $child_name = htmlentities($_POST['child_name']);
        $age = $_POST['age'];
        $hometown = $_POST['hometown'];
        $boy_girl = $_POST['boy_girl'];
        $email = $_POST['email'];
        $first_name = htmlentities($_POST['first_name']);
        $last_name = htmlentities($_POST['last_name']);
        $address1 = htmlentities($_POST['address1']);
        $address2 = htmlentities($_POST['address2']);
        $city = htmlentities($_POST['city']);
        $state = $_POST['state'];
        $zip = htmlentities($_POST['zip']);
        $country = htmlentities($_POST['country']);
        $payment_type = $_POST['payment_type'];
        $paid = $_POST['paid'];
        $mailed = $_POST['mailed'];
} else if (strcmp ($res, "INVALID") == 0) {
}       

        $query = "INSERT INTO customer_list (
        number, child_name, age, hometown, boy_girl, first_name, last_name, email,
        address1, address2, city, state, zip, country, payment_type, paid, mailed)
        VALUES ('', 
        '".mysql_real_escape_string($child_name)."',
        '".mysql_real_escape_string($age)."',
        '".mysql_real_escape_string($hometown)."',
        '".mysql_real_escape_string($boy_girl)."',
        '".mysql_real_escape_string($first_name)."',
        '".mysql_real_escape_string($last_name)."',
        '".mysql_real_escape_string($email)."',
        '".mysql_real_escape_string($address1)."',
        '".mysql_real_escape_string($address2)."',
        '".mysql_real_escape_string($city)."',
        '".mysql_real_escape_string($state)."',
        '".mysql_real_escape_string($zip)."',
        '".mysql_real_escape_string($country)."',
        '".mysql_real_escape_string($payment_type)."',
        '".mysql_real_escape_string($paid)."',
        '".mysql_real_escape_string($mailed)."')";
            if ($query_run = mysql_query($query)) {

                $subject = "Thank You for Your Order";
                $message = "Thank you for placing your order with My-Letter-From-Santa-Claus.com. \n\nYou can expect to receive your personalized letter soon. Please make note of your customer number. Your customer number is: ".mysql_insert_id().". \n\nPlease send all inquiries to : info@my-letter-from-santa-claus.com";
                $from = "info@my-letter-from-santa-claus.com";
                $headers = "From:" . $from;
                mail($email, $subject, $message, $headers);
                echo 'Thank you for your order.';
                echo 'Letter For '.$child_name;
            } else {
                echo mysql_error();
            }

除了直接更改为自己的变量外,我大部分都是直接从x.com复制的.什么都没有发布到数据库,但这不是问题,因为我什至无法回显数据.几件事正在输入数据库中,但不是我的订单页面中的数据-它是在Paypal上作为信用卡信息输入的名字和姓氏,对于payment_type,它说"instan"(我最大化了(最多6个字符),但是正如您从HTML的隐藏输入字段中所看到的那样,我想发布值"paypal".我该如何解决?

I copied most of it directly from x.com except for changing to my own variables of course. Nothing is getting posted to the database but that's not the issue since I cannot even echo the data. A couple things are being entered into the database but it's not the data from my order page - it is the first name and last name that is entered as the credit card info on Paypal, and for payment_type it says "instan" (I maxed it at 6 characters) but as you can see from the hidden input field in the HTML, I wanted to post the value "paypal." How do I fix this?

推荐答案

您是否正在使用Paypal沙箱进行测试?如果没有,我强烈建议您: https://developer.paypal.com/,以及手册: https://cms.paypal.com/cms_content/US/en_US/files/developer/PP_Sandbox_UserGuide.pdf .

are you using the Paypal Sandbox for testing? If not, I strongly recommend it: https://developer.paypal.com/, and the manual: https://cms.paypal.com/cms_content/US/en_US/files/developer/PP_Sandbox_UserGuide.pdf.

我在您的代码中看不到字段名称="business".这是贝宝用来识别您的卖方帐户的字段.但也许只与"cmd"参数有关(我使用_xclick).

I don't see the field name="business" in you code. That is the field which Paypal uses to identify you seller account. But maybe it only has to do with the "cmd" parameter (I use _xclick).

这是一组目前对我有用的字段,也许对您有帮助:

Here is a set of fields which works at this time for me, maybe it helps you:

<form name="_xclick" action="https://www.paypal.com/de/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="business" value="seller_email_here">
    <input type="hidden" name="notify_url" value="ipn_url_here">
    <input type="hidden" name="return" value="redirect_url">
    <input type="hidden" name="cancel_return" value="redirect_if_cancelled_url">
    <input type="hidden" name="amount" value="number_of_items">
    <input type="hidden" name="currency_code" value="EUR">
    <input type="hidden" name="item_name" value="product_name">
    <input type="hidden" name="item_number" value="product_number">

这篇关于首次通过Paypal重定向用户时,如何传递发布的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆