BxBaseModPaymentModule.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 BasePayment Base classes for Payment like modules
  7. * @ingroup TridentModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModPaymentModule extends BxDolModule
  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 serviceUpdateDependentModules($sModule = 'all', $bInstall = true)
  21. {
  22. $aModules = $sModule == 'all' ? $this->_oDb->getModulesBy(array('type' => 'modules')) : array($this->_oDb->getModuleByName($sModule));
  23. foreach($aModules as $aModule) {
  24. $mixedData = $this->callGetPaymentData($aModule['name']);
  25. if($mixedData === false)
  26. continue;
  27. $sMethodName = $bInstall ? 'insertModule' : 'deleteModule';
  28. $this->_oDb->$sMethodName($mixedData);
  29. }
  30. }
  31. public function serviceGetCurrencyInfo()
  32. {
  33. return array(
  34. 'sign' => $this->_oConfig->getDefaultCurrencySign(),
  35. 'code' => $this->_oConfig->getDefaultCurrencyCode()
  36. );
  37. }
  38. public function serviceGetOption($sOption)
  39. {
  40. $sMethod = 'get' . bx_gen_method_name($sOption);
  41. if(method_exists($this->_oConfig, $sMethod))
  42. return $this->_oConfig->$sMethod();
  43. return $this->_oDb->getParam($this->_oConfig->getPrefix('options') . $sOption);
  44. }
  45. public function serviceGetProvidersCart($iVendorId)
  46. {
  47. $aVendorProviders = $this->_oDb->getVendorInfoProvidersCart($iVendorId);
  48. $aResult = array();
  49. foreach($aVendorProviders as $aProvider) {
  50. $aProvider['caption_cart'] = _t($this->_sLangsPrefix . 'txt_cart_' . $aProvider['name']);
  51. $aResult[] = $aProvider;
  52. }
  53. return $aResult;
  54. }
  55. public function getVendorInfo($iUserId)
  56. {
  57. return array_merge($this->getProfileInfo($iUserId), array(
  58. 'currency_code' => $this->_oConfig->getDefaultCurrencyCode(),
  59. 'currency_sign' => $this->_oConfig->getDefaultCurrencySign()
  60. ));
  61. }
  62. public function getProfileId()
  63. {
  64. return bx_get_logged_profile_id();
  65. }
  66. public function getProfileInfo($iUserId = 0)
  67. {
  68. $oProfile = $this->getObjectUser($iUserId);
  69. $oAccount = $oProfile->getAccountObject();
  70. return array(
  71. 'id' => $iUserId,
  72. 'name' => $oProfile->getDisplayName(),
  73. 'email' => $oAccount->getEmail(),
  74. 'link' => $oProfile->getUrl(),
  75. 'icon' => $oProfile->getIcon(),
  76. 'unit' => $oProfile->getUnit(),
  77. 'active' => $oProfile->isActive(),
  78. );
  79. }
  80. public function getObjectUser($iUserId = 0)
  81. {
  82. bx_import('BxDolProfile');
  83. $oProfile = BxDolProfile::getInstance($iUserId);
  84. if (!$oProfile) {
  85. bx_import('BxDolProfileUndefined');
  86. $oProfile = BxDolProfileUndefined::getInstance();
  87. }
  88. return $oProfile;
  89. }
  90. public function getObjectJoin()
  91. {
  92. $sClassName = $this->_oConfig->getClassPrefix() . 'Join';
  93. if(!isset($GLOBALS['bxDolClasses'][$sClassName])) {
  94. bx_import('Join', $this->_aModule);
  95. $GLOBALS['bxDolClasses'][$sClassName] = new $sClassName();
  96. }
  97. return $GLOBALS['bxDolClasses'][$sClassName];
  98. }
  99. public function getObjectCart()
  100. {
  101. $sClassName = $this->_oConfig->getClassPrefix() . 'Cart';
  102. if(!isset($GLOBALS['bxDolClasses'][$sClassName])) {
  103. bx_import('Cart', $this->_aModule);
  104. $GLOBALS['bxDolClasses'][$sClassName] = new $sClassName();
  105. }
  106. return $GLOBALS['bxDolClasses'][$sClassName];
  107. }
  108. public function getObjectOrders()
  109. {
  110. $sClassName = $this->_oConfig->getClassPrefix() . 'Orders';
  111. if(!isset($GLOBALS['bxDolClasses'][$sClassName])) {
  112. bx_import('Orders', $this->_aModule);
  113. $GLOBALS['bxDolClasses'][$sClassName] = new $sClassName();
  114. }
  115. return $GLOBALS['bxDolClasses'][$sClassName];
  116. }
  117. public function getObjectDetails()
  118. {
  119. $sClassName = $this->_oConfig->getClassPrefix() . 'Details';
  120. if(!isset($GLOBALS['bxDolClasses'][$sClassName])) {
  121. bx_import('Details', $this->_aModule);
  122. $GLOBALS['bxDolClasses'][$sClassName] = new $sClassName();
  123. }
  124. return $GLOBALS['bxDolClasses'][$sClassName];
  125. }
  126. public function getObjectProvider($sProvider, $mixedVendorId = BX_PAYMENT_EMPTY_ID)
  127. {
  128. $aProvider = $this->_oDb->getProviders(array('type' => 'by_name', 'name' => $sProvider));
  129. if(empty($aProvider) || !is_array($aProvider) || empty($aProvider['class_name']))
  130. return false;
  131. if(is_numeric($mixedVendorId) && (int)$mixedVendorId != BX_PAYMENT_EMPTY_ID)
  132. $aProvider['options'] = $this->_oDb->getOptions((int)$mixedVendorId, $aProvider['id']);
  133. $sClassPath = !empty($aProvider['class_file']) ? BX_DIRECTORY_PATH_ROOT . $aProvider['class_file'] : $this->_oConfig->getClassPath() . $aProvider['class_name'] . '.php';
  134. if(!file_exists($sClassPath))
  135. return false;
  136. require_once($sClassPath);
  137. return new $aProvider['class_name']($aProvider);
  138. }
  139. public function callGetPaymentData($mixedModule)
  140. {
  141. $sMethod = 'get_payment_data';
  142. if(!BxDolRequest::serviceExists($mixedModule, $sMethod))
  143. return false;
  144. return BxDolService::call($mixedModule, $sMethod);
  145. }
  146. public function callGetCartItem($mixedModule, $aParams)
  147. {
  148. return BxDolService::call($mixedModule, 'get_cart_item', $aParams);
  149. }
  150. public function callGetCartItems($mixedModule, $aParams)
  151. {
  152. return BxDolService::call($mixedModule, 'get_cart_items', $aParams);
  153. }
  154. public function callRegisterCartItem($mixedModule, $aParams)
  155. {
  156. return BxDolService::call($mixedModule, 'register_cart_item', $aParams);
  157. }
  158. public function callRegisterSubscriptionItem($mixedModule, $aParams)
  159. {
  160. return BxDolService::call($mixedModule, 'register_subscription_item', $aParams);
  161. }
  162. public function callUnregisterCartItem($mixedModule, $aParams)
  163. {
  164. return BxDolService::call($mixedModule, 'unregister_cart_item', $aParams);
  165. }
  166. public function callUnregisterSubscriptionItem($mixedModule, $aParams)
  167. {
  168. return BxDolService::call($mixedModule, 'unregister_subscription_item', $aParams);
  169. }
  170. public function callCancelSubscriptionItem($mixedModule, $aParams)
  171. {
  172. return BxDolService::call($mixedModule, 'cancel_subscription_item', $aParams);
  173. }
  174. }
  175. /** @} */