开发者

How can i Curl into paypal to confirm payment after express checkout in a webshop? PHP

开发者 https://www.devze.com 2023-02-27 03:55 出处:网络
When you click the Express Checkout PayPal button on any webshop, it redirects you to a spesific paypal login link, for paying the order.

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_USERAG开发者_高级运维ENT, $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);


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消