Angelleye_PayPal_Financing

Angell EYE PayPal Financing (Bill Me Later) Class Library An open source PHP library written to easily work with PayPal's API's.

Defined (1)

The class is defined in the following location(s).

/classes/lib/angelleye/paypal-php-library/includes/paypal.financing.class.php  
  1. class Angelleye_PayPal_Financing extends Angelleye_PayPal 
  2. var $AccessKey = ''; 
  3. var $ClientSecret = ''; 
  4.  
  5. /** 
  6. * Constructor 
  7. * @access public 
  8. * @param array config preferences 
  9. * @return void 
  10. */ 
  11. function __construct($DataArray) 
  12. parent::__construct($DataArray); 
  13.  
  14. $this->AccessKey = isset($DataArray['AccessKey']) ? $DataArray['AccessKey'] : ''; 
  15. $this->ClientSecret = isset($DataArray['ClientSecret']) && $DataArray['ClientSecret'] != '' ? $DataArray['ClientSecret'] : ''; 
  16.  
  17. if($this->Sandbox) 
  18. $this->EndPointURL = isset($DataArray['EndPointURL']) && $DataArray['EndPointURL'] != '' ? $DataArray['EndPointURL'] : 'https://api.financing-mint.paypal.com/finapi/v1/publishers/'; 
  19. else 
  20. $this->EndPointURL = isset($DataArray['EndPointURL']) && $DataArray['EndPointURL'] != '' ? $DataArray['EndPointURL'] : 'https://api.financing.paypal.com/finapi/v1/publishers/'; 
  21.  
  22. /** 
  23. * Build all HTTP headers required for the API call. 
  24. * @access public 
  25. * @param boolean $PrintHeaders - Whether to print headers on screen or not (true/false) 
  26. * @return array $headers 
  27. */ 
  28. function BuildHeaders($PrintHeaders) 
  29. $timestamp = intval(round(microtime(true) * 1000)); 
  30. $token = sha1($this->ClientSecret.$timestamp); 
  31.  
  32. $headers = array( 
  33. "AUTHORIZATION: FPA ".$this->AccessKey.":".$token.":".$timestamp,  
  34. "CONTENT-TYPE: application/json",  
  35. "ACCEPT: application/json" 
  36. ); 
  37.  
  38. if($PrintHeaders) 
  39. echo '<pre />'; 
  40. print_r($headers); 
  41.  
  42. return $headers; 
  43.  
  44. /** 
  45. * Send the API request to PayPal using CURL 
  46. * @access public 
  47. * @param string JSON string 
  48. * @return string 
  49. */ 
  50. function CURLRequest($Request = "", $APIName = "", $APIOperation = "") 
  51. $curl = curl_init(); 
  52. // curl_setopt($curl, CURLOPT_HEADER, TRUE); 
  53. curl_setopt($curl, CURLOPT_VERBOSE, 1); 
  54. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); 
  55. curl_setopt($curl, CURLOPT_TIMEOUT, 30); 
  56. curl_setopt($curl, CURLOPT_URL, $this->EndPointURL); 
  57. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
  58. curl_setopt($curl, CURLOPT_POSTFIELDS, $Request); 
  59. curl_setopt($curl, CURLOPT_HTTPHEADER, $this->BuildHeaders(FALSE)); 
  60.  
  61. $Response = curl_exec($curl);  
  62. curl_close($curl); 
  63. return $Response;  
  64.  
  65. /** 
  66. * Get all errors returned from PayPal 
  67. * @access public 
  68. * @param array PayPal NVP response 
  69. * @return array 
  70. */ 
  71. function GetErrors($JSONResponse) 
  72. $JSONResponse = json_decode($JSONResponse); 
  73. $Errors = isset($JSONResponse->errors) ? $JSONResponse->errors : array(); 
  74.  
  75. return $Errors; 
  76.  
  77. function BannerEnrollment($DataArray) 
  78. $PayPalRequest['bnCode'] = $this->APIButtonSource; 
  79.  
  80. if(isset($DataArray['PayerID'])) 
  81. $PayPalRequest['payerId'] = $DataArray['PayerID'];  
  82.  
  83. if(isset($DataArray['SellerName'])) 
  84. $PayPalRequest['sellerName'] = $DataArray['SellerName'];  
  85.  
  86. if(isset($DataArray['EmailAddress'])) 
  87. $PayPalRequest['emailAddress'] = $DataArray['EmailAddress'];  
  88.  
  89. $JSONRequest = json_encode($PayPalRequest);  
  90. $JSONResponse = $this->CURLRequest($JSONRequest, "", ""); 
  91. $ResponseArray = json_decode($JSONResponse); 
  92.  
  93. $Errors = $this->GetErrors($JSONResponse); 
  94. $PayerID = isset($ResponseArray->payerId) ? $ResponseArray->payerId : ''; 
  95. $PublisherID = isset($ResponseArray->publisherId) ? $ResponseArray->publisherId : ''; 
  96.  
  97.  
  98. $ResultArray = array( 
  99. 'RawRequest' => $JSONRequest,  
  100. 'RawResponse' => $JSONResponse,  
  101. 'PayerID' => $PayerID,  
  102. 'PublisherID' => $PublisherID,  
  103. 'Errors' => $Errors 
  104. ); 
  105.  
  106. return $ResultArray;