BxPaymentJoin.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. * TODO: Should be tested when paid memberships with "Paid Before Join" or some similar feature will appear.
  24. */
  25. public function serviceGetBlockJoin()
  26. {
  27. $sSessionKeyPending = $this->_oModule->_oConfig->getKey('KEY_SESSION_PENDING');
  28. $sRequestKeyPending = $this->_oModule->_oConfig->getKey('KEY_REQUEST_PENDING');
  29. $oSession = BxDolSession::getInstance();
  30. $iPendingId = (int)$oSession->getValue($sSessionKeyPending);
  31. if(empty($iPendingId) && bx_get($sRequestKeyPending) !== false) {
  32. $iPendingId = (int)bx_get($sRequestKeyPending);
  33. $oSession->setValue($sSessionKeyPending, $iPendingId);
  34. }
  35. if(empty($iPendingId))
  36. return MsgBox(_t($this->_sLangsPrefix . 'err_not_allowed'));
  37. $aPending = $this->_oModule->_oDb->getOrderPending(array('type' => 'id', 'id' => $iPendingId));
  38. if(empty($aPending['order']) || (int)$aPending['error_code'] != 1)
  39. return MsgBox(_t($this->_sLangsPrefix . 'err_not_processed'));
  40. if((int)$aPending['processed'] == 1)
  41. return MsgBox(_t($this->_sLangsPrefix . 'err_already_processed'));
  42. //--- 'System' -> 'Join after Payment' for Alerts Engine ---//
  43. $bOverride = false;
  44. $sOverrideError = '';
  45. bx_alert('system', 'join_after_payment', 0, 0, array('override' => &$bOverride, 'override_error' => &$sOverrideError));
  46. if($bOverride)
  47. return;
  48. //--- 'System' -> 'Join after Payment' for Alerts Engine ---//
  49. $sContent = BxDolService::call('system', 'create_account_form', array(array('action' => $this->_oModule->_oConfig->getUrl('URL_JOIN'))), 'TemplServiceAccount');
  50. if(!empty($sOverrideError))
  51. $sContent = MsgBox(_t($sOverrideError)) . $sContent;
  52. return array(
  53. 'content' => $sContent
  54. );
  55. }
  56. public function performJoin($iPendingId, $sClientName = '', $sClientEmail = '')
  57. {
  58. BxDolSession::getInstance()->setValue($this->_oModule->_oConfig->getKey('KEY_SESSION_PENDING'), (int)$iPendingId);
  59. if(!empty($sClientName) && !empty($sClientEmail)) {
  60. $aTemplate = BxDolEmailTemplates::getInstance()->parseTemplate($this->_oModule->_oConfig->getPrefix('general') . 'paid_need_join', array(
  61. 'RealName' => $sClientName,
  62. 'JoinLink' => $this->_oModule->_oConfig->getUrl('URL_JOIN', array($this->_oModule->_oConfig->getKey('KEY_REQUEST_PENDING') => (int)$iPendingId))
  63. ));
  64. sendMail($sClientEmail, $aTemplate['Subject'], $aTemplate['Body'], 0, array(), BX_EMAIL_SYSTEM);
  65. }
  66. header('Location: ' . $this->_oModule->_oConfig->getUrl('URL_JOIN'));
  67. exit;
  68. }
  69. public function onProfileJoin($iProfileId)
  70. {
  71. $sSessionKeyPending = $this->_oModule->_oConfig->getKey('KEY_SESSION_PENDING');
  72. $oSession = BxDolSession::getInstance();
  73. $iPendingId = (int)$oSession->getValue($sSessionKeyPending);
  74. if(empty($iProfileId) || empty($iPendingId))
  75. return;
  76. $aPending = $this->_oModule->_oDb->getOrderPending(array('type' => 'id', 'id' => $iPendingId));
  77. if(empty($aPending) || (isset($aPending['client_id']) && (int)$aPending['client_id'] != 0))
  78. return;
  79. if(!$this->_oModule->_oDb->updateOrderPending($iPendingId, array('client_id' => $iProfileId)))
  80. return;
  81. $this->_oModule->registerPayment($iPendingId);
  82. $oSession->unsetValue($sSessionKeyPending);
  83. }
  84. }
  85. /** @} */