I'm working on a PHP + curl script to make payments (NOT TO RECEIVE) via the famous PP payment gw.
I'm able to fill a cart on an external website (not mine) and login for the payment (express checkout). After the login, I see the button "continue", which submits a POST form.
I'm able to send the requested parameters but I'm not able to retrieve the callback url contained into the response, so I just can't go there. I think I'm missing 2 parameters generated perhaps by a js: fso and fsi.
I followed the manual procedure (Firebug / NET panel / POST data) and I can confirm that the callback url is there. Following the last part of my code, thanks for any help.
#CURL SETUP
$session = curl_init();
curl_setopt($session, CURLOPT_HEADER, 1);
curl_setopt($session, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($session, CURLOPT_HTTPGET, 1 );
#MY CURL OPERATION
curl_setopt($session, CURLOPT_URL, $website);
curl_setopt($session, CURLOPT_POST, 1 );
curl_setopt($session, CURLOPT_POSTFIELDS, $postfields );
curl_setopt($session, CURLOPT_DNS_USE_GLOBAL_CACHE, false );
curl_setopt($session, CURLOPT_DNS_CACHE_TIMEOUT, 2 );
curl_setopt($session, CURLOPT_COOKIEJAR, $cookie );
curl_setopt($session, CURLOPT_COOKIEFILE, $cookie );
curl_setopt($session, CURLOPT_FOLLOWLOCATION, true ); //needed for 302
$output = curl_exec($session);
print_r($output);
I tried to get inspiration searchin around and from premade PHP classes, but all websites talk about receiving payments, not making payments.
您需要设置CURLOPT_RETURNTRANSFER
以返回curl_exec()
的值(响应),而不是直接将其输出:
curl_setopt($session, CURLOPT_RETURNTRANSFER, true );
I did it myself
ON CURL setup:
//suppress 100 continue curl bug
curl_setopt($session, CURLOPT_HTTPHEADER, array('Expect:') );
AFTER curl_exec
$lastUrl = curl_getinfo($session, CURLINFO_EFFECTIVE_URL);
$redirs = curl_getinfo($session, CURLINFO_REDIRECT_COUNT);
LET'S PRINT OUT THE RESULTS
echo "LAST URL<br><pre>".$lastUrl."</pre>";
echo "NUMBER OF REDIRS<br><pre>".$output."</pre>";
echo "LAST URL<br><pre>".$output."</pre>";
die();
every header will contain all the curl passages and please keep in mind that the steps you see into any debugger (safari web inspector, firebug, etc etc) eg
- 302 Found
- 302 Moved Temporarily
represent 1 single redirection. I hope it's useful for somebody else.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.