Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. <?php
  2. class Paypal {
  3.  
  4. private $user = '';
  5. private $password = '';
  6. private $signature = '';
  7. private $endpoint = 'https://api-3t.sandbox.paypal.com/nvp';
  8. public $errors = array();
  9.  
  10. public function __construct($user = 'seller_api1.linox.com',$password = 'E8BEUX7T447ADU4K',$signature = 'AFcWxV21C7fd0v3bYYYRCpSSRl31Aq2ySAZ-mZO5WnXxfeVsJRGsAdq-',$sandbox = true)
  11. {
  12. $this->user = $user;
  13. $this->password = $password;
  14. $this->signature = $signature;
  15. $this->sandbox = $sandbox;
  16. if(!$sandbox)
  17. {
  18. $this->endpoint = str_replace('sandbox.','',$this->endpoint);
  19. }
  20. }
  21.  
  22. public function request($method,$params)
  23. {
  24. $params = array_merge($params, array(
  25. 'METHOD' => $method,
  26. 'USER' => $this->user,
  27. 'PWD' => $this->password,
  28. 'SIGNATURE' => $this->signature,
  29. 'VERSION' => '74.0'
  30. ));
  31. $params = http_build_query($params);
  32. $curl = curl_init();
  33. curl_setopt_array($curl, array(
  34. CURLOPT_URL => $this->endpoint,
  35. CURLOPT_POST => 1,
  36. CURLOPT_POSTFIELDS => $params,
  37. CURLOPT_RETURNTRANSFER => 1,
  38. CURLOPT_SSL_VERIFYPEER => false,
  39. CURLOPT_SSL_VERIFYHOST => false,
  40. CURLOPT_VERBOSE => 1
  41. ));
  42.  
  43. $response = curl_exec($curl);
  44. $responseArray = array();
  45. parse_str($response,$responseArray);
  46.  
  47. if(curl_errno($curl))
  48. {
  49. $this->errors = curl_error($curl);
  50. curl_close($curl);
  51. return false;
  52. }
  53. else {
  54. if($responseArray['ACK'] == 'Success')
  55. {
  56. return $responseArray;
  57. curl_close($curl);
  58. }else{
  59. $this->errors = $responseArray;
  60. curl_close($curl);
  61. return false;
  62. }
  63. }
  64. }
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement