BxBaseModPaymentModule.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup BasePayment Base classes for Payment like modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModPaymentModule extends BxBaseModGeneralModule
  12. {
  13. protected $_sLangsPrefix;
  14. function __construct($aModule)
  15. {
  16. parent::__construct($aModule);
  17. $this->_oConfig->init($this->_oDb);
  18. $this->_sLangsPrefix = $this->_oConfig->getPrefix('langs');
  19. }
  20. public function serviceGetSafeServices()
  21. {
  22. return array();
  23. }
  24. /**
  25. * @page service Service Calls
  26. * @section bx_base_payment Base Payment
  27. * @subsection bx_base_payment-integration Integration
  28. * @subsubsection bx_base_payment-update_dependent_modules update_dependent_modules
  29. *
  30. * @code bx_srv('bx_payment', 'update_dependent_modules', [...]); @endcode
  31. *
  32. * Get payments dependent modules and save them.
  33. *
  34. * @param $sModule (optional) string value with module name. All modules are used by default.
  35. * @param $bInstall (optional) boolean value determining whether the install or uninstall operation is performed.
  36. *
  37. * @see BxBaseModPaymentModule::serviceUpdateDependentModules
  38. */
  39. /**
  40. * @ref bx_base_payment-update_dependent_modules "update_dependent_modules"
  41. */
  42. public function serviceUpdateDependentModules($sModule = 'all', $bInstall = true)
  43. {
  44. $aModules = $sModule == 'all' ? $this->_oDb->getModulesBy(array('type' => 'modules'), false) : array($this->_oDb->getModuleByName($sModule, false));
  45. foreach($aModules as $aModule) {
  46. if(empty($aModule) || empty($aModule['name']))
  47. continue;
  48. $mixedData = $this->callGetPaymentData($aModule['name']);
  49. if($mixedData === false)
  50. continue;
  51. $sMethodName = $bInstall ? 'insertModule' : 'deleteModule';
  52. $this->_oDb->$sMethodName($mixedData);
  53. }
  54. }
  55. /**
  56. * @page service Service Calls
  57. * @section bx_base_payment Base Payment
  58. * @subsection bx_base_payment-other Other
  59. * @subsubsection bx_base_payment-generate_license generate_license
  60. *
  61. * @code bx_srv('bx_payment', 'generate_license'); @endcode
  62. *
  63. * Generate license.
  64. *
  65. * @return a string with license.
  66. *
  67. * @see BxBaseModPaymentModule::serviceGenerateLicense
  68. */
  69. /**
  70. * @ref bx_base_payment-generate_license "generate_license"
  71. */
  72. public function serviceGenerateLicense()
  73. {
  74. return $this->_oConfig->getLicense();
  75. }
  76. /**
  77. * @page service Service Calls
  78. * @section bx_base_payment Base Payment
  79. * @subsection bx_base_payment-other Other
  80. * @subsubsection bx_base_payment-get_currency_info get_currency_info
  81. *
  82. * @code bx_srv('bx_payment', 'get_currency_info', [...]); @endcode
  83. *
  84. * Get default currency info (sign and code).
  85. *
  86. * @return an array with currency info.
  87. *
  88. * @see BxBaseModPaymentModule::serviceGetCurrencyInfo
  89. */
  90. /**
  91. * @ref bx_base_payment-get_currency_info "get_currency_info"
  92. */
  93. public function serviceGetCurrencyInfo()
  94. {
  95. return array(
  96. 'sign' => $this->_oConfig->getDefaultCurrencySign(),
  97. 'code' => $this->_oConfig->getDefaultCurrencyCode()
  98. );
  99. }
  100. /**
  101. * @page service Service Calls
  102. * @section bx_base_payment Base Payment
  103. * @subsection bx_base_payment-other Other
  104. * @subsubsection bx_base_payment-get_option get_option
  105. *
  106. * @code bx_srv('bx_payment', 'get_option', [...]); @endcode
  107. *
  108. * Get value of payment provider configuration option.
  109. *
  110. * @param $sOption string value with option name.
  111. * @return string with option value.
  112. *
  113. * @see BxBaseModPaymentModule::serviceGetOption
  114. */
  115. /**
  116. * @ref bx_base_payment-get_option "get_option"
  117. */
  118. public function serviceGetOption($sOption)
  119. {
  120. $sMethod = 'get' . bx_gen_method_name($sOption);
  121. if(method_exists($this->_oConfig, $sMethod))
  122. return $this->_oConfig->$sMethod();
  123. return $this->_oDb->getParam($this->_oConfig->getPrefix('options') . $sOption);
  124. }
  125. /**
  126. * @page service Service Calls
  127. * @section bx_base_payment Base Payment
  128. * @subsection bx_base_payment-other Other
  129. * @subsubsection bx_base_payment-get_providers_cart get_providers_cart
  130. *
  131. * @code bx_srv('bx_payment', 'get_providers_cart', [...]); @endcode
  132. *
  133. * Get list of available payment providers which can process single time payments via Shopping Cart.
  134. *
  135. * @param $iVendorId integer value with vendor ID.
  136. * @return an array with special format.
  137. *
  138. * @see BxBaseModPaymentModule::serviceGetProvidersCart
  139. */
  140. /**
  141. * @ref bx_base_payment-get_providers_cart "get_providers_cart"
  142. */
  143. public function serviceGetProvidersCart($iVendorId)
  144. {
  145. $aVendorProviders = $this->_oDb->getVendorInfoProvidersSingle($iVendorId);
  146. $aResult = array();
  147. foreach($aVendorProviders as $aProvider) {
  148. $aProvider['caption_cart'] = _t($this->_sLangsPrefix . 'txt_cart_' . $aProvider['name']);
  149. $aResult[] = $aProvider;
  150. }
  151. return $aResult;
  152. }
  153. public function getVendorInfo($iUserId)
  154. {
  155. return array_merge($this->getProfileInfo($iUserId), array(
  156. 'currency_code' => $this->_oConfig->getDefaultCurrencyCode(),
  157. 'currency_sign' => $this->_oConfig->getDefaultCurrencySign()
  158. ));
  159. }
  160. public function getObjectJoin()
  161. {
  162. $sClassName = $this->_oConfig->getClassPrefix() . 'Join';
  163. if(!isset($GLOBALS['bxDolClasses'][$sClassName])) {
  164. bx_import('Join', $this->_aModule);
  165. $GLOBALS['bxDolClasses'][$sClassName] = new $sClassName();
  166. }
  167. return $GLOBALS['bxDolClasses'][$sClassName];
  168. }
  169. public function getObjectCart()
  170. {
  171. $sClassName = $this->_oConfig->getClassPrefix() . 'Cart';
  172. if(!isset($GLOBALS['bxDolClasses'][$sClassName])) {
  173. bx_import('Cart', $this->_aModule);
  174. $GLOBALS['bxDolClasses'][$sClassName] = new $sClassName();
  175. }
  176. return $GLOBALS['bxDolClasses'][$sClassName];
  177. }
  178. public function getObjectOrders()
  179. {
  180. $sClassName = $this->_oConfig->getClassPrefix() . 'Orders';
  181. if(!isset($GLOBALS['bxDolClasses'][$sClassName])) {
  182. bx_import('Orders', $this->_aModule);
  183. $GLOBALS['bxDolClasses'][$sClassName] = new $sClassName();
  184. }
  185. return $GLOBALS['bxDolClasses'][$sClassName];
  186. }
  187. public function getObjectDetails()
  188. {
  189. $sClassName = $this->_oConfig->getClassPrefix() . 'Details';
  190. if(!isset($GLOBALS['bxDolClasses'][$sClassName])) {
  191. bx_import('Details', $this->_aModule);
  192. $GLOBALS['bxDolClasses'][$sClassName] = new $sClassName();
  193. }
  194. return $GLOBALS['bxDolClasses'][$sClassName];
  195. }
  196. public function getObjectSubscriptions()
  197. {
  198. $sClassName = $this->_oConfig->getClassPrefix() . 'Subscriptions';
  199. if(!isset($GLOBALS['bxDolClasses'][$sClassName])) {
  200. bx_import('Subscriptions', $this->_aModule);
  201. $GLOBALS['bxDolClasses'][$sClassName] = new $sClassName();
  202. }
  203. return $GLOBALS['bxDolClasses'][$sClassName];
  204. }
  205. public function getObjectProvider($sProvider, $mixedVendorId = BX_PAYMENT_EMPTY_ID)
  206. {
  207. $aProvider = $this->_oDb->getProviders(array('type' => 'by_name', 'name' => $sProvider));
  208. if(empty($aProvider) || !is_array($aProvider) || empty($aProvider['class_name']))
  209. return false;
  210. if(is_numeric($mixedVendorId) && (int)$mixedVendorId != BX_PAYMENT_EMPTY_ID)
  211. $aProvider['options'] = $this->_oDb->getOptions((int)$mixedVendorId, $aProvider['id']);
  212. $sClassPath = !empty($aProvider['class_file']) ? BX_DIRECTORY_PATH_ROOT . $aProvider['class_file'] : $this->_oConfig->getClassPath() . $aProvider['class_name'] . '.php';
  213. if(!file_exists($sClassPath))
  214. return false;
  215. require_once($sClassPath);
  216. return new $aProvider['class_name']($aProvider);
  217. }
  218. public function callGetPaymentData($mixedModule)
  219. {
  220. $sMethod = 'get_payment_data';
  221. if(!BxDolRequest::serviceExists($mixedModule, $sMethod))
  222. return false;
  223. return BxDolService::call($mixedModule, $sMethod);
  224. }
  225. public function callGetCartItem($mixedModule, $aParams)
  226. {
  227. return BxDolService::call($mixedModule, 'get_cart_item', $aParams);
  228. }
  229. public function callGetCartItems($mixedModule, $aParams)
  230. {
  231. return BxDolService::call($mixedModule, 'get_cart_items', $aParams);
  232. }
  233. public function callRegisterCartItem($mixedModule, $aParams)
  234. {
  235. return BxDolService::call($mixedModule, 'register_cart_item', $aParams);
  236. }
  237. public function callReregisterCartItem($mixedModule, $aParams)
  238. {
  239. return BxDolService::call($mixedModule, 'reregister_cart_item', $aParams);
  240. }
  241. public function callRegisterSubscriptionItem($mixedModule, $aParams)
  242. {
  243. return BxDolService::call($mixedModule, 'register_subscription_item', $aParams);
  244. }
  245. public function callReregisterSubscriptionItem($mixedModule, $aParams)
  246. {
  247. return BxDolService::call($mixedModule, 'reregister_subscription_item', $aParams);
  248. }
  249. public function callUnregisterCartItem($mixedModule, $aParams)
  250. {
  251. return BxDolService::call($mixedModule, 'unregister_cart_item', $aParams);
  252. }
  253. public function callUnregisterSubscriptionItem($mixedModule, $aParams)
  254. {
  255. return BxDolService::call($mixedModule, 'unregister_subscription_item', $aParams);
  256. }
  257. public function callCancelSubscriptionItem($mixedModule, $aParams)
  258. {
  259. return BxDolService::call($mixedModule, 'cancel_subscription_item', $aParams);
  260. }
  261. }
  262. /** @} */