BxPaymentConfig.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup Payment Payment
  7. * @ingroup TridentModules
  8. *
  9. * @{
  10. */
  11. class BxPaymentConfig extends BxBaseModPaymentConfig
  12. {
  13. function __construct($aModule)
  14. {
  15. parent::__construct($aModule);
  16. $sBaseUrl = BX_DOL_URL_ROOT . $this->getBaseUri();
  17. $this->CNF = array_merge($this->CNF, array(
  18. 'URL_JOIN' => 'page.php?i=payment-join',
  19. 'URL_CARTS' => 'page.php?i=payment-carts',
  20. 'URL_CART' => 'page.php?i=payment-cart',
  21. 'URL_CART_CHECKOUT' => $sBaseUrl . 'initialize_checkout/' . BX_PAYMENT_TYPE_SINGLE . '/',
  22. 'URL_SUBSCRIBE' => $sBaseUrl . 'subscribe/',
  23. 'URL_SUBSCRIPTIONS' => 'page.php?i=payment-sbs-list',
  24. 'URL_HISTORY' => 'page.php?i=payment-history',
  25. 'URL_ORDERS' => 'page.php?i=payment-orders',
  26. 'URL_DETAILS' => 'page.php?i=payment-details',
  27. 'URL_RETURN' => 'page.php?i=payment-cart',
  28. 'URL_RETURN_DATA' => $sBaseUrl . 'finalize_checkout/',
  29. 'URL_NOTIFY' => $sBaseUrl . 'notify/',
  30. 'KEY_ARRAY_PRICE_SINGLE' => 'price_single',
  31. 'KEY_ARRAY_PRICE_RECURRING' => 'price_recurring',
  32. // some language keys
  33. 'T' => array(
  34. 'MSG_ITEM_ADDED' => '_bx_payment_msg_item_added',
  35. 'MSG_ITEM_DELETED' => '_bx_payment_msg_item_deleted',
  36. 'ERR_WRONG_DATA' => '_bx_payment_err_wrong_data',
  37. 'ERR_REQUIRED_LOGIN' => '_bx_payment_err_required_login',
  38. 'ERR_NOT_ACCEPT_PAYMENTS' => '_bx_payment_err_not_accept_payments',
  39. 'ERR_SELF_PURCHASE' => '_bx_payment_err_self_purchase',
  40. 'ERR_INACTIVE_VENDOR' => '_bx_payment_err_inactive_vendor',
  41. 'ERR_UNKNOWN_VENDOR' => '_bx_payment_err_unknown_vendor',
  42. 'BLOCK_TITLE_CART' => '_bx_payment_page_block_title_cart',
  43. 'POPUP_PROVIDERS_SELECT' => '_bx_payment_popup_title_crd_providers_select',
  44. 'TXT_CART_PROVIDER' => '_bx_payment_txt_cart_'
  45. )
  46. ));
  47. $this->_aHtmlIds = array(
  48. 'cart' => array(
  49. 'providers_select' => $this->_sName . '-cart-providers-select-',
  50. ),
  51. 'history' => array(
  52. 'order_history_view' => $this->_sName . '-order-view-history',
  53. ),
  54. 'subscription' => array(
  55. 'order_subscription_view' => $this->_sName . '-order-view-subscription',
  56. 'order_subscription_get_details' => $this->_sName . '-order-get-details-subscription',
  57. 'order_subscription_get_billing' => $this->_sName . '-order-get-billing-subscription',
  58. 'order_subscription_change_billing' => $this->_sName . '-order-change-billing-subscription',
  59. 'form_subscription_change_billing' => $this->_sName . '-form-change-billing-subscription',
  60. ),
  61. 'pending' => array(
  62. 'order_pending_view' => $this->_sName . '-order-view-pending',
  63. 'order_pending_process' => $this->_sName . '-order-process',
  64. ),
  65. 'processed' => array(
  66. 'order_processed_view' => $this->_sName . '-order-view-processed',
  67. 'order_processed_add' => $this->_sName . '-order-add',
  68. 'order_processed_client_id' => $this->_sName . '-oa-client-id',
  69. 'order_processed_client' => $this->_sName . '-oa-client',
  70. 'order_processed_items' => $this->_sName . '-oa-items',
  71. ),
  72. );
  73. $this->_aPerPage = array(
  74. 'orders' => 10,
  75. 'history' => 10
  76. );
  77. $this->_aHandlers = array();
  78. $this->_aJsClasses = array(
  79. 'cart' => 'BxPaymentCart',
  80. 'history' => 'BxPaymentOrders',
  81. 'subscription' => 'BxPaymentSubscriptions',
  82. 'pending' => 'BxPaymentOrders',
  83. 'processed' => 'BxPaymentOrders',
  84. 'stripe' => 'BxPaymentProviderStripe'
  85. );
  86. $this->_aJsObjects = array(
  87. 'cart' => 'oPaymentCart',
  88. 'history' => 'oPaymentOrders',
  89. 'subscription' => 'oBxPaymentSubscriptions',
  90. 'pending' => 'oPaymentOrders',
  91. 'processed' => 'oPaymentOrders',
  92. 'stripe' => 'oPaymentProviderStripe'
  93. );
  94. }
  95. public function getLicense()
  96. {
  97. list($fMilliSec, $iSec) = explode(' ', microtime());
  98. $fSeed = (float)$iSec + ((float)$fMilliSec * 100000);
  99. srand($fSeed);
  100. $sResult = '';
  101. for($i=0; $i < 16; ++$i) {
  102. switch(rand(1,2)) {
  103. case 1:
  104. $c = chr(rand(ord('A'),ord('Z')));
  105. break;
  106. case 2:
  107. $c = chr(rand(ord('0'),ord('9')));
  108. break;
  109. }
  110. $sResult .= $c;
  111. }
  112. return $sResult;
  113. }
  114. public function getPrice($sType, $aItem)
  115. {
  116. $fPrice = 0;
  117. switch($sType) {
  118. case BX_PAYMENT_TYPE_SINGLE:
  119. $fPrice = $aItem[$this->getKey('KEY_ARRAY_PRICE_SINGLE')];
  120. break;
  121. case BX_PAYMENT_TYPE_RECURRING:
  122. $fPrice = $aItem[$this->getKey('KEY_ARRAY_PRICE_RECURRING')];
  123. break;
  124. }
  125. return (float)$fPrice;
  126. }
  127. public function getModuleId($mixedId)
  128. {
  129. if(is_numeric($mixedId))
  130. return (int)$mixedId;
  131. if(is_string($mixedId)) {
  132. $aInfo = $this->_oDb->getModuleByName($mixedId);
  133. if(!is_array($aInfo) || empty($aInfo['id']))
  134. $aInfo = $this->_oDb->getModuleByUri($mixedId);
  135. if(is_array($aInfo) && !empty($aInfo['id']))
  136. return (int)$aInfo['id'];
  137. }
  138. return 0;
  139. }
  140. public function descriptorA2S($a)
  141. {
  142. return implode($this->getDivider('DIVIDER_DESCRIPTOR'), $a);
  143. }
  144. public function descriptorS2A($s)
  145. {
  146. return explode($this->getDivider('DIVIDER_DESCRIPTOR'), $s);
  147. }
  148. /**
  149. * Conver items to array with necessary structure.
  150. *
  151. * @param string/array $mixed - string with cart items divided with (:) or an array of cart items.
  152. * @return array with items.
  153. */
  154. public function descriptorsM2A($mixed)
  155. {
  156. $aResult = array();
  157. if(is_string($mixed))
  158. $aItems = explode($this->getDivider('DIVIDER_DESCRIPTORS'), $mixed);
  159. else if(is_array($mixed))
  160. $aItems = $mixed;
  161. else
  162. $aItems = array();
  163. foreach($aItems as $sItem) {
  164. $aItem = $this->descriptorS2A($sItem);
  165. $aResult[] = array('vendor_id' => $aItem[0], 'module_id' => $aItem[1], 'item_id' => $aItem[2], 'item_count' => $aItem[3]);
  166. }
  167. return $aResult;
  168. }
  169. public function http2https($s)
  170. {
  171. if(strncmp($s, 'https://', 8) === 0)
  172. return $s;
  173. return 'https://' . bx_ltrim_str($s, 'http://');
  174. }
  175. }
  176. /** @} */