tpayValidate

Class Fields.

Defined (1)

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

/includes/lib/src/_class_tpay/validate.php  
  1. class Validate 
  2. const PAYMENT_TYPE_BASIC = 'basic'; 
  3. const PAYMENT_TYPE_BASIC_API = 'basic_api'; 
  4. const PAYMENT_TYPE_CARD = 'card'; 
  5. const PAYMENT_TYPE_CARD_DIRECT = 'card_direct'; 
  6. const PAYMENT_TYPE_SZKWAL = 'szkwal'; 
  7. const PAYMENT_TYPE_WHITE_LABEL = 'whiteLabel'; 
  8. const PAYMENT_TYPE_EHAT = 'ehat'; 
  9. const PAYMENT_TYPE_SMS = 'sms'; 
  10. const CARD_DEREGISTER = 'deregister'; 
  11. const NUMBERS = 'numbers'; 
  12. const PHONE = 'phone'; 
  13. const REQUIRED = 'required'; 
  14. const VALIDATION = 'validation'; 
  15. const FLOAT = 'float'; 
  16. const FILTER = 'filter'; 
  17. const STRING = 'string'; 
  18. const MAXLENGHT_128 = 'maxlenght_128'; 
  19. const OPTIONS = 'options'; 
  20. const KANAL = 'kanal'; 
  21. const MAXLENGHT_512 = 'maxlenght_512'; 
  22. const EMAIL_LIST = 'email_list'; 
  23. const OPIS_DODATKOWY = 'opis_dodatkowy'; 
  24. const MAXLENGHT_32 = 'maxlenght_32'; 
  25. const EMAIL = 'email'; 
  26. const MAXLENGHT_64 = 'maxlenght_64'; 
  27. const TEST_MODE = 'test_mode'; 
  28. const AMOUNT = 'amount'; 
  29. const ORDER_ID = 'order_id'; 
  30. const MAXLENGHT_40 = 'maxlenght_40'; 
  31. const MINLENGTH_40 = 'minlength_40'; 
  32. const MAXLENGTH_40 = 'maxlength_40'; 
  33. const UNKNOWN_PAYMENT_TYPE_S = 'Unknown payment type: %s'; 
  34. const TYPE = 'type'; 
  35. const BOOLEAN = 'boolean'; 
  36. private static $cardPaymentLanguages = array( 
  37. 'pl' => 'pl_PL',  
  38. 'en' => 'en_EN',  
  39. 'es' => 'sp_SP',  
  40. 'it' => 'it_IT',  
  41. 'ru' => 'ru_RU',  
  42. 'fr' => 'fr_FR',  
  43. ); 
  44. /** 
  45. * List of ISO currency codes supported on card payments 
  46. * @var array 
  47. */ 
  48. private static $isoCurrencyCodes = array( 
  49. 784 => 'AED',  
  50. 41 => 'AMD',  
  51. 532 => 'ANG',  
  52. 973 => 'AOA',  
  53. 26 => 'ARS',  
  54. 30 => 'AUD',  
  55. 533 => 'AWG',  
  56. 944 => 'AZN',  
  57. 977 => 'BAM',  
  58. 42 => 'BBD',  
  59. 40 => 'BDT',  
  60. 975 => 'BGN',  
  61. 4 => 'BHD',  
  62. 108 => 'BIF',  
  63. 48 => 'BMD',  
  64. 6 => 'BOB',  
  65. 986 => 'BRL',  
  66. 36 => 'BSD',  
  67. 58 => 'BWP',  
  68. 933 => 'BYN',  
  69. 124 => 'CAD',  
  70. 976 => 'CDF',  
  71. 756 => 'CHF',  
  72. 152 => 'CLP',  
  73. 156 => 'CNY',  
  74. 170 => 'COP',  
  75. 188 => 'CRC',  
  76. 132 => 'CVE',  
  77. 203 => 'CZK',  
  78. 208 => 'DKK',  
  79. 214 => 'DOP',  
  80. 10 => 'DZD',  
  81. 818 => 'EGP',  
  82. 230 => 'ETB',  
  83. 978 => 'EUR',  
  84. 242 => 'FJD',  
  85. 826 => 'GBP',  
  86. 981 => 'GEL',  
  87. 936 => 'GHS',  
  88. 270 => 'GMD',  
  89. 320 => 'GTQ',  
  90. 328 => 'GYD',  
  91. 344 => 'HKD',  
  92. 340 => 'HNL',  
  93. 191 => 'HRK',  
  94. 332 => 'HTG',  
  95. 348 => 'HUF',  
  96. 360 => 'IDR',  
  97. 376 => 'ILS',  
  98. 356 => 'INR',  
  99. 364 => 'IRR',  
  100. 352 => 'ISK',  
  101. 388 => 'JMD',  
  102. 400 => 'JOD',  
  103. 392 => 'JPY',  
  104. 404 => 'KES',  
  105. 417 => 'KGS',  
  106. 116 => 'KHR',  
  107. 410 => 'KRW',  
  108. 414 => 'KWD',  
  109. 136 => 'KYD',  
  110. 398 => 'KZT',  
  111. 422 => 'LBP',  
  112. 144 => 'LKR',  
  113. 434 => 'LYD',  
  114. 504 => 'MAD',  
  115. 498 => 'MDL',  
  116. 969 => 'MGA',  
  117. 807 => 'MKD',  
  118. 104 => 'MMK',  
  119. 496 => 'MNT',  
  120. 446 => 'MOP',  
  121. 480 => 'MUR',  
  122. 454 => 'MWK',  
  123. 484 => 'MXN',  
  124. 458 => 'MYR',  
  125. 516 => 'NAD',  
  126. 566 => 'NGN',  
  127. 558 => 'NIO',  
  128. 578 => 'NOK',  
  129. 524 => 'NPR',  
  130. 554 => 'NZD',  
  131. 512 => 'OMR',  
  132. 590 => 'PAB',  
  133. 604 => 'PEN',  
  134. 598 => 'PGK',  
  135. 608 => 'PHP',  
  136. 586 => 'PKR',  
  137. 985 => 'PLN',  
  138. 600 => 'PYG',  
  139. 634 => 'QAR',  
  140. 946 => 'RON',  
  141. 941 => 'RSD',  
  142. 643 => 'RUB',  
  143. 646 => 'RWF',  
  144. 682 => 'SAR',  
  145. 690 => 'SCR',  
  146. 752 => 'SEK',  
  147. 702 => 'SGD',  
  148. 760 => 'SYP',  
  149. 764 => 'THB',  
  150. 788 => 'TND',  
  151. 949 => 'TRY',  
  152. 780 => 'TTD',  
  153. 901 => 'TWD',  
  154. 834 => 'TZS',  
  155. 980 => 'UAH',  
  156. 840 => 'USD',  
  157. 858 => 'UYU',  
  158. 860 => 'UZS',  
  159. 704 => 'VND',  
  160. 882 => 'WST',  
  161. 950 => 'XAF',  
  162. 951 => 'XCD',  
  163. 952 => 'XOF',  
  164. 953 => 'XPF',  
  165. 886 => 'YER',  
  166. 710 => 'ZAR',  
  167. 967 => 'ZMW',  
  168. ); 
  169. /** 
  170. * List of ISO 3166-1 country codes 
  171. * @var array 
  172. */ 
  173. private static $isoCountryCodes = array( 
  174. 'AF' => 'AFG',  
  175. 'AX' => 'ALA',  
  176. 'AL' => 'ALB',  
  177. 'DZ' => 'DZA',  
  178. 'AS' => 'ASM',  
  179. 'AD' => 'AND',  
  180. 'AO' => 'AGO',  
  181. 'AI' => 'AIA',  
  182. 'AQ' => 'AQ',  
  183. 'AG' => 'ATG',  
  184. 'AR' => 'ARG',  
  185. 'AM' => 'ARM',  
  186. 'AW' => 'ABW',  
  187. 'AU' => 'AUS',  
  188. 'AT' => 'AUT',  
  189. 'AZ' => 'AZE',  
  190. 'BS' => 'BHS',  
  191. 'BH' => 'BHR',  
  192. 'BD' => 'BGD',  
  193. 'BB' => 'BRB',  
  194. 'BY' => 'BLR',  
  195. 'BE' => 'BEL',  
  196. 'BZ' => 'BLZ',  
  197. 'BJ' => 'BEN',  
  198. 'BM' => 'BMU',  
  199. 'BT' => 'BTN',  
  200. 'BO' => 'BOL',  
  201. 'BA' => 'BIH',  
  202. 'BW' => 'BWA',  
  203. 'BV' => 'BV',  
  204. 'BR' => 'BRA',  
  205. 'IO' => 'IO',  
  206. 'BN' => 'BRN',  
  207. 'BG' => 'BGR',  
  208. 'BF' => 'BFA',  
  209. 'BI' => 'BDI',  
  210. 'KH' => 'KHM',  
  211. 'CM' => 'CMR',  
  212. 'CA' => 'CAN',  
  213. 'CV' => 'CV',  
  214. 'KY' => 'CYM',  
  215. 'CF' => 'CAF',  
  216. 'TD' => 'TCD',  
  217. 'CL' => 'CHL',  
  218. 'CN' => 'CHN',  
  219. 'CX' => 'CX',  
  220. 'CC' => 'CC',  
  221. 'CO' => 'COL',  
  222. 'KM' => 'COM',  
  223. 'CG' => 'COG',  
  224. 'CD' => 'COD',  
  225. 'CK' => 'COK',  
  226. 'CR' => 'CRI',  
  227. 'CI' => 'CIV',  
  228. 'HR' => 'HRV',  
  229. 'CU' => 'CUB',  
  230. 'CY' => 'CYP',  
  231. 'CZ' => 'CZE',  
  232. 'DK' => 'DNK',  
  233. 'DJ' => 'DJI',  
  234. 'DM' => 'DMA',  
  235. 'DO' => 'DOM',  
  236. 'EC' => 'ECU',  
  237. 'EG' => 'EGY',  
  238. 'SV' => 'SLV',  
  239. 'GQ' => 'GNQ',  
  240. 'ER' => 'ERI',  
  241. 'EE' => 'EST',  
  242. 'ET' => 'ETH',  
  243. 'FK' => 'FLK',  
  244. 'FO' => 'FRO',  
  245. 'FJ' => 'FJI',  
  246. 'FI' => 'FIN',  
  247. 'FR' => 'FRA',  
  248. 'GF' => 'GUF',  
  249. 'PF' => 'PYF',  
  250. 'TF' => 'IF',  
  251. 'GA' => 'GAB',  
  252. 'GM' => 'GMB',  
  253. 'GE' => 'GEO',  
  254. 'DE' => 'DEU',  
  255. 'GH' => 'GHA',  
  256. 'GI' => 'GIB',  
  257. 'GR' => 'GRC',  
  258. 'GL' => 'GRL',  
  259. 'GD' => 'GRD',  
  260. 'GP' => 'GLP',  
  261. 'GU' => 'GUM',  
  262. 'GT' => 'GTM',  
  263. 'GG' => 'GGY',  
  264. 'GN' => 'GIN',  
  265. 'GW' => 'GNB',  
  266. 'GY' => 'GUY',  
  267. 'HT' => 'HTI',  
  268. 'HM' => 'HM',  
  269. 'VA' => 'VAT',  
  270. 'HN' => 'HND',  
  271. 'HK' => 'HKG',  
  272. 'HU' => 'HUN',  
  273. 'IS' => 'ISL',  
  274. 'IN' => 'IND',  
  275. 'ID' => 'IDN',  
  276. 'IR' => 'IRN',  
  277. 'IQ' => 'IRQ',  
  278. 'IE' => 'IRL',  
  279. 'IM' => 'IMN',  
  280. 'IL' => 'ISR',  
  281. 'IT' => 'ITA',  
  282. 'JM' => 'JAM',  
  283. 'JP' => 'JPN',  
  284. 'JE' => 'JEY',  
  285. 'JO' => 'JOR',  
  286. 'KZ' => 'KAZ',  
  287. 'KE' => 'KEN',  
  288. 'KI' => 'KIR',  
  289. 'KR' => 'PRK',  
  290. 'KW' => 'KWT',  
  291. 'KG' => 'KGZ',  
  292. 'LA' => 'LAO',  
  293. 'LV' => 'LVA',  
  294. 'LB' => 'LBN',  
  295. 'LS' => 'LSO',  
  296. 'LR' => 'LBR',  
  297. 'LY' => 'LBY',  
  298. 'LI' => 'LIE',  
  299. 'LT' => 'LTU',  
  300. 'LU' => 'LUX',  
  301. 'MO' => 'MAC',  
  302. 'MK' => 'MKD',  
  303. 'MG' => 'MDG',  
  304. 'MW' => 'MWI',  
  305. 'MY' => 'MYS',  
  306. 'MV' => 'MDV',  
  307. 'ML' => 'MLI',  
  308. 'MT' => 'MLT',  
  309. 'MH' => 'MHL',  
  310. 'MQ' => 'MTQ',  
  311. 'MR' => 'MRT',  
  312. 'MU' => 'MUS',  
  313. 'YT' => 'MYT',  
  314. 'MX' => 'MEX',  
  315. 'FM' => 'FSM',  
  316. 'MD' => 'MDA',  
  317. 'MC' => 'MCO',  
  318. 'MN' => 'MNG',  
  319. 'ME' => 'MNE',  
  320. 'MS' => 'MSR',  
  321. 'MA' => 'MAR',  
  322. 'MZ' => 'MOZ',  
  323. 'MM' => 'MMR',  
  324. 'NA' => 'NAM',  
  325. 'NR' => 'NRU',  
  326. 'NP' => 'NPL',  
  327. 'NL' => 'NLD',  
  328. 'AN' => 'AN',  
  329. 'NC' => 'NCL',  
  330. 'NZ' => 'NZL',  
  331. 'NI' => 'NIC',  
  332. 'NE' => 'NER',  
  333. 'NG' => 'NGA',  
  334. 'NU' => 'NIU',  
  335. 'NF' => 'NFK',  
  336. 'MP' => 'MNP',  
  337. 'NO' => 'NOR',  
  338. 'OM' => 'OMN',  
  339. 'PK' => 'PAK',  
  340. 'PW' => 'PLW',  
  341. 'PS' => 'PSE',  
  342. 'PA' => 'PAN',  
  343. 'PG' => 'PNG',  
  344. 'PY' => 'PRY',  
  345. 'PE' => 'PER',  
  346. 'PH' => 'PHL',  
  347. 'PN' => 'PCN',  
  348. 'PL' => 'POL',  
  349. 'PT' => 'PRT',  
  350. 'PR' => 'PRI',  
  351. 'QA' => 'QAT',  
  352. 'RE' => 'REU',  
  353. 'RO' => 'ROU',  
  354. 'RU' => 'RUS',  
  355. 'RW' => 'RWA',  
  356. 'BL' => 'BLM',  
  357. 'SH' => 'SHN',  
  358. 'KN' => 'KNA',  
  359. 'LC' => 'LCA',  
  360. 'MF' => 'MAF',  
  361. 'PM' => 'SPM',  
  362. 'VC' => 'VCT',  
  363. 'WS' => 'WSM',  
  364. 'SM' => 'SMR',  
  365. 'ST' => 'STP',  
  366. 'SA' => 'SAU',  
  367. 'SN' => 'SEN',  
  368. 'RS' => 'SRB',  
  369. 'SC' => 'SYC',  
  370. 'SL' => 'SLE',  
  371. 'SG' => 'SGP',  
  372. 'SK' => 'SVK',  
  373. 'SI' => 'SVN',  
  374. 'SB' => 'SLB',  
  375. 'SO' => 'SOM',  
  376. 'ZA' => 'ZAF',  
  377. 'GS' => 'GS',  
  378. 'ES' => 'ESP',  
  379. 'LK' => 'LKA',  
  380. 'SD' => 'SSD',  
  381. 'SR' => 'SUR',  
  382. 'SJ' => 'SJM',  
  383. 'SZ' => 'SWZ',  
  384. 'SE' => 'SWE',  
  385. 'CH' => 'CHE',  
  386. 'SY' => 'SYR',  
  387. 'TW' => 'TW',  
  388. 'TJ' => 'TJK',  
  389. 'TZ' => 'TZA',  
  390. 'TH' => 'THA',  
  391. 'TL' => 'TLS',  
  392. 'TG' => 'TGO',  
  393. 'TK' => 'TKL',  
  394. 'TO' => 'TON',  
  395. 'TT' => 'TTO',  
  396. 'TN' => 'TUN',  
  397. 'TR' => 'TUR',  
  398. 'TM' => 'TKM',  
  399. 'TC' => 'TCA',  
  400. 'TV' => 'TUV',  
  401. 'UG' => 'UGA',  
  402. 'UA' => 'UKR',  
  403. 'AE' => 'ARE',  
  404. 'GB' => 'GBR',  
  405. 'US' => 'USA',  
  406. 'UM' => 'UM',  
  407. 'UY' => 'URY',  
  408. 'UZ' => 'UZB',  
  409. 'VU' => 'VUT',  
  410. 'VE' => 'VEN',  
  411. 'VN' => 'VNM',  
  412. 'VG' => 'VG',  
  413. 'VI' => 'VIR',  
  414. 'WF' => 'WLF',  
  415. 'EH' => 'ESH',  
  416. 'YE' => 'YEM',  
  417. 'ZM' => 'ZMB',  
  418. 'ZW' => 'ZWE',  
  419. ); 
  420. /** 
  421. * List of supported request fields for basic payment 
  422. * @var array 
  423. */ 
  424. private static $panelPaymentRequestFields = array( 
  425.  
  426. /** 
  427. * Transaction amount with dot as decimal separator. 
  428. */ 
  429. 'kwota' => array( 
  430. self::REQUIRED => true,  
  431. self::VALIDATION => array(self::FLOAT),  
  432. ),  
  433. /** 
  434. * Transaction description 
  435. */ 
  436. 'opis' => array( 
  437. self::REQUIRED => true,  
  438. self::VALIDATION => array(self::STRING, self::MAXLENGHT_128),  
  439. self::FILTER => 'text' 
  440. ),  
  441. /** 
  442. * The secondary parameter to the transaction identification. 
  443. * After the transaction returned as a parameter tr_crc. 
  444. */ 
  445. 'crc' => array( 
  446. self::REQUIRED => false,  
  447. self::VALIDATION => array(self::STRING, self::MAXLENGHT_128),  
  448. ),  
  449. /** 
  450. * Allow only online payment. 
  451. * Prevents the channel selection, which at the moment is not able to post real-time payment. 
  452. */ 
  453. 'online' => array( 
  454. self::REQUIRED => false,  
  455. self::VALIDATION => array(self::OPTIONS),  
  456. self::OPTIONS => array(0, 1),  
  457. ),  
  458. /** 
  459. * Imposing the customer the pre-payment channel. 
  460. * Could be changed manually by customer. 
  461. * Required for register transaction by transaction API 
  462. */ 
  463. self::KANAL => array( 
  464. self::REQUIRED => false,  
  465. self::VALIDATION => array('uint'),  
  466. ),  
  467. /** 
  468. * Customer will be presented only the selected group. 
  469. */ 
  470. 'grupa' => array( 
  471. self::REQUIRED => false,  
  472. self::VALIDATION => array('unit'),  
  473. ),  
  474. /** 
  475. * The resulting URL return address that will send the result of a transaction in the form POST parameters. 
  476. */ 
  477. 'wyn_url' => array( 
  478. self::REQUIRED => false,  
  479. self::VALIDATION => array(self::STRING, self::MAXLENGHT_512),  
  480. self::FILTER => 'url' 
  481. ),  
  482. /** 
  483. * E-mail address to which you will be notified about the status of the transaction. 
  484. */ 
  485. 'wyn_email' => array( 
  486. self::REQUIRED => false,  
  487. self::VALIDATION => array(self::EMAIL_LIST),  
  488. ),  
  489. /** 
  490. * Description payees during the transaction. 
  491. */ 
  492. 'opis_sprzed' => array( 
  493. self::REQUIRED => false,  
  494. self::VALIDATION => array(self::STRING, self::MAXLENGHT_128),  
  495. self::FILTER => 'text' 
  496. ),  
  497. /** 
  498. * Optional field used during card transactions processed through Elavon. 
  499. * The value of the field is passed to Elavon as *TEKST REF. TRANSAKCJI*. 
  500. * Acceptable characters are a-z, AZ (without Polish), 0-9 and space. 
  501. * All others will be removed. 
  502. * Max 32 signs. 
  503. */ 
  504. self::OPIS_DODATKOWY => array( 
  505. self::REQUIRED => false,  
  506. self::VALIDATION => array(self::OPIS_DODATKOWY, self::MAXLENGHT_32),  
  507. self::FILTER => 'mixed' 
  508. ),  
  509. /** 
  510. * The URL to which the customer will be transferred after successful completion of the transaction. 
  511. */ 
  512. 'pow_url' => array( 
  513. self::REQUIRED => false,  
  514. self::VALIDATION => array(self::STRING, self::MAXLENGHT_512),  
  515. self::FILTER => 'url' 
  516. ),  
  517. /** 
  518. * The URL to which the client will be transferred in the event of an error. 
  519. * Default is pow_url 
  520. */ 
  521. 'pow_url_blad' => array( 
  522. self::REQUIRED => false,  
  523. self::VALIDATION => array(self::STRING, self::MAXLENGHT_512),  
  524. self::FILTER => 'url' 
  525. ),  
  526. /** 
  527. * Transactional panel language. 
  528. * Default is PL 
  529. */ 
  530. 'jezyk' => array( 
  531. self::REQUIRED => false,  
  532. self::VALIDATION => array(self::OPTIONS),  
  533. self::OPTIONS => array('PL', 'EN', 'DE', 'IT', 'ES', 'FR', 'RU'),  
  534. ),  
  535. /** 
  536. * Customer email address. 
  537. */ 
  538. self::EMAIL => array( 
  539. self::REQUIRED => false,  
  540. self::VALIDATION => array(self::STRING, self::MAXLENGHT_64),  
  541. self::FILTER => 'mail' 
  542. ),  
  543. /** 
  544. * Customer surname. 
  545. */ 
  546. 'nazwisko' => array( 
  547. self::REQUIRED => false,  
  548. self::VALIDATION => array(self::STRING, self::MAXLENGHT_64),  
  549. self::FILTER => 'name' 
  550. ),  
  551. /** 
  552. * Customer name. 
  553. */ 
  554. 'imie' => array( 
  555. self::REQUIRED => false,  
  556. self::VALIDATION => array(self::STRING, self::MAXLENGHT_64),  
  557. self::FILTER => 'name' 
  558. ),  
  559. /** 
  560. * Customer address. 
  561. */ 
  562. 'adres' => array( 
  563. self::REQUIRED => false,  
  564. self::VALIDATION => array(self::STRING, self::MAXLENGHT_64),  
  565. self::FILTER => 'text' 
  566. ),  
  567. /** 
  568. * Customer city. 
  569. */ 
  570. 'miasto' => array( 
  571. self::REQUIRED => false,  
  572. self::VALIDATION => array(self::STRING, self::MAXLENGHT_32),  
  573. self::FILTER => 'name' 
  574. ),  
  575. /** 
  576. * Customer postal code. 
  577. */ 
  578. 'kod' => array( 
  579. self::REQUIRED => false,  
  580. self::VALIDATION => array(self::STRING, 'maxlenght_10'),  
  581. self::FILTER => 'text' 
  582. ),  
  583. /** 
  584. * Country code. 
  585. * Alphanumeric, 2 or 3 signs compatible with ISO 3166-1 
  586. */ 
  587. 'kraj' => array( 
  588. self::REQUIRED => false,  
  589. self::VALIDATION => array('country_code'),  
  590. ),  
  591. /** 
  592. * Customer phone. 
  593. */ 
  594. 'telefon' => array( 
  595. self::REQUIRED => false,  
  596. self::VALIDATION => array(self::STRING, 'maxlenght_16'),  
  597. self::FILTER => self::PHONE 
  598. ),  
  599. /** 
  600. * The parameter indicating acceptance of Terms tpay if it is available on the payee. 
  601. */ 
  602. 'akceptuje_regulamin' => array( 
  603. self::REQUIRED => false,  
  604. self::VALIDATION => array(self::OPTIONS),  
  605. self::OPTIONS => array(0, 1),  
  606. ),  
  607. ); 
  608. /** 
  609. * List of fields available in response for basic payment 
  610. * @var array 
  611. */ 
  612. private static $panelPaymentResponseFields = array( 
  613. /** 
  614. * The transaction ID assigned by the system tpay 
  615. */ 
  616. 'tr_id' => array( 
  617. self::REQUIRED => true,  
  618. self::TYPE => self::STRING,  
  619. self::VALIDATION => array(self::STRING),  
  620. ),  
  621. /** 
  622. * Date of transaction. 
  623. */ 
  624. 'tr_date' => array( 
  625. self::REQUIRED => true,  
  626. self::TYPE => self::STRING,  
  627. self::VALIDATION => array(self::STRING),  
  628.  
  629. ),  
  630. /** 
  631. * The secondary parameter to the transaction identification. 
  632. */ 
  633. 'tr_crc' => array( 
  634. self::REQUIRED => true,  
  635. self::TYPE => self::STRING,  
  636. self::VALIDATION => array(self::STRING),  
  637. ),  
  638. /** 
  639. * Transaction amount. 
  640. */ 
  641. 'tr_amount' => array( 
  642. self::REQUIRED => true,  
  643. self::TYPE => self::FLOAT,  
  644. self::VALIDATION => array(self::FLOAT),  
  645. ),  
  646. /** 
  647. * The amount paid for the transaction. 
  648. * Note: Depending on the settings, the amount paid can be different 
  649. * than transactions eg. When the customer does overpayment. 
  650. */ 
  651. 'tr_paid' => array( 
  652. self::REQUIRED => true,  
  653. self::TYPE => self::FLOAT,  
  654. self::VALIDATION => array(self::FLOAT),  
  655. ),  
  656. /** 
  657. * Description of the transaction. 
  658. */ 
  659. 'tr_desc' => array( 
  660. self::REQUIRED => true,  
  661. self::TYPE => self::STRING,  
  662. self::VALIDATION => array(self::STRING),  
  663. ),  
  664. /** 
  665. * Transaction status: TRUE in the case of the correct result or FALSE in the case of an error. 
  666. * Note: Depending on the settings, the transaction may be correct status,  
  667. * even if the amount paid is different from the amount of the transaction! 
  668. * Eg. If the Seller accepts the overpayment or underpayment threshold is set. 
  669. */ 
  670. 'tr_status' => array( 
  671. self::REQUIRED => true,  
  672. self::TYPE => self::STRING,  
  673. self::VALIDATION => array(self::OPTIONS),  
  674. self::OPTIONS => array(0, 1, true, false, 'TRUE', 'FALSE'),  
  675. ),  
  676. /** 
  677. * Transaction error status. 
  678. * Could have the following values: 
  679. * - none 
  680. * - overpay 
  681. * - surcharge 
  682. */ 
  683. 'tr_error' => array( 
  684. self::REQUIRED => true,  
  685. self::TYPE => self::STRING,  
  686. self::VALIDATION => array(self::OPTIONS),  
  687. self::OPTIONS => array('none', 'overpay', 'surcharge'),  
  688. ),  
  689. /** 
  690. * Customer email address. 
  691. */ 
  692. 'tr_email' => array( 
  693. self::REQUIRED => true,  
  694. self::TYPE => self::STRING,  
  695. self::VALIDATION => array(self::EMAIL_LIST),  
  696. ),  
  697. /** 
  698. * The checksum verifies the data sent to the payee. 
  699. * It is built according to the following scheme using the MD5 hash function: 
  700. * MD5(id + tr_id + tr_amount + tr_crc + security code) 
  701. */ 
  702. 'md5sum' => array( 
  703. self::REQUIRED => true,  
  704. self::TYPE => self::STRING,  
  705. self::VALIDATION => array(self::STRING, 'maxlength_32', 'minlength_32'),  
  706. ),  
  707. /** 
  708. * Transaction marker indicates whether the transaction was executed in test mode: 
  709. * 1 * in test mode 
  710. * 0 * in normal mode 
  711. */ 
  712. self::TEST_MODE => array( 
  713. self::REQUIRED => false,  
  714. self::TYPE => 'int',  
  715. self::VALIDATION => array(self::OPTIONS),  
  716. self::OPTIONS => array(0, 1),  
  717. ),  
  718. /** 
  719. * The parameter is sent only when you use a payment channel or MasterPass or V.me. 
  720. * Could have the following values: *masterpass* or *vme* 
  721. */ 
  722. 'wallet' => array( 
  723. self::REQUIRED => false,  
  724. self::TYPE => self::STRING,  
  725. ),  
  726. ); 
  727. /** 
  728. * List of supported fields for card payment request 
  729. * @var array 
  730. */ 
  731. private static $cardPaymentRequestFields = array( 
  732. /** 
  733. * Transaction amount 
  734. */ 
  735. self::AMOUNT => array( 
  736. self::REQUIRED => true,  
  737. self::VALIDATION => array(self::FLOAT),  
  738. ),  
  739. /** 
  740. * Client name 
  741. */ 
  742. 'name' => array( 
  743. self::REQUIRED => true,  
  744. self::VALIDATION => array(self::STRING, self::MAXLENGHT_64),  
  745. ),  
  746. /** 
  747. * Client email 
  748. */ 
  749. self::EMAIL => array( 
  750. self::REQUIRED => true,  
  751. self::VALIDATION => array(self::STRING, self::EMAIL_LIST),  
  752. ),  
  753. /** 
  754. * Sale description 
  755. */ 
  756. 'desc' => array( 
  757. self::REQUIRED => true,  
  758. self::VALIDATION => array(self::STRING, self::MAXLENGHT_128),  
  759. ),  
  760. /** 
  761. * Value from partner system 
  762. */ 
  763. self::ORDER_ID => array( 
  764. self::REQUIRED => false,  
  765. self::VALIDATION => array(self::STRING, self::MAXLENGHT_40),  
  766. ),  
  767. /** 
  768. * Value from partner system 
  769. */ 
  770. 'currency' => array( 
  771. self::REQUIRED => true,  
  772. self::VALIDATION => array(self::OPTIONS),  
  773. self::OPTIONS => array('985', '826', '840', '978', '203'),  
  774. ),  
  775. ); 
  776. /** 
  777. * List of fields available in card payment response 
  778. * @var array 
  779. */ 
  780. private static $cardPaymentResponseFields = array( 
  781. /** 
  782. * Method type 
  783. */ 
  784. self::TYPE => array( 
  785. self::REQUIRED => true,  
  786. self::TYPE => self::STRING,  
  787. self::VALIDATION => array(self::OPTIONS),  
  788. self::OPTIONS => array('sale', 'refund', 'deregister'),  
  789. ),  
  790. /** 
  791. * Merchant optional value 
  792. */ 
  793. self::ORDER_ID => array( 
  794. self::REQUIRED => true,  
  795. self::TYPE => self::STRING,  
  796. self::VALIDATION => array(self::STRING, self::MAXLENGHT_40) 
  797. ),  
  798. /** 
  799. * Payment status 
  800. */ 
  801. 'status' => array( 
  802. self::REQUIRED => true,  
  803. self::TYPE => self::STRING,  
  804. self::VALIDATION => array(self::OPTIONS),  
  805. self::OPTIONS => array('correct', 'declined'),  
  806. ),  
  807. /** 
  808. * Message checksum 
  809. */ 
  810. 'sign' => array( 
  811. self::REQUIRED => true,  
  812. self::TYPE => self::STRING,  
  813. self::VALIDATION => array(self::STRING, self::MAXLENGHT_128, self::MINLENGTH_40) 
  814. ),  
  815. /** 
  816. * Created sale/refund id 
  817. */ 
  818. 'sale_auth' => array( 
  819. self::REQUIRED => true,  
  820. self::TYPE => self::STRING,  
  821. self::VALIDATION => array(self::STRING, self::MAXLENGHT_40) 
  822. ),  
  823. /** 
  824. * Date of accounting/deregistering 
  825. */ 
  826. 'date' => array( 
  827. self::REQUIRED => true,  
  828. self::TYPE => self::STRING,  
  829. self::VALIDATION => array(self::STRING) 
  830. ),  
  831. /** 
  832. * carry value of 1 if account has test mode, otherwise parameter not sent 
  833. */ 
  834. self::TEST_MODE => array( 
  835. self::REQUIRED => false,  
  836. self::TYPE => self::STRING,  
  837. self::VALIDATION => array(self::STRING, 'maxlength_1', 'minlength_1') 
  838. ),  
  839. /** 
  840. * shortcut for client card number, eg ****5678 
  841. */ 
  842. 'card' => array( 
  843. self::REQUIRED => true,  
  844. self::TYPE => self::STRING,  
  845. self::VALIDATION => array(self::STRING, 'maxlength_8', 'minlength_8') 
  846. ),  
  847. ); 
  848. /** 
  849. * List of supported fields for card direct payment request 
  850. * @var array 
  851. */ 
  852. private static $cardDirectPaymentRequestFields = array( 
  853. /** 
  854. * Transaction amount 
  855. */ 
  856. self::AMOUNT => array( 
  857. self::REQUIRED => true,  
  858. self::VALIDATION => array(self::FLOAT),  
  859. ),  
  860. /** 
  861. * Client name 
  862. */ 
  863. 'name' => array( 
  864. self::REQUIRED => true,  
  865. self::VALIDATION => array(self::STRING, self::MAXLENGHT_64),  
  866. ),  
  867. /** 
  868. * Client email 
  869. */ 
  870. self::EMAIL => array( 
  871. self::REQUIRED => true,  
  872. self::VALIDATION => array(self::STRING, self::EMAIL_LIST),  
  873. ),  
  874. /** 
  875. * Sale description 
  876. */ 
  877. 'desc' => array( 
  878. self::REQUIRED => true,  
  879. self::VALIDATION => array(self::STRING, self::MAXLENGHT_128),  
  880. ),  
  881. /** 
  882. * Value from partner system 
  883. */ 
  884. self::ORDER_ID => array( 
  885. self::REQUIRED => false,  
  886. self::VALIDATION => array(self::STRING, self::MAXLENGHT_40),  
  887. ),  
  888. /** 
  889. * 3ds return url enabled 
  890. */ 
  891. 'enable_pow_url' => array( 
  892. self::REQUIRED => false,  
  893. self::VALIDATION => array(self::BOOLEAN),  
  894. ),  
  895. /** 
  896. * 3ds success return url 
  897. */ 
  898. 'pow_url' => array( 
  899. self::REQUIRED => false,  
  900. self::VALIDATION => array(self::STRING),  
  901. ),  
  902. /** 
  903. * 3ds failure return url 
  904. */ 
  905. 'pow_url_blad' => array( 
  906. self::REQUIRED => false,  
  907. self::VALIDATION => array(self::STRING),  
  908. ),  
  909. /** 
  910. * language 
  911. */ 
  912. 'language' => array( 
  913. self::REQUIRED => false,  
  914. self::VALIDATION => array(self::STRING),  
  915. ),  
  916. ); 
  917. /** 
  918. * List of fields available in card direct payment response 
  919. * @var array 
  920. */ 
  921. private static $cardDeregisterResponseFields = array( 
  922. /** 
  923. * client authorization ID, sent if onetimer option is not set 
  924. * when creating client and client has not been deregistered (himself or by api) 
  925. */ 
  926. 'cli_auth' => array( 
  927. self::REQUIRED => true,  
  928. self::TYPE => self::STRING,  
  929. self::VALIDATION => array(self::STRING, self::MAXLENGTH_40, self::MINLENGTH_40),  
  930. ),  
  931. /** 
  932. * carry value of 1 if account has test mode, otherwise parameter not sent 
  933. */ 
  934. self::TEST_MODE => array( 
  935. self::REQUIRED => false,  
  936. self::TYPE => 'int',  
  937. self::VALIDATION => array('int'),  
  938. ),  
  939. /** 
  940. * Date of accounting/deregistering 
  941. */ 
  942. 'date' => array( 
  943. self::REQUIRED => true,  
  944. self::TYPE => self::STRING,  
  945. self::VALIDATION => array(self::STRING),  
  946. self::FILTER => 'date' 
  947. ),  
  948. /** 
  949. * Message checksum 
  950. */ 
  951. 'sign' => array( 
  952. self::REQUIRED => true,  
  953. self::TYPE => self::STRING,  
  954. self::VALIDATION => array(self::STRING, 'maxlength_128', self::MINLENGTH_40),  
  955. ),  
  956. ); 
  957. /** 
  958. * List of supported fields for szkwal payment request 
  959. * @var array 
  960. */ 
  961. private static $szkwalRequestFields = array( 
  962. /** 
  963. * User api login 
  964. */ 
  965. 'api_login' => array( 
  966. self::REQUIRED => true,  
  967. self::VALIDATION => array(self::STRING),  
  968. ),  
  969. /** 
  970. * User api password 
  971. */ 
  972. 'api_password' => array( 
  973. self::REQUIRED => true,  
  974. self::VALIDATION => array(self::STRING),  
  975. ),  
  976. /** 
  977. * Client name 
  978. */ 
  979. 'cli_name' => array( 
  980. self::REQUIRED => true,  
  981. self::VALIDATION => array(self::STRING, 'maxlength_96'),  
  982. self::FILTER => 'name' 
  983. ),  
  984. /** 
  985. * Client email 
  986. */ 
  987. 'cli_email' => array( 
  988. self::REQUIRED => true,  
  989. self::VALIDATION => array(self::STRING, 'maxlength_128'),  
  990. self::FILTER => 'mail' 
  991. ),  
  992. /** 
  993. * Client phone 
  994. */ 
  995. 'cli_phone' => array( 
  996. self::REQUIRED => true,  
  997. self::VALIDATION => array(self::STRING, 'maxlength_32'),  
  998. self::FILTER => self::PHONE 
  999. ),  
  1000. /** 
  1001. * Title the client will be paying with; according to agreed format; 
  1002. */ 
  1003. 'title' => array( 
  1004. self::REQUIRED => true,  
  1005. self::VALIDATION => array(self::STRING),  
  1006. ),  
  1007. /** 
  1008. * Optional field sent in notifications 
  1009. */ 
  1010. 'crc' => array( 
  1011. self::REQUIRED => true,  
  1012. self::VALIDATION => array(self::STRING, 'maxlength_64'),  
  1013. self::FILTER => 'text' 
  1014. ),  
  1015. /** 
  1016. * Client account number 
  1017. */ 
  1018. 'cli_account' => array( 
  1019. self::REQUIRED => true,  
  1020. self::VALIDATION => array(self::STRING, 'minlenght_26', 'maxlength_26'),  
  1021. self::FILTER => self::NUMBERS 
  1022. ),  
  1023. /** 
  1024. * Checksum 
  1025. */ 
  1026. 'hash' => array( 
  1027. self::REQUIRED => true,  
  1028. self::VALIDATION => array(self::STRING, self::MINLENGTH_40, self::MAXLENGTH_40),  
  1029. self::FILTER => 'sign' 
  1030. ),  
  1031. ); 
  1032. /** 
  1033. * List of fields available in szkwal payment response 
  1034. * @var array 
  1035. */ 
  1036. private static $szkwalResponseFields = array( 
  1037. /** 
  1038. * Unique SZKWa* payment ID 
  1039. */ 
  1040. 'pay_id' => array( 
  1041. self::REQUIRED => false,  
  1042. self::TYPE => 'int',  
  1043. self::VALIDATION => array('uint'),  
  1044. ),  
  1045. /** 
  1046. * Unique SZKWa* notification ID 
  1047. */ 
  1048. 'not_id' => array( 
  1049. self::REQUIRED => false,  
  1050. self::TYPE => 'int',  
  1051. self::VALIDATION => array('uint'),  
  1052. ),  
  1053. /** 
  1054. * The title of payment in agreed format 
  1055. */ 
  1056. 'title' => array( 
  1057. self::REQUIRED => false,  
  1058. self::TYPE => self::STRING,  
  1059. self::VALIDATION => array(self::STRING),  
  1060. ),  
  1061. /** 
  1062. * Additional client field 
  1063. */ 
  1064. 'crc' => array( 
  1065. self::REQUIRED => false,  
  1066. self::TYPE => self::STRING,  
  1067. self::VALIDATION => array(self::STRING),  
  1068. ),  
  1069. /** 
  1070. * Transaction amount 
  1071. */ 
  1072. self::AMOUNT => array( 
  1073. self::REQUIRED => false,  
  1074. self::TYPE => self::FLOAT,  
  1075. self::VALIDATION => array(self::FLOAT),  
  1076. ),  
  1077. /** 
  1078. * Message checksum 
  1079. */ 
  1080. 'hash' => array( 
  1081. self::REQUIRED => false,  
  1082. self::TYPE => self::STRING,  
  1083. self::VALIDATION => array(self::STRING, self::MAXLENGTH_40, self::MINLENGTH_40),  
  1084. ),  
  1085. ); 
  1086. /** 
  1087. * List of supported fields for white label payment request 
  1088. * @var array 
  1089. */ 
  1090. private static $whiteLabelRequestFields = array( 
  1091. /** 
  1092. * User api login 
  1093. */ 
  1094. 'api_login' => array( 
  1095. self::REQUIRED => true,  
  1096. self::VALIDATION => array(self::STRING),  
  1097. ),  
  1098. /** 
  1099. * User api password 
  1100. */ 
  1101. 'api_password' => array( 
  1102. self::REQUIRED => true,  
  1103. self::VALIDATION => array(self::STRING),  
  1104. ),  
  1105. /** 
  1106. * Client name 
  1107. */ 
  1108. 'cli_name' => array( 
  1109. self::REQUIRED => true,  
  1110. self::VALIDATION => array(self::STRING, 'maxlenght_96'),  
  1111. self::FILTER => 'text' 
  1112. ),  
  1113. /** 
  1114. * Client email 
  1115. */ 
  1116. 'cli_email' => array( 
  1117. self::REQUIRED => true,  
  1118. self::VALIDATION => array(self::STRING, self::MAXLENGHT_128),  
  1119. self::FILTER => 'mail' 
  1120. ),  
  1121. /** 
  1122. * Client phone 
  1123. */ 
  1124. 'cli_phone' => array( 
  1125. self::REQUIRED => true,  
  1126. self::VALIDATION => array(self::MAXLENGHT_32),  
  1127. self::FILTER => self::PHONE 
  1128. ),  
  1129. /** 
  1130. * Order id (payment title) the customer will be paying with; according to agreed format; 
  1131. */ 
  1132. 'order' => array( 
  1133. self::REQUIRED => true,  
  1134. self::VALIDATION => array(self::STRING),  
  1135. ),  
  1136. /** 
  1137. * Transaction amount 
  1138. */ 
  1139. self::AMOUNT => array( 
  1140. self::REQUIRED => true,  
  1141. self::VALIDATION => array(self::FLOAT),  
  1142. ),  
  1143. /** 
  1144. * Message checksum 
  1145. */ 
  1146. 'hash' => array( 
  1147. self::REQUIRED => true,  
  1148. self::VALIDATION => array(self::STRING, self::MAXLENGHT_40),  
  1149. self::FILTER => 'sign' 
  1150. ),  
  1151. ); 
  1152.  
  1153.  
  1154. /** 
  1155. * Check all variables required in response 
  1156. * Parse variables to valid types 
  1157. * @param string $paymentType 
  1158. * @return array 
  1159. * @throws TException 
  1160. */ 
  1161. public static function getResponse($paymentType) 
  1162. $ready = array(); 
  1163. $missed = array(); 
  1164.  
  1165. switch ($paymentType) { 
  1166. case static::PAYMENT_TYPE_BASIC: 
  1167. case static::PAYMENT_TYPE_EHAT: 
  1168. $responseFields = static::$panelPaymentResponseFields; 
  1169. break; 
  1170. case static::PAYMENT_TYPE_CARD: 
  1171. $responseFields = static::$cardPaymentResponseFields; 
  1172. break; 
  1173. case static::PAYMENT_TYPE_SZKWAL: 
  1174. $responseFields = static::$szkwalResponseFields; 
  1175. break; 
  1176. case static::CARD_DEREGISTER: 
  1177. $responseFields = static::$cardDeregisterResponseFields; 
  1178. break; 
  1179. default: 
  1180. throw new TException(sprintf(static::UNKNOWN_PAYMENT_TYPE_S, $paymentType)); 
  1181.  
  1182. foreach ($responseFields as $fieldName => $field) { 
  1183. if (Util::post($fieldName, static::STRING) === false) { 
  1184. if ($field[static::REQUIRED] === true) { 
  1185. $missed[] = $fieldName; 
  1186. } else { 
  1187. $val = Util::post($fieldName, static::STRING); 
  1188. switch ($field[static::TYPE]) { 
  1189. case static::STRING: 
  1190. $val = (string)$val; 
  1191. break; 
  1192. case 'int': 
  1193. $val = (int)$val; 
  1194. break; 
  1195. case static::FLOAT: 
  1196. $val = (float)$val; 
  1197. break; 
  1198. default: 
  1199. throw new TException(sprintf('unknown field type in getResponse - field name= %s', $fieldName)); 
  1200. $ready[$fieldName] = $val; 
  1201.  
  1202. if (count($missed) > 0) { 
  1203. throw new TException(sprintf('Missing fields in tpay response: %s', implode(', ', $missed))); 
  1204.  
  1205. foreach ($ready as $fieldName => $fieldVal) { 
  1206. static::validateOne($paymentType, $fieldName, $fieldVal, false); 
  1207.  
  1208. return $ready; 
  1209.  
  1210. /** 
  1211. * Check one field form 
  1212. * @param string $paymentType payment type 
  1213. * @param string $name field name 
  1214. * @param mixed $value field value 
  1215. * @param bool $notResp is it not response value 
  1216. * @return bool 
  1217. * @throws TException 
  1218. */ 
  1219. public static function validateOne($paymentType, $name, $value, $notResp = true) 
  1220. switch ($paymentType) { 
  1221. case static::PAYMENT_TYPE_BASIC: 
  1222. case static::PAYMENT_TYPE_EHAT: 
  1223. $requestFields = $notResp ? static::$panelPaymentRequestFields : static::$panelPaymentResponseFields; 
  1224. break; 
  1225. case static::PAYMENT_TYPE_BASIC_API: 
  1226. $requestFields = static::$panelPaymentRequestFields; 
  1227. $requestFields[static::KANAL][static::REQUIRED] = true; 
  1228. break; 
  1229. case static::PAYMENT_TYPE_CARD: 
  1230. $requestFields = $notResp ? static::$cardPaymentRequestFields : static::$cardPaymentResponseFields; 
  1231. break; 
  1232. case static::PAYMENT_TYPE_CARD_DIRECT: 
  1233. $requestFields = static::$cardDirectPaymentRequestFields; 
  1234. break; 
  1235. case static::PAYMENT_TYPE_SZKWAL: 
  1236. $requestFields = $notResp ? static::$szkwalRequestFields : static::$szkwalResponseFields; 
  1237. break; 
  1238. case static::PAYMENT_TYPE_WHITE_LABEL: 
  1239. $requestFields = static::$whiteLabelRequestFields; 
  1240. break; 
  1241. default: 
  1242. throw new TException(sprintf(static::UNKNOWN_PAYMENT_TYPE_S, $paymentType)); 
  1243.  
  1244. if (!is_string($name)) { 
  1245. throw new TException('Invalid field name'); 
  1246. if (!array_key_exists($name, $requestFields)) { 
  1247. throw new TException('Field with this name is not supported ' . $name); 
  1248.  
  1249. $fieldConfig = $requestFields[$name]; 
  1250.  
  1251. if ($fieldConfig[static::REQUIRED] === false && ($value === '' || $value === false)) { 
  1252. return true; 
  1253.  
  1254. if (isset($fieldConfig[static::VALIDATION]) === true) { 
  1255.  
  1256. foreach ($fieldConfig[static::VALIDATION] as $validator) { 
  1257.  
  1258. switch ($validator) { 
  1259. case 'uint': 
  1260. static::validateUint($value, $name); 
  1261. break; 
  1262. case static::FLOAT: 
  1263. static::validateFloat($value, $name); 
  1264. break; 
  1265. case static::STRING: 
  1266. static::validateString($value, $name); 
  1267. break; 
  1268. case static::BOOLEAN: 
  1269. static::validateBoolean($value, $name); 
  1270. break; 
  1271. case static::OPIS_DODATKOWY: 
  1272. static::validateDescription($value, $name); 
  1273. break; 
  1274. case static::EMAIL_LIST: 
  1275. static::validateEmailList($value, $name); 
  1276. break; 
  1277. case static::OPTIONS: 
  1278. static::validateOptions($value, $fieldConfig[static::OPTIONS], $name); 
  1279. break; 
  1280. case 'country_code': 
  1281. static::validateCountryCode($value, $name); 
  1282. break; 
  1283. default: 
  1284. break; 
  1285. if (strpos($validator, 'maxlenght') === 0) { 
  1286. $max = explode('_', $validator); 
  1287. $max = (int)$max[1]; 
  1288. static::validateMaxLenght($value, $max, $name); 
  1289. if (strpos($validator, 'minlength') === 0) { 
  1290. $min = explode('_', $validator); 
  1291. $min = (int)$min[1]; 
  1292. static::validateMinLength($value, $min, $name); 
  1293. if (!static::filterValues($value, $fieldConfig)) { 
  1294. throw new TException( 
  1295. sprintf('Value of field "%s" contains illegal characters. Value: ' . $value, $name) 
  1296. ); 
  1297.  
  1298.  
  1299. return true; 
  1300.  
  1301. /** 
  1302. * Check if variable is uint 
  1303. * @param mixed $value variable to check 
  1304. * @param string $name field name 
  1305. * @throws TException 
  1306. */ 
  1307. private static function validateUint($value, $name) 
  1308. if (!is_int($value)) { 
  1309. throw new TException(sprintf('Field "%s" must be an integer', $name)); 
  1310. } else { 
  1311. if ($value <= 0) { 
  1312. throw new TException(sprintf('Field "%s" must be higher than zero', $name)); 
  1313.  
  1314. /** 
  1315. * Check if variable is float 
  1316. * @param mixed $value variable to check 
  1317. * @param string $name field name 
  1318. * @throws TException 
  1319. */ 
  1320. private static function validateFloat($value, $name) 
  1321. if (!is_numeric($value) && !is_int($value)) { 
  1322. throw new TException(sprintf('Field "%s" must be a float|int number', $name)); 
  1323. } else { 
  1324. if ($value < 0) { 
  1325. throw new TException(sprintf('Field "%s" must be higher than zero', $name)); 
  1326.  
  1327. /** 
  1328. * Check if variable is string 
  1329. * @param mixed $value variable to check 
  1330. * @param string $name field name 
  1331. * @throws TException 
  1332. */ 
  1333. private static function validateString($value, $name) 
  1334. if (!is_string($value)) { 
  1335. throw new TException(sprintf('Field "%s" must be a string, type given: ' . gettype($value), $name)); 
  1336.  
  1337. /** 
  1338. * Check if variable is string 
  1339. * @param mixed $value variable to check 
  1340. * @param string $name field name 
  1341. * @throws TException 
  1342. */ 
  1343. private static function validateBoolean($value, $name) 
  1344. if (!is_bool($value)) { 
  1345. throw new TException(sprintf('Field "%s" must be a boolean', $name)); 
  1346.  
  1347. /** 
  1348. * Check if variable is valid description 
  1349. * @param mixed $value variable to check 
  1350. * @param string $name field name 
  1351. * @throws TException 
  1352. */ 
  1353. private static function validateDescription($value, $name) 
  1354. if (preg_match('/[^a-zA-Z0-9 ]/', $value) !== 0) { 
  1355. throw new TException( 
  1356. sprintf('Field "%s" contains invalid characters. Only a-z A-Z 0-9 and space', $name) 
  1357. ); 
  1358.  
  1359. /** 
  1360. * Check if variable is valid email list 
  1361. * @param mixed $value variable to check 
  1362. * @param string $name field name 
  1363. * @throws TException 
  1364. */ 
  1365. private static function validateEmailList($value, $name) 
  1366. if (!is_string($value)) { 
  1367. throw new TException(sprintf('Field "%s" must be a string', $name)); 
  1368. $emails = explode(', ', $value); 
  1369. foreach ($emails as $email) { 
  1370. if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) { 
  1371. throw new TException( 
  1372. sprintf('Field "%s" contains invalid email address', $name) 
  1373. ); 
  1374.  
  1375. /** 
  1376. * Check if variable has expected value 
  1377. * @param mixed $value variable to check 
  1378. * @param array $options available options 
  1379. * @param string $name field name 
  1380. * @throws TException 
  1381. */ 
  1382. private static function validateOptions($value, $options, $name) 
  1383. if (!in_array($value, $options, true)) { 
  1384. throw new TException(sprintf('Field "%s" has unsupported value', $name)); 
  1385.  
  1386. /** 
  1387. * Check if variable is valid country code 
  1388. * @param mixed $value variable to check 
  1389. * @param string $name field name 
  1390. * @throws TException 
  1391. */ 
  1392. private static function validateCountryCode($value, $name) 
  1393. if (!is_string($value) 
  1394. || (strlen($value) !== 2 && strlen($value) !== 3) 
  1395. || (!in_array($value, static::$isoCountryCodes) && !isset(static::$isoCountryCodes[$value])) 
  1396. ) { 
  1397. throw new TException( 
  1398. sprintf('Field "%s" has invalid country code', $name) 
  1399. ); 
  1400.  
  1401. /** 
  1402. * Check variable max lenght 
  1403. * @param mixed $value variable to check 
  1404. * @param int $max max lenght 
  1405. * @param string $name field name 
  1406. * @throws TException 
  1407. */ 
  1408. private static function validateMaxLenght($value, $max, $name) 
  1409. if (strlen($value) > $max) { 
  1410. throw new TException( 
  1411. sprintf('Value of field "%s" is too long. Max %d characters', $name, $max) 
  1412. ); 
  1413.  
  1414. /** 
  1415. * Check variable min length 
  1416. * @param mixed $value variable to check 
  1417. * @param int $min min length 
  1418. * @param string $name field name 
  1419. * @throws TException 
  1420. */ 
  1421. private static function validateMinLength($value, $min, $name) 
  1422. if (strlen($value) < $min) { 
  1423. throw new TException( 
  1424. sprintf('Value of field "%s" is too short. Min %d characters', $name, $min) 
  1425. ); 
  1426.  
  1427. /** 
  1428. * RegExp filter for fields validation 
  1429. * @param string $value 
  1430. * @param array $fieldConfig 
  1431. * @return bool 
  1432. * @throws TException 
  1433. */ 
  1434. private static function filterValues($value, $fieldConfig) 
  1435. $filters = array( 
  1436. static::PHONE => '/[^0-9]\+ /',  
  1437. static::NUMBERS => '/[^0-9]/',  
  1438. 'letters' => '/[^A-Za-z]/',  
  1439. 'mixed' => '/[^A-Za-z0-9]/',  
  1440. 'date' => '/[^0-9 \-:]/',  
  1441. 'text' => '/[^\-\p{Latin}A-Za-z0-9 \., #_()\/\!]/u',  
  1442. 'name' => '/[^\-\p{Latin} ]/u',  
  1443. 'sign' => '/[^A-Za-z!\., _\-0-9]/' 
  1444. ); 
  1445.  
  1446. if (isset($fieldConfig[static::FILTER])) { 
  1447. $filterName = $fieldConfig[static::FILTER]; 
  1448. if (array_key_exists($filterName, $filters)) { 
  1449. if ((bool)preg_match($filters[$filterName], $value)) { 
  1450. return false; 
  1451. } else { 
  1452. if ((($filterName === 'mail') && !filter_var($value, FILTER_VALIDATE_EMAIL)) 
  1453. || 
  1454. (($filterName === 'url') && !((preg_match('/http:/', $value)) || preg_match('/https:/', $value))) 
  1455. || 
  1456. (($filterName === static::BOOLEAN) && !is_bool($value)) 
  1457. ) { 
  1458. return false; 
  1459. return true; 
  1460.  
  1461. /** 
  1462. * Validate merchant Id 
  1463. * @param int $merchantId 
  1464. * @throws TException 
  1465. */ 
  1466. public static function validateMerchantId($merchantId) 
  1467. if (!is_int($merchantId) || $merchantId <= 0) { 
  1468. throw new TException('Invalid merchantId'); 
  1469.  
  1470. /** 
  1471. * Validate merchant secret 
  1472. * @param string $merchantSecret 
  1473. * @throws TException 
  1474. */ 
  1475. public static function validateMerchantSecret($merchantSecret) 
  1476. if (!is_string($merchantSecret) || strlen($merchantSecret) === 0) { 
  1477. throw new TException('Invalid secret code'); 
  1478.  
  1479. /** 
  1480. * Validate Card Api Key 
  1481. * @param string $cardApiKey 
  1482. * @throws TException 
  1483. */ 
  1484. public static function validateCardApiKey($cardApiKey) 
  1485. if (!is_string($cardApiKey) || strlen($cardApiKey) === 0) { 
  1486. throw new TException('Invalid card API key'); 
  1487.  
  1488. /** 
  1489. * Validate Card Api Password 
  1490. * @param string $cardApiPassword 
  1491. * @throws TException 
  1492. */ 
  1493. public static function validateCardApiPassword($cardApiPassword) 
  1494. if (!is_string($cardApiPassword) || strlen($cardApiPassword) === 0) { 
  1495. throw new TException('Invalid card API pass'); 
  1496.  
  1497. /** 
  1498. * Validate card verification code 
  1499. * @param string $cardCode 
  1500. * @throws TException 
  1501. */ 
  1502. public static function validateCardCode($cardCode) 
  1503. if (!is_string($cardCode) || strlen($cardCode) === 0 || strlen($cardCode) > 40) { 
  1504. throw new TException('Invalid card code'); 
  1505.  
  1506. /** 
  1507. * Validate card hash algorithm 
  1508. * @param string $hashAlg 
  1509. * @throws TException 
  1510. */ 
  1511. public static function validateCardHashAlg($hashAlg) 
  1512. if (!in_array($hashAlg, array('sha1', 'sha256', 'sha512', 'ripemd160', 'ripemd320', 'md5'))) { 
  1513. throw new TException('Invalid hash algorithm'); 
  1514.  
  1515. /** 
  1516. * Validate card RSA key 
  1517. * @param string $keyRSA 
  1518. * @throws TException 
  1519. */ 
  1520. public static function validateCardRSAKey($keyRSA) 
  1521. if (!is_string($keyRSA) || strlen($keyRSA) === 0) { 
  1522. throw new TException('Invalid card RSA key'); 
  1523.  
  1524. /** 
  1525. * Validate card currency code 
  1526. * @param string $currency 
  1527. * @throws TException 
  1528. * @return int 
  1529. */ 
  1530. public static function validateCardCurrency($currency) 
  1531. if (strlen($currency) !== 3) { 
  1532. throw new TException('Currency is invalid.'); 
  1533.  
  1534. switch (gettype($currency)) { 
  1535. case 'string': 
  1536. if (in_array($currency, static::$isoCurrencyCodes)) { 
  1537. $currency = array_search($currency, static::$isoCurrencyCodes); 
  1538. } elseif (array_key_exists((int)$currency, static::$isoCurrencyCodes)) { 
  1539. $currency = (int)$currency; 
  1540. } else { 
  1541. throw new TException('Currency is not supported.'); 
  1542.  
  1543. break; 
  1544. case 'integer': 
  1545. if (!array_key_exists($currency, static::$isoCurrencyCodes)) { 
  1546. throw new TException('Currency is not supported.'); 
  1547. break; 
  1548. default: 
  1549. throw new TException('Currency variable type not supported.'); 
  1550. return $currency; 
  1551.  
  1552.  
  1553. /** 
  1554. * Validate card payment language 
  1555. * @param string $language 
  1556. * @throws TException 
  1557. * @return string 
  1558. */ 
  1559. public static function validateCardLanguage($language) 
  1560. if (!is_string($language)) { 
  1561. throw new TException('Invalid language value type.'); 
  1562. if (in_array($language, static::$cardPaymentLanguages)) { 
  1563. $language = array_search($language, static::$cardPaymentLanguages); 
  1564. } elseif (!array_key_exists($language, static::$cardPaymentLanguages)) { 
  1565. $language = 'en'; 
  1566. return $language; 
  1567.  
  1568.  
  1569. /** 
  1570. * Validate payment config 
  1571. * @param string $paymentType 
  1572. * @param array $config 
  1573. * @return array 
  1574. * @throws TException 
  1575. */ 
  1576. public static function validateConfig($paymentType, $config) 
  1577. if (!is_array($config)) { 
  1578. throw new TException('Config is not an array'); 
  1579. } else { 
  1580. if (count($config) === 0) { 
  1581. throw new TException('Config is empty'); 
  1582. $ready = array(); 
  1583. foreach ($config as $key => $value) { 
  1584. if (Validate::validateOne($paymentType, $key, $value) === true) { 
  1585. $ready[$key] = $value; 
  1586. Validate::isSetRequiredPaymentFields($paymentType, $ready); 
  1587.  
  1588. return $ready; 
  1589.  
  1590. /** 
  1591. * Check if all required fields isset in config 
  1592. * @param string $paymentType 
  1593. * @param array $config 
  1594. * @throws TException 
  1595. */ 
  1596. public static function isSetRequiredPaymentFields($paymentType, $config) 
  1597. $missing = array(); 
  1598.  
  1599. switch ($paymentType) { 
  1600. case static::PAYMENT_TYPE_BASIC: 
  1601. case static::PAYMENT_TYPE_EHAT: 
  1602. $requestFields = static::$panelPaymentRequestFields; 
  1603. break; 
  1604. case static::PAYMENT_TYPE_BASIC_API: 
  1605. $requestFields = static::$panelPaymentRequestFields; 
  1606. $requestFields[static::KANAL][static::REQUIRED] = true; 
  1607. break; 
  1608. case static::PAYMENT_TYPE_CARD: 
  1609. $requestFields = static::$cardPaymentRequestFields; 
  1610. break; 
  1611. case static::PAYMENT_TYPE_CARD_DIRECT: 
  1612. $requestFields = static::$cardDirectPaymentRequestFields; 
  1613. break; 
  1614. case static::PAYMENT_TYPE_SZKWAL: 
  1615. $requestFields = static::$szkwalRequestFields; 
  1616. break; 
  1617. case static::PAYMENT_TYPE_WHITE_LABEL: 
  1618. $requestFields = static::$whiteLabelRequestFields; 
  1619. break; 
  1620. default: 
  1621. throw new TException(sprintf(static::UNKNOWN_PAYMENT_TYPE_S, $paymentType)); 
  1622.  
  1623. foreach ($requestFields as $fieldName => $field) { 
  1624. if ($field[static::REQUIRED] === true && !isset($config[$fieldName])) { 
  1625. $missing[] = $fieldName; 
  1626. if (count($missing) !== 0) { 
  1627. throw new TException(sprintf('Missing mandatory fields: %s', implode(', ', $missing)));