Advertisement
Guest User

Untitled

a guest
Aug 24th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. <?php
  2. class CurlRequest
  3. {
  4. public static function post($url, $data, $headers=[], $user=false)
  5. {
  6. foreach ($data as &$d) {
  7. $d = urlencode($d);
  8. }
  9. $fields_string = "";
  10. foreach($data as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
  11. $ch = curl_init($url);
  12. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  13. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
  14. curl_setopt($ch,CURLOPT_POST, count($data));
  15. if ($user) {
  16. curl_setopt($ch, CURLOPT_USERPWD, $user);
  17. }
  18. curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
  19. $q = curl_exec($ch);
  20. $q2 = curl_getinfo($ch,CURLINFO_HTTP_CODE);
  21. curl_close($ch);
  22. if ($q2 == 200) {
  23. return $q;
  24. } else {
  25. return false;
  26. }
  27. }
  28. public static function get($url, $data, $headers=[])
  29. {
  30. foreach ($data as &$d) {
  31. $d = urlencode($d);
  32. }
  33. $fields_string = "";
  34. foreach($data as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
  35. $ch = curl_init($url."?".$fields_string);
  36. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  37. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
  38. $q = curl_exec($ch);
  39. curl_close($ch);
  40. return $q;
  41. }
  42. }
  43. class PayPal
  44. {
  45. private $clientId;
  46. private $clientSecret;
  47. private $accessToken;
  48. public function __construct($clientId, $clientSecret)
  49. {
  50. $this->clientId = $clientId;
  51. $this->clientSecret = $clientSecret;
  52. $q = CurlRequest::post("https://api.sandbox.paypal.com/v1/oauth2/token",["grant_type" => "client_credentials"],["Accept: application/json"],$clientId.":".$clientSecret);
  53. if($q) {
  54. $q = json_decode($q,true);
  55. $this->accessToken = $q['access_token'];
  56. echo $this->accessToken;
  57. }
  58. }
  59. public function pay()
  60. {
  61. $q = CurlRequest::post("",["access_token" => $this->accessToken, "amount" => ]);
  62. }
  63. }
  64.  
  65. $p = new PayPal("AQr-2Wl1kauMouHhW95aJzQLWjHUuypVq4O1WV3tXrZ9zixW9-Qcdtil-fNYsrDjtQ8JoCAFBiCCh3ah","EJ49tuWUksfOhUc-2hFghE-P1ncwTL_dKsZbHN3A--A7ohIeqj7E9B1Gtq6t_K9tVmfKBvp_qI7sjYEX");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement