简体   繁体   English

尝试使用cURL提交Paypal表单…

[英]Trying to Submit Paypal Form with cURL…

I have been researching how to pass a Paypal form submission automatically without a user clicking the checkout button. 我一直在研究如何在没有用户单击结帐按钮的情况下自动通过Paypal表单提交。 Here is the code I have so to do this: 这是我这样做的代码:

<?php
$post_data['cmd'] = '_xclick';
$post_data['business'] = 'myemail@website.com';
$post_data['item_name'] = 'The Items You are Purchasing';
$post_data['amount'] = '25';
$post_data['no_shipping'] = '1';
$post_data['no_note'] = '1';
$post_data['currency_code'] = 'USD';
$post_data['bn'] = 'PP-BuyNowBF';

foreach ( $post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}
$post_string = implode ('&', $post_items);

$curl_connection = curl_init('https://www.paypal.com/cgi-bin/webscr');
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1); 

curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string); 

$result = curl_exec($curl_connection);

curl_close($curl_connection); 
?>

As best as I can tell this should pass the values over to Paypal and ask the user to pay $25 for 'The Items You are Purchasing' to 'myemail@website.com.' 据我所知,这应该将值传递给Paypal,并要求用户向“ myemail@website.com”支付25美元的“您正在购买的商品”。 But for some reason it is not working, do you know why? 但是由于某种原因它无法正常工作,您知道为什么吗?

As I see, you are using Buy It Now Button. 如我所见,您正在使用“立即购买”按钮。 It dos'n work with curl because user(customer) should take part in the payment process: log in into his(her) account on PayPal or enter payment and billing information if he doesn't have it, confirm payment and return to your 'shop' manually. 它不能与curl配合使用,因为用户(客户)应参与付款过程:登录其在PayPal上的帐户,如果没有,请输入付款和帐单信息,确认付款并返回到手动“购物”。 How user could do this with curl? 用户如何使用curl做到这一点? All PayPal behaviour will be stored in the curl vaiables(if we can say so) If you are tied with this payment metho and don't want the button to be clicked mannually(read form to be submitted), you may submit it automatically using javascript. 所有PayPal行为都将存储在curl随货售卖店中(如果可以这样说的话)。如果您对此付款方式有所了解,并且不希望手动单击该按钮(请阅读表格以提交),则可以使用以下方式自动提交: javascript。 Or you may redirect user to the PalPal and pass all parameters via GET. 或者,您可以将用户重定向到PalPal,并通过GET传递所有参数。 It also should work. 它也应该起作用。 Otherwise you should use PayPal Payments Pro. 否则,您应该使用PayPal Payments Pro。 Concretely - Direct Payment. 具体而言-直接付款。 User will fill out form on your site (credit card, billing info, etc) and you could use curl to finish payment. 用户将在您的网站上填写表格(信用卡,账单信息等),然后您可以使用curl来完成付款。

Sorry for bad English. 对不起,英语不好。 I tried to be clear. 我试图弄清楚。 I hope it will be helpfull. 希望对您有所帮助。

Looking at your requirements, all you need to do is keep the post information in the last page before you want the customer to be redirected to paypal. 查看您的要求,您需要做的就是在希望将客户重定向到Paypal之前,将帖子信息保留在最后一页中。

Something like 就像是

<!-- Display all items etc. -->

<form action='https://www.paypal.com/cgi-bin/webscr' method='POST'>
POST DATA

Submit button
</form>

You could also an extra page where you post all the information into a page and use javascript to auto submit the form. 您也可以在一个额外的页面上将所有信息发布到页面中,并使用javascript自动提交表单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM