BxBaseModPaymentSubscriptions.php 6.0 KB

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