BxBaseModPaymentModule.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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-get_currency_info get_currency_info
  56. *
  57. * @code bx_srv('bx_payment', 'get_currency_info', [...]); @endcode
  58. *
  59. * Get default currency info (sign and code).
  60. *
  61. * @return an array with currency info.
  62. *
  63. * @see BxBaseModPaymentModule::serviceGetCurrencyInfo
  64. */
  65. /**
  66. * @ref bx_base_payment-get_currency_info "get_currency_info"
  67. */
  68. public function serviceGetCurrencyInfo()
  69. {
  70. return array(
  71. 'sign' => $this->_oConfig->getDefaultCurrencySign(),
  72. 'code' => $this->_oConfig->getDefaultCurrencyCode()
  73. );
  74. }
  75. /**
  76. * @page service Service Calls
  77. * @section bx_base_payment Base Payment
  78. * @subsection bx_base_payment-other Other
  79. * @subsubsection bx_base_payment-get_option get_option
  80. *
  81. * @code bx_srv('bx_payment', 'get_option', [...]); @endcode
  82. *
  83. * Get value of payment provider configuration option.
  84. *
  85. * @param $sOption string value with option name.
  86. * @return string with option value.
  87. *
  88. * @see BxBaseModPaymentModule::serviceGetOption
  89. */
  90. /**
  91. * @ref bx_base_payment-get_option "get_option"
  92. */
  93. public function serviceGetOption($sOption)
  94. {
  95. $sMethod = 'get' . bx_gen_method_name($sOption);
  96. if(method_exists($this->_oConfig, $sMethod))
  97. return $this->_oConfig->$sMethod();
  98. return $this->_oDb->getParam($this->_oConfig->getPrefix('options') . $sOption);
  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_providers_cart get_providers_cart
  105. *
  106. * @code bx_srv('bx_payment', 'get_providers_cart', [...]); @endcode
  107. *
  108. * Get list of available payment providers which can process single time payments via Shopping Cart.
  109. *
  110. * @param $iVendorId integer value with vendor ID.
  111. * @return an array with special format.
  112. *
  113. * @see BxBaseModPaymentModule::serviceGetProvidersCart
  114. */
  115. /**
  116. * @ref bx_base_payment-get_providers_cart "get_providers_cart"
  117. */
  118. public function serviceGetProvidersCart($iVendorId)
  119. {
  120. $aVendorProviders = $this->_oDb->getVendorInfoProvidersSingle($iVendorId);
  121. $aResult = array();
  122. foreach($aVendorProviders as $aProvider) {
  123. $aProvider['caption_cart'] = _t($this->_sLangsPrefix . 'txt_cart_' . $aProvider['name']);
  124. $aResult[] = $aProvider;
  125. }
  126. return $aResult;
  127. }
  128. public function getVendorInfo($iUserId)
  129. {
  130. return array_merge($this->getProfileInfo($iUserId), array(
  131. 'currency_code' => $this->_oConfig->getDefaultCurrencyCode(),
  132. 'currency_sign' => $this->_oConfig->getDefaultCurrencySign()
  133. ));
  134. }
  135. public function getObjectJoin()
  136. {
  137. $sClassName = $this->_oConfig->getClassPrefix() . 'Join';
  138. if(!isset($GLOBALS['bxDolClasses'][$sClassName])) {
  139. bx_import('Join', $this->_aModule);
  140. $GLOBALS['bxDolClasses'][$sClassName] = new $sClassName();
  141. }
  142. return $GLOBALS['bxDolClasses'][$sClassName];
  143. }
  144. public function getObjectCart()
  145. {
  146. $sClassName = $this->_oConfig->getClassPrefix() . 'Cart';
  147. if(!isset($GLOBALS['bxDolClasses'][$sClassName])) {
  148. bx_import('Cart', $this->_aModule);
  149. $GLOBALS['bxDolClasses'][$sClassName] = new $sClassName();
  150. }
  151. return $GLOBALS['bxDolClasses'][$sClassName];
  152. }
  153. public function getObjectOrders()
  154. {
  155. $sClassName = $this->_oConfig->getClassPrefix() . 'Orders';
  156. if(!isset($GLOBALS['bxDolClasses'][$sClassName])) {
  157. bx_import('Orders', $this->_aModule);
  158. $GLOBALS['bxDolClasses'][$sClassName] = new $sClassName();
  159. }
  160. return $GLOBALS['bxDolClasses'][$sClassName];
  161. }
  162. public function getObjectDetails()
  163. {
  164. $sClassName = $this->_oConfig->getClassPrefix() . 'Details';
  165. if(!isset($GLOBALS['bxDolClasses'][$sClassName])) {
  166. bx_import('Details', $this->_aModule);
  167. $GLOBALS['bxDolClasses'][$sClassName] = new $sClassName();
  168. }
  169. return $GLOBALS['bxDolClasses'][$sClassName];
  170. }
  171. public function getObjectSubscriptions()
  172. {
  173. $sClassName = $this->_oConfig->getClassPrefix() . 'Subscriptions';
  174. if(!isset($GLOBALS['bxDolClasses'][$sClassName])) {
  175. bx_import('Subscriptions', $this->_aModule);
  176. $GLOBALS['bxDolClasses'][$sClassName] = new $sClassName();
  177. }
  178. return $GLOBALS['bxDolClasses'][$sClassName];
  179. }
  180. public function getObjectProvider($sProvider, $mixedVendorId = BX_PAYMENT_EMPTY_ID)
  181. {
  182. $aProvider = $this->_oDb->getProviders(array('type' => 'by_name', 'name' => $sProvider));
  183. if(empty($aProvider) || !is_array($aProvider) || empty($aProvider['class_name']))
  184. return false;
  185. if(is_numeric($mixedVendorId) && (int)$mixedVendorId != BX_PAYMENT_EMPTY_ID)
  186. $aProvider['options'] = $this->_oDb->getOptions((int)$mixedVendorId, $aProvider['id']);
  187. $sClassPath = !empty($aProvider['class_file']) ? BX_DIRECTORY_PATH_ROOT . $aProvider['class_file'] : $this->_oConfig->getClassPath() . $aProvider['class_name'] . '.php';
  188. if(!file_exists($sClassPath))
  189. return false;
  190. require_once($sClassPath);
  191. return new $aProvider['class_name']($aProvider);
  192. }
  193. public function callGetPaymentData($mixedModule)
  194. {
  195. $sMethod = 'get_payment_data';
  196. if(!BxDolRequest::serviceExists($mixedModule, $sMethod))
  197. return false;
  198. return BxDolService::call($mixedModule, $sMethod);
  199. }
  200. public function callGetCartItem($mixedModule, $aParams)
  201. {
  202. return BxDolService::call($mixedModule, 'get_cart_item', $aParams);
  203. }
  204. public function callGetCartItems($mixedModule, $aParams)
  205. {
  206. return BxDolService::call($mixedModule, 'get_cart_items', $aParams);
  207. }
  208. public function callRegisterCartItem($mixedModule, $aParams)
  209. {
  210. return BxDolService::call($mixedModule, 'register_cart_item', $aParams);
  211. }
  212. public function callReregisterCartItem($mixedModule, $aParams)
  213. {
  214. return BxDolService::call($mixedModule, 'reregister_cart_item', $aParams);
  215. }
  216. public function callRegisterSubscriptionItem($mixedModule, $aParams)
  217. {
  218. return BxDolService::call($mixedModule, 'register_subscription_item', $aParams);
  219. }
  220. public function callReregisterSubscriptionItem($mixedModule, $aParams)
  221. {
  222. return BxDolService::call($mixedModule, 'reregister_subscription_item', $aParams);
  223. }
  224. public function callUnregisterCartItem($mixedModule, $aParams)
  225. {
  226. return BxDolService::call($mixedModule, 'unregister_cart_item', $aParams);
  227. }
  228. public function callUnregisterSubscriptionItem($mixedModule, $aParams)
  229. {
  230. return BxDolService::call($mixedModule, 'unregister_subscription_item', $aParams);
  231. }
  232. public function callCancelSubscriptionItem($mixedModule, $aParams)
  233. {
  234. return BxDolService::call($mixedModule, 'cancel_subscription_item', $aParams);
  235. }
  236. }
  237. /** @} */