Last active
December 23, 2015 08:29
-
-
Save hallvors/6608223 to your computer and use it in GitHub Desktop.
PHP script to test if PayPal does mobile browser sniffing correctly for Firefox OS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if(isset($_GET['pp_init'])){ | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, "https://api-3t.sandbox.paypal.com/nvp"); | |
$post = "METHOD=SetExpressCheckout&VERSION=93&USER=sdk-three_api1.sdk.com&PWD=QFZCWN5HZM8VBG7Q&SIGNATURE=A-IzJhZZjhg29XQ2qnhapuwxIDzyAZQ92FRP5dqBzVesOkzbdUONzmOU&PAYMENTREQUEST_0_AMT=5.00&PAYMENTREQUEST_0_CURRENCYCODE=USD&PAYMENTREQUEST_0_PAYMENTACTION=Sale&RETURNURL=http://www.example.org&CANCELURL=http://www.example.org"; | |
curl_setopt($ch, CURLOPT_POST, true); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
$data = curl_exec($ch); | |
$token = ''; | |
$parsed = urldecode($data); echo $parsed; | |
$data = array(); | |
$bits = explode('&', $parsed); | |
foreach( $bits as $idx=>$namevalue){ | |
$parts = explode('=', $namevalue); | |
$data[$parts[0]] = $parts[1]; | |
} | |
if( $data['ACK']==='Success' && $data['TOKEN'] ){ | |
header('Location: https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout-mobile&token='.$data['TOKEN']); | |
} | |
var_dump($data); | |
curl_close($ch); | |
exit; | |
}else if(isset($_GET['uaxml'])){ | |
header('Content-type: application/xml'); | |
header('Content-disposition: attachment; filename="useragentswitcher.xml"'); | |
echo '<useragentswitcher><useragent description="iPhone 5.0" useragent="Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3" appcodename="Mozilla" appname="Netscape" appversion="5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16" platform="iPhone" vendor="Apple Computer, Inc." vendorsub=""/><useragent description="FirefoxOS" useragent="Mozilla/5.0 (Mobile; rv:18.0) Gecko/18.0 Firefox/18.0" appcodename="Mozilla" appname="Netscape" appversion="5.0 (Windows)" platform="Win32" vendor="" vendorsub=""/></useragentswitcher>'; | |
exit; | |
}else if( ! preg_match('/Mozilla\/5\.0 \(Mobile;/', $_SERVER['HTTP_USER_AGENT'])){ | |
echo '<html><head><title>Error: must have a Firefox OS user-agent for this test</title></head><body><p>To run this test successfully, please do the following:</p><ul><li>Use Firefox with the <a href="https://addons.mozilla.org/en-US/firefox/addon/user-agent-switcher/">User Agent Switcher</a> extension installed</li><li>Download <a href="?uaxml">user agent data</a> and save it somewhere temporary</li><li>In the User Agent Switcher preferences (menu: "Tools > Default User Agent > Edit User Agents", use the import feature to load the file you just saved</li><li>In the "Tools > Default User Agent" menu, choose "FirefoxOS" and re-load this page</li></ul></body></html>'; | |
exit; | |
} | |
?> | |
<!DOCTYPE html> | |
<html><head><title>PayPal mobile express checkout</title></head> | |
<body> | |
<p>Test a redirect to PayPal mobile express checkout by clicking <a href="?pp_init=1">this link</a>. When the PayPal page loads, verify that the address contains "cmd=_express-checkout-mobile".</p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment