在网上商店快速结帐后,如何使用 paypal 确认付款? PHP

发布于 2024-11-01 15:28:55 字数 2356 浏览 1 评论 0原文

当您在任何网上商店点击 Express Checkout PayPal 按钮时,它会将您重定向到特定的 PayPal 登录链接,用于支付订单。

我已经花了三天时间寻找一个简单的 paypal php curl 脚本,该脚本可以让您从这一步登录并确认付款,但没有找到任何东西。我只找到了从 PayPal 主页登录的脚本,当您中断 PayPal 流程时,该脚本将无法工作。

我发现不可能使用 API 来完成此操作,因此必须通过 CURL 来完成。

我之所以要求这个,是因为我经营一个直销网站,并且希望自动化某些步骤,例如下订单和支付订单。一个有效的代码不仅可以帮助我,还可以帮助所有希望以某种形式实现自动化购买的人。

我将粘贴我制作的非工作脚本,它只会给我一条来自贝宝的“抱歉 - 您的上一个操作无法完成”消息,如果这可以以任何方式提供帮助的话。



$agent = "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.8) Gecko/20061025 Firefox/1.5.0.8";
$header[] = "text/html; charset UTF-8";
$url = $_GET[link];
// $url = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&&token=EC-EXAMPLE7839244";
$email = urlencode("email");
$password = urlencode("password");
$cookies = "cookies.txt";

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_REFERER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);
curl_setopt($ch, CURLOPT_URL, $url);

// HIT LOGINPAGE
$login = curl_exec ($ch);
// PRINT LOGINPAGE
var_dump($login);

// GET LOGIN-LINK AND SET POSTFIELDS
preg_match("/merchantpaymentweb\?cmd\=\_flow(.*?)\"/", $login, $output);
$link = "https://www.paypal.com/c2/cgi-bin/merchantpaymentweb?cmd=_flow$output[1]";
// PRINT LOGIN-LINK
echo "LINK: $link
"; preg_match("/CONTEXT\" value=\"(.*?)\"/", $login, $output); $CONTEXT = $output[1]; $postfields = "CONTEXT=$CONTEXT&close_external_flow=false&cmd=_flow&external_close_account_payment_flow=payment_flow&flow_name=xpt/Merchant/hostedpayments/Login&flow_name=xpt/Merchant/hostedpayments/Login&form_charset=UTF-8&id=&login.x=Log+In&login_email=".$email."&login_password=".$password."&myAllTextSubmitID="; echo "
POSTFIELDS : \"$postfields\"
"; curl_setopt($ch, CURLOPT_URL, $link); curl_setopt ($ch, CURLOPT_POST, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, $postfields); // POST FORM, fails, gives "Sorry - Your last action could not be completed" message $should_be_logged_in_now = curl_exec($ch); var_dump($should_be_logged_in_now);

When you click the Express Checkout PayPal button on any webshop, it redirects you to a spesific paypal login link, for paying the order.

I have been searching high and low for 3 days now for a simple paypal php curl script that logs you in from this step, and confirms the payment, but have not been able to find anything. I only found scripts that logs you in from the mainpage of paypal, which wont work as you break the paypal flow.

I found out it is not possible to use the API for this, so its gotta be done by CURL.

Im asking for this because I run a dropshipping website, and would like to automate certain steps, like placing and paying orders. A working code for this would help not just me, but all looking to automate buying in some form.

I will paste the non-working script that I made, which only gives me a "Sorry - Your last action could not be completed" message from paypal, if that can help in any way at all..



$agent = "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.8) Gecko/20061025 Firefox/1.5.0.8";
$header[] = "text/html; charset UTF-8";
$url = $_GET[link];
// $url = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&&token=EC-EXAMPLE7839244";
$email = urlencode("email");
$password = urlencode("password");
$cookies = "cookies.txt";

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_REFERER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);
curl_setopt($ch, CURLOPT_URL, $url);

// HIT LOGINPAGE
$login = curl_exec ($ch);
// PRINT LOGINPAGE
var_dump($login);

// GET LOGIN-LINK AND SET POSTFIELDS
preg_match("/merchantpaymentweb\?cmd\=\_flow(.*?)\"/", $login, $output);
$link = "https://www.paypal.com/c2/cgi-bin/merchantpaymentweb?cmd=_flow$output[1]";
// PRINT LOGIN-LINK
echo "LINK: $link
"; preg_match("/CONTEXT\" value=\"(.*?)\"/", $login, $output); $CONTEXT = $output[1]; $postfields = "CONTEXT=$CONTEXT&close_external_flow=false&cmd=_flow&external_close_account_payment_flow=payment_flow&flow_name=xpt/Merchant/hostedpayments/Login&flow_name=xpt/Merchant/hostedpayments/Login&form_charset=UTF-8&id=&login.x=Log+In&login_email=".$email."&login_password=".$password."&myAllTextSubmitID="; echo "
POSTFIELDS : \"$postfields\"
"; curl_setopt($ch, CURLOPT_URL, $link); curl_setopt ($ch, CURLOPT_POST, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, $postfields); // POST FORM, fails, gives "Sorry - Your last action could not be completed" message $should_be_logged_in_now = curl_exec($ch); var_dump($should_be_logged_in_now);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仲春光 2024-11-08 15:28:55

我对使用 PayPal 不太熟悉。由于退款,我四年前就停止使用它了。

您可能需要检查 PayPal Pro API 这是一项付费服务​​。这可能就是您正在寻找的东西,而不是处理 CURL & 。 PayPal,因为您提到使用 API。

I am not much familiar with using PayPal. I stopped using it like 4 years ago due to charge-backs I had.

You might want to check PayPal Pro API which is a paid service. This might be what you are looking for instead of dealing with CURL & PayPal since you mentioned about using API.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文