我正在开发一个网站,客户有多种付款方式,包括 PayPal 付款标准。由于我正在收集有关客户的大量数据,因此我想在将用户发送到 PayPal 的服务器之前在我的服务器上处理表单。一种选择是将数据连接成单个字符串,将字符串分配给custom
字段,然后在 IPN 响应中对其进行处理,但我发现这是一个非常不雅的解决方案。相反,在收集用户数据后,我尝试使用 cURL 提交标准的 HTML PayPal 表单。如何将用户重定向到 PayPal 以完成结帐流程?
// Process PayPal payment
if ($method == 'PayPal') {
// Prepare POST data
$query = array();
$query['notify_url'] = 'http://example.com/ipn';
$query['cmd'] = '_cart';
$query['upload'] = '1';
$query['business'] = 'email@example.com';
$query['address_override'] = '1';
$query['first_name'] = $first_name;
$query['last_name'] = $last_name;
$query['email'] = $email;
$query['address1'] = $ship_to_address;
$query['city'] = $ship_to_city;
$query['state'] = $ship_to_state;
$query['zip'] = $ship_to_zip;
$query['item_name_'.$i] = $item['description'];
$query['quantity_'.$i] = $item['quantity'];
$query['amount_'.$i] = $item['info']['price'];
// Prepare query string
$query_string = '';
foreach ($query as $key=>$value) {
$query_string .= $key.'='.urlencode($value).'&';
}
$query_string = rtrim($query_string, '&');
// Open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, 'https://www.paypal.com/cgi-bin/webscr');
curl_setopt($ch,CURLOPT_POST, count($query));
curl_setopt($ch,CURLOPT_POSTFIELDS, $query_string);
// Execute post
$result = curl_exec($ch);
// Close connection
curl_close($ch);
}