BxPaymentSubscriptions.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 Payment Payment
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxPaymentSubscriptions extends BxBaseModPaymentSubscriptions
  12. {
  13. function __construct()
  14. {
  15. $this->MODULE = 'bx_payment';
  16. parent::__construct();
  17. }
  18. /*
  19. * Service methods
  20. */
  21. public function serviceGetBlockList()
  22. {
  23. return $this->_getBlock('list');
  24. }
  25. public function serviceGetBlockHistory()
  26. {
  27. return $this->_getBlock('history');
  28. }
  29. public function serviceSubscribe($iSellerId, $sSellerProvider, $iModuleId, $iItemId, $iItemCount)
  30. {
  31. $CNF = &$this->_oModule->_oConfig->CNF;
  32. $iClientId = $this->_oModule->getProfileId();
  33. $mixedResult = $this->_checkData($iClientId, $iSellerId, $iModuleId, $iItemId, $iItemCount);
  34. if($mixedResult !== true)
  35. return $mixedResult;
  36. $aSellerProviders = $this->_oModule->_oDb->getVendorInfoProvidersRecurring($iSellerId);
  37. if(empty($aSellerProviders))
  38. return array('code' => 5, 'message' => _t($CNF['T']['ERR_NOT_ACCEPT_PAYMENTS']));
  39. $aCartItem = array($iSellerId, $iModuleId, $iItemId, $iItemCount);
  40. $sCartItem = $this->_oModule->_oConfig->descriptorA2S($aCartItem);
  41. if(empty($sSellerProvider)) {
  42. $sId = $this->_oModule->_oConfig->getHtmlIds('cart', 'providers_select') . BX_PAYMENT_TYPE_RECURRING;
  43. $sTitle = _t($CNF['T']['POPUP_PROVIDERS_SELECT']);
  44. return array('popup' => BxTemplStudioFunctions::getInstance()->popupBox($sId, $sTitle, $this->_oModule->_oTemplate->displayProvidersSelector($aCartItem, $aSellerProviders)));
  45. }
  46. $aProvider = $aSellerProviders[$sSellerProvider];
  47. $mixedResult = $this->_oModule->serviceInitializeCheckout(BX_PAYMENT_TYPE_RECURRING, $iSellerId, $aProvider['name'], array($sCartItem));
  48. if(is_string($mixedResult))
  49. return array('code' => 6, 'message' => _t($mixedResult));
  50. return $mixedResult;
  51. }
  52. protected function _getBlock($sType)
  53. {
  54. $CNF = &$this->_oModule->_oConfig->CNF;
  55. $sMethod = 'displayBlockSbs' . bx_gen_method_name($sType);
  56. if(!method_exists($this->_oModule->_oTemplate, $sMethod))
  57. return MsgBox(_t('_Empty'));
  58. $iUserId = $this->_oModule->getProfileId();
  59. if(empty($iUserId))
  60. return MsgBox(_t($CNF['T']['ERR_REQUIRED_LOGIN']));
  61. $this->_oModule->setSiteSubmenu('menu_sbs_submenu', 'sbs-' . $sType);
  62. return array(
  63. 'content' => $this->_oModule->_oTemplate->$sMethod($iUserId)
  64. );
  65. }
  66. }
  67. /** @} */