Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. $ch = curl_init();
  2. curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/oauth2/token");
  3. curl_setopt($ch, CURLOPT_HEADER, false);
  4. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  5. curl_setopt($ch, CURLOPT_POST, true);
  6. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  7. curl_setopt($ch, CURLOPT_USERPWD, $clientId.":".$secret);
  8. curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
  9.  
  10. $result = curl_exec($ch);
  11.  
  12. if(empty($result))die("Error: No response.");
  13. else
  14. {
  15. $json = json_decode($result);
  16.  
  17. $sAccessToken = $json->access_token;
  18. $sTokenType = $json->token_type;
  19. $sAppID = $json->app_id;
  20. print_r($json);
  21. }
  22. curl_close($ch);
  23.  
  24. $ch2 = curl_init();
  25.  
  26. //curl -v https://api.sandbox.paypal.com/v1/payments/payment
  27. curl_setopt($ch2, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/payments/payment");
  28.  
  29. //-H "Content-Type:application/json"
  30. //-H "Authorization: Bearer <Access-Token>"
  31. curl_setopt($ch2, CURLOPT_HTTPHEADER, array(
  32. "Content-Type:application/json",
  33. "Authorization: Bearer ".$sAccessToken,
  34. ));
  35.  
  36.  
  37.  
  38. $payer = array(
  39. 'payment_method' => 'credit_card',
  40. 'funding_instruments' => array(
  41. 'credit_card' => array(
  42.  
  43. 'number' => "4417119669820331",
  44. "type" => "visa",
  45. "expire_month" => "11",
  46. "expire_year" => "2018",
  47. "cvv2" => "874",
  48. "first_name" => "Betsy",
  49. "last_name" => "Buyer",
  50. "billing_address" => array(
  51. "line1" => "111 First Street",
  52. "city" => "Saratoga",
  53. "state" => "CA",
  54. "postal_code" => "95070",
  55. "country_code" => "US"
  56. ),
  57. ),
  58. ),
  59. );
  60.  
  61. $params = array(
  62. 'intent' => 'sale',
  63. 'payer' => $payer,
  64. 'transactions' => array(array(
  65. "amount" =>"7.47",
  66. "currency" =>"USD",
  67. "details" => array(
  68. "subtotal"=>"7.41",
  69. "tax"=>"0.03",
  70. "shipping"=>"0.03"
  71. ),
  72. "description" => "This is the payment transaction description."
  73. )
  74. ));
  75.  
  76. curl_setopt($ch2, CURLOPT_POST, true );
  77. curl_setopt($ch2, CURLOPT_POSTFIELDS, json_encode( $params ) );
  78. curl_setopt($ch2, CURLOPT_SSL_VERIFYHOST, false );
  79. curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, false );
  80. curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true );
  81.  
  82. $response2 = curl_exec( $ch2 );
  83. $errrors2 = curl_error($ch2);
  84.  
  85. print_r($response2." / ");
  86. print_r($errrors2);
  87. curl_close($ch2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement