tpayPaymentDAC

Class PaymentDAC.

Defined (1)

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

/includes/lib/src/_class_tpay/paymentDac.php  
  1. class PaymentDAC 
  2. /** 
  3. * Merchant id 
  4. * @var int 
  5. */ 
  6. private $merchantId = '[MERCHANT_ID]'; 
  7.  
  8. /** 
  9. * Merchant secret 
  10. * @var string 
  11. */ 
  12. private $merchantSecret = '[MERCHANT_SECRET]'; 
  13.  
  14. /** 
  15. * Transaction API key 
  16. * @var string 
  17. */ 
  18. private $apiKey = '[TRANSACTION_API_KEY]'; 
  19.  
  20. /** 
  21. * Transaction API password 
  22. * @var string 
  23. */ 
  24. private $apiPass = '[TRANSACTION_API_PASS]'; 
  25.  
  26. /** 
  27. * DAC payment chanel 
  28. * @var int 
  29. */ 
  30. private $channelDAC = 29; 
  31.  
  32. /** 
  33. * PaymentBasic class constructor 
  34. * @param string|bool $merchantId merchant id 
  35. * @param string|bool $merchantSecret merchant secret 
  36. * @param string|bool $apiKey transaction API key 
  37. * @param string|bool $apiPass transaction API password 
  38. */ 
  39. public function __construct($merchantId = false, $merchantSecret = false, $apiKey = false, $apiPass = false) 
  40. if($merchantId !== false) { 
  41. $this->merchantId = $merchantId; 
  42. if($merchantSecret !== false) { 
  43. $this->merchantSecret = $merchantSecret; 
  44. if($apiKey !== false) { 
  45. $this->apiKey = $apiKey; 
  46. if($apiPass !== false) { 
  47. $this->apiPass = $apiPass; 
  48.  
  49. require_once(dirname(__FILE__) . '/util.php'); 
  50.  
  51. Util::loadClass('validate'); 
  52. Util::loadClass('exception'); 
  53. Util::loadClass('lang'); 
  54. Util::loadClass('transactionApi'); 
  55. Util::checkVersionPHP(); 
  56.  
  57. Validate::validateMerchantId($this->merchantId); 
  58. Validate::validateMerchantSecret($this->merchantSecret); 
  59.  
  60. /** 
  61. * Register new DAC transaction and create HTML block with information 
  62. * about transaction and merchant data 
  63. * @param array $config transaction config 
  64. * @param string $staticFilesURL static files url 
  65. * @param string $merchantData merchant data 
  66. * @return array 
  67. */ 
  68. public function registerTransaction($config, $staticFilesURL = '', $merchantData = '') 
  69. $api = new TransactionAPI($this->apiKey, $this->apiPass, $this->merchantId, $this->merchantSecret); 
  70.  
  71. $config['kanal'] = $this->channelDAC; 
  72. $transactionData = $api->create($config); 
  73. $transactionData['crc'] = $config['crc']; 
  74.  
  75. return array( 
  76. 'html' => $this->getConfirmationBlock($transactionData, $staticFilesURL, $merchantData),  
  77. 'data' => $transactionData 
  78. ); 
  79.  
  80. /** 
  81. * Get HTML string with confirmation block 
  82. * @param array $transactionData registered transaction data from tpay server 
  83. * @param string $staticFilesURL browser url to library 
  84. * @param string $merchantData merchant data to 
  85. * @return string 
  86. */ 
  87. private function getConfirmationBlock($transactionData, $staticFilesURL, $merchantData) 
  88. $data = array( 
  89. 'static_files_url' => $staticFilesURL,  
  90. 'merchant_data' => $merchantData,  
  91. 'transaction' => $transactionData 
  92. ); 
  93.  
  94. return Util::parseTemplate('dac/_tpl/confirmation', $data);