Angelleye_PayPal

Angell EYE PayPal NVP 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.class.php  
  1. class Angelleye_PayPal 
  2.  
  3. var $APIUsername = ''; 
  4. var $APIPassword = ''; 
  5. var $APISignature = ''; 
  6. var $APISubject = ''; 
  7. var $APIVersion = ''; 
  8. var $APIButtonSource = ''; 
  9. var $APIMode = ''; 
  10. var $EndPointURL = ''; 
  11. var $Sandbox = ''; 
  12. var $PathToCertKeyPEM = ''; 
  13. var $SSL = ''; 
  14. var $Force_tls_one_point_two = ''; 
  15.  
  16. /** 
  17. * Constructor 
  18. * @access public 
  19. * @param array config preferences 
  20. * @return void 
  21. */ 
  22. function __construct($DataArray) 
  23. $DataArray = apply_filters( 'angelleye_paypal_construct_params', $DataArray ); 
  24.  
  25. if(isset($DataArray['Sandbox'])) 
  26. $this->Sandbox = $DataArray['Sandbox']; 
  27.  
  28. else 
  29. $this->Sandbox = true; 
  30.  
  31. $this->APIVersion = isset($DataArray['APIVersion']) ? $DataArray['APIVersion'] : '124.0'; 
  32. $this->APIMode = isset($DataArray['APIMode']) ? $DataArray['APIMode'] : 'Signature'; 
  33. $this->APIButtonSource = 'AngellEYE_SP_WooCommerce'; 
  34. $this->PathToCertKeyPEM = '/path/to/cert/pem.txt'; 
  35. $this->SSL = $_SERVER['SERVER_PORT'] == '443' ? true : false; 
  36. $this->APISubject = isset($DataArray['APISubject']) ? $DataArray['APISubject'] : ''; 
  37. $this->Force_tls_one_point_two = isset($DataArray['Force_tls_one_point_two']) ? $DataArray['Force_tls_one_point_two'] : 'no'; 
  38.  
  39. if($this->Sandbox) 
  40. // Show Errors 
  41. //error_reporting(E_ALL); 
  42. //ini_set('display_errors', '1'); 
  43.  
  44. # Sandbox 
  45. $this->APIUsername = isset($DataArray['APIUsername']) && $DataArray['APIUsername'] != '' ? $DataArray['APIUsername'] : ''; 
  46. $this->APIPassword = isset($DataArray['APIPassword']) && $DataArray['APIPassword'] != '' ? $DataArray['APIPassword'] : ''; 
  47. $this->APISignature = isset($DataArray['APISignature']) && $DataArray['APISignature'] != '' ? $DataArray['APISignature'] : ''; 
  48. $this->EndPointURL = isset($DataArray['EndPointURL']) && $DataArray['EndPointURL'] != '' ? $DataArray['EndPointURL'] : 'https://api-3t.sandbox.paypal.com/nvp';  
  49. else 
  50. $this->APIUsername = isset($DataArray['APIUsername']) && $DataArray['APIUsername'] != '' ? $DataArray['APIUsername'] : ''; 
  51. $this->APIPassword = isset($DataArray['APIPassword']) && $DataArray['APIPassword'] != '' ? $DataArray['APIPassword'] : ''; 
  52. $this->APISignature = isset($DataArray['APISignature']) && $DataArray['APISignature'] != '' ? $DataArray['APISignature'] : ''; 
  53. $this->EndPointURL = isset($DataArray['EndPointURL']) && $DataArray['EndPointURL'] != '' ? $DataArray['EndPointURL'] : 'https://api-3t.paypal.com/nvp'; 
  54.  
  55. // Create the NVP credentials string which is required in all calls. 
  56. $this->NVPCredentials = 'USER=' . $this->APIUsername . '&PWD=' . $this->APIPassword . '&VERSION=' . $this->APIVersion . '&BUTTONSOURCE=' . $this->APIButtonSource; 
  57. $this->NVPCredentials .= $this->APISubject != '' ? '&SUBJECT=' . $this->APISubject : ''; 
  58. $this->NVPCredentials .= $this->APIMode == 'Signature' ? '&SIGNATURE=' . $this->APISignature : ''; 
  59.  
  60. $this->Countries = array( 
  61. 'Afghanistan' => 'AF',  
  62. 'land Islands' => 'AX',  
  63. 'Albania' => 'AL',  
  64. 'Algeria' => 'DZ',  
  65. 'American Samoa' => 'AS',  
  66. 'Andorra' => 'AD',  
  67. 'Angola' => 'AO',  
  68. 'Anguilla' => 'AI',  
  69. 'Antarctica' => 'AQ',  
  70. 'Antigua and Barbuda' => 'AG',  
  71. 'Argentina' => 'AR',  
  72. 'Armenia' => 'AM',  
  73. 'Aruba' => 'AW',  
  74. 'Australia' => 'AU',  
  75. 'Austria' => 'AT',  
  76. 'Azerbaijan' => 'AZ',  
  77. 'Bahamas' => 'BS',  
  78. 'Bahrain' => 'BH',  
  79. 'Bangladesh' => 'BD',  
  80. 'Barbados' => 'BB',  
  81. 'Belarus' => 'BY',  
  82. 'Belgium' => 'BE',  
  83. 'Belize' => 'BZ',  
  84. 'Benin' => 'BJ',  
  85. 'Bermuda' => 'BM',  
  86. 'Bhutan' => 'BT',  
  87. 'Bolivia' => 'BO',  
  88. 'Bosnia and Herzegovina' => 'BA',  
  89. 'Botswana' => 'BW',  
  90. 'Bouvet Island' => 'BV',  
  91. 'Brazil' => 'BR',  
  92. 'British Indian Ocean Territory' => 'IO',  
  93. 'Brunei Darussalam' => 'BN',  
  94. 'Bulgaria' => 'BG',  
  95. 'Burkina Faso' => 'BF',  
  96. 'Burundi' => 'BI',  
  97. 'Cambodia' => 'KH',  
  98. 'Cameroon' => 'CM',  
  99. 'Canada' => 'CA',  
  100. 'Cape Verde' => 'CV',  
  101. 'Cayman Islands' => 'KY',  
  102. 'Central African Republic' => 'CF',  
  103. 'Chad' => 'TD',  
  104. 'Chile' => 'CL',  
  105. 'China' => 'CN',  
  106. 'Christmas Island' => 'CX',  
  107. 'Cocos (Keeling) Islands' => 'CC',  
  108. 'Colombia' => 'CO',  
  109. 'Comoros' => 'KM',  
  110. 'Congo' => 'CG',  
  111. 'Congo, The Democratic Republic of the' => 'CD',  
  112. 'Cook Islands' => 'CK',  
  113. 'Costa Rica' => 'CR',  
  114. "Cote D'Ivoire" => 'CI',  
  115. 'Croatia' => 'HR',  
  116. 'Cuba' => 'CU',  
  117. 'Cyprus' => 'CY',  
  118. 'Czech Republic' => 'CZ',  
  119. 'Denmark' => 'DK',  
  120. 'Djibouti' => 'DJ',  
  121. 'Dominica' => 'DM',  
  122. 'Dominican Republic' => 'DO',  
  123. 'Ecuador' => 'EC',  
  124. 'Egypt' => 'EG',  
  125. 'El Salvador' => 'SV',  
  126. 'Equatorial Guinea' => 'GQ',  
  127. 'Eritrea' => 'ER',  
  128. 'Estonia' => 'EE',  
  129. 'Ethiopia' => 'ET',  
  130. 'Falkland Islands (Malvinas)' => 'FK',  
  131. 'Faroe Islands' => 'FO',  
  132. 'Fiji' => 'FJ',  
  133. 'Finland' => 'FI',  
  134. 'France' => 'FR',  
  135. 'French Guiana' => 'GF',  
  136. 'French Polynesia' => 'PF',  
  137. 'French Southern Territories' => 'TF',  
  138. 'Gabon' => 'GA',  
  139. 'Gambia' => 'GM',  
  140. 'Georgia' => 'GE',  
  141. 'Germany' => 'DE',  
  142. 'Ghana' => 'GH',  
  143. 'Gibraltar' => 'GI',  
  144. 'Greece' => 'GR',  
  145. 'Greenland' => 'GL',  
  146. 'Grenada' => 'GD',  
  147. 'Guadeloupe' => 'GP',  
  148. 'Guam' => 'GU',  
  149. 'Guatemala' => 'GT',  
  150. 'Guernsey' => 'GG',  
  151. 'Guinea' => 'GN',  
  152. 'Guinea-Bissau' => 'GW',  
  153. 'Guyana' => 'GY',  
  154. 'Haiti' => 'HT',  
  155. 'Heard Island and McDonald Islands' => 'HM',  
  156. 'Holy See (Vatican City State)' => 'VA',  
  157. 'Honduras' => 'HN',  
  158. 'Hong Kong' => 'HK',  
  159. 'Hungary' => 'HU',  
  160. 'Iceland' => 'IS',  
  161. 'India' => 'IN',  
  162. 'Indonesia' => 'ID',  
  163. 'Iran, Islamic Republic of' => 'IR',  
  164. 'Iraq' => 'IQ',  
  165. 'Ireland' => 'IE',  
  166. 'Isle of Man' => 'IM',  
  167. 'Israel' => 'IL',  
  168. 'Italy' => 'IT',  
  169. 'Jamaica' => 'JM',  
  170. 'Japan' => 'JP',  
  171. 'Jersey' => 'JE',  
  172. 'Jordan' => 'JO',  
  173. 'Kazakhstan' => 'KZ',  
  174. 'Kenya' => 'KE',  
  175. 'Kiribati' => 'KI',  
  176. "Korea, Democratic People's Republic of" => 'KP',  
  177. 'Korea, Republic of' => 'KR',  
  178. 'Kuwait' => 'KW',  
  179. 'Kyrgyzstan' => 'KG',  
  180. "Laos People's Democratic Republic" => 'LA',  
  181. 'Latvia' => 'LV',  
  182. 'Lebanon' => 'LB',  
  183. 'Lesotho' => 'LS',  
  184. 'Liberia' => 'LR',  
  185. 'Libyan Arab Jamahiriya' => 'LY',  
  186. 'Liechtenstein' => 'LI',  
  187. 'Lithuania' => 'LT',  
  188. 'Luxembourg' => 'LU',  
  189. 'Macao' => 'MO',  
  190. 'Macedonia, The former Yugoslav Republic of' => 'MK',  
  191. 'Madagascar' => 'MG',  
  192. 'Malawi' => 'MW',  
  193. 'Malaysia' => 'MY',  
  194. 'Maldives' => 'MV',  
  195. 'Mali' => 'ML',  
  196. 'Malta' => 'MT',  
  197. 'Marshall Islands' => 'MH',  
  198. 'Martinique' => 'MQ',  
  199. 'Mauritania' => 'MR',  
  200. 'Mauritius' => 'MU',  
  201. 'Mayotte' => 'YT',  
  202. 'Mexico' => 'MX',  
  203. 'Micronesia, Federated States of' => 'FM',  
  204. 'Moldova, Republic of' => 'MD',  
  205. 'Monaco' => 'MC',  
  206. 'Mongolia' => 'MN',  
  207. 'Montserrat' => 'MS',  
  208. 'Morocco' => 'MA',  
  209. 'Mozambique' => 'MZ',  
  210. 'Myanmar' => 'MM',  
  211. 'Namibia' => 'NA',  
  212. 'Nauru' => 'NR',  
  213. 'Nepal' => 'NP',  
  214. 'Netherlands' => 'NL',  
  215. 'Netherlands Antilles' => 'AN',  
  216. 'New Caledonia' => 'NC',  
  217. 'New Zealand' => 'NZ',  
  218. 'Nicaragua' => 'NI',  
  219. 'Niger' => 'NE',  
  220. 'Nigeria' => 'NG',  
  221. 'Niue' => 'NU',  
  222. 'Norfolk Island' => 'NF',  
  223. 'Northern Mariana Islands' => 'MP',  
  224. 'Norway' => 'NO',  
  225. 'Oman' => 'OM',  
  226. 'Pakistan' => 'PK',  
  227. 'Palau' => 'PW',  
  228. 'Palestinian Territory, Occupied' => 'PS',  
  229. 'Panama' => 'PA',  
  230. 'Papua New Guinea' => 'PG',  
  231. 'Paraguay' => 'PY',  
  232. 'Peru' => 'PE',  
  233. 'Philippines' => 'PH',  
  234. 'Pitcairn' => 'PN',  
  235. 'Poland' => 'PL',  
  236. 'Portugal' => 'PT',  
  237. 'Puerto Rico' => 'PR',  
  238. 'Qatar' => 'QA',  
  239. 'Reunion' => 'RE',  
  240. 'Romania' => 'RO',  
  241. 'Russian Federation' => 'RU',  
  242. 'Rwanda' => 'RW',  
  243. 'Saint Helena' => 'SH',  
  244. 'Saint Kitts and Nevis' => 'KN',  
  245. 'Saint Lucia' => 'LC',  
  246. 'Saint Pierre and Miquelon' => 'PM',  
  247. 'Saint Vincent and the Grenadines' => 'VC',  
  248. 'Samoa' => 'WS',  
  249. 'San Marino' => 'SM',  
  250. 'Sao Tome and Principe' => 'ST',  
  251. 'Saudi Arabia' => 'SA',  
  252. 'Senegal' => 'SN',  
  253. 'Serbia and Montenegro' => 'CS',  
  254. 'Seychelles' => 'SC',  
  255. 'Sierra Leone' => 'SL',  
  256. 'Singapore' => 'SG',  
  257. 'Slovakia' => 'SK',  
  258. 'Slovenia' => 'SI',  
  259. 'Solomon Islands' => 'SB',  
  260. 'Somalia' => 'SO',  
  261. 'South Africa' => 'ZA',  
  262. 'South Georgia and the South Sandwich Islands' => 'GS',  
  263. 'Spain' => 'ES',  
  264. 'Sri Lanka' => 'LK',  
  265. 'Sudan' => 'SD',  
  266. 'Suriname' => 'SR',  
  267. 'SValbard and Jan Mayen' => 'SJ',  
  268. 'Swaziland' => 'SZ',  
  269. 'Sweden' => 'SE',  
  270. 'Switzerland' => 'CH',  
  271. 'Syrian Arab Republic' => 'SY',  
  272. 'Taiwan, Province of China' => 'TW',  
  273. 'Tajikistan' => 'TJ',  
  274. 'Tanzania, United Republic of' => 'TZ',  
  275. 'Thailand' => 'TH',  
  276. 'Timor-Leste' => 'TL',  
  277. 'Togo' => 'TG',  
  278. 'Tokelau' => 'TK',  
  279. 'Tonga' => 'TO',  
  280. 'Trinidad and Tobago' => 'TT',  
  281. 'Tunisia' => 'TN',  
  282. 'Turkey' => 'TR',  
  283. 'Turkmenistan' => 'TM',  
  284. 'Turks and Caicos Islands' => 'TC',  
  285. 'Tuvalu' => 'TV',  
  286. 'Uganda' => 'UG',  
  287. 'Ukraine' => 'UA',  
  288. 'United Arab Emirates' => 'AE',  
  289. 'United Kingdom' => 'GB',  
  290. 'United States' => 'US',  
  291. 'United States Minor Outlying Islands' => 'UM',  
  292. 'Uruguay' => 'UY',  
  293. 'Uzbekistan' => 'UZ',  
  294. 'Vanuatu' => 'VU',  
  295. 'Venezuela' => 'VE',  
  296. 'Viet Nam' => 'VN',  
  297. 'Virgin Islands, British' => 'VG',  
  298. 'Virgin Islands, U.S.' => 'VI',  
  299. 'Wallis and Futuna' => 'WF',  
  300. 'Western Sahara' => 'EH',  
  301. 'Yemen' => 'YE',  
  302. 'Zambia' => 'ZM',  
  303. 'Zimbabwe' => 'ZW'); 
  304.  
  305. $this->States = array( 
  306. 'Alberta' => 'AB',  
  307. 'British Columbia' => 'BC',  
  308. 'Manitoba' => 'MB',  
  309. 'New Brunswick' => 'NB',  
  310. 'Newfoundland and Labrador' => 'NF',  
  311. 'Northwest Territories' => 'NT',  
  312. 'Nova Scotia' => 'NS',  
  313. 'Nunavut' => 'NU',  
  314. 'Ontario' => 'ON',  
  315. 'Prince Edward Island' => 'PE',  
  316. 'Quebec' => 'QC',  
  317. 'Saskatchewan' => 'SK',  
  318. 'Yukon' => 'YK',  
  319. 'Alabama' => 'AL',  
  320. 'Alaska' => 'AK',  
  321. 'American Samoa' => 'AS',  
  322. 'Arizona' => 'AZ',  
  323. 'Arkansas' => 'AR',  
  324. 'California' => 'CA',  
  325. 'Colorado' => 'CO',  
  326. 'Connecticut' => 'CT',  
  327. 'Delaware' => 'DE',  
  328. 'District of Columbia' => 'DC',  
  329. 'Federated States of Micronesia' => 'FM',  
  330. 'Florida' => 'FL',  
  331. 'Georgia' => 'GA',  
  332. 'Guam' => 'GU',  
  333. 'Hawaii' => 'HI',  
  334. 'Idaho' => 'ID',  
  335. 'Illinois' => 'IL',  
  336. 'Indiana' => 'IN',  
  337. 'Iowa' => 'IA',  
  338. 'Kansas' => 'KS',  
  339. 'Kentucky' => 'KY',  
  340. 'Louisiana' => 'LA',  
  341. 'Maine' => 'ME',  
  342. 'Marshall Islands' => 'MH',  
  343. 'Maryland' => 'MD',  
  344. 'Massachusetts' => 'MA',  
  345. 'Michigan' => 'MI',  
  346. 'Minnesota' => 'MN',  
  347. 'Mississippi' => 'MS',  
  348. 'Missouri' => 'MO',  
  349. 'Montana' => 'MT',  
  350. 'Nebraska' => 'NE',  
  351. 'Nevada' => 'NV',  
  352. 'New Hampshire' => 'NH',  
  353. 'New Jersey' => 'NJ',  
  354. 'New Mexico' => 'NM',  
  355. 'New York' => 'NY',  
  356. 'North Carolina' => 'NC',  
  357. 'North Dakota' => 'ND',  
  358. 'Northern Mariana Islands' => 'MP',  
  359. 'Ohio' => 'OH',  
  360. 'Oklahoma' => 'OK',  
  361. 'Oregon' => 'OR',  
  362. 'Palau' => 'PW',  
  363. 'Pennsylvania' => 'PA',  
  364. 'Puerto Rico' => 'PR',  
  365. 'Rhode Island' => 'RI',  
  366. 'South Carolina' => 'SC',  
  367. 'South Dakota' => 'SD',  
  368. 'Tennessee' => 'TN',  
  369. 'Texas' => 'TX',  
  370. 'Utah' => 'UT',  
  371. 'Vermont' => 'VT',  
  372. 'Virgin Islands' => 'VI',  
  373. 'Virginia' => 'VA',  
  374. 'Washington' => 'WA',  
  375. 'West Virginia' => 'WV',  
  376. 'Wisconsin' => 'WI',  
  377. 'Wyoming' => 'WY',  
  378. 'Armed Forces Americas' => 'AA',  
  379. 'Armed Forces' => 'AE',  
  380. 'Armed Forces Pacific' => 'AP'); 
  381.  
  382. $this->AVSCodes = array("A" => "Address Matches Only (No ZIP)",  
  383. "B" => "Address Matches Only (No ZIP)",  
  384. "C" => "This tranaction was declined.",  
  385. "D" => "Address and Postal Code Match",  
  386. "E" => "This transaction was declined.",  
  387. "F" => "Address and Postal Code Match",  
  388. "G" => "Global Unavailable - N/A",  
  389. "I" => "International Unavailable - N/A",  
  390. "N" => "None - Transaction was declined.",  
  391. "P" => "Postal Code Match Only (No Address)",  
  392. "R" => "Retry - N/A",  
  393. "S" => "Service not supported - N/A",  
  394. "U" => "Unavailable - N/A",  
  395. "W" => "Nine-Digit ZIP Code Match (No Address)",  
  396. "X" => "Exact Match - Address and Nine-Digit ZIP",  
  397. "Y" => "Address and five-digit Zip match",  
  398. "Z" => "Five-Digit ZIP Matches (No Address)"); 
  399.  
  400. $this->CVV2Codes = array( 
  401. "E" => "N/A",  
  402. "M" => "Match",  
  403. "N" => "No Match",  
  404. "P" => "Not Processed - N/A",  
  405. "S" => "Service Not Supported - N/A",  
  406. "U" => "Service Unavailable - N/A",  
  407. "X" => "No Response - N/A" 
  408. ); 
  409.  
  410. $this->CurrencyCodes = array( 
  411. 'AUD' => 'Austrailian Dollar',  
  412. 'BRL' => 'Brazilian Real',  
  413. 'CAD' => 'Canadian Dollar',  
  414. 'CZK' => 'Czeck Koruna',  
  415. 'DKK' => 'Danish Krone',  
  416. 'EUR' => 'Euro',  
  417. 'HKD' => 'Hong Kong Dollar',  
  418. 'HUF' => 'Hungarian Forint',  
  419. 'ILS' => 'Israeli New Sheqel',  
  420. 'JPY' => 'Japanese Yen',  
  421. 'MYR' => 'Malaysian Ringgit',  
  422. 'MXN' => 'Mexican Peso',  
  423. 'NOK' => 'Norwegian Krone',  
  424. 'NZD' => 'New Zealand Dollar',  
  425. 'PHP' => 'Philippine Peso',  
  426. 'PLN' => 'Polish Zloty',  
  427. 'GBP' => 'Pound Sterling',  
  428. 'SGD' => 'Singapore Dollar',  
  429. 'SEK' => 'Swedish Krona',  
  430. 'CHF' => 'Swiss Franc',  
  431. 'TWD' => 'Taiwan New Dollar',  
  432. 'THB' => 'Thai Baht',  
  433. 'USD' => 'U.S. Dollar' 
  434. ); 
  435.  
  436.  
  437. } // End function PayPalPro() 
  438.  
  439. /** 
  440. * Get the current API version setting 
  441. * @access public 
  442. * @return string 
  443. */ 
  444. function GetAPIVersion() 
  445. return $this->APIVersion;  
  446.  
  447. /** 
  448. * Get the country code of the requested country 
  449. * @access public 
  450. * @param string country name 
  451. * @return string 
  452. */ 
  453. function GetCountryCode($CountryName) 
  454. return $this->Countries[$CountryName]; 
  455.  
  456. /** 
  457. * Get the state code for a requestad state 
  458. * @access public 
  459. * @param string state/province name 
  460. * @return string 
  461. */ 
  462. function GetStateCode($StateOrProvinceName) 
  463. return $this->States[$StateOrProvinceName]; 
  464.  
  465. /** 
  466. * Get the country name based on the country code 
  467. * @access public 
  468. * @param string country code 
  469. * @return string 
  470. */ 
  471. function GetCountryName($CountryCode) 
  472. $Countries = array_flip($this->Countries); 
  473. return $Countries[$CountryCode]; 
  474.  
  475. /** 
  476. * Get the state name based on the l 
  477. * @access public 
  478. * @param array state/province code 
  479. * @return string 
  480. */ 
  481. function GetStateName($StateOrProvinceName) 
  482. $States = array_flip($this->States); 
  483. return $States[$StateOrProvinceName]; 
  484.  
  485. /** 
  486. * Get the AVS (address verification) message 
  487. * @access public 
  488. * @param string AVS code 
  489. * @return string 
  490. */ 
  491. function GetAVSCodeMessage($AVSCode) 
  492. {  
  493. return $this->AVSCodes[$AVSCode]; 
  494.  
  495. /** 
  496. * Get the security digits (CVV2 Code) message 
  497. * @access public 
  498. * @param string CVV2 code 
  499. * @return string 
  500. */ 
  501. function GetCVV2CodeMessage($CVV2Code) 
  502. return $this->CVV2Codes[$CVV2Code];  
  503.  
  504. /** 
  505. * Get the currency code text value 
  506. * @access public 
  507. * @param string currency code 
  508. * @return string 
  509. */ 
  510. function GetCurrencyCodeText($CurrencyCode) 
  511. return $this->CurrencyCodes[$CurrencyCode]; 
  512.  
  513. /** 
  514. * Get the currency code based on the text value 
  515. * @access public 
  516. * @param string text value 
  517. * @return string 
  518. */ 
  519. function GetCurrencyCode($CurrencyCodeText) 
  520. $CurrencyCodes = array_flip($this->CurrencyCodes); 
  521. return $CurrencyCodes[$CurrencyCodeText]; 
  522.  
  523. /** 
  524. * Send the API request to PayPal using CURL 
  525. * @access public 
  526. * @param string NVP string 
  527. * @return string 
  528. */ 
  529. function CURLRequest($Request = "", $APIName = "", $APIOperation = "") 
  530. $curl = curl_init(); 
  531. // curl_setopt($curl, CURLOPT_HEADER, TRUE); 
  532. curl_setopt($curl, CURLOPT_VERBOSE, 1); 
  533. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); 
  534. curl_setopt($curl, CURLOPT_TIMEOUT, 30); 
  535. curl_setopt($curl, CURLOPT_URL, $this->EndPointURL); 
  536. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
  537. curl_setopt($curl, CURLOPT_POSTFIELDS, $Request); 
  538. if( isset($this->Force_tls_one_point_two) && $this->Force_tls_one_point_two == 'yes') { 
  539. curl_setopt($curl, CURLOPT_SSLVERSION, 6); 
  540.  
  541. if($this->APIMode == 'Certificate') 
  542. curl_setopt($curl, CURLOPT_SSLCERT, $this->PathToCertKeyPEM); 
  543.  
  544. $Response = curl_exec($curl); 
  545. $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); 
  546.  
  547. if ($Response === false || $httpCode != 200) { 
  548. $curl_error = curl_error($curl); 
  549. $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); 
  550. $Response = array( 'CURL_ERROR' =>curl_error($curl) ); 
  551. }  
  552.  
  553. curl_close($curl); 
  554.  
  555. return $Response;  
  556.  
  557. /** 
  558. * Convert an NVP string to an array with URL decoded values 
  559. * @access public 
  560. * @param string NVP string 
  561. * @return array 
  562. */ 
  563. function NVPToArray($NVPString) 
  564. $proArray = array(); 
  565. while(strlen($NVPString)) 
  566. // name 
  567. $keypos= strpos($NVPString, '='); 
  568. $keyval = substr($NVPString, 0, $keypos); 
  569. // value 
  570. $valuepos = strpos($NVPString, '&') ? strpos($NVPString, '&'): strlen($NVPString); 
  571. $valval = substr($NVPString, $keypos+1, $valuepos-$keypos-1); 
  572. // decoding the respose 
  573. $proArray[$keyval] = urldecode($valval); 
  574. $NVPString = substr($NVPString, $valuepos+1, strlen($NVPString)); 
  575.  
  576. return $proArray; 
  577.  
  578.  
  579. /** 
  580. * Check whether or not the API returned SUCCESS or SUCCESSWITHWARNING 
  581. * @access public 
  582. * @param string ACK returned from PayPal 
  583. * @return boolean 
  584. */ 
  585. function APICallSuccessful($ack) 
  586. if(strtoupper($ack) != 'SUCCESS' && strtoupper($ack) != 'SUCCESSWITHWARNING' && strtoupper($ack) != 'PARTIALSUCCESS') 
  587. return false; 
  588. else 
  589. return true; 
  590.  
  591. /** 
  592. * Check whether or not warnings were returned 
  593. * @access public 
  594. * @param string ACK returned from PayPal 
  595. * @return boolean 
  596. */ 
  597. function WarningsReturned($ack) 
  598. if(strtoupper($ack) == 'SUCCESSWITHWARNING') 
  599. return true; 
  600. else 
  601. return false;  
  602.  
  603. /** 
  604. * Get all errors returned from PayPal 
  605. * @access public 
  606. * @param array PayPal NVP response 
  607. * @return array 
  608. */ 
  609. function GetErrors($DataArray) 
  610.  
  611. $Errors = array(); 
  612. $n = 0; 
  613. while(isset($DataArray['L_ERRORCODE' . $n . ''])) 
  614. $LErrorCode = isset($DataArray['L_ERRORCODE' . $n . '']) ? $DataArray['L_ERRORCODE' . $n . ''] : ''; 
  615. $LShortMessage = isset($DataArray['L_SHORTMESSAGE' . $n . '']) ? $DataArray['L_SHORTMESSAGE' . $n . ''] : ''; 
  616. $LLongMessage = isset($DataArray['L_LONGMESSAGE' . $n . '']) ? $DataArray['L_LONGMESSAGE' . $n . ''] : ''; 
  617. $LSeverityCode = isset($DataArray['L_SEVERITYCODE' . $n . '']) ? $DataArray['L_SEVERITYCODE' . $n . ''] : ''; 
  618.  
  619. $CurrentItem = array( 
  620. 'L_ERRORCODE' => $LErrorCode,  
  621. 'L_SHORTMESSAGE' => $LShortMessage,  
  622. 'L_LONGMESSAGE' => $LLongMessage,  
  623. 'L_SEVERITYCODE' => $LSeverityCode 
  624. ); 
  625.  
  626. array_push($Errors, $CurrentItem); 
  627. $n++; 
  628.  
  629. return $Errors; 
  630.  
  631.  
  632. /** 
  633. * Display errors on screen using line breaks. 
  634. * @access public 
  635. * @param array Errors array returned from class 
  636. * @return output 
  637. */ 
  638. function DisplayErrors($Errors) 
  639. foreach($Errors as $ErrorVar => $ErrorVal) 
  640. $CurrentError = $Errors[$ErrorVar]; 
  641. foreach($CurrentError as $CurrentErrorVar => $CurrentErrorVal) 
  642. if($CurrentErrorVar == 'L_ERRORCODE') 
  643. $CurrentVarName = 'Error Code'; 
  644. elseif($CurrentErrorVar == 'L_SHORTMESSAGE') 
  645. $CurrentVarName = 'Short Message'; 
  646. elseif($CurrentErrorVar == 'L_LONGMESSAGE') 
  647. $CurrentVarName = 'Long Message'; 
  648. elseif($CurrentErrorVar == 'L_SEVERITYCODE') 
  649. $CurrentVarName = 'Severity Code'; 
  650.  
  651. echo $CurrentVarName . ': ' . $CurrentErrorVal . '<br />';  
  652. echo '<br />'; 
  653.  
  654. /** 
  655. * Parse order items from an NVP string 
  656. * @access public 
  657. * @param array NVP string 
  658. * @return array 
  659. */ 
  660. function GetOrderItems($DataArray) 
  661.  
  662. $OrderItems = array(); 
  663. $n = 0; 
  664. while(isset($DataArray['L_NAME' . $n . ''])) 
  665. $LName = isset($DataArray['L_NAME' . $n . '']) ? $DataArray['L_NAME' . $n . ''] : ''; 
  666. $LDesc = isset($DataArray['L_DESC' . $n . '']) ? $DataArray['L_DESC' . $n . ''] : ''; 
  667. $LNumber = isset($DataArray['L_NUMBER' . $n . '']) ? $DataArray['L_NUMBER' . $n . ''] : ''; 
  668. $LQTY = isset($DataArray['L_QTY' . $n . '']) ? $DataArray['L_QTY' . $n . ''] : ''; 
  669. $LAmt = isset($DataArray['L_AMT' . $n . '']) ? $DataArray['L_AMT' . $n . ''] : ''; 
  670. $LTaxAmt = isset($DataArray['L_TAXAMT' . $n . '']) ? $DataArray['L_TAXAMT' . $n . ''] : ''; 
  671. $LOptionsName = isset($DataArray['L_OPTIONSNAME' . $n . '']) ? $DataArray['L_OPTIONSNAME' . $n . ''] : ''; 
  672. $LOptionsValue = isset($DataArray['L_OPTIONSVALUE' . $n . '']) ? $DataArray['L_OPTIONSVALUE' . $n . ''] : ''; 
  673. $LItemWeightValue = isset($DataArray['L_ITEMWEIGHTVALUE' . $n . '']) ? $DataArray['L_ITEMWEIGHTVALUE' . $n . ''] : ''; 
  674. $LItemWeightUnit = isset($DataArray['L_ITEMWEIGHTUNIT' . $n . '']) ? $DataArray['L_ITEMWEIGHTUNIT' . $n . ''] : ''; 
  675. $LItemWidthValue = isset($DataArray['L_ITEMWEIGHTVALUE' . $n . '']) ? $DataArray['L_ITEMWEIGHTVALUE' . $n . ''] : ''; 
  676. $LItemWidthUnit = isset($DataArray['L_ITEMWIDTHUNIT' . $n . '']) ? $DataArray['L_ITEMWIDTHUNIT' . $n . ''] : ''; 
  677. $LItemLengthValue = isset($DataArray['L_ITEMLENGTHVALUE' . $n . '']) ? $DataArray['L_ITEMLENGTHVALUE' . $n . ''] : ''; 
  678. $LItemLengthUnit = isset($DataArray['L_ITEMLENGTHUNIT' . $n . '']) ? $DataArray['L_ITEMLENGTHUNIT' . $n . ''] : ''; 
  679. $LeBayTransID = isset($DataArray['L_EBAYITEMTXNID' . $n . '']) ? $DataArray['L_EBAYITEMTXNID' . $n . ''] : ''; 
  680. $LeBayOrderID = isset($DataArray['L_EBAYITEMORDERID' . $n . '']) ? $DataArray['L_EBAYITEMORDERID' . $n . ''] : ''; 
  681.  
  682. $CurrentItem = array( 
  683. 'L_NAME' => $LName,  
  684. 'L_DESC' => $LDesc,  
  685. 'L_NUMBER' => $LNumber,  
  686. 'L_QTY' => $LQTY,  
  687. 'L_AMT' => $LAmt,  
  688. 'L_OPTIONSNAME' => $LOptionsName,  
  689. 'L_OPTIONSVALUE' => $LOptionsValue,  
  690. 'L_ITEMWEIGHTVALUE' => $LItemWeightValue,  
  691. 'L_ITEMWEIGHTUNIT' => $LItemWeightUnit,  
  692. 'L_ITEMWIDTHVALUE' => $LItemWidthValue,  
  693. 'L_ITEMWIDTHUNIT' => $LItemWidthUnit,  
  694. 'L_ITEMLENGTHVALUE' => $LItemLengthValue,  
  695. 'L_ITEMLENGTHUNIT' => $LItemLengthUnit,  
  696. 'L_TAXAMT' => $LTaxAmt,  
  697. 'L_EBAYITEMTXNID' => $LeBayTransID,  
  698. 'L_EBAYITEMORDERID' => $LeBayOrderID 
  699. ); 
  700.  
  701. array_push($OrderItems, $CurrentItem); 
  702. $n++; 
  703.  
  704. return $OrderItems; 
  705.  
  706. } // End function GetOrderItems 
  707.  
  708.  
  709. /** 
  710. * Get all payment(s) details from an NVP string 
  711. * @access public 
  712. * @param array NVP string 
  713. * @return array 
  714. */ 
  715. function GetPayments($DataArray) 
  716. $Payments = array(); 
  717. $n = 0; 
  718. while(isset($DataArray['PAYMENTREQUEST_' . $n . '_AMT'])) 
  719. {  
  720. $Payment = array( 
  721. 'SHIPTONAME' => isset($DataArray['PAYMENTREQUEST_' . $n . '_SHIPTONAME']) ? $DataArray['PAYMENTREQUEST_' . $n . '_SHIPTONAME'] : '',  
  722. 'SHIPTOSTREET' => isset($DataArray['PAYMENTREQUEST_' . $n . '_SHIPTOSTREET']) ? $DataArray['PAYMENTREQUEST_' . $n . '_SHIPTOSTREET'] : '',  
  723. 'SHIPTOSTREET2' => isset($DataArray['PAYMENTREQUEST_' . $n . '_SHIPTOSTREET2']) ? $DataArray['PAYMENTREQUEST_' . $n . '_SHIPTOSTREET2'] : '',  
  724. 'SHIPTOCITY' => isset($DataArray['PAYMENTREQUEST_' . $n . '_SHIPTOCITY']) ? $DataArray['PAYMENTREQUEST_' . $n . '_SHIPTOCITY'] : '',  
  725. 'SHIPTOSTATE' => isset($DataArray['PAYMENTREQUEST_' . $n . '_SHIPTOSTATE']) ? $DataArray['PAYMENTREQUEST_' . $n . '_SHIPTOSTATE'] : '',  
  726. 'SHIPTOZIP' => isset($DataArray['PAYMENTREQUEST_' . $n . '_SHIPTOZIP']) ? $DataArray['PAYMENTREQUEST_' . $n . '_SHIPTOZIP'] : '',  
  727. 'SHIPTOCOUNTRYCODE' => isset($DataArray['PAYMENTREQUEST_' . $n . '_SHIPTOCOUNTRYCODE']) ? $DataArray['PAYMENTREQUEST_' . $n . '_SHIPTOCOUNTRYCODE'] : '',  
  728. 'SHIPTOCOUNTRYNAME' => isset($DataArray['PAYMENTREQUEST_' . $n . '_SHIPTOCOUNTRYNAME']) ? $DataArray['PAYMENTREQUEST_' . $n . '_SHIPTOCOUNTRYNAME'] : '',  
  729. 'SHIPTOPHONENUM' => isset($DataArray['PAYMENTREQUEST_' . $n . '_SHIPTOPHONENUM']) ? $DataArray['PAYMENTREQUEST_' . $n . '_SHIPTOPHONENUM'] : '',  
  730. 'ADDRESSSTATUS' => isset($DataArray['PAYMENTREQUEST_' . $n . '_ADDRESSSTATUS']) ? $DataArray['PAYMENTREQUEST_' . $n . '_ADDRESSSTATUS'] : '',  
  731. 'AMT' => isset($DataArray['PAYMENTREQUEST_' . $n . '_AMT']) ? $DataArray['PAYMENTREQUEST_' . $n . '_AMT'] : '',  
  732. 'CURRENCYCODE' => isset($DataArray['PAYMENTREQUEST_' . $n . '_CURRENCYCODE']) ? $DataArray['PAYMENTREQUEST_' . $n . '_CURRENCYCODE'] : '',  
  733. 'ITEMAMT' => isset($DataArray['PAYMENTREQUEST_' . $n . '_ITEMAMT']) ? $DataArray['PAYMENTREQUEST_' . $n . '_ITEMAMT'] : '',  
  734. 'SHIPPINGAMT' => isset($DataArray['PAYMENTREQUEST_' . $n . '_SHIPPINGAMT']) ? $DataArray['PAYMENTREQUEST_' . $n . '_SHIPPINGAMT'] : '',  
  735. 'INSURANCEOPTIONOFFERED' => isset($DataArray['PAYMENTREQUEST_' . $n . '_INSURANCEOPTIONOFFERED']) ? $DataArray['PAYMENTREQUEST_' . $n . '_INSURANCEOPTIONOFFERED'] : '',  
  736. 'HANDLINGAMT' => isset($DataArray['PAYMENTREQUEST_' . $n . '_HANDLINGAMT']) ? $DataArray['PAYMENTREQUEST_' . $n . '_HANDLINGAMT'] : '',  
  737. 'TAXAMT' => isset($DataArray['PAYMENTREQUEST_' . $n . '_TAXAMT']) ? $DataArray['PAYMENTREQUEST_' . $n . '_TAXAMT'] : '',  
  738. 'DESC' => isset($DataArray['PAYMENTREQUEST_' . $n . '_DESC']) ? $DataArray['PAYMENTREQUEST_' . $n . '_DESC'] : '',  
  739. 'CUSTOM' => isset($DataArray['PAYMENTREQUEST_' . $n . '_CUSTOM']) ? $DataArray['PAYMENTREQUEST_' . $n . '_CUSTOM'] : '',  
  740. 'INVNUM' => isset($DataArray['PAYMENTREQUEST_' . $n . '_INVNUM']) ? $DataArray['PAYMENTREQUEST_' . $n . '_INVNUM'] : '',  
  741. 'NOTIFYURL' => isset($DataArray['PAYMENTREQUEST_' . $n . '_NOTIFYURL']) ? $DataArray['PAYMENTREQUEST_' . $n . '_NOTIFYURL'] : '',  
  742. 'NOTETEXT' => isset($DataArray['PAYMENTREQUEST_' . $n . '_NOTETEXT']) ? $DataArray['PAYMENTREQUEST_' . $n . '_NOTETEXT'] : '',  
  743. 'TRANSACTIONID' => isset($DataArray['PAYMENTREQUEST_' . $n . '_TRANSACTIONID']) ? $DataArray['PAYMENTREQUEST_' . $n . '_TRANSACTIONID'] : '',  
  744. 'ALLOWEDPAYMENTMETHOD' => isset($DataArray['PAYMENTREQUEST_' . $n . '_ALLOWEDPAYMENTMETHOD']) ? $DataArray['PAYMENTREQUEST_' . $n . '_ALLOWEDPAYMENTMETHOD'] : '',  
  745. 'PAYMENTREQUESTID' => isset($DataArray['PAYMENTREQUEST_' . $n . '_PAYMENTREQUESTID']) ? $DataArray['PAYMENTREQUEST_' . $n . '_PAYMENTREQUESTID'] : '' 
  746. ); 
  747.  
  748. $n_items = 0; 
  749. $OrderItems = array(); 
  750. while(isset($DataArray['L_PAYMENTREQUEST_' . $n . '_AMT' . $n_items])) 
  751. $Item = array( 
  752. 'NAME' => isset($DataArray['L_PAYMENTREQUEST_' . $n . '_NAME' . $n_items]) ? $DataArray['L_PAYMENTREQUEST_' . $n . '_NAME' . $n_items] : '',  
  753. 'DESC' => isset($DataArray['L_PAYMENTREQUEST_' . $n . '_DESC' . $n_items]) ? $DataArray['L_PAYMENTREQUEST_' . $n . '_DESC' . $n_items] : '',  
  754. 'AMT' => isset($DataArray['L_PAYMENTREQUEST_' . $n . '_AMT' . $n_items]) ? $DataArray['L_PAYMENTREQUEST_' . $n . '_AMT' . $n_items] : '',  
  755. 'NUMBER' => isset($DataArray['L_PAYMENTREQUEST_' . $n . '_NUMBER' . $n_items]) ? $DataArray['L_PAYMENTREQUEST_' . $n . '_NUMBER' . $n_items] : '',  
  756. 'QTY' => isset($DataArray['L_PAYMENTREQUEST_' . $n . '_QTY' . $n_items]) ? $DataArray['L_PAYMENTREQUEST_' . $n . '_QTY' . $n_items] : '',  
  757. 'TAXAMT' => isset($DataArray['L_PAYMENTREQUEST_' . $n . '_TAXAMT' . $n_items]) ? $DataArray['L_PAYMENTREQUEST_' . $n . '_TAXAMT' . $n_items] : '',  
  758. 'ITEMWEIGHTVALUE' => isset($DataArray['L_PAYMENTREQUEST_' . $n . '_ITEMWEIGHTVALUE' . $n_items]) ? $DataArray['L_PAYMENTREQUEST_' . $n . '_ITEMWEIGHTVALUE' . $n_items] : '',  
  759. 'ITEMWEIGHTUNIT' => isset($DataArray['L_PAYMENTREQUEST_' . $n . '_ITEMWEIGHTUNIT' . $n_items]) ? $DataArray['L_PAYMENTREQUEST_' . $n . '_ITEMWEIGHTUNIT' . $n_items] : '',  
  760. 'ITEMLENGTHVALUE' => isset($DataArray['L_PAYMENTREQUEST_' . $n . '_ITEMLENGTHVALUE' . $n_items]) ? $DataArray['L_PAYMENTREQUEST_' . $n . '_ITEMLENGTHVALUE' . $n_items] : '',  
  761. 'ITEMLENGTHUNIT' => isset($DataArray['L_PAYMENTREQUEST_' . $n . '_ITEMLENGTHUNIT' . $n_items]) ? $DataArray['L_PAYMENTREQUEST_' . $n . '_ITEMLENGTHUNIT' . $n_items] : '',  
  762. 'ITEMWIDTHVALUE' => isset($DataArray['L_PAYMENTREQUEST_' . $n . '_ITEMWIDTHVALUE' . $n_items]) ? $DataArray['L_PAYMENTREQUEST_' . $n . '_ITEMWIDTHVALUE' . $n_items] : '',  
  763. 'ITEMWIDTHUNIT' => isset($DataArray['L_PAYMENTREQUEST_' . $n . '_ITEMWIDTHUNIT' . $n_items]) ? $DataArray['L_PAYMENTREQUEST_' . $n . '_ITEMWIDTHUNIT' . $n_items] : '',  
  764. 'ITEMHEIGHTVALUE' => isset($DataArray['L_PAYMENTREQUEST_' . $n . '_ITEMHEIGHTVALUE' . $n_items]) ? $DataArray['L_PAYMENTREQUEST_' . $n . '_ITEMHEIGHTVALUE' . $n_items] : '',  
  765. 'ITEMHEIGHTUNIT' => isset($DataArray['L_PAYMENTREQUEST_' . $n . '_ITEMHEIGHTUNIT' . $n_items]) ? $DataArray['L_PAYMENTREQUEST_' . $n . '_ITEMHEIGHTUNIT' . $n_items] : '',  
  766. 'EBAYITEMNUMBER' => isset($DataArray['L_PAYMENTREQUEST_' . $n . '_EBAYITEMNUMBER' . $n_items]) ? $DataArray['L_PAYMENTREQUEST_' . $n . '_EBAYITEMNUMBER' . $n_items] : '',  
  767. 'EBAYAUCTIONTXNID' => isset($DataArray['L_PAYMENTREQUEST_' . $n . '_EBAYAUCTIONTXNID' . $n_items]) ? $DataArray['L_PAYMENTREQUEST_' . $n . '_EBAYAUCTIONTXNID' . $n_items] : '',  
  768. 'EBAYITEMORDERID' => isset($DataArray['L_PAYMENTREQUEST_' . $n . '_EBAYITEMORDERID' . $n_items]) ? $DataArray['L_PAYMENTREQUEST_' . $n . '_EBAYITEMORDERID' . $n_items] : '',  
  769. 'EBAYITEMCARTID' => isset($DataArray['L_PAYMENTREQUEST_' . $n . '_EBAYITEMCARTID' . $n_items]) ? $DataArray['L_PAYMENTREQUEST_' . $n . '_EBAYITEMCARTID' . $n_items] : '' 
  770. ); 
  771.  
  772. array_push($OrderItems, $Item); 
  773. $n_items++;  
  774. $Payment['ORDERITEMS'] = $OrderItems; 
  775.  
  776. array_push($Payments, $Payment); 
  777. $n++; 
  778.  
  779. return $Payments; 
  780.  
  781. /** 
  782. * Parse payment info from Express Checkout API response 
  783. * @access public 
  784. * @param array NVP response string 
  785. * @return array 
  786. */ 
  787. function GetExpressCheckoutPaymentInfo($DataArray) 
  788. $Payments = array(); 
  789. $n = 0; 
  790.  
  791. while(isset($DataArray['PAYMENTINFO_' . $n . '_TRANSACTIONID'])) 
  792. {  
  793. $PaymentInfo = array( 
  794. 'TRANSACTIONID' => isset($DataArray['PAYMENTINFO_' . $n . '_TRANSACTIONID']) ? $DataArray['PAYMENTINFO_' . $n . '_TRANSACTIONID'] : '',  
  795. 'TRANSACTIONTYPE' => isset($DataArray['PAYMENTINFO_' . $n . '_TRANSACTIONTYPE']) ? $DataArray['PAYMENTINFO_' . $n . '_TRANSACTIONTYPE'] : '',  
  796. 'PAYMENTTYPE' => isset($DataArray['PAYMENTINFO_' . $n . '_PAYMENTTYPE']) ? $DataArray['PAYMENTINFO_' . $n . '_PAYMENTTYPE'] : '',  
  797. 'ORDERTIME' => isset($DataArray['PAYMENTINFO_' . $n . '_ORDERTIME']) ? $DataArray['PAYMENTINFO_' . $n . '_ORDERTIME'] : '',  
  798. 'AMT' => isset($DataArray['PAYMENTINFO_' . $n . '_AMT']) ? $DataArray['PAYMENTINFO_' . $n . '_AMT'] : '',  
  799. 'CURRENCYCODE' => isset($DataArray['PAYMENTINFO_' . $n . '_CURRENCYCODE']) ? $DataArray['PAYMENTINFO_' . $n . '_CURRENCYCODE'] : '',  
  800. 'FEEAMT' => isset($DataArray['PAYMENTINFO_' . $n . '_FEEAMT']) ? $DataArray['PAYMENTINFO_' . $n . '_FEEAMT'] : '',  
  801. 'SETTLEAMT' => isset($DataArray['PAYMENTINFO_' . $n . '_SETTLEAMT']) ? $DataArray['PAYMENTINFO_' . $n . '_SETTLEAMT'] : '',  
  802. 'TAXAMT' => isset($DataArray['PAYMENTINFO_' . $n . '_TAXAMT']) ? $DataArray['PAYMENTINFO_' . $n . '_TAXAMT'] : '',  
  803. 'EXCHANGERATE' => isset($DataArray['PAYMENTINFO_' . $n . '_EXCHANGERATE']) ? $DataArray['PAYMENTINFO_' . $n . '_EXCHANGERATE'] : '',  
  804. 'PAYMENTSTATUS' => isset($DataArray['PAYMENTINFO_' . $n . '_PAYMENTSTATUS']) ? $DataArray['PAYMENTINFO_' . $n . '_PAYMENTSTATUS'] : '',  
  805. 'PENDINGREASON' => isset($DataArray['PAYMENTINFO_' . $n . '_PENDINGREASON']) ? $DataArray['PAYMENTINFO_' . $n . '_PENDINGREASON'] : '',  
  806. 'REASONCODE' => isset($DataArray['PAYMENTINFO_' . $n . '_REASONCODE']) ? $DataArray['PAYMENTINFO_' . $n . '_REASONCODE'] : '',  
  807. 'PROTECTIONELIGIBILITY' => isset($DataArray['PAYMENTINFO_' . $n . '_PROTECTIONELIGIBILITY']) ? $DataArray['PAYMENTINFO_' . $n . '_PROTECTIONELIGIBILITY'] : '',  
  808. 'EBAYITEMAUCTIONTRANSACTIONID' => isset($DataArray['PAYMENTINFO_' . $n . '_EBAYITEMAUCTIONTRANSACTIONID']) ? $DataArray['PAYMENTINFO_' . $n . '_EBAYITEMAUCTIONTRANSACTIONID'] : '',  
  809. 'PAYMENTREQUESTID' => isset($DataArray['PAYMENTINFO_' . $n . '_PAYMENTREQUESTID']) ? $DataArray['PAYMENTINFO_' . $n . '_PAYMENTREQUESTID'] : ''  
  810. ); 
  811.  
  812. array_push($Payments, $PaymentInfo); 
  813. $n++; 
  814. return $Payments; 
  815.  
  816. /** 
  817. * Mask the API credential values in the API call for logging purposes. 
  818. * @access public 
  819. * @param string API request string. 
  820. * @return boolean 
  821. */ 
  822. function MaskAPIResult($api_result) 
  823. $api_result_array = $this->NVPToArray($api_result); 
  824.  
  825. if(isset($api_result_array['SIGNATURE'])) 
  826. $api_result_array['USER'] = '*****'; 
  827. $api_result_array['PWD'] = '*****'; 
  828. $api_result_array['SIGNATURE'] = '*****'; 
  829. if (array_key_exists('ACCT', $api_result_array)) { 
  830. $api_result_array['ACCT'] = '*****'; 
  831. if (array_key_exists('CVV2', $api_result_array)) { 
  832. $api_result_array['CVV2'] = '*****'; 
  833. if (array_key_exists('EXPDATE', $api_result_array)) { 
  834. $api_result_array['EXPDATE'] = '*****'; 
  835.  
  836. $api_result = ''; 
  837. foreach($api_result_array as $var => $val) 
  838. $api_result .= $var.'='.$val.'&';  
  839.  
  840. $api_result_length = strlen($api_result); 
  841. $api_result = substr($api_result, 0, $api_result_length-1); 
  842.  
  843. return $api_result; 
  844.  
  845. /** 
  846. * Save log info to a location on the disk. 
  847. * @access public 
  848. * @param array NVP response string 
  849. * @return boolean 
  850. */ 
  851. function Logger($filename, $string_data) 
  852. {  
  853. $timestamp = strtotime('now'); 
  854. $timestamp = date('mdY_giA_', $timestamp); 
  855.  
  856. $string_data = $this->MaskAPIResult($string_data); 
  857.  
  858. $string_data_indiv = ''; 
  859. $string_data_array = $this->NVPToArray($string_data); 
  860.  
  861. foreach($string_data_array as $var => $val) 
  862. $string_data_indiv .= $var.'='.$val.chr(13); 
  863.  
  864. $file = $_SERVER['DOCUMENT_ROOT']."/paypal/logs/".$timestamp.$filename.".txt"; 
  865. $fh = fopen($file, 'w'); 
  866. fwrite($fh, $string_data.chr(13).chr(13).$string_data_indiv); 
  867. fclose($fh); 
  868.  
  869. return true;  
  870.  
  871. /** 
  872. * Capture a previously authorized transaction 
  873. * @access public 
  874. * @param array call config data 
  875. * @return array 
  876. */ 
  877. function DoCapture($DataArray) 
  878. $DCFieldsNVP = '&METHOD=DoCapture'; 
  879.  
  880. // DoCapture Fields 
  881. $DCFields = isset($DataArray['DCFields']) ? $DataArray['DCFields'] : array(); 
  882.  
  883. foreach($DCFields as $DCFieldsVar => $DCFieldsVal) 
  884. $DCFieldsNVP .= $DCFieldsVal != '' ? '&' . strtoupper($DCFieldsVar) . '=' . urlencode($DCFieldsVal) : ''; 
  885.  
  886. $NVPRequest = $this->NVPCredentials . $DCFieldsNVP; 
  887. $NVPResponse = $this->CURLRequest($NVPRequest); 
  888. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  889. return $NVPResponse; 
  890. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  891. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  892.  
  893. $Errors = $this->GetErrors($NVPResponseArray); 
  894.  
  895. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  896. $NVPResponseArray['ERRORS'] = $Errors; 
  897. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  898. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  899.  
  900. return $NVPResponseArray; 
  901.  
  902.  
  903.  
  904. /** 
  905. * Authorize an amount for processing against a credit card 
  906. * @access public 
  907. * @param array call config data 
  908. * @return array 
  909. */ 
  910. function DoAuthorization($DataArray) 
  911. $DAFieldsNVP = '&METHOD=DoAuthorization'; 
  912.  
  913. $DAFields = isset($DataArray['DAFields']) ? $DataArray['DAFields'] : array(); 
  914.  
  915. foreach($DAFields as $DAFieldsVar => $DAFieldsVal) 
  916. $DAFieldsNVP .= $DAFieldsVal != '' ? '&' . strtoupper($DAFieldsVar) . '=' . urlencode($DAFieldsVal) : ''; 
  917.  
  918. $NVPRequest = $this->NVPCredentials . $DAFieldsNVP; 
  919. $NVPResponse = $this->CURLRequest($NVPRequest); 
  920. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  921. return $NVPResponse; 
  922. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  923. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  924.  
  925. $Errors = $this->GetErrors($NVPResponseArray); 
  926.  
  927. $NVPResponseArray['ERRORS'] = $Errors; 
  928. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  929. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  930. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  931.  
  932. return $NVPResponseArray;  
  933.  
  934.  
  935. /** 
  936. * Reauthorize a previously authorization transaction 
  937. * @access public 
  938. * @param array call config data 
  939. * @return array 
  940. */ 
  941. function DoReauthorization($DataArray) 
  942. {  
  943. $DRFieldsNVP = '&METHOD=DoReAuthorization'; 
  944.  
  945. $DRFields = isset($DataArray['DRFields']) ? $DataArray['DRFields'] : array(); 
  946.  
  947. foreach($DRFields as $DRFieldsVar => $DRFieldsVal) 
  948. $DRFieldsNVP .= $DRFieldsVal != '' ? '&' . strtoupper($DRFieldsVar) . '=' . urlencode($DRFieldsVal) : ''; 
  949.  
  950. $NVPRequest = $this->NVPCredentials . $DRFieldsNVP; 
  951. $NVPResponse = $this->CURLRequest($NVPRequest); 
  952. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  953. return $NVPResponse; 
  954. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  955. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  956.  
  957. $Errors = $this->GetErrors($NVPResponseArray); 
  958.  
  959. $NVPResponseArray['ERRORS'] = $Errors; 
  960. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  961. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  962. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  963.  
  964. return $NVPResponseArray;  
  965.  
  966.  
  967. /** 
  968. * Void a previously authorized transaction. 
  969. * @access public 
  970. * @param array call config data 
  971. * @return array 
  972. */ 
  973. function DoVoid($DataArray) 
  974. {  
  975. $DVFieldsNVP = '&METHOD=DoVoid'; 
  976.  
  977. $DVFields = isset($DataArray['DVFields']) ? $DataArray['DVFields'] : array(); 
  978.  
  979. foreach($DVFields as $DVFieldsVar => $DVFieldsVal) 
  980. $DVFieldsNVP .= $DVFieldsVal != '' ? '&' . strtoupper($DVFieldsVar) . '=' . urlencode($DVFieldsVal) : ''; 
  981.  
  982. $NVPRequest = $this->NVPCredentials . $DVFieldsNVP; 
  983. $NVPResponse = $this->CURLRequest($NVPRequest); 
  984. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  985. return $NVPResponse; 
  986. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  987. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  988.  
  989. $Errors = $this->GetErrors($NVPResponseArray); 
  990.  
  991. $NVPResponseArray['ERRORS'] = $Errors; 
  992. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  993. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  994. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  995.  
  996. return $NVPResponseArray;  
  997.  
  998.  
  999. /** 
  1000. * Create a mass payment 
  1001. * @access public 
  1002. * @param array call config data 
  1003. * @return array 
  1004. */ 
  1005. function MassPay($DataArray) 
  1006. $MPFieldsNVP = '&METHOD=MassPay'; 
  1007. $MPItemsNVP = ''; 
  1008.  
  1009. // MassPay Fields 
  1010. $MPFields = isset($DataArray['MPFields']) ? $DataArray['MPFields'] : array(); 
  1011.  
  1012. foreach($MPFields as $MPFieldsVar => $MPFieldsVal) 
  1013. $MPFieldsNVP .= $MPFieldsVal != '' ? '&' . strtoupper($MPFieldsVar) . '=' . urlencode($MPFieldsVal) : ''; 
  1014.  
  1015. // MassPay Items Fields  
  1016. $MPItems = isset($DataArray['MPItems']) ? $DataArray['MPItems'] : array(); 
  1017. $n = 0; 
  1018. foreach($MPItems as $MPItemsVar => $MPItemsVal) 
  1019. $CurrentItem = $MPItems[$MPItemsVar]; 
  1020. foreach($CurrentItem as $CurrentItemVar => $CurrentItemVal) 
  1021. $MPItemsNVP .= $CurrentItemVal != '' ? '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal) : ''; 
  1022. $n++; 
  1023.  
  1024. $NVPRequest = $this->NVPCredentials . $MPFieldsNVP . $MPItemsNVP; 
  1025. $NVPResponse = $this->CURLRequest($NVPRequest); 
  1026. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  1027. return $NVPResponse; 
  1028. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  1029. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  1030.  
  1031. $Errors = $this->GetErrors($NVPResponseArray); 
  1032.  
  1033. $NVPResponseArray['ERRORS'] = $Errors; 
  1034. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  1035. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  1036. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  1037.  
  1038. return $NVPResponseArray; 
  1039.  
  1040.  
  1041. /** 
  1042. * Refund a prevously processed transaction. 
  1043. * @access public 
  1044. * @param array call config data 
  1045. * @return array 
  1046. */ 
  1047. function RefundTransaction($DataArray) 
  1048. $RTFieldsNVP = '&METHOD=RefundTransaction'; 
  1049.  
  1050. $RTFields = isset($DataArray['RTFields']) ? $DataArray['RTFields'] : array(); 
  1051.  
  1052. foreach($RTFields as $RTFieldsVar => $RTFieldsVal) 
  1053. $RTFieldsNVP .= $RTFieldsVal != '' ? '&' . strtoupper($RTFieldsVar) . '=' . urlencode($RTFieldsVal) : ''; 
  1054.  
  1055. $NVPRequest = $this->NVPCredentials . $RTFieldsNVP; 
  1056. $NVPResponse = $this->CURLRequest($NVPRequest); 
  1057. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  1058. return $NVPResponse; 
  1059. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  1060. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  1061.  
  1062. $Errors = $this->GetErrors($NVPResponseArray); 
  1063.  
  1064. $NVPResponseArray['ERRORS'] = $Errors; 
  1065. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  1066. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  1067. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  1068.  
  1069. return $NVPResponseArray; 
  1070.  
  1071.  
  1072. /** 
  1073. * Retrieve details about a previous transaction. 
  1074. * @access public 
  1075. * @param array call config data 
  1076. * @return array 
  1077. */ 
  1078. function GetTransactionDetails($DataArray) 
  1079. {  
  1080. $GTDFieldsNVP = '&METHOD=GetTransactionDetails'; 
  1081.  
  1082. $GTDFields = isset($DataArray['GTDFields']) ? $DataArray['GTDFields'] : array(); 
  1083.  
  1084. foreach($GTDFields as $GTDFieldsVar => $GTDFieldsVal) 
  1085. $GTDFieldsNVP .= $GTDFieldsVal != '' ? '&' . strtoupper($GTDFieldsVar) . '=' . urlencode($GTDFieldsVal) : ''; 
  1086.  
  1087. $NVPRequest = $this->NVPCredentials . $GTDFieldsNVP; 
  1088. $NVPResponse = $this->CURLRequest($NVPRequest); 
  1089. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  1090. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  1091.  
  1092. $Errors = $this->GetErrors($NVPResponseArray); 
  1093. $OrderItems = $this->GetOrderItems($NVPResponseArray); 
  1094.  
  1095. $NVPResponseArray['ERRORS'] = $Errors; 
  1096. $NVPResponseArray['ORDERITEMS'] = $OrderItems; 
  1097. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  1098. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  1099. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  1100.  
  1101. return $NVPResponseArray; 
  1102.  
  1103.  
  1104. /** 
  1105. * Process a credit card directly. 
  1106. * @access public 
  1107. * @param array call config data 
  1108. * @return array 
  1109. */ 
  1110. function DoDirectPayment($DataArray) 
  1111. // Create empty holders for each portion of the NVP string 
  1112. $DPFieldsNVP = '&METHOD=DoDirectPayment'; 
  1113. $CCDetailsNVP = ''; 
  1114. $PayerInfoNVP = ''; 
  1115. $PayerNameNVP = ''; 
  1116. $BillingAddressNVP = ''; 
  1117. $ShippingAddressNVP = ''; 
  1118. $PaymentDetailsNVP = ''; 
  1119. $OrderItemsNVP = ''; 
  1120. $Secure3DNVP = ''; 
  1121.  
  1122. // DP Fields 
  1123. $DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array(); 
  1124. foreach($DPFields as $DPFieldsVar => $DPFieldsVal) 
  1125. $DPFieldsNVP .= $DPFieldsVal != '' ? '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal) : ''; 
  1126.  
  1127. // CC Details Fields 
  1128. $CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array(); 
  1129. foreach($CCDetails as $CCDetailsVar => $CCDetailsVal) 
  1130. $CCDetailsNVP .= $CCDetailsVal != '' ? '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal) : ''; 
  1131.  
  1132. // PayerInfo Type Fields 
  1133. $PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array(); 
  1134. foreach($PayerInfo as $PayerInfoVar => $PayerInfoVal) 
  1135. $PayerInfoNVP .= $PayerInfoVal != '' ? '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal) : ''; 
  1136.  
  1137. // Payer Name Fields 
  1138. $PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array(); 
  1139. foreach($PayerName as $PayerNameVar => $PayerNameVal) 
  1140. $PayerNameNVP .= $PayerNameVal != '' ? '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal) : ''; 
  1141.  
  1142. // Address Fields (Billing) 
  1143. $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array(); 
  1144. foreach($BillingAddress as $BillingAddressVar => $BillingAddressVal) 
  1145. $BillingAddressNVP .= $BillingAddressVal != '' ? '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal) : ''; 
  1146.  
  1147. // Payment Details Type Fields 
  1148. $PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array(); 
  1149. foreach($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) 
  1150. $PaymentDetailsNVP .= $PaymentDetailsVal != '' ? '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal) : ''; 
  1151.  
  1152. // Payment Details Item Type Fields 
  1153. $OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array(); 
  1154. $n = 0; 
  1155. foreach($OrderItems as $OrderItemsVar => $OrderItemsVal) 
  1156. $CurrentItem = $OrderItems[$OrderItemsVar]; 
  1157. foreach($CurrentItem as $CurrentItemVar => $CurrentItemVal) 
  1158. $OrderItemsNVP .= $CurrentItemVal != '' ? '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal) : ''; 
  1159. $n++; 
  1160.  
  1161. // Ship To Address Fields 
  1162. $ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array(); 
  1163. foreach($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) 
  1164. $ShippingAddressNVP .= $ShippingAddressVal != '' ? '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal) : ''; 
  1165.  
  1166. // 3D Secure Fields 
  1167. $Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array(); 
  1168. foreach($Secure3D as $Secure3DVar => $Secure3DVal) 
  1169. $Secure3DNVP .= $Secure3DVal != '' ? '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal) : ''; 
  1170.  
  1171. // Now that we have each chunk we need to go ahead and append them all together for our entire NVP string 
  1172. $NVPRequest = $this->NVPCredentials . $DPFieldsNVP . $CCDetailsNVP . $PayerInfoNVP . $PayerNameNVP . $BillingAddressNVP . $PaymentDetailsNVP . $OrderItemsNVP . $ShippingAddressNVP . $Secure3DNVP; 
  1173. $NVPResponse = $this->CURLRequest($NVPRequest); 
  1174. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  1175. return $NVPResponse; 
  1176. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  1177. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  1178.  
  1179. $Errors = $this->GetErrors($NVPResponseArray); 
  1180.  
  1181. $NVPResponseArray['ERRORS'] = $Errors; 
  1182. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  1183. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  1184. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  1185.  
  1186. return $NVPResponseArray; 
  1187.  
  1188.  
  1189. /** 
  1190. * Begin the Express Checkout flow 
  1191. * @access public 
  1192. * @param array call config data 
  1193. * @return array 
  1194. */ 
  1195. function SetExpressCheckout($DataArray) 
  1196. {  
  1197. $SECFieldsNVP = '&METHOD=SetExpressCheckout'; 
  1198. $SurveyChoicesNVP = ''; 
  1199. $PaymentsNVP = ''; 
  1200. $ShippingOptionsNVP = ''; 
  1201. $BillingAgreementsNVP = ''; 
  1202.  
  1203. // SetExpressCheckout Request Fields 
  1204. $SECFields = isset($DataArray['SECFields']) ? $DataArray['SECFields'] : array(); 
  1205. foreach($SECFields as $SECFieldsVar => $SECFieldsVal) 
  1206. if(strtoupper($SECFieldsVar) != 'SKIPDETAILS') 
  1207. $SECFieldsNVP .= $SECFieldsVal != '' ? '&' . strtoupper($SECFieldsVar) . '=' . urlencode($SECFieldsVal) : ''; 
  1208. else 
  1209. $SkipDetails = $SECFieldsVal ? true : false;  
  1210.  
  1211. // Check to see if the REDIRECTURL should include user-action 
  1212. if(isset($SkipDetails) && $SkipDetails) 
  1213. $SkipDetailsOption = 'useraction=commit'; 
  1214. else 
  1215. $SkipDetailsOption = 'useraction=continue'; 
  1216.  
  1217. // Survey Choices 
  1218. $SurveyChoices = isset($DataArray['SurveyChoices']) ? $DataArray['SurveyChoices'] : array(); 
  1219. if($SECFields['surveyquestion'] != '') 
  1220. $n = 0; 
  1221. foreach($SurveyChoices as $SurveyChoice) 
  1222. $SurveyChoicesNVP .= $SurveyChoice != '' ? '&' . 'L_SURVEYCHOICE' . $n . '=' . urlencode($SurveyChoice) : ''; 
  1223. $n++;  
  1224.  
  1225. // Payment Details Type Fields 
  1226. $Payments = isset($DataArray['Payments']) ? $DataArray['Payments'] : array(); 
  1227. $n = 0; 
  1228. foreach($Payments as $PaymentsVar => $PaymentsVal) 
  1229. $CurrentPayment = $Payments[$PaymentsVar]; 
  1230. foreach($CurrentPayment as $CurrentPaymentVar => $CurrentPaymentVal) 
  1231. if(strtoupper($CurrentPaymentVar) != 'ORDER_ITEMS') 
  1232. $PaymentsNVP .= $CurrentPaymentVal != '' ? '&PAYMENTREQUEST_' . $n . '_' . strtoupper($CurrentPaymentVar) . '=' . urlencode($CurrentPaymentVal) : ''; 
  1233. else 
  1234. $PaymentOrderItems = $CurrentPayment['order_items']; 
  1235. $n_item = 0; 
  1236. foreach($PaymentOrderItems as $OrderItemsVar => $OrderItemsVal) 
  1237. $CurrentItem = $PaymentOrderItems[$OrderItemsVar]; 
  1238. foreach($CurrentItem as $CurrentItemVar => $CurrentItemVal) 
  1239. {  
  1240. $PaymentsNVP .= $CurrentItemVal != '' ? '&L_PAYMENTREQUEST_' . $n . '_' . strtoupper($CurrentItemVar) . $n_item . '=' . urlencode($CurrentItemVal) : ''; 
  1241. $n_item++; 
  1242. }  
  1243. $n++; 
  1244.  
  1245. // Billing Agreements 
  1246. $BillingAgreements = isset($DataArray['BillingAgreements']) ? $DataArray['BillingAgreements'] : array(); 
  1247. $n = 0; 
  1248. foreach($BillingAgreements as $BillingAgreementVar => $BillingAgreementVal) 
  1249. $CurrentItem = $BillingAgreements[$BillingAgreementVar]; 
  1250. foreach($CurrentItem as $CurrentItemVar => $CurrentItemVal) 
  1251. $BillingAgreementsNVP .= $CurrentItemVal != '' ? '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal) : ''; 
  1252. $n++;  
  1253.  
  1254. // Shipping Options Fields 
  1255. $ShippingOptions = isset($DataArray['ShippingOptions']) ? $DataArray['ShippingOptions'] : array(); 
  1256. $n = 0; 
  1257. foreach($ShippingOptions as $ShippingOptionsVar => $ShippingOptionsVal) 
  1258. $CurrentOption = $ShippingOptions[$ShippingOptionsVar]; 
  1259. foreach($CurrentOption as $CurrentOptionVar => $CurrentOptionVal) 
  1260. $ShippingOptionsNVP .= $CurrentOptionVal != '' ? '&' . strtoupper($CurrentOptionVar) . $n . '=' . urlencode($CurrentOptionVal) : ''; 
  1261. $n++;  
  1262.  
  1263. $NVPRequest = $this->NVPCredentials . $SECFieldsNVP . $SurveyChoicesNVP . $ShippingOptionsNVP . $BillingAgreementsNVP . $PaymentsNVP; 
  1264. $NVPResponse = $this->CURLRequest($NVPRequest); 
  1265. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  1266. return $NVPResponse; 
  1267. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  1268. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  1269.  
  1270. $Errors = $this->GetErrors($NVPResponseArray); 
  1271.  
  1272. if(isset($NVPResponseArray['TOKEN']) && $NVPResponseArray['TOKEN'] != '') 
  1273. if($this->Sandbox) 
  1274. $NVPResponseArray['REDIRECTURLDIGITALGOODS'] = 'https://www.sandbox.paypal.com/incontext?'.$SkipDetailsOption.'&token='.$NVPResponseArray['TOKEN']; 
  1275. $NVPResponseArray['REDIRECTURL'] = 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&' . $SkipDetailsOption . '&token=' . $NVPResponseArray['TOKEN'];  
  1276. else 
  1277. $NVPResponseArray['REDIRECTURLDIGITALGOODS'] = 'https://www.paypal.com/incontext?'.$SkipDetailsOption.'&token='.$NVPResponseArray['TOKEN']; 
  1278. $NVPResponseArray['REDIRECTURL'] = 'https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&' . $SkipDetailsOption . '&token=' . $NVPResponseArray['TOKEN']; 
  1279.  
  1280. $NVPResponseArray['ERRORS'] = $Errors; 
  1281. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  1282. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  1283. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  1284.  
  1285. return $NVPResponseArray; 
  1286.  
  1287. } // End function SetExpressCheckout() 
  1288.  
  1289. /** 
  1290. * Generate an NVP response to return to PayPal's Instant Update (callback) API. 
  1291. * @access public 
  1292. * @param array call config data 
  1293. * @return array 
  1294. */ 
  1295. function CallbackResponse($DataArray) 
  1296. {  
  1297. $CBFieldsNVP = 'METHOD=CallbackResponse';  
  1298. $ShippingOptionsNVP = ''; 
  1299.  
  1300. // Basic callback response fields. 
  1301. $CBFields = isset($DataArray['CBFields']) ? $DataArray['CBFields'] : array(); 
  1302. foreach($CBFields as $CBFieldsVar => $CBFieldsVal) 
  1303. $CBFieldsNVP .= $CBFieldsVal != '' ? '&' . strtoupper($CBFieldsVar) . '=' . urlencode($CBFieldsVal) : ''; 
  1304.  
  1305. // Shipping Options Fields 
  1306. $ShippingOptions = isset($DataArray['ShippingOptions']) ? $DataArray['ShippingOptions'] : array(); 
  1307. $n = 0; 
  1308. foreach($ShippingOptions as $ShippingOptionsVar => $ShippingOptionsVal) 
  1309. $CurrentOption = $ShippingOptions[$ShippingOptionsVar]; 
  1310. foreach($CurrentOption as $CurrentOptionVar => $CurrentOptionVal) 
  1311. $ShippingOptionsNVP .= $CurrentOptionVal != '' ? '&' . strtoupper($CurrentOptionVar) . $n . '=' . urlencode($CurrentOptionVal) : ''; 
  1312. $n++;  
  1313.  
  1314. $NVPResponse = $CBFieldsNVP . $ShippingOptionsNVP; 
  1315.  
  1316. return $NVPResponse; 
  1317.  
  1318.  
  1319. /** 
  1320. * Retrieve Express Checkout information back from PayPal to continue a checkout 
  1321. * after a user has signed in to PayPal and clicked Continue (or Pay) 
  1322. * @access public 
  1323. * @param array call config data 
  1324. * @return array 
  1325. */ 
  1326. function GetExpressCheckoutDetails($Token) 
  1327. $GECDFieldsNVP = '&METHOD=GetExpressCheckoutDetails&TOKEN=' . $Token; 
  1328.  
  1329. $NVPRequest = $this->NVPCredentials . $GECDFieldsNVP; 
  1330. $NVPResponse = $this->CURLRequest($NVPRequest); 
  1331. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  1332. return $NVPResponse; 
  1333. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  1334. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  1335.  
  1336. $Errors = $this->GetErrors($NVPResponseArray); 
  1337. $OrderItems = $this->GetOrderItems($NVPResponseArray); 
  1338. $Payments = $this->GetPayments($NVPResponseArray); 
  1339.  
  1340. $NVPResponseArray['ERRORS'] = $Errors; 
  1341. $NVPResponseArray['ORDERITEMS'] = $OrderItems; 
  1342. $NVPResponseArray['PAYMENTS'] = $Payments; 
  1343. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  1344. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  1345. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  1346.  
  1347. return $NVPResponseArray; 
  1348.  
  1349.  
  1350. } // End function GetExpressCheckoutDetails() 
  1351.  
  1352. /** 
  1353. * Finalize an Express Checkout payment and actually process the payment 
  1354. * @access public 
  1355. * @param array call config data 
  1356. * @return array 
  1357. */ 
  1358.  
  1359.  
  1360. function DoExpressCheckoutPayment($DataArray) { 
  1361. $DECPFieldsNVP = '&METHOD=DoExpressCheckoutPayment'; 
  1362. $PaymentsNVP = ''; 
  1363. $UserSelectedOptionsNVP = ''; 
  1364.  
  1365. // DoExpressCheckoutPayment Fields 
  1366. $DECPFields = isset($DataArray['DECPFields']) ? $DataArray['DECPFields'] : array(); 
  1367. foreach ($DECPFields as $DECPFieldsVar => $DECPFieldsVal) { 
  1368. $DECPFieldsNVP .= $DECPFieldsVal != '' ? '&' . strtoupper($DECPFieldsVar) . '=' . urlencode($DECPFieldsVal) : ''; 
  1369.  
  1370. // Payment Details Type Fields 
  1371. $Payments = isset($DataArray['Payments']) ? $DataArray['Payments'] : array(); 
  1372. $n = 0; 
  1373. foreach ($Payments as $PaymentsVar => $PaymentsVal) { 
  1374. $CurrentPayment = $Payments[$PaymentsVar]; 
  1375. foreach ($CurrentPayment as $CurrentPaymentVar => $CurrentPaymentVal) { 
  1376. if (strtoupper($CurrentPaymentVar) == 'ORDER_ITEMS') { 
  1377. $PaymentOrderItems = $CurrentPayment['order_items']; 
  1378. $n_item = 0; 
  1379. foreach ($PaymentOrderItems as $OrderItemsVar => $OrderItemsVal) { 
  1380. $CurrentItem = $PaymentOrderItems[$OrderItemsVar]; 
  1381. foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) { 
  1382. $PaymentsNVP .= $CurrentItemVal != '' ? '&L_PAYMENTREQUEST_' . $n . '_' . strtoupper($CurrentItemVar) . $n_item . '=' . urlencode($CurrentItemVal) : ''; 
  1383. $n_item++; 
  1384. } elseif (strtoupper($CurrentPaymentVar) == 'REDEEMED_OFFERS') { 
  1385. $RedeemedOffers = $CurrentPayment['redeemed_offers']; 
  1386. $n_item = 0; 
  1387. foreach ($RedeemedOffers as $RedeemedOfferVar => $RedeemedOfferVal) { 
  1388. $CurrentRedeemedOffer = $RedeemedOffers[$RedeemedOfferVar]; 
  1389. foreach ($CurrentRedeemedOffer as $CurrentRedeemedOfferVar => $CurrentRedeemedOfferVal) { 
  1390. $PaymentsNVP .= $CurrentRedeemedOfferVal != '' ? '&L_PAYMENTREQUEST_' . $n . '_' . strtoupper($CurrentRedeemedOfferVar) . $n_item . '=' . urlencode($CurrentRedeemedOfferVal) : ''; 
  1391. $n_item++; 
  1392. } elseif (strtoupper($CurrentPaymentVar) == 'MERCHANT_DATA_VARS') { 
  1393. $MerchantDataVars = $CurrentPayment['merchant_data_vars']; 
  1394. $n_item = 0; 
  1395. foreach ($MerchantDataVars as $MerchantDataVarsVar => $MerchantDataVarsVal) { 
  1396. $CurrentMerchantDataVar = $MerchantDataVars[$MerchantDataVarsVar]; 
  1397. foreach ($CurrentMerchantDataVar as $CurrentMerchantDataVarVar => $CurrentMerchantDataVarVal) { 
  1398. $PaymentsNVP .= $CurrentMerchantDataVarVal != '' ? '&L_PAYMENTREQUEST_' . $n . '_' . strtoupper($CurrentMerchantDataVarVar) . $n_item . '=' . urlencode($CurrentMerchantDataVarVal) : ''; 
  1399. $n_item++; 
  1400. } else { 
  1401. $PaymentsNVP .= $CurrentPaymentVal != '' ? '&PAYMENTREQUEST_' . $n . '_' . strtoupper($CurrentPaymentVar) . '=' . urlencode($CurrentPaymentVal) : ''; 
  1402. $n++; 
  1403.  
  1404. // User Selected Options 
  1405. $UserSelectedOptions = isset($DataArray['UserSelectedOptions']) ? $DataArray['UserSelectedOptions'] : array(); 
  1406. foreach ($UserSelectedOptions as $UserSelectedOptionVar => $UserSelectedOptionVal) { 
  1407. $UserSelectedOptionsNVP .= $UserSelectedOptionVal != '' ? '&' . strtoupper($UserSelectedOptionVar) . '=' . urlencode($UserSelectedOptionVal) : ''; 
  1408.  
  1409. $NVPRequest = $this->NVPCredentials . $DECPFieldsNVP . $PaymentsNVP . $UserSelectedOptionsNVP; 
  1410. $NVPResponse = $this->CURLRequest($NVPRequest); 
  1411. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  1412. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  1413.  
  1414. $Errors = $this->GetErrors($NVPResponseArray); 
  1415.  
  1416. // Loop through all possible payments and parse out data accordingly. 
  1417. // This is to handle parallel payments. 
  1418. $n = 0; 
  1419. $Payments = array(); 
  1420. while (isset($NVPResponseArray['PAYMENTINFO_' . $n . '_AMT'])) { 
  1421. $Payment = array( 
  1422. 'TRANSACTIONID' => isset($NVPResponseArray['PAYMENTINFO_' . $n . '_TRANSACTIONID']) ? $NVPResponseArray['PAYMENTINFO_' . $n . '_TRANSACTIONID'] : '',  
  1423. 'TRANSACTIONTYPE' => isset($NVPResponseArray['PAYMENTINFO_' . $n . '_TRANSACTIONTYPE']) ? $NVPResponseArray['PAYMENTINFO_' . $n . '_TRANSACTIONTYPE'] : '',  
  1424. 'PAYMENTTYPE' => isset($NVPResponseArray['PAYMENTINFO_' . $n . '_PAYMENTTYPE']) ? $NVPResponseArray['PAYMENTINFO_' . $n . '_PAYMENTTYPE'] : '',  
  1425. 'ORDERTIME' => isset($NVPResponseArray['PAYMENTINFO_' . $n . '_ORDERTIME']) ? $NVPResponseArray['PAYMENTINFO_' . $n . '_ORDERTIME'] : '',  
  1426. 'AMT' => isset($NVPResponseArray['PAYMENTINFO_' . $n . '_AMT']) ? $NVPResponseArray['PAYMENTINFO_' . $n . '_AMT'] : '',  
  1427. 'FEEAMT' => isset($NVPResponseArray['PAYMENTINFO_' . $n . '_FEEAMT']) ? $NVPResponseArray['PAYMENTINFO_' . $n . '_FEEAMT'] : '',  
  1428. 'SETTLEAMT' => isset($NVPResponseArray['PAYMENTINFO_' . $n . '_SETTLEAMT']) ? $NVPResponseArray['PAYMENTINFO_' . $n . '_SETTLEAMT'] : '',  
  1429. 'TAXAMT' => isset($NVPResponseArray['PAYMENTINFO_' . $n . '_TAXAMT']) ? $NVPResponseArray['PAYMENTINFO_' . $n . '_TAXAMT'] : '',  
  1430. 'EXCHANGERATE' => isset($NVPResponseArray['PAYMENTINFO_' . $n . '_EXCHANGERATE']) ? $NVPResponseArray['PAYMENTINFO_' . $n . '_EXCHANGERATE'] : '',  
  1431. 'CURRENCYCODE' => isset($NVPResponseArray['PAYMENTINFO_' . $n . '_CURRENCYCODE']) ? $NVPResponseArray['PAYMENTINFO_' . $n . '_CURRENCYCODE'] : '',  
  1432. 'PAYMENTSTATUS' => isset($NVPResponseArray['PAYMENTINFO_' . $n . '_PAYMENTSTATUS']) ? $NVPResponseArray['PAYMENTINFO_' . $n . '_PAYMENTSTATUS'] : '',  
  1433. 'PENDINGREASON' => isset($NVPResponseArray['PAYMENTINFO_' . $n . '_PENDINGREASON']) ? $NVPResponseArray['PAYMENTINFO_' . $n . '_PENDINGREASON'] : '',  
  1434. 'REASONCODE' => isset($NVPResponseArray['PAYMENTINFO_' . $n . '_REASONCODE']) ? $NVPResponseArray['PAYMENTINFO_' . $n . '_REASONCODE'] : '',  
  1435. 'PROTECTIONELIGIBILITY' => isset($NVPResponseArray['PAYMENTINFO_' . $n . '_PROTECTIONELIGIBILITY']) ? $NVPResponseArray['PAYMENTINFO_' . $n . '_PROTECTIONELIGIBILITY'] : '',  
  1436. 'ERRORCODE' => isset($NVPResponseArray['PAYMENTINFO_' . $n . '_ERRORCODE']) ? $NVPResponseArray['PAYMENTINFO_' . $n . '_ERRORCODE'] : '' 
  1437. ); 
  1438.  
  1439. // Pull out FMF info for current payment.  
  1440. $FMFilters = array(); 
  1441. $n_filters = 0; 
  1442. while (isset($NVPResponseArray['L_PAYMENTINFO_' . $n . '_FMFFILTERID' . $n_filters])) { 
  1443. $FMFilter = array( 
  1444. 'ID' => isset($NVPResponseArray['L_PAYMENTINFO_' . $n . '_FMFFILTERID' . $n_filters]) ? $NVPResponseArray['L_PAYMENTINFO_' . $n . '_FMFFILTERID' . $n_filters] : '',  
  1445. 'NAME' => isset($NVPResponseArray['L_PAYMENTINFO_' . $n . '_FMFFILTERNAME' . $n_filters]) ? $NVPResponseArray['L_PAYMENTINFO_' . $n . '_FMFFILTERNAME' . $n_filters] : '' 
  1446. ); 
  1447. $n_filters++; 
  1448. $Payment['FMFILTERS'] = $FMFilters; 
  1449.  
  1450. // Pull error info for current payment. 
  1451. $PaymentErrors = array(); 
  1452. while (isset($NVPResponseArray['PAYMENTREQUEST_' . $n . '_ERRORCODE'])) { 
  1453. $Error = array( 
  1454. 'ERRORCODE' => isset($NVPResponseArray['PAYMENTREQUEST_' . $n . '_ERRORCODE']) ? $NVPResponseArray['PAYMENTREQUEST_' . $n . '_ERRORCODE'] : '',  
  1455. 'SHORTMESSAGE' => isset($NVPResponseArray['PAYMENTREQUEST_' . $n . '_SHORTMESSAGE']) ? $NVPResponseArray['PAYMENTREQUEST_' . $n . '_SHORTMESSAGE'] : '',  
  1456. 'LONGMESSAGE' => isset($NVPResponseArray['PAYMENTREQUEST_' . $n . '_LONGMESSAGE']) ? $NVPResponseArray['PAYMENTREQUEST_' . $n . '_LONGMESSAGE'] : '',  
  1457. 'SEVERITYCODE' => isset($NVPResponseArray['PAYMENTREQUEST_' . $n . '_SEVERITYCODE']) ? $NVPResponseArray['PAYMENTREQUEST_' . $n . '_SEVERITYCODE'] : '',  
  1458. 'ACK' => isset($NVPResponseArray['PAYMENTREQUEST_' . $n . '_ACK']) ? $NVPResponseArray['PAYMENTREQUEST_' . $n . '_ACK'] : '' 
  1459. ); 
  1460. array_push($PaymentErrors, $Error); 
  1461. $Payment['ERRORS'] = $PaymentErrors; 
  1462.  
  1463. array_push($Payments, $Payment); 
  1464. $n++; 
  1465.  
  1466. $NVPResponseArray['ERRORS'] = $Errors; 
  1467. $NVPResponseArray['PAYMENTS'] = $Payments; 
  1468. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  1469. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  1470. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  1471.  
  1472. return $NVPResponseArray; 
  1473.  
  1474.  
  1475. /** 
  1476. * Search PayPal for transactions in your account history. 
  1477. * @access public 
  1478. * @param array call config data 
  1479. * @return array 
  1480. */ 
  1481. function TransactionSearch($DataArray) 
  1482. $TSFieldsNVP = '&METHOD=TransactionSearch'; 
  1483. $PayerNameNVP = ''; 
  1484.  
  1485. // Transaction Search Fields 
  1486. $TSFields = isset($DataArray['TSFields']) ? $DataArray['TSFields'] : array(); 
  1487. foreach($TSFields as $TSFieldsVar => $TSFieldsVal) 
  1488. $TSFieldsNVP .= $TSFieldsVal != '' ? '&' . strtoupper($TSFieldsVar) . '=' . urlencode($TSFieldsVal) : ''; 
  1489.  
  1490. // Payer Name Fields 
  1491. $PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array(); 
  1492. foreach($PayerName as $PayerNameVar => $PayerNameVal) 
  1493. $PayerNameNVP .= $PayerNameVal != '' ? '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal) : ''; 
  1494.  
  1495. $NVPRequest = $this->NVPCredentials . $TSFieldsNVP . $PayerNameNVP; 
  1496. $NVPResponse = $this->CURLRequest($NVPRequest); 
  1497. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  1498. return $NVPResponse; 
  1499. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  1500. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  1501.  
  1502. $Errors = $this->GetErrors($NVPResponseArray); 
  1503.  
  1504. $SearchResults = array(); 
  1505. $n = 0; 
  1506. while(isset($NVPResponseArray['L_TIMESTAMP' . $n . ''])) 
  1507. $LTimestamp = isset($NVPResponseArray['L_TIMESTAMP' . $n . '']) ? $NVPResponseArray['L_TIMESTAMP' . $n . ''] : ''; 
  1508. $LTimeZone = isset($NVPResponseArray['L_TIMEZONE' . $n . '']) ? $NVPResponseArray['L_TIMEZONE' . $n . ''] : ''; 
  1509. $LType = isset($NVPResponseArray['L_TYPE' . $n . '']) ? $NVPResponseArray['L_TYPE' . $n . ''] : ''; 
  1510. $LEmail = isset($NVPResponseArray['L_EMAIL' . $n . '']) ? $NVPResponseArray['L_EMAIL' . $n . ''] : ''; 
  1511. $LName = isset($NVPResponseArray['L_NAME' . $n . '']) ? $NVPResponseArray['L_NAME' . $n . ''] : ''; 
  1512. $LTransID = isset($NVPResponseArray['L_TRANSACTIONID' . $n . '']) ? $NVPResponseArray['L_TRANSACTIONID' . $n . ''] : ''; 
  1513. $LStatus = isset($NVPResponseArray['L_STATUS' . $n . '']) ? $NVPResponseArray['L_STATUS' . $n . ''] : ''; 
  1514. $LAmt = isset($NVPResponseArray['L_AMT' . $n . '']) ? $NVPResponseArray['L_AMT' . $n . ''] : ''; 
  1515. $LFeeAmt = isset($NVPResponseArray['L_FEEAMT' . $n . '']) ? $NVPResponseArray['L_FEEAMT' . $n . ''] : ''; 
  1516. $LNetAmt = isset($NVPResponseArray['L_NETAMT' . $n . '']) ? $NVPResponseArray['L_NETAMT' . $n . ''] : ''; 
  1517.  
  1518. $CurrentItem = array( 
  1519. 'L_TIMESTAMP' => $LTimestamp,  
  1520. 'L_TIMEZONE' => $LTimeZone,  
  1521. 'L_TYPE' => $LType,  
  1522. 'L_EMAIL' => $LEmail,  
  1523. 'L_NAME' => $LName,  
  1524. 'L_TRANSACTIONID' => $LTransID,  
  1525. 'L_STATUS' => $LStatus,  
  1526. 'L_AMT' => $LAmt,  
  1527. 'L_FEEAMT' => $LFeeAmt,  
  1528. 'L_NETAMT' => $LNetAmt 
  1529. ); 
  1530.  
  1531. array_push($SearchResults, $CurrentItem); 
  1532. $n++; 
  1533.  
  1534. $NVPResponseArray['ERRORS'] = $Errors; 
  1535. $NVPResponseArray['SEARCHRESULTS'] = $SearchResults; 
  1536. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  1537. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  1538. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  1539.  
  1540. return $NVPResponseArray; 
  1541.  
  1542.  
  1543.  
  1544. /** 
  1545. * Credit money back to a credit card without a previous transaction reference. 
  1546. * @access public 
  1547. * @param array call config data 
  1548. * @return array 
  1549. */ 
  1550. function DoNonReferencedCredit($DataArray) 
  1551. $DNRCFieldsNVP = '&METHOD=DoNonReferencedCredit'; 
  1552. $CCDetailsNVP = ''; 
  1553. $PayerName = ''; 
  1554. $PayerInfoNVP = ''; 
  1555. $BillingAddressNVP = ''; 
  1556.  
  1557. // DoNonReferencedCredit Fields 
  1558. $DNRCFields = isset($DataArray['DNRCFields']) ? $DataArray['DNRCFields'] : array(); 
  1559. foreach($DNRCFields as $DNRCFieldsVar => $DNRCFieldsVal) 
  1560. $DNRCFieldsNVP .= $DNRCFieldsVal != '' ? '&' . strtoupper($DNRCFieldsVar) . '=' . urlencode($DNRCFieldsVal) : ''; 
  1561.  
  1562. // CC Details Fields 
  1563. $CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array(); 
  1564. foreach($CCDetails as $CCDetailsVar => $CCDetailsVal) 
  1565. $CCDetailsNVP .= $CCDetailsVal != '' ? '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal) : ''; 
  1566.  
  1567. // Payer Name Fields 
  1568. $PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array(); 
  1569. $PayerNameNVP = ''; 
  1570. foreach($PayerName as $PayerNameVar => $PayerNameVal) 
  1571. $PayerNameNVP .= $PayerNameVal != '' ? '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal) : ''; 
  1572.  
  1573. // Payer Info Fields 
  1574. $PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array(); 
  1575. foreach($PayerInfo as $PayerInfoVar => $PayerInfoVal) 
  1576. $PayerInfoNVP .= $PayerInfoVal != '' ? '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal) : ''; 
  1577.  
  1578. // Address Fields (Billing) 
  1579. $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array(); 
  1580. foreach($BillingAddress as $BillingAddressVar => $BillingAddressVal) 
  1581. $BillingAddressNVP .= $BillingAddressVal != '' ? '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal) : ''; 
  1582.  
  1583. $NVPRequest = $this->NVPCredentials . $DNRCFieldsNVP . $CCDetailsNVP . $PayerNameNVP . $PayerInfoNVP . $BillingAddressNVP; 
  1584. $NVPResponse = $this->CURLRequest($NVPRequest); 
  1585. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  1586. return $NVPResponse; 
  1587. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  1588. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  1589.  
  1590. $Errors = $this->GetErrors($NVPResponseArray); 
  1591.  
  1592. $NVPResponseArray['ERRORS'] = $Errors; 
  1593. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  1594. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  1595. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  1596.  
  1597. return $NVPResponseArray; 
  1598.  
  1599.  
  1600. /** 
  1601. * Process a new transaction using the same billing info from a previous transaction. 
  1602. * @access public 
  1603. * @param array call config data 
  1604. * @return array 
  1605. */ 
  1606. function DoReferenceTransaction($DataArray) 
  1607. {  
  1608. $DRTFieldsNVP = '&METHOD=DoReferenceTransaction'; 
  1609. $CCDetailsNVP = ''; 
  1610. $PayerInfoNVP = ''; 
  1611. $BillingAddressNVP = ''; 
  1612. $ShippingAddressNVP = ''; 
  1613. $PaymentDetailsNVP = ''; 
  1614. $OrderItemsNVP = ''; 
  1615.  
  1616. // DoReferenceTransaction Fields 
  1617. $DRTFields = isset($DataArray['DRTFields']) ? $DataArray['DRTFields'] : array(); 
  1618. foreach($DRTFields as $DRTFieldsVar => $DRTFieldsVal) 
  1619. $DRTFieldsNVP .= $DRTFieldsVal != '' ? '&' . strtoupper($DRTFieldsVar) . '=' . urlencode($DRTFieldsVal) : ''; 
  1620.  
  1621. // Ship To Address Fields 
  1622. $ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array(); 
  1623. foreach($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) 
  1624. $ShippingAddressNVP .= $ShippingAddressVal != '' ? '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal) : ''; 
  1625.  
  1626. // Payment Details Item Type Fields 
  1627. $OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array(); 
  1628. $n = 0; 
  1629. foreach($OrderItems as $OrderItemsVar => $OrderItemsVal) 
  1630. $CurrentItem = $OrderItems[$OrderItemsVar]; 
  1631. foreach($CurrentItem as $CurrentItemVar => $CurrentItemVal) 
  1632. $OrderItemsNVP .= $CurrentItemVal != '' ? '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal) : ''; 
  1633. $n++; 
  1634.  
  1635. // CC Details Fields 
  1636. $CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array(); 
  1637. foreach($CCDetails as $CCDetailsVar => $CCDetailsVal) 
  1638. $CCDetailsNVP .= $CCDetailsVal != '' ? '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal) : ''; 
  1639.  
  1640. // PayerInfo Type Fields 
  1641. $PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array(); 
  1642. foreach($PayerInfo as $PayerInfoVar => $PayerInfoVal) 
  1643. $PayerInfoNVP .= $PayerInfoVal != '' ? '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal) : ''; 
  1644.  
  1645. // Address Fields (Billing) 
  1646. $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array(); 
  1647. foreach($BillingAddress as $BillingAddressVar => $BillingAddressVal) 
  1648. $BillingAddressNVP .= $BillingAddressVal != '' ? '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal) : ''; 
  1649.  
  1650. // Payment Details Fields 
  1651. $PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array(); 
  1652. foreach($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) 
  1653. $PaymentDetailsNVP .= $PaymentDetailsVal != '' ? '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal) : ''; 
  1654.  
  1655. $NVPRequest = $this->NVPCredentials . $DRTFieldsNVP . $ShippingAddressNVP . $OrderItemsNVP . $CCDetailsNVP . $PayerInfoNVP . $BillingAddressNVP . $PaymentDetailsNVP; 
  1656. $NVPResponse = $this->CURLRequest($NVPRequest); 
  1657. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  1658. return $NVPResponse; 
  1659. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  1660. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  1661.  
  1662. $Errors = $this->GetErrors($NVPResponseArray);  
  1663.  
  1664. $NVPResponseArray['ERRORS'] = $Errors; 
  1665. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  1666. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  1667. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  1668.  
  1669. return $NVPResponseArray; 
  1670.  
  1671. /** 
  1672. * Get the current PayPal balance. 
  1673. * @access public 
  1674. * @param array call config data 
  1675. * @return array 
  1676. */ 
  1677. function GetBalance($DataArray) 
  1678. $GBFieldsNVP = '&METHOD=GetBalance'; 
  1679.  
  1680. // GetBalance Fields 
  1681. $GBFields = isset($DataArray['GBFields']) ? $DataArray['GBFields'] : array(); 
  1682. foreach($GBFields as $GBFieldsVar => $GBFieldsVal) 
  1683. $GBFieldsNVP .= $GBFieldsVal != '' ? '&' . strtoupper($GBFieldsVar) . '=' . urlencode($GBFieldsVal) : ''; 
  1684.  
  1685. $NVPRequest = $this->NVPCredentials . $GBFieldsNVP; 
  1686. $NVPResponse = $this->CURLRequest($NVPRequest); 
  1687. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  1688. return $NVPResponse; 
  1689. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  1690. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  1691.  
  1692. $Errors = $this->GetErrors($NVPResponseArray); 
  1693.  
  1694. $BalanceResults = array(); 
  1695. $n = 0; 
  1696. while(isset($NVPResponseArray['L_AMT' . $n . ''])) 
  1697. $LAmt = isset($NVPResponseArray['L_AMT' . $n . '']) ? $NVPResponseArray['L_AMT' . $n . ''] : ''; 
  1698. $LCurrencyCode = isset($NVPResponseArray['L_CURRENCYCODE' . $n . '']) ? $NVPResponseArray['L_CURRENCYCODE' . $n . ''] : ''; 
  1699.  
  1700. $CurrentItem = array( 
  1701. 'L_AMT' => $LAmt,  
  1702. 'L_CURRENCYCODE' => $LCurrencyCode 
  1703. ); 
  1704.  
  1705. array_push($BalanceResults, $CurrentItem); 
  1706. $n++;  
  1707.  
  1708. $NVPResponseArray['ERRORS'] = $Errors; 
  1709. $NVPResponseArray['BALANCERESULTS'] = $BalanceResults; 
  1710. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  1711. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  1712. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  1713.  
  1714. return $NVPResponseArray; 
  1715.  
  1716.  
  1717. /** 
  1718. * Get the users PayPal account ID. 
  1719. * @access public 
  1720. * @param array call config data 
  1721. * @return array 
  1722. */ 
  1723. function GetPalDetails() 
  1724. $GPFieldsNVP = '&METHOD=GetPalDetails'; 
  1725.  
  1726. $NVPRequest = $this->NVPCredentials . $GPFieldsNVP; 
  1727. $NVPResponse = $this->CURLRequest($NVPRequest); 
  1728. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  1729. return $NVPResponse; 
  1730. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  1731. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  1732.  
  1733. $Errors = $this->GetErrors($NVPResponseArray); 
  1734.  
  1735. $NVPResponseArray['ERRORS'] = $Errors; 
  1736. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  1737. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  1738. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  1739.  
  1740. return $NVPResponseArray;  
  1741.  
  1742. /** 
  1743. * Verify an address against PayPal's system. 
  1744. * @access public 
  1745. * @param array call config data 
  1746. * @return array 
  1747. */ 
  1748. function AddressVerify($DataArray) 
  1749. $AVFieldsNVP = '&METHOD=AddressVerify'; 
  1750.  
  1751. $AVFields = isset($DataArray['AVFields']) ? $DataArray['AVFields'] : array(); 
  1752. foreach($AVFields as $AVFieldsVar => $AVFieldsVal) 
  1753. $AVFieldsNVP .= $AVFieldsVal != '' ? '&' . strtoupper($AVFieldsVar) . '=' . urlencode($AVFieldsVal) : ''; 
  1754.  
  1755. $NVPRequest = $this->NVPCredentials . $AVFieldsNVP; 
  1756. $NVPResponse = $this->CURLRequest($NVPRequest); 
  1757. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  1758. return $NVPResponse; 
  1759. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  1760. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  1761.  
  1762. $Errors = $this->GetErrors($NVPResponseArray); 
  1763.  
  1764. $NVPResponseArray['ERRORS'] = $Errors; 
  1765. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  1766. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  1767. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  1768.  
  1769. return $NVPResponseArray; 
  1770.  
  1771. /** 
  1772. * Update the status of a transaction in a pending status. 
  1773. * @access public 
  1774. * @param array call config data 
  1775. * @return array 
  1776. */ 
  1777. function ManagePendingTransactionStatus($DataArray) 
  1778. {  
  1779. $MPTSFieldsNVP = '&METHOD=ManagePendingTransactionStatus'; 
  1780.  
  1781. $MPTSFields = isset($DataArray['MPTSFields']) ? $DataArray['MPTSFields'] : array(); 
  1782. foreach($MPTSFields as $MPTSFieldsVar => $MPTSFieldsVal) 
  1783. $MPTSFieldsNVP .= $MPTSFieldsVal != '' ? '&' . strtoupper($MPTSFieldsVar) . '=' . urlencode($MPTSFieldsVal) : ''; 
  1784.  
  1785. $NVPRequest = $this->NVPCredentials . $MPTSFieldsNVP; 
  1786. $NVPResponse = $this->CURLRequest($NVPRequest); 
  1787. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  1788. return $NVPResponse; 
  1789. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  1790. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  1791.  
  1792. $Errors = $this->GetErrors($NVPResponseArray); 
  1793.  
  1794. $NVPResponseArray['ERRORS'] = $Errors; 
  1795. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  1796. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  1797. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  1798.  
  1799. return $NVPResponseArray; 
  1800.  
  1801. /** 
  1802. * Create a profile to automatically process transactions at given intervals. 
  1803. * @access public 
  1804. * @param array call config data 
  1805. * @return array 
  1806. */ 
  1807. function CreateRecurringPaymentsProfile($DataArray) 
  1808. $CRPPFieldsNVP = '&METHOD=CreateRecurringPaymentsProfile'; 
  1809. $OrderItemsNVP = ''; 
  1810.  
  1811. $CRPPFields = isset($DataArray['CRPPFields']) ? $DataArray['CRPPFields'] : array(); 
  1812. foreach($CRPPFields as $CRPPFieldsVar => $CRPPFieldsVal) 
  1813. $CRPPFieldsNVP .= $CRPPFieldsVal != '' ? '&' . strtoupper($CRPPFieldsVar) . '=' . urlencode($CRPPFieldsVal) : ''; 
  1814.  
  1815. $ProfileDetails = isset($DataArray['ProfileDetails']) ? $DataArray['ProfileDetails'] : array(); 
  1816. foreach($ProfileDetails as $ProfileDetailsVar => $ProfileDetailsVal) 
  1817. $CRPPFieldsNVP .= $ProfileDetailsVal != '' ? '&' . strtoupper($ProfileDetailsVar) . '=' . urlencode($ProfileDetailsVal) : ''; 
  1818.  
  1819. $ScheduleDetails = isset($DataArray['ScheduleDetails']) ? $DataArray['ScheduleDetails'] : array(); 
  1820. foreach($ScheduleDetails as $ScheduleDetailsVar => $ScheduleDetailsVal) 
  1821. $CRPPFieldsNVP .= $ScheduleDetailsVal != '' ? '&' . strtoupper($ScheduleDetailsVar) . '=' . urlencode($ScheduleDetailsVal) : ''; 
  1822.  
  1823. $BillingPeriod = isset($DataArray['BillingPeriod']) ? $DataArray['BillingPeriod'] : array(); 
  1824. foreach($BillingPeriod as $BillingPeriodVar => $BillingPeriodVal) 
  1825. $CRPPFieldsNVP .= $BillingPeriodVal != '' ? '&' . strtoupper($BillingPeriodVar) . '=' . urlencode($BillingPeriodVal) : ''; 
  1826.  
  1827. $ActivationDetails = isset($DataArray['ActivationDetails']) ? $DataArray['ActivationDetails'] : array(); 
  1828. foreach($ActivationDetails as $ActivationDetailsVar => $ActivationDetailsVal) 
  1829. $CRPPFieldsNVP .= $ActivationDetailsVal != '' ? '&' . strtoupper($ActivationDetailsVar) . '=' . urlencode($ActivationDetailsVal) : ''; 
  1830.  
  1831. $CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array(); 
  1832. foreach($CCDetails as $CCDetailsVar => $CCDetailsVal) 
  1833. $CRPPFieldsNVP .= $CCDetails != '' ? '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal) : ''; 
  1834.  
  1835. $PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array(); 
  1836. foreach($PayerInfo as $PayerInfoVar => $PayerInfoVal) 
  1837. $CRPPFieldsNVP .= $PayerInfoVal != '' ? '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal) : ''; 
  1838.  
  1839. $PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array(); 
  1840. foreach($PayerName as $PayerNameVar => $PayerNameVal) 
  1841. $CRPPFieldsNVP .= $PayerNameVal != '' ? '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal) : ''; 
  1842.  
  1843. $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array(); 
  1844. foreach($BillingAddress as $BillingAddressVar => $BillingAddressVal) 
  1845. $CRPPFieldsNVP .= $BillingAddressVal != '' ? '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal) : ''; 
  1846.  
  1847. $ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array(); 
  1848. foreach($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) 
  1849. $CRPPFieldsNVP .= $ShippingAddressVal != '' ? '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal) : ''; 
  1850.  
  1851. // Payment Details Item Type Fields 
  1852. $OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array(); 
  1853. $n = 0; 
  1854. $m = 0; 
  1855. foreach($OrderItems as $OrderItemsVar => $OrderItemsVal) 
  1856. $CurrentItem = $OrderItems[$OrderItemsVar]; 
  1857. foreach($CurrentItem as $CurrentItemVar => $CurrentItemVal) 
  1858. $OrderItemsNVP .= $CurrentItemVal != '' ? '&L_PAYMENTREQUEST_' . $n . '_' . strtoupper($CurrentItemVar) . $m . '=' . urlencode($CurrentItemVal) : ''; 
  1859. $m++; 
  1860.  
  1861. $NVPRequest = $this->NVPCredentials . $CRPPFieldsNVP . $OrderItemsNVP; 
  1862. $NVPResponse = $this->CURLRequest($NVPRequest); 
  1863. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  1864. return $NVPResponse; 
  1865. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  1866. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  1867.  
  1868. $Errors = $this->GetErrors($NVPResponseArray); 
  1869.  
  1870. $NVPResponseArray['ERRORS'] = $Errors; 
  1871. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  1872. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  1873. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  1874.  
  1875. return $NVPResponseArray;  
  1876.  
  1877. /** 
  1878. * Retrieve the details of a previously created recurring payments profile. 
  1879. * @access public 
  1880. * @param array call config data 
  1881. * @return array 
  1882. */ 
  1883. function GetRecurringPaymentsProfileDetails($DataArray) 
  1884. $GRPPDFieldsNVP = '&METHOD=GetRecurringPaymentsProfileDetails'; 
  1885.  
  1886. $GRPPDFields = isset($DataArray['GRPPDFields']) ? $DataArray['GRPPDFields'] : array(); 
  1887. foreach($GRPPDFields as $GRPPDFieldsVar => $GRPPDFieldsVal) 
  1888. $GRPPDFieldsNVP .= $GRPPDFieldsVal != '' ? '&' . strtoupper($GRPPDFieldsVar) . '=' . urlencode($GRPPDFieldsVal) : ''; 
  1889.  
  1890. $NVPRequest = $this->NVPCredentials . $GRPPDFieldsNVP; 
  1891. $NVPResponse = $this->CURLRequest($NVPRequest); 
  1892. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  1893. return $NVPResponse; 
  1894. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  1895. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  1896.  
  1897. $Errors = $this->GetErrors($NVPResponseArray); 
  1898.  
  1899. $NVPResponseArray['ERRORS'] = $Errors; 
  1900. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  1901. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  1902. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  1903.  
  1904. return $NVPResponseArray; 
  1905.  
  1906. /** 
  1907. * Update the status of a previously created recurring payments profile. 
  1908. * @access public 
  1909. * @param array call config data 
  1910. * @return array 
  1911. */ 
  1912. function ManageRecurringPaymentsProfileStatus($DataArray) 
  1913. $MRPPSFieldsNVP = '&METHOD=ManageRecurringPaymentsProfileStatus'; 
  1914.  
  1915. $MRPPSFields = isset($DataArray['MRPPSFields']) ? $DataArray['MRPPSFields'] : array(); 
  1916. foreach($MRPPSFields as $MRPPSFieldsVar => $MRPPSFieldsVal) 
  1917. $MRPPSFieldsNVP .= $MRPPSFieldsVal != '' ? '&' . strtoupper($MRPPSFieldsVar) . '=' . urlencode($MRPPSFieldsVal) : ''; 
  1918.  
  1919. $NVPRequest = $this->NVPCredentials . $MRPPSFieldsNVP; 
  1920. $NVPResponse = $this->CURLRequest($NVPRequest); 
  1921. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  1922. return $NVPResponse; 
  1923. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  1924. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  1925.  
  1926. $Errors = $this->GetErrors($NVPResponseArray); 
  1927.  
  1928. $NVPResponseArray['ERRORS'] = $Errors; 
  1929. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  1930. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  1931. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  1932.  
  1933. return $NVPResponseArray; 
  1934.  
  1935. /** 
  1936. * Process the outstanding amount on a recurring payments profile. 
  1937. * @access public 
  1938. * @param array call config data 
  1939. * @return array 
  1940. */ 
  1941. function BillOutstandingAmount($DataArray) 
  1942. $BOAFieldsNVP = '&METHOD=BillOutstandingAmount'; 
  1943.  
  1944. $BOAFields = isset($DataArray['BOAFields']) ? $DataArray['BOAFields'] : array(); 
  1945. foreach($BOAFields as $BOAFieldsVar => $BOAFieldsVal) 
  1946. $BOAFieldsNVP .= $BOAFieldsVal != '' ? '&' . strtoupper($BOAFieldsVar) . '=' . urlencode($BOAFieldsVal) : ''; 
  1947.  
  1948. $NVPRequest = $this->NVPCredentials . $BOAFieldsNVP; 
  1949. $NVPResponse = $this->CURLRequest($NVPRequest); 
  1950. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  1951. return $NVPResponse; 
  1952. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  1953. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  1954.  
  1955. $Errors = $this->GetErrors($NVPResponseArray); 
  1956.  
  1957. $NVPResponseArray['ERRORS'] = $Errors; 
  1958. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  1959. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  1960. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  1961.  
  1962. return $NVPResponseArray;  
  1963.  
  1964. /** 
  1965. * Update the details of a recurring payments profile. 
  1966. * @access public 
  1967. * @param array call config data 
  1968. * @return array 
  1969. */ 
  1970. function UpdateRecurringPaymentsProfile($DataArray) 
  1971. $URPPFieldsNVP = '&METHOD=UpdateRecurringPaymentsProfile'; 
  1972.  
  1973. $URPPFields = isset($DataArray['URPPFields']) ? $DataArray['URPPFields'] : array(); 
  1974. foreach($URPPFields as $URPPFieldsVar => $URPPFieldsVal) 
  1975. $URPPFieldsNVP .= $URPPFieldsVal != '' ? '&' . strtoupper($URPPFieldsVar) . '=' . urlencode($URPPFieldsVal) : ''; 
  1976.  
  1977. $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array(); 
  1978. foreach($BillingAddress as $BillingAddressVar => $BillingAddressVal) 
  1979. $URPPFieldsNVP .= $BillingAddressVal != '' ? '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal) : ''; 
  1980.  
  1981. $ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array(); 
  1982. foreach($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) 
  1983. $URPPFieldsNVP .= $ShippingAddressVal != '' ? '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal) : ''; 
  1984.  
  1985. $BillingPeriod = isset($DataArray['BillingPeriod']) ? $DataArray['BillingPeriod'] : array(); 
  1986. foreach($BillingPeriod as $BillingPeriodVar => $BillingPeriodVal) 
  1987. $URPPFieldsNVP .= $BillingPeriodVal != '' ? '&' . strtoupper($BillingPeriodVar) . '=' . urlencode($BillingPeriodVal) : ''; 
  1988.  
  1989. $CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array(); 
  1990. foreach($CCDetails as $CCDetailsVar => $CCDetailsVal) 
  1991. $URPPFieldsNVP .= $CCDetailsVal != '' ? '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal) : ''; 
  1992.  
  1993. $PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array(); 
  1994. foreach($PayerInfo as $PayerInfoVar => $PayerInfoVal) 
  1995. $URPPFieldsNVP .= $PayerInfoVal != '' ? '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal) : ''; 
  1996.  
  1997. $NVPRequest = $this->NVPCredentials . $URPPFieldsNVP; 
  1998. $NVPResponse = $this->CURLRequest($NVPRequest); 
  1999. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  2000. return $NVPResponse; 
  2001. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  2002. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  2003.  
  2004. $Errors = $this->GetErrors($NVPResponseArray); 
  2005.  
  2006. $NVPResponseArray['ERRORS'] = $Errors; 
  2007. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  2008. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  2009. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  2010.  
  2011. return $NVPResponseArray;  
  2012.  
  2013. /** 
  2014. * Get the status of an existing recurring payments profile. 
  2015. * @access public 
  2016. * @param array call config data 
  2017. * @return array 
  2018. */ 
  2019. function GetRecurringPaymentsProfileStatus($ProfileID) 
  2020. $GRPPDFields = array('profileid' => $ProfileID); 
  2021. $PayPalRequestData = array('GRPPDFields' => $GRPPDFields); 
  2022.  
  2023. $PayPalResult = $this->GetRecurringPaymentsProfileDetails($PayPalRequestData); 
  2024. $PayPalErrors = $PayPalResult['ERRORS']; 
  2025. $ProfileStatus = isset($PayPalResult['STATUS']) ? $PayPalResult['STATUS'] : 'Unknown'; 
  2026.  
  2027. $ResponseArray = array( 
  2028. 'PayPalResult' => $PayPalResult,  
  2029. 'ProfileStatus' => $ProfileStatus 
  2030. ); 
  2031.  
  2032. return $ResponseArray;  
  2033.  
  2034. /** 
  2035. * Initiates the creation of a billing agreement. 
  2036. * @access public 
  2037. * @param Token 
  2038. * @return array 
  2039. */ 
  2040. function CreateBillingAgreement($Token) 
  2041. $CBAFieldsNVP = '&METHOD=CreateBillingAgreement&TOKEN='.urlencode($Token); 
  2042.  
  2043. $NVPRequest = $this->NVPCredentials . $CBAFieldsNVP; 
  2044. $NVPResponse = $this->CURLRequest($NVPRequest); 
  2045. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  2046. return $NVPResponse; 
  2047. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  2048. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  2049.  
  2050. $Errors = $this->GetErrors($NVPResponseArray); 
  2051.  
  2052. $NVPResponseArray['ERRORS'] = $Errors; 
  2053. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  2054. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  2055. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  2056.  
  2057. return $NVPResponseArray;  
  2058.  
  2059. /** 
  2060. * Initiates the creation of a billing agreement. 
  2061. * @access public 
  2062. * @param array call config data 
  2063. * @return array 
  2064. */ 
  2065. function SetCustomerBillingAgreement($DataArray) 
  2066. {  
  2067. $SCBAFieldsNVP = '&METHOD=SetCustomerBillingAgreement'; 
  2068. $BillingAgreementsNVP = ''; 
  2069.  
  2070. $SCBAFields = isset($DataArray['SCBAFields']) ? $DataArray['SCBAFields'] : array(); 
  2071. foreach($SCBAFields as $SCBAFieldsVar => $SCBAFieldsVal) 
  2072. $SCBAFieldsNVP .= $SCBAFieldsVal != '' ? '&' . strtoupper($SCBAFieldsVar) . '=' . urlencode($SCBAFieldsVal) : ''; 
  2073.  
  2074. $BillingAgreements = isset($DataArray['BillingAgreements']) ? $DataArray['BillingAgreements'] : array(); 
  2075. $n = 0; 
  2076. foreach($BillingAgreements as $BillingAgreementVar => $BillingAgreementVal) 
  2077. $CurrentItem = $BillingAgreements[$BillingAgreementVar]; 
  2078. foreach($CurrentItem as $CurrentItemVar => $CurrentItemVal) 
  2079. $BillingAgreementsNVP .= $CurrentItemVal != '' ? '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal) : ''; 
  2080. $n++;  
  2081.  
  2082. $NVPRequest = $this->NVPCredentials . $SCBAFieldsNVP . $BillingAgreementsNVP; 
  2083. $NVPResponse = $this->CURLRequest($NVPRequest); 
  2084. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  2085. return $NVPResponse; 
  2086. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  2087. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  2088.  
  2089. $Errors = $this->GetErrors($NVPResponseArray); 
  2090.  
  2091. $NVPResponseArray['ERRORS'] = $Errors; 
  2092. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  2093. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  2094. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  2095.  
  2096. return $NVPResponseArray; 
  2097.  
  2098. /** 
  2099. * Obtains information about a billing agreement's PayPal account holder.  
  2100. * @access public 
  2101. * @param array call config data 
  2102. * @return array 
  2103. */ 
  2104. function GetBillingAgreementCustomerDetails($Token) 
  2105. $GBACDFieldsNVP = '&METHOD=GetBillingAgreementCustomerDetails&TOKEN=' . $Token; 
  2106.  
  2107. $NVPRequest = $this->NVPCredentials . $GBACDFieldsNVP; 
  2108. $NVPResponse = $this->CURLRequest($NVPRequest); 
  2109. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  2110. return $NVPResponse; 
  2111. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  2112. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  2113.  
  2114. $Errors = $this->GetErrors($NVPResponseArray); 
  2115.  
  2116. $NVPResponseArray['ERRORS'] = $Errors; 
  2117. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  2118. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  2119. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  2120.  
  2121. return $NVPResponseArray; 
  2122.  
  2123. /** 
  2124. * Update details about a billing agreement.  
  2125. * @access public 
  2126. * @param array call config data 
  2127. * @return array 
  2128. */ 
  2129. function BillAgreementUpdate($DataArray) 
  2130. $BAUFieldsNVP = '&METHOD=BillAgreementUpdate'; 
  2131.  
  2132. $BAUFields = isset($DataArray['BAUFields']) ? $DataArray['BAUFields'] : array(); 
  2133. foreach($BAUFields as $BAUFieldsVar => $BAUFieldsVal) 
  2134. $BAUFieldsNVP .= $BAUFieldsVal != '' ? '&' . strtoupper($BAUFieldsVar) . '=' . urlencode($BAUFieldsVal) : ''; 
  2135.  
  2136. $NVPRequest = $this->NVPCredentials . $BAUFieldsNVP; 
  2137. $NVPResponse = $this->CURLRequest($NVPRequest); 
  2138. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  2139. return $NVPResponse; 
  2140. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  2141. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  2142.  
  2143. $Errors = $this->GetErrors($NVPResponseArray); 
  2144.  
  2145. $NVPResponseArray['ERRORS'] = $Errors; 
  2146. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  2147. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  2148. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  2149.  
  2150. return $NVPResponseArray; 
  2151.  
  2152.  
  2153. /** 
  2154. * Setup the mobile checkout flow. 
  2155. * @access public 
  2156. * @param array call config data 
  2157. * @return array 
  2158. */ 
  2159. function SetMobileCheckout($DataArray) 
  2160. $SMCFieldsNVP = '&METHOD=SetMobileCheckout'; 
  2161.  
  2162. $SMCFields = isset($DataArray['SMCFields']) ? $DataArray['SMCFields'] : array(); 
  2163. foreach($SMCFields as $SMCFieldsVar => $SMCFieldsVal) 
  2164. $SMCFieldsNVP .= $SMCFieldsVal != '' ? '&' . strtoupper($SMCFieldsVar) . '=' . urlencode($SMCFieldsVal) : ''; 
  2165.  
  2166. $ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array(); 
  2167. foreach($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) 
  2168. $SMCFieldsNVP .= $SMCFieldsVal != '' ? '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal) : ''; 
  2169.  
  2170. $NVPRequest = $this->NVPCredentials . $SMCFieldsNVP; 
  2171. $NVPResponse = $this->CURLRequest($NVPRequest); 
  2172. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  2173. return $NVPResponse; 
  2174. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  2175. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  2176.  
  2177. $Errors = $this->GetErrors($NVPResponseArray); 
  2178.  
  2179. $NVPResponseArray['ERRORS'] = $Errors; 
  2180. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  2181. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  2182. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  2183.  
  2184. return $NVPResponseArray; 
  2185.  
  2186. /** 
  2187. * Finalize and process the sale from a mobile checkout flow. 
  2188. * @access public 
  2189. * @param array call config data 
  2190. * @return array 
  2191. */ 
  2192. function DoMobileCheckoutPayment($DataArray) 
  2193. $DMCPFieldsNVP = '&METHOD=DoMobileCheckoutPayment'; 
  2194.  
  2195. $DMCPFields = isset($DataArray['DMCPFields']) ? $DataArray['DMCPFields'] : array(); 
  2196. foreach($DMCPFields as $DMCPFieldsVar => $DMCPFieldsVal) 
  2197. $DMCPFieldsNVP .= $DMCPFieldsVal != '' ? '&' . strtoupper($DMCPFieldsVar) . '=' . urlencode($DMCPFieldsVal) : ''; 
  2198.  
  2199. $NVPRequest = $this->NVPCredentials . $DMCPFieldsNVP; 
  2200. $NVPResponse = $this->CURLRequest($NVPRequest); 
  2201. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  2202. return $NVPResponse; 
  2203. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  2204. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  2205.  
  2206. $Errors = $this->GetErrors($NVPResponseArray); 
  2207.  
  2208. $NVPResponseArray['ERRORS'] = $Errors; 
  2209. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  2210. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  2211. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  2212.  
  2213. return $NVPResponseArray; 
  2214. }  
  2215.  
  2216. /** 
  2217. * Set authorization params 
  2218. * @access public 
  2219. * @param array call config data 
  2220. * @return array 
  2221. */ 
  2222. function SetAuthFlowParam($DataArray) 
  2223. {  
  2224. $SetAuthFlowParamFieldsNVP = '&METHOD=SetAuthFlowParam'; 
  2225.  
  2226. // SetAuthFlowParam Fields 
  2227. $SetAuthFlowParamFields = isset($DataArray['SetAuthFlowParamFields']) ? $DataArray['SetAuthFlowParamFields'] : array(); 
  2228. foreach($SetAuthFlowParamFields as $SetAuthFlowParamFieldsVar => $SetAuthFlowParamFieldsVal) 
  2229. $SetAuthFlowParamFieldsNVP .= $SetAuthFlowParamFieldsVal != '' ? '&' . strtoupper($SetAuthFlowParamFieldsVar) . '=' . urlencode($SetAuthFlowParamFieldsVal) : ''; 
  2230.  
  2231. // ShippingAddress Fields 
  2232. $ShippingAddressFields = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array(); 
  2233. foreach($ShippingAddressFields as $ShippingAddressFieldsVar => $ShippingAddressFieldsVal) 
  2234. $SetAuthFlowParamFieldsNVP .= $ShippingAddressFieldsVal != '' ? '&' . strtoupper($ShippingAddressFieldsVar) . '=' . urlencode($ShippingAddressFieldsVal) : ''; 
  2235.  
  2236. $NVPRequest = $this->NVPCredentials . $SetAuthFlowParamFieldsNVP; 
  2237. $NVPResponse = $this->CURLRequest($NVPRequest); 
  2238. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  2239. return $NVPResponse; 
  2240. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  2241. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  2242.  
  2243. $Errors = $this->GetErrors($NVPResponseArray); 
  2244. $Token = isset($NVPResponseArray['TOKEN']) ? $NVPResponseArray['TOKEN'] : ''; 
  2245. $RedirectURL = $Token != '' ? 'https://www.paypal.com/us/cgi-bin/webscr?cmd=_account-authenticate-login&token=' . $Token : ''; 
  2246.  
  2247. $NVPResponseArray['ERRORS'] = $Errors; 
  2248. $NVPResponseArray['REDIRECTURL'] = $RedirectURL; 
  2249. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  2250. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  2251. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  2252.  
  2253. return $NVPResponseArray; 
  2254.  
  2255. /** 
  2256. * Get authorization details 
  2257. * @access public 
  2258. * @param string token 
  2259. * @return array 
  2260. */ 
  2261. function GetAuthDetails($Token) 
  2262. $GetAuthDetailsFieldsNVP = '&METHOD=GetAuthDetails&TOKEN=' . $Token; 
  2263.  
  2264. $NVPRequest = $this->NVPCredentials . $GetAuthDetailsFieldsNVP; 
  2265. $NVPResponse = $this->CURLRequest($NVPRequest); 
  2266. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  2267. return $NVPResponse; 
  2268. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  2269. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  2270.  
  2271. $Errors = $this->GetErrors($NVPResponseArray); 
  2272.  
  2273. $NVPResponseArray['ERRORS'] = $Errors; 
  2274. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  2275. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  2276. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  2277.  
  2278. return $NVPResponseArray; 
  2279.  
  2280.  
  2281. /** 
  2282. * Retrieve the current API permissions granted for the application. 
  2283. * @access public 
  2284. * @param string token 
  2285. * @return array 
  2286. */ 
  2287. function GetAccessPermissionsDetails($Token) 
  2288. $GetAccessPermissionsDetailsNVP = '&METHOD=GetAccessPermissionsDetails&TOKEN=' . $Token; 
  2289.  
  2290. $NVPRequest = $this->NVPCredentials . $GetAccessPermissionsDetailsNVP; 
  2291. $NVPResponse = $this->CURLRequest($NVPRequest); 
  2292. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  2293. return $NVPResponse; 
  2294. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  2295. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  2296.  
  2297. $Errors = $this->GetErrors($NVPResponseArray); 
  2298.  
  2299. $Permissions = array(); 
  2300. $n = 0; 
  2301. while(isset($NVPResponseArray['L_ACCESSPERMISSIONNAME' . $n . ''])) 
  2302. $LName = isset($NVPResponseArray['L_ACCESSPERMISSIONNAME' . $n . '']) ? $NVPResponseArray['L_ACCESSPERMISSIONNAME' . $n . ''] : ''; 
  2303. $LStatus = isset($NVPResponseArray['L_ACCESSPERMISSIONSTATUS' . $n . '']) ? $NVPResponseArray['L_ACCESSPERMISSIONSTATUS' . $n . ''] : ''; 
  2304.  
  2305. $CurrentItem = array( 
  2306. 'L_ACCESSPERMISSIONNAME' => $LName,  
  2307. 'L_ACCESSPERMISSIONSTATUS' => $LStatus 
  2308. ); 
  2309.  
  2310. array_push($ActivePermissions, $CurrentItem); 
  2311. $n++;  
  2312.  
  2313. $NVPResponseArray['ERRORS'] = $Errors; 
  2314. $NVPResponseArray['Permissions'] = $Permissions; 
  2315. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  2316. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  2317. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  2318.  
  2319. return $NVPResponseArray;  
  2320.  
  2321. /** 
  2322. * Set the access permissions for an application on a 3rd party user's account. 
  2323. * @access public 
  2324. * @param array call config data 
  2325. * @return array 
  2326. */ 
  2327. function SetAccessPermissions($DataArray) 
  2328. $SetAccessPermissionsNVP = '&METHOD=SetAccessPermissions'; 
  2329.  
  2330. // SetAccessPermissions Fields 
  2331. $SetAccessPermissionsFields = isset($DataArray['SetAccessPermissionsFields']) ? $DataArray['SetAccessPermissionsFields'] : array(); 
  2332. foreach($SetAccessPermissionsFields as $SetAccessPermissionsFieldsVar => $SetAccessPermissionsFieldsVal) 
  2333. $SetAccessPermissionsNVP .= $SetAccessPermissionsFieldsVal != '' ? '&' . strtoupper($SetAccessPermissionsFieldsVar) . '=' . urlencode($SetAccessPermissionsFieldsVal) : ''; 
  2334.  
  2335. $n = 0; 
  2336. $RequiredPermissions = isset($DataArray['RequiredPermissions']) ? $DataArray['RequiredPermissions'] : array(); 
  2337. foreach($RequiredPermissions as $RequiredPermission) 
  2338. $SetAccessPermissionsNVP .= '&L_REQUIREDACCESSPERMISSIONS' . $n . '=' . urlencode($RequiredPermission); 
  2339. $n++; 
  2340.  
  2341. $n = 0; 
  2342. $OptionalPermissions = isset($DataArray['OptionalPermissions']) ? $DataArray['OptionalPermissions'] : array(); 
  2343. foreach($OptionalPermissions as $OptionalPermission) 
  2344. $SetAccessPermissionsNVP .= '&L_OPTIONALACCESSPERMISSIONS' . $n . '=' . urlencode($OptionalPermission); 
  2345. $n++; 
  2346.  
  2347. $NVPRequest = $this->NVPCredentials . $SetAccessPermissionsNVP; 
  2348. $NVPResponse = $this->CURLRequest($NVPRequest); 
  2349. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  2350. return $NVPResponse; 
  2351. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  2352. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  2353.  
  2354. $Errors = $this->GetErrors($NVPResponseArray); 
  2355. $Token = isset($NVPResponseArray['TOKEN']) ? $NVPResponseArray['TOKEN'] : ''; 
  2356.  
  2357. if($this->Sandbox) 
  2358. $RedirectURL = $Token != '' ? 'https://www.sandbox.paypal.com/us/cgi-bin/webscr?cmd=_access-permission-login&token=' . $Token : ''; 
  2359. $LogoutRedirectURL = $Token != '' ? 'https://www.sandbox.paypal.com/us/cgi-bin/webscr?cmd=_access-permission-logout&token=' . $Token : ''; 
  2360. else 
  2361. $RedirectURL = $Token != '' ? 'https://www.paypal.com/us/cgi-bin/webscr?cmd=_access-permission-login&token=' . $Token : ''; 
  2362. $LogoutRedirectURL = $Token != '' ? 'https://www.paypal.com/us/cgi-bin/webscr?cmd=_access-permission-logout&token=' . $Token : ''; 
  2363.  
  2364. $NVPResponseArray['ERRORS'] = $Errors; 
  2365. $NVPResponseArray['REDIRECTURL'] = $RedirectURL; 
  2366. $NVPResponseArray['LOGOUTREDIRECTURL'] = $LogoutRedirectURL; 
  2367. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  2368. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  2369. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  2370.  
  2371. return $NVPResponseArray; 
  2372.  
  2373. /** 
  2374. * Update the access permissions for an application on a 3rd party user's account. 
  2375. * @access public 
  2376. * @param array call config data 
  2377. * @return array 
  2378. */ 
  2379. function UpdateAccessPermissions($PayerID) 
  2380. $UpdateAcccessPermissionsNVP = '&METHOD=UpdateAccessPermissions&PAYERID=' . $PayerID;  
  2381.  
  2382. $NVPRequest = $this->NVPCredentials . $UpdateAcccessPermissionsNVP; 
  2383. $NVPResponse = $this->CURLRequest($NVPRequest); 
  2384. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  2385. return $NVPResponse; 
  2386. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  2387. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  2388.  
  2389. $Errors = $this->GetErrors($NVPResponseArray); 
  2390.  
  2391. $NVPResponseArray['ERRORS'] = $Errors; 
  2392. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  2393. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  2394. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  2395.  
  2396. return $NVPResponseArray; 
  2397.  
  2398.  
  2399. /** 
  2400. * The request contains optional fields that are not currently used.  
  2401. * All buttons are automatically requested. 
  2402. * @access public 
  2403. * @param array call config data 
  2404. * @return array 
  2405. */ 
  2406. function BMButtonSearch($DataArray) 
  2407. $BMButtonSearchNVP = '&METHOD=BMButtonSearch'; 
  2408.  
  2409. // BMButtonSearch Fields 
  2410. $BMButtonSearchFields = isset($DataArray['BMButtonSearchFields']) ? $DataArray['BMButtonSearchFields'] : array(); 
  2411. foreach($BMButtonSearchFields as $BMButtonSearchFieldsVar => $BMButtonSearchFieldsVal) 
  2412. $BMButtonSearchNVP .= $BMButtonSearchFieldsVal != '' ? '&' . strtoupper($BMButtonSearchFieldsVar) . '=' . urlencode($BMButtonSearchFieldsVal) : ''; 
  2413.  
  2414. $NVPRequest = $this->NVPCredentials . $BMButtonSearchNVP; 
  2415. $NVPResponse = $this->CURLRequest($NVPRequest); 
  2416. if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ) { 
  2417. return $NVPResponse; 
  2418. $NVPRequestArray = $this->NVPToArray($NVPRequest); 
  2419. $NVPResponseArray = $this->NVPToArray($NVPResponse); 
  2420.  
  2421. $Errors = $this->GetErrors($NVPResponseArray); 
  2422.  
  2423. $SearchResults = array(); 
  2424. $n = 0; 
  2425. while(isset($NVPResponseArray['L_HOSTEDBUTTONID' . $n . ''])) 
  2426. $LHostedButtonID = isset($NVPResponseArray['L_HOSTEDBUTTONID' . $n . '']) ? $NVPResponseArray['L_HOSTEDBUTTONID' . $n . ''] : ''; 
  2427. $LButtonType = isset($NVPResponseArray['L_BUTTONTYPE' . $n . '']) ? $NVPResponseArray['L_BUTTONTYPE' . $n . ''] : ''; 
  2428. $LItemName = isset($NVPResponseArray['L_ITEMNAME' . $n . '']) ? $NVPResponseArray['L_ITEMNAME' . $n . ''] : ''; 
  2429. $LModifyDate = isset($NVPResponseArray['L_MODIFYDATE' . $n . '']) ? $NVPResponseArray['L_MODIFYDATE' . $n . ''] : ''; 
  2430.  
  2431. $CurrentItem = array( 
  2432. 'L_HOSTEDBUTTONID' => $LHostedButtonID,  
  2433. 'L_BUTTONTYPE' => $LButtonType,  
  2434. 'L_ITEMNAME' => $LItemName,  
  2435. 'L_MODIFYDATE' => $LModifyDate 
  2436. ); 
  2437.  
  2438. array_push($SearchResults, $CurrentItem); 
  2439. $n++; 
  2440.  
  2441. $NVPResponseArray['ERRORS'] = $Errors; 
  2442. $NVPResponseArray['SEARCHRESULTS'] = $SearchResults; 
  2443. $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; 
  2444. $NVPResponseArray['RAWREQUEST'] = $this->MaskAPIResult($NVPRequest); 
  2445. $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; 
  2446.  
  2447. return $NVPResponseArray;