Angelleye_PayPal_PayFlow

Angell EYE PayPal PayFlow Class 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.payflow.class.php  
  1. class Angelleye_PayPal_PayFlow extends Angelleye_PayPal 
  2. {  
  3. /** 
  4. * Constructor 
  5. * @access public 
  6. * @param array config preferences 
  7. * @return void 
  8. */ 
  9. function __construct($DataArray) 
  10. $DataArray = apply_filters( 'angelleye_paypal_payflow_construct_params', $DataArray ); 
  11.  
  12. parent::__construct($DataArray); 
  13.  
  14. $this->APIVendor = isset($DataArray['APIVendor']) ? $DataArray['APIVendor'] : ''; 
  15. $this->APIPartner = isset($DataArray['APIPartner']) ? $DataArray['APIPartner'] : ''; 
  16. $this->Verbosity = isset($DataArray['Verbosity']) ? $DataArray['Verbosity'] : 'HIGH'; 
  17. $this->Force_tls_one_point_two = isset($DataArray['Force_tls_one_point_two']) ? $DataArray['Force_tls_one_point_two'] : 'no'; 
  18.  
  19. if($this->Sandbox) 
  20. $this->APIEndPoint = 'https://pilot-payflowpro.paypal.com'; 
  21. else 
  22. $this->APIEndPoint = 'https://payflowpro.paypal.com'; 
  23.  
  24. $this->NVPCredentials = 'BUTTONSOURCE['.strlen($this->APIButtonSource).']='.$this->APIButtonSource.'&VERBOSITY['.strlen($this->Verbosity).']='.$this->Verbosity.'&USER['.strlen($this->APIUsername).']='.$this->APIUsername.'&VENDOR['.strlen($this->APIVendor).']='.$this->APIVendor.'&PARTNER['.strlen($this->APIPartner).']='.$this->APIPartner.'&PWD['.strlen($this->APIPassword).']='.$this->APIPassword; 
  25. $this->NVPCredentials_masked = 'BUTTONSOURCE['.strlen($this->APIButtonSource).']='.$this->APIButtonSource.'&VERBOSITY['.strlen($this->Verbosity).']='.$this->Verbosity.'&USER['.strlen($this->APIUsername).']=*****&VENDOR['.strlen($this->APIVendor).']=*****&PARTNER['.strlen($this->APIPartner).']='.$this->APIPartner.'&PWD['.strlen($this->APIPassword).']='.'*****'; 
  26.  
  27. $this->TransactionStateCodes = array( 
  28. '1' => 'Error',  
  29. '6' => 'Settlement Pending',  
  30. '7' => 'Settlement in Progress',  
  31. '8' => 'Settlement Completed Successfully',  
  32. '11' => 'Settlement Failed',  
  33. '14' => 'Settlement Incomplete' 
  34. ); 
  35. }  
  36.  
  37. /** 
  38. * GetTransactionStateCodeMessage 
  39. *  
  40. * @access public 
  41. * @param number 
  42. * @return string 
  43. */ 
  44. function GetTransactionStateCodeMessage($Code) 
  45. return $this -> TransactionStateCodes[$Code]; 
  46.  
  47. /** 
  48. * CURLRequest 
  49. *  
  50. * @access public 
  51. * @param string Request 
  52. * @return string 
  53. */ 
  54. function CURLRequest($Request = "", $APIName = "", $APIOperation = "", $PrintHeaders = false) 
  55.  
  56. $unique_id = date('YmdGis').rand(1000, 9999); 
  57.  
  58. $headers[] = "Content-Type: text/namevalue"; //or text/xml if using XMLPay. 
  59. $headers[] = "Content-Length : " . strlen ($Request); // Length of data to be passed 
  60. $headers[] = "X-VPS-Timeout: 45"; 
  61. $headers[] = "X-VPS-Request-ID:" . $unique_id; 
  62.  
  63. $curl = curl_init(); 
  64. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); 
  65. curl_setopt($curl, CURLOPT_HEADER, 1); 
  66. curl_setopt($curl, CURLOPT_VERBOSE, 1); 
  67. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 0); 
  68. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); 
  69. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); 
  70. curl_setopt($curl, CURLOPT_FORBID_REUSE, true); 
  71. curl_setopt($curl, CURLOPT_TIMEOUT, 90); 
  72. curl_setopt($curl, CURLOPT_URL, $this->APIEndPoint); 
  73. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
  74. curl_setopt($curl, CURLOPT_POST, 1); 
  75. curl_setopt($curl, CURLOPT_POSTFIELDS, $Request); 
  76. if( isset($this->Force_tls_one_point_two) && $this->Force_tls_one_point_two == 'yes') { 
  77. curl_setopt($curl, CURLOPT_SSLVERSION, 6); 
  78.  
  79. // Try to submit the transaction up to 3 times with 5 second delay. This can be used 
  80. // in case of network issues. The idea here is since you are posting via HTTPS there 
  81. // could be general network issues, so try a few times before you tell customer there 
  82. // is an issue. 
  83.  
  84. $Response = curl_exec($curl); 
  85. if($Response === false) { 
  86. return array( 'CURL_ERROR' =>curl_error($curl) ); 
  87. } else { 
  88. $i=1; 
  89. while ($i++ <= 3) { 
  90. if($i != 2) { 
  91. $Response = curl_exec($curl); 
  92. $headers = curl_getinfo($curl); 
  93. if ($headers['http_code'] != 200) { 
  94. sleep(5); // Let's wait 5 seconds to see if its a temporary network issue. 
  95. } else if ($headers['http_code'] == 200) { 
  96. // we got a good response, drop out of loop. 
  97. break; 
  98. curl_close($curl); 
  99. return $Response; 
  100.  
  101.  
  102. /** 
  103. * Convert an NVP string to an array with URL decoded values 
  104. * @access public 
  105. * @param string NVP string 
  106. * @return array 
  107. */ 
  108. function NVPToArray($NVPString) 
  109. $proArray = array(); 
  110. parse_str($NVPString, $proArray); 
  111. return $proArray; 
  112.  
  113. /** 
  114. * ProcessTransaction 
  115. *  
  116. * @access public 
  117. * @param array request parameters 
  118. * @return array 
  119. */ 
  120. function ProcessTransaction($DataArray) 
  121. $NVPRequest = $this->NVPCredentials; 
  122. $NVPRequestmask = $this->NVPCredentials_masked; 
  123. $star = '*****'; 
  124.  
  125. foreach($DataArray as $DataArrayVar => $DataArrayVal) 
  126. if($DataArrayVal != '') 
  127. $NVPRequest .= '&'.strtoupper($DataArrayVar).'['.strlen($DataArrayVal).']='.$DataArrayVal; 
  128. $NVPRequestmask .= '&'.strtoupper($DataArrayVar).'['.strlen($DataArrayVal).']='.$DataArrayVal; 
  129.  
  130. $NVPResponse = $this->CURLRequest($NVPRequest); 
  131. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  132. return $NVPResponse; 
  133. $NVPResponse = strstr($NVPResponse, "RESULT"); 
  134. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  135.  
  136. $NVPResponseArray['RAWREQUEST'] = $NVPRequestmask; 
  137. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  138.  
  139. return $NVPResponseArray;