BxBaseModPaymentSubscriptions.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 BxBaseModPaymentSubscriptions extends BxDol
  12. {
  13. protected $MODULE;
  14. protected $_oModule;
  15. protected $_bSingleSeller;
  16. protected $_iSingleSeller;
  17. function __construct()
  18. {
  19. parent::__construct();
  20. $this->_oModule = BxDolModule::getInstance($this->MODULE);
  21. $this->_bSingleSeller = $this->_oModule->_oConfig->isSingleSeller();
  22. $this->_iSingleSeller = 0;
  23. if($this->_bSingleSeller)
  24. $this->_iSingleSeller = $this->_oModule->_oConfig->getSiteAdmin();
  25. }
  26. /**
  27. * @page service Service Calls
  28. * @section bx_base_payment Base Payment
  29. * @subsection bx_base_payment-integration Integration
  30. * @subsubsection bx_base_payment-get_subscriptions_url get_subscriptions_url
  31. *
  32. * @code bx_srv('bx_payment', 'get_subscriptions_url', [...], 'Subscriptions'); @endcode
  33. *
  34. * Get subscriptions page URL.
  35. *
  36. * @param $iVendor (optional) integer value with vendor ID.
  37. * @return string with URL.
  38. *
  39. * @see BxBaseModPaymentSubscriptions::serviceGetSubscriptionsUrl
  40. */
  41. /**
  42. * @ref bx_base_payment-get_subscriptions_url "get_subscriptions_url"
  43. */
  44. public function serviceGetSubscriptionsUrl($iVendor = 0)
  45. {
  46. if(!$this->_oModule->isLogged())
  47. return '';
  48. if($iVendor == 0)
  49. return $this->_oModule->_oConfig->getUrl('URL_SUBSCRIPTIONS');
  50. return bx_append_url_params($this->_oModule->_oConfig->getUrl('URL_SUBSCRIPTIONS'), array('seller_id' => $iVendor));
  51. }
  52. /**
  53. * @page service Service Calls
  54. * @section bx_base_payment Base Payment
  55. * @subsection bx_base_payment-integration Integration
  56. * @subsubsection bx_base_payment-get_subscribe_url get_subscribe_url
  57. *
  58. * @code bx_srv('bx_payment', 'get_subscribe_url', [...], 'Subscriptions'); @endcode
  59. *
  60. * Get action URL to initialize subscription.
  61. *
  62. * @param $iVendor integer value with vendor ID.
  63. * @param $sVendorProvider string value with a name of payment provider to be used for processing.
  64. * @param $mixedModuleId mixed value (ID, Name or URI) determining a module from which the action was initiated.
  65. * @param $iItemId integer value with item ID.
  66. * @param $iItemCount (optional) integer value with a number of items for purchasing. It's equal to 1 in case of subscription.
  67. * @return string with URL.
  68. *
  69. * @see BxBaseModPaymentSubscriptions::serviceGetSubscribeUrl
  70. */
  71. /**
  72. * @ref bx_base_payment-get_subscribe_url "get_subscribe_url"
  73. */
  74. public function serviceGetSubscribeUrl($iVendorId, $sVendorProvider, $mixedModuleId, $iItemId, $iItemCount = 1)
  75. {
  76. if(!$this->_oModule->isLogged())
  77. return '';
  78. if($this->_bSingleSeller)
  79. $iVendorId = $this->_iSingleSeller;
  80. return bx_append_url_params($this->_oModule->_oConfig->getUrl('URL_SUBSCRIBE'), array(
  81. 'seller_id' => $iVendorId,
  82. 'seller_provider' => $sVendorProvider,
  83. 'module_id' => $mixedModuleId,
  84. 'item_id' => $iItemId,
  85. 'item_count' => $iItemCount
  86. ));
  87. }
  88. /**
  89. * @page service Service Calls
  90. * @section bx_base_payment Base Payment
  91. * @subsection bx_base_payment-integration Integration
  92. * @subsubsection bx_base_payment-get_subscribe_js get_subscribe_js
  93. *
  94. * @code bx_srv('bx_payment', 'get_subscribe_js', [...], 'Subscriptions'); @endcode
  95. *
  96. * Get JavaScript code to use in OnClick attributes of HTML elements.
  97. *
  98. * @param $iVendor integer value with vendor ID.
  99. * @param $sVendorProvider string value with a name of payment provider to be used for processing.
  100. * @param $mixedModuleId mixed value (ID, Name or URI) determining a module from which the action was initiated.
  101. * @param $iItemId integer value with item ID.
  102. * @param $iItemCount (optional) integer value with a number of items for purchasing. It's equal to 1 in case of subscription.
  103. * @param $sRedirect (optional) string value with redirect URL, if it's needed.
  104. * @return string with JavaScript code.
  105. *
  106. * @see BxBaseModPaymentSubscriptions::serviceGetSubscribeJs
  107. */
  108. /**
  109. * @ref bx_base_payment-get_subscribe_js "get_subscribe_js"
  110. */
  111. public function serviceGetSubscribeJs($iVendorId, $sVendorProvider, $mixedModuleId, $iItemId, $iItemCount = 1, $sRedirect = '', $aCustom = array())
  112. {
  113. $iModuleId = $this->_oModule->_oConfig->getModuleId($mixedModuleId);
  114. if(empty($iModuleId))
  115. return '';
  116. if($this->_bSingleSeller)
  117. $iVendorId = $this->_iSingleSeller;
  118. return $this->_oModule->_oTemplate->displaySubscribeJs($iVendorId, $sVendorProvider, $iModuleId, $iItemId, $iItemCount, $sRedirect, $aCustom);
  119. }
  120. /**
  121. * @page service Service Calls
  122. * @section bx_base_payment Base Payment
  123. * @subsection bx_base_payment-integration Integration
  124. * @subsubsection bx_base_payment-get_subscribe_js get_subscribe_js
  125. *
  126. * @code bx_srv('bx_payment', 'get_subscribe_js', [...], 'Subscriptions'); @endcode
  127. *
  128. * Get JavaScript code to use in OnClick attributes of HTML elements.
  129. *
  130. * @param $iVendor integer value with vendor ID.
  131. * @param $sVendorProvider string value with a name of payment provider to be used for processing.
  132. * @param $mixedModuleId mixed value (ID, Name or URI) determining a module from which the action was initiated.
  133. * @param $iItemId integer value with item ID.
  134. * @param $iItemCount (optional) integer value with a number of items for purchasing. It's equal to 1 in case of subscription.
  135. * @param $sItemAddons (optional) string with attached addons.
  136. * @param $sRedirect (optional) string value with redirect URL, if it's needed.
  137. * @return string with JavaScript code.
  138. *
  139. * @see BxBaseModPaymentSubscriptions::serviceGetSubscribeJs
  140. */
  141. /**
  142. * @ref bx_base_payment-get_subscribe_js "get_subscribe_js"
  143. */
  144. public function serviceGetSubscribeJsWithAddons($iVendorId, $sVendorProvider, $mixedModuleId, $iItemId, $iItemCount = 1, $sItemAddons = '', $sRedirect = '', $aCustom = array())
  145. {
  146. $iModuleId = $this->_oModule->_oConfig->getModuleId($mixedModuleId);
  147. if(empty($iModuleId))
  148. return '';
  149. if($this->_bSingleSeller)
  150. $iVendorId = $this->_iSingleSeller;
  151. return $this->_oModule->_oTemplate->displaySubscribeJsWithAddons($iVendorId, $sVendorProvider, $iModuleId, $iItemId, $iItemCount, $sItemAddons, $sRedirect, $aCustom);
  152. }
  153. /**
  154. * @page service Service Calls
  155. * @section bx_base_payment Base Payment
  156. * @subsection bx_base_payment-integration Integration
  157. * @subsubsection bx_base_payment-get_subscribe_link get_subscribe_link
  158. *
  159. * @code bx_srv('bx_payment', 'get_subscribe_link', [...], 'Subscriptions'); @endcode
  160. *
  161. * Get "Subscribe" link including HTML tag and cart JavaScript code.
  162. *
  163. * @param $iVendor integer value with vendor ID.
  164. * @param $sVendorProvider string value with a name of payment provider to be used for processing.
  165. * @param $mixedModuleId mixed value (ID, Name or URI) determining a module from which the action was initiated.
  166. * @param $iItemId integer value with item ID.
  167. * @param $iItemCount (optional) integer value with a number of items for purchasing. It's equal to 1 in case of subscription.
  168. * @param $sRedirect (optional) string value with redirect URL, if it's needed.
  169. * @return HTML string with link to display on the site.
  170. *
  171. * @see BxBaseModPaymentSubscriptions::serviceGetSubscribeLink
  172. */
  173. /**
  174. * @ref bx_base_payment-get_subscribe_link "get_subscribe_link"
  175. */
  176. public function serviceGetSubscribeLink($iVendorId, $sVendorProvider, $mixedModuleId, $iItemId, $iItemCount = 1, $sRedirect = '', $aCustom = array())
  177. {
  178. $iModuleId = $this->_oModule->_oConfig->getModuleId($mixedModuleId);
  179. if(empty($iModuleId))
  180. return '';
  181. if($this->_bSingleSeller)
  182. $iVendorId = $this->_iSingleSeller;
  183. return $this->_oModule->_oTemplate->displaySubscribeLink($iVendorId, $sVendorProvider, $iModuleId, $iItemId, $iItemCount, $sRedirect, $aCustom);
  184. }
  185. }
  186. /** @} */