<?php

////////////////////////////////////////////////////////
// GET AN ACCESS TOKEN FROM PAYPAL 

$ch = curl_init();

// PRODUCTION
$clientId = "AZsMPHqx0TlbCyV_8AY5LlNzzmilpaP8lbfQQQ4iPRpk_WC8hOWFWdvnGMgln4RJAAO2oWd7g1PhhMtu";
$secret = "EFZpihetGeQCYOA_zWas7iTQ1Le32fSmBvgZd5tZ01TvonU8hwxEQnbjD6Xjmqzasu4ZtiDHmO4sBaRa";

// SANDBOX
//$clientId = "AfbGagMA8OwwgX0fxBjzZrHn_aCZQEXUptCPW6e8ybFG7nepqq9sNDg-CdnHGFzEH_t9b5BalIwwiRrZ";
//$secret = "EISNV0-LkFw6R8302kwFVRhnXI8iHOt4Clr_F0UJmH9oeaeG8sh_UsLMReh-hMZfdgNQInVEjcpTzj1u";

curl_setopt($ch, CURLOPT_URL, "https://api.paypal.com/v1/oauth2/token");
//curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/oauth2/token");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSLVERSION , 6); //NEW ADDITION
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $clientId.":".$secret);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");

$result = curl_exec($ch);

if (empty($result))
	die("Error: No response.");
else {
	//$json = json_decode($result);
	//return $result;
	print($result);
	//print_r($json);
	//return $json;
	//print_r($json->access_token);
	//return $json->access_token;
}

curl_close($ch); //THIS CODE IS NOW WORKING!

exit;
////////////////////////////////////////////////////////
// https://voicetrivia.com/pay/genaccessToken.php

//A21AANYPHc5vWJ7hFkmRo-5BglccMgZLIKwhMgGL2wdkkOYAsxiyugiX7H5M8kgYuiEOaHbzMl3e5Ph2VXcHG7xUdRvURQ43Q 
//[token_type] => Bearer 
//[app_id] => APP-80B18685FE3645629 
//[expires_in] => 32400 
//[nonce] => 2024-08-12T23:52:42Zgj4eJFoliALztgqMr4xZoXW3Fr0kDYbdxaZpTbFgCBE )

?>