Skip to content

Instantly share code, notes, and snippets.

@ramses-lopez
Last active August 21, 2017 04:26
Show Gist options
  • Save ramses-lopez/c449fb51d852468e6b68e98fc348003f to your computer and use it in GitHub Desktop.
Save ramses-lopez/c449fb51d852468e6b68e98fc348003f to your computer and use it in GitHub Desktop.
PHP cURL Post
<?php
// $paymentObject = '{
// 'intent': "sale",
// "payer": {
// "payment_method": "credit_card",
// "funding_instruments": [{
// "credit_card": {
// "number": "4032032647673208",
// "type": "visa",
// "expire_month": 8,
// "expire_year": 2022,
// "cvv2": "874",
// "first_name": "Ramses",
// "last_name": "Lopez",
// "billing_address": {
// "line1": "111 First Street",
// "city": "Saratoga",
// "state": "CA",
// "postal_code": "95070",
// "country_code": "US"
// }
// }
// }]
// },
// "transactions": [{
// "amount": {
// "total": "7.47",
// "currency": "USD",
// "details": {
// "subtotal": "7.41",
// "tax": "0.03",
// "shipping": "0.03"
// }
// },
// "description": "The payment transaction description."
// }]
// }';
$clientID = "AXVggvfsNB7SfW_gZNZ7TenVbkW5pylY9s9W3U6edvw5JTRK7TvazrFSUnFc4bzW4xUgihfZCaPHhctH";
$secret = "EAN4vZfE1UYAvc6Xne70swlhlH40EGx-n_ThjikMwZTfqqOQw9NdJDRvul1GJPw2FZhJ3HZRAO5LhNmH";
$authBase64 = base64_encode($clientID . ':' . $secret);
//
$body = array('grant_type' => 'client_credentials');
// // $data = array("name" => "Hagrid", "age" => "36");
$dataString = json_encode($body);
//
$ch = curl_init('https://api.sandbox.paypal.com/v1/oauth2/token?grant_type=client_credentials');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataString);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Accept: application/json",
"Accept-Language: en_US",
"Authorization: Basic " .$authBase64,
'Content-Type: application/json',
'Content-Length: ' . strlen($dataString)
));
$result = curl_exec($ch);
if($result === false) {
echo 'Curl error: ' . curl_error($ch);
}
else {
echo "\n\n-------------\n\n";
echo var_dump($result);
echo "\n\n";
echo 'Operation completed without any errors';
}
// LOCAL TEST
//
// $ch = curl_init('http://192.168.1.128:3000/api/v1.0/match');
// curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
// curl_setopt($ch, CURLOPT_POSTFIELDS, $dataString);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// curl_setopt($ch, CURLOPT_HTTPHEADER, array(
// "Accept: application/json"
// ,"Accept-Language: en_US"
// ,"Authorization: Basic " .$authBase64
// ,'Content-Type: application/json'
// ,'Content-Length: ' . strlen($dataString)
// ));
//
// $result = curl_exec($ch);
//
// if($result === false) {
// echo 'Curl error: ' . curl_error($ch);
// }
// else {
// echo "\n\n-------------\n\n";
// echo var_dump($result);
// echo "\n\n";
// echo 'Operation completed without any errors';
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment