BxPaymentJoin.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup Payment Payment
  7. * @ingroup TridentModules
  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_import('BxDolAlerts');
  46. $oAlert = new BxDolAlerts('system', 'join_after_payment', 0, 0, array('override' => &$bOverride, 'override_error' => &$sOverrideError));
  47. $oAlert->alert();
  48. if($bOverride)
  49. return;
  50. //--- 'System' -> 'Join after Payment' for Alerts Engine ---//
  51. $sContent = BxDolService::call('system', 'create_account_form', array(array('action' => $this->_oModule->_oConfig->getUrl('URL_JOIN'))), 'TemplServiceAccount');
  52. if(!empty($sOverrideError))
  53. $sContent = MsgBox(_t($sOverrideError)) . $sContent;
  54. return array(
  55. 'content' => $sContent
  56. );
  57. }
  58. public function performJoin($iPendingId, $sClientName = '', $sClientEmail = '')
  59. {
  60. BxDolSession::getInstance()->setValue($this->_oModule->_oConfig->getKey('KEY_SESSION_PENDING'), (int)$iPendingId);
  61. if(!empty($sClientName) && !empty($sClientEmail)) {
  62. bx_import('BxDolEmailTemplates');
  63. $oEmailTemplates = new BxDolEmailTemplates();
  64. $aTemplate = $oEmailTemplates->parseTemplate($this->_oModule->_oConfig->getPrefix('general') . 'paid_need_join', array(
  65. 'RealName' => $sClientName,
  66. 'JoinLink' => $this->_oModule->_oConfig->getUrl('URL_JOIN', array($this->_oModule->_oConfig->getKey('KEY_REQUEST_PENDING') => (int)$iPendingId))
  67. ));
  68. sendMail($sClientEmail, $aTemplate['Subject'], $aTemplate['Body'], 0, array(), 'html', false, true);
  69. }
  70. header('Location: ' . $this->_oModule->_oConfig->getUrl('URL_JOIN'));
  71. exit;
  72. }
  73. public function onProfileJoin($iProfileId)
  74. {
  75. $sSessionKeyPending = $this->_oModule->_oConfig->getKey('KEY_SESSION_PENDING');
  76. $oSession = BxDolSession::getInstance();
  77. $iPendingId = (int)$oSession->getValue($sSessionKeyPending);
  78. if(empty($iProfileId) || empty($iPendingId))
  79. return;
  80. $aPending = $this->_oModule->_oDb->getOrderPending(array('type' => 'id', 'id' => $iPendingId));
  81. if(empty($aPending) || (isset($aPending['client_id']) && (int)$aPending['client_id'] != 0))
  82. return;
  83. if(!$this->_oModule->_oDb->updateOrderPending($iPendingId, array('client_id' => $iProfileId)))
  84. return;
  85. $this->_oModule->registerPayment($iPendingId);
  86. $oSession->unsetValue($sSessionKeyPending);
  87. }
  88. }
  89. /** @} */