tpayPaymentWhiteLabel

Class PaymentWhiteLabel.

Defined (1)

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

/includes/lib/src/_class_tpay/paymentWhiteLabel.php  
  1. class PaymentWhiteLabel extends PaymentSzkwal 
  2. const APILOGIN = 'api_login'; 
  3. const APIPASS = 'api_password'; 
  4.  
  5. /** 
  6. * PaymentWhiteLabel class constructor 
  7. * @param string|bool $apiLogin API login 
  8. * @param string|bool $apiPass API password 
  9. * @param string|bool $apiHash API hash 
  10. * @param string|bool $partnerUniqueAddress API partner unique address 
  11. * @param string|bool $titleFormat API title format 
  12. */ 
  13. public function __construct($apiLogin = false, $apiPass = false, $apiHash = false,  
  14. $partnerUniqueAddress = false, $titleFormat = false) 
  15. parent::__construct($apiLogin, $apiPass, $apiHash, $partnerUniqueAddress, $titleFormat); 
  16.  
  17. /** 
  18. * Method used to add new order to the system 
  19. * @param string $clientName customer name; up to 96 alphanumeric characters 
  20. * @param string $clientEmail customer e-mail; up to 128 alphanumeric characters, must be a valid e-mail address 
  21. * @param string $clientPhone customer phone; up to 32 numeric characters 
  22. * @param float $amount field containing order amount, dot separated, e.g. 123.45 
  23. * @throws TException 
  24. * @return string 
  25. */ 
  26. public function registerOrder($clientName, $clientEmail, $clientPhone, $amount) 
  27. $title = $this->generateTitle(); 
  28.  
  29. $hash = sha1($clientName . $clientEmail . $clientPhone . $title . $amount . $this->apiHash); 
  30.  
  31. $postData = array( 
  32. static::APILOGIN => $this->apiLogin,  
  33. static::APIPASS => $this->apiPass,  
  34. 'cli_name' => $clientName,  
  35. 'cli_email' => $clientEmail,  
  36. 'cli_phone' => $clientPhone,  
  37. 'order' => $title,  
  38. 'amount' => $amount,  
  39. 'hash' => $hash,  
  40. ); 
  41.  
  42. Validate::validateConfig(Validate::PAYMENT_TYPE_WHITE_LABEL, $postData); 
  43.  
  44. Util::log('White label request data ', print_r($postData, true)); 
  45. $res = $this->request('RegisterOrder', $postData); 
  46. $this->checkError($res); 
  47.  
  48. Util::log('White label server resp', print_r($res, true)); 
  49. if (strpos($res, '<result>correct</result>') !== -1) { 
  50. return $title; 
  51. } else { 
  52. throw new TException('Invalid server response'); 
  53.  
  54. /** 
  55. * Method used to acquire report of incoming payments. 
  56. * Method returns list of all payments in the specified period. 
  57. * @param string $order 
  58. * @param int $startTime time in unix timestamp format 
  59. * @param int|bool $endTime time in unix timestamp format 
  60. * @param string $separator 
  61. * @return mixed 
  62. */ 
  63. public function paymentsReport($order, $startTime, $endTime = false, $separator = ';') 
  64. $postData = array( 
  65. static::APILOGIN => $this->apiLogin,  
  66. static::APIPASS => $this->apiPass,  
  67. 'order' => $order,  
  68. 'separator' => $separator,  
  69. ); 
  70. $postData['from'] = date('Y-m-d', (int)$startTime); 
  71. $endTime = ($endTime !== false) ? (int)$endTime : time(); 
  72. $postData['to'] = date('Y-m-d', $endTime); 
  73.  
  74. $postData['hash'] = sha1($order . $postData['from'] . $postData['to'] . $separator . $this->apiHash); 
  75.  
  76. return $this->request('PaymentsReport', $postData); 
  77.  
  78. /** 
  79. * Get information about all available bank channels. 
  80. * @throws TException 
  81. * @return mixed 
  82. */ 
  83. public function getBanksData() 
  84. $data = $this->getBanks(); 
  85. return array( 
  86. 'data' => $data,  
  87. 'html' => Util::parseTemplate('white_label/_tpl/bankList', $data),  
  88. ); 
  89.  
  90.  
  91. /** 
  92. * Bank transfer instruction for specific bank id 
  93. * @param int $bankID bank id 
  94. * @throws TException 
  95. * @return string[] 
  96. */ 
  97. public function getBankInstr($bankID) 
  98. $postData = array( 
  99. static::APILOGIN => $this->apiLogin,  
  100. static::APIPASS => $this->apiPass,  
  101. 'bank_id' => $bankID,  
  102. ); 
  103. $res = $this->request('GetBankInstr', $postData); 
  104.  
  105. preg_match_all('/<bank_instr>(.*)<\/bank_instr>/', $res, $matches); 
  106. if (isset($matches[1]) && isset($matches[1][0])) { 
  107. $instructions = json_decode($matches[1][0], true); 
  108. } else { 
  109. throw new TException('Invalid server response'); 
  110.  
  111. $data = array( 
  112. 'bank_id' => $bankID,  
  113. 'instructions' => $instructions,  
  114. ); 
  115.  
  116. return Util::parseTemplate('white_label/_tpl/bankInstruction', $data);