BxPaymentJoin.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 BxPaymentJoin extends BxBaseModPaymentJoin
  12. {
  13. protected $_sLangsPrefix;
  14. function __construct()
  15. {
  16. $this->MODULE = 'bx_payment';
  17. parent::__construct();
  18. $this->_sLangsPrefix = $this->_oModule->_oConfig->getPrefix('langs');
  19. }
  20. /*
  21. * Service methods
  22. */
  23. /**
  24. * @page service Service Calls
  25. * @section bx_payment Payment
  26. * @subsection bx_payment-page_blocks Page Blocks
  27. * @subsubsection bx_payment-get_block_join get_block_join
  28. *
  29. * @code bx_srv('bx_payment', 'get_block_join', [...], 'Join'); @endcode
  30. *
  31. * Get page block with join form to complete the payment.
  32. * TODO: Should be tested when paid memberships with "Paid Before Join" or some similar feature will appear.
  33. *
  34. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  35. *
  36. * @see BxPaymentJoin::serviceGetBlockJoin
  37. */
  38. /**
  39. * @ref bx_payment-get_block_join "get_block_join"
  40. */
  41. public function serviceGetBlockJoin()
  42. {
  43. $sSessionKeyPending = $this->_oModule->_oConfig->getKey('KEY_SESSION_PENDING');
  44. $sRequestKeyPending = $this->_oModule->_oConfig->getKey('KEY_REQUEST_PENDING');
  45. $oSession = BxDolSession::getInstance();
  46. $iPendingId = (int)$oSession->getValue($sSessionKeyPending);
  47. if(empty($iPendingId) && bx_get($sRequestKeyPending) !== false) {
  48. $iPendingId = (int)bx_get($sRequestKeyPending);
  49. $oSession->setValue($sSessionKeyPending, $iPendingId);
  50. }
  51. if(empty($iPendingId))
  52. return array(
  53. 'content' => MsgBox(_t($this->_sLangsPrefix . 'err_not_allowed'))
  54. );
  55. $aPending = $this->_oModule->_oDb->getOrderPending(array('type' => 'id', 'id' => $iPendingId));
  56. if(empty($aPending['order']) || (int)$aPending['error_code'] != 1)
  57. return array(
  58. 'content' => MsgBox(_t($this->_sLangsPrefix . 'err_not_processed'))
  59. );
  60. if((int)$aPending['processed'] == 1)
  61. return array(
  62. 'content' => MsgBox(_t($this->_sLangsPrefix . 'err_already_processed'))
  63. );
  64. //--- 'System' -> 'Join after Payment' for Alerts Engine ---//
  65. $bOverride = false;
  66. $sOverrideError = '';
  67. bx_alert('system', 'join_after_payment', 0, 0, array('override' => &$bOverride, 'override_error' => &$sOverrideError));
  68. if($bOverride)
  69. return;
  70. //--- 'System' -> 'Join after Payment' for Alerts Engine ---//
  71. $sContent = BxDolService::call('system', 'create_account_form', array(array('action' => $this->_oModule->_oConfig->getUrl('URL_JOIN'))), 'TemplServiceAccount');
  72. if(!empty($sOverrideError))
  73. $sContent = MsgBox(_t($sOverrideError)) . $sContent;
  74. return array(
  75. 'content' => $sContent
  76. );
  77. }
  78. public function performJoin($iPendingId, $sClientName = '', $sClientEmail = '')
  79. {
  80. BxDolSession::getInstance()->setValue($this->_oModule->_oConfig->getKey('KEY_SESSION_PENDING'), (int)$iPendingId);
  81. if(!empty($sClientName) && !empty($sClientEmail)) {
  82. $aTemplate = BxDolEmailTemplates::getInstance()->parseTemplate($this->_oModule->_oConfig->getPrefix('general') . 'paid_need_join', array(
  83. 'RealName' => $sClientName,
  84. 'JoinLink' => $this->_oModule->_oConfig->getUrl('URL_JOIN', array($this->_oModule->_oConfig->getKey('KEY_REQUEST_PENDING') => (int)$iPendingId))
  85. ));
  86. sendMail($sClientEmail, $aTemplate['Subject'], $aTemplate['Body'], 0, array(), BX_EMAIL_SYSTEM);
  87. }
  88. header('Location: ' . $this->_oModule->_oConfig->getUrl('URL_JOIN'));
  89. exit;
  90. }
  91. public function onProfileJoin($iProfileId)
  92. {
  93. $sSessionKeyPending = $this->_oModule->_oConfig->getKey('KEY_SESSION_PENDING');
  94. $oSession = BxDolSession::getInstance();
  95. $iPendingId = (int)$oSession->getValue($sSessionKeyPending);
  96. if(empty($iProfileId) || empty($iPendingId))
  97. return;
  98. $aPending = $this->_oModule->_oDb->getOrderPending(array('type' => 'id', 'id' => $iPendingId));
  99. if(empty($aPending) || (isset($aPending['client_id']) && (int)$aPending['client_id'] != 0))
  100. return;
  101. if(!$this->_oModule->_oDb->updateOrderPending($iPendingId, array('client_id' => $iProfileId)))
  102. return;
  103. $this->_oModule->registerPayment($iPendingId);
  104. $oSession->unsetValue($sSessionKeyPending);
  105. }
  106. }
  107. /** @} */