Take the 2-minute tour ×

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..

$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);

$login = curl_exec ($ch);

preg_match("/merchantpaymentweb\?cmd\=\_flow(.*?)\"/", $login, $output);
$link = "https://www.paypal.com/c2/cgi-bin/merchantpaymentweb?cmd=_flow$output[1]";
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);
share|improve this question
paypal informs you of the transaction to any url you specify, you don't need to query them –  Dagon Apr 18 '11 at 0:34
i dont get what you mean. –  jagarock Apr 18 '11 at 0:45
IPN: cms.paypal.com/us/cgi-bin/… –  Dagon Apr 18 '11 at 3:25
isnt IPN only for reacting to things happening on your own account? what i read in the link supports this. when you place an order in a webshop and press the express checkout button, nothing happens in your account. im talking about you, buying from another persons webshop here, maybe i was unclear –  jagarock Apr 18 '11 at 4:29
ok, then you simply can't do that. –  Dagon Apr 18 '11 at 6:28

1 Answer 1

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.

share|improve this answer
i asked in the x.com forums if the paypal api can do this, got a negative answer from a staff in there :/ –  jagarock Apr 18 '11 at 0:20
I'm not sure if what you want is even possible. If I would be the main guy for such stuff in PayPal, I would never allow such action. You could make things easier tho with PayPal PRO API. If they don't have such feature in it, I don't think you could achieve it with CURL without having any security issues. In the end, it is a web-shop, security is important for you. –  Revenant Apr 18 '11 at 0:33
it should be possible to emulate the manual logging in and pressing the confirm button. everything is possible, isnt that the saying. its possible to login from the frontpage so why shouldnt it be from the checkout flow. security is not an issue on my side, as i will be manually clicking the "order and pay item from website" button in my backend system. –  jagarock Apr 18 '11 at 0:40
for all of the people out there making a living of dropshipping like me and buying 50+ different items every day, im sure someone has done it. i would be willing to pay for a working script. –  jagarock Apr 18 '11 at 0:46
I didn't mean, it is not possible at all. I just meant if I were authorized person in PayPal about such Tech stuff, I would never let PayPal members to be able to take such action due to security issues it might bring. You could check it here codecanyon.net/item/easy-e/231528 and even try to contact with author if you are willing to pay. Seems (s)he is good with PayPal. –  Revenant Apr 18 '11 at 0:58

Your Answer


