BxBaseModPaymentSubscriptions.php 8.5 KB

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