1
0

BxBaseModPaymentModule.php 9.5 KB

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