AntonLV 5 лет назад
Родитель
Сommit
548a1399b4

+ 12 - 0
modules/base/payment/classes/BxBaseModPaymentModule.php

@@ -279,6 +279,18 @@ class BxBaseModPaymentModule extends BxBaseModGeneralModule
         return new $aProvider['class_name']($aProvider);
     }
 
+    /**
+     * Method to fire alert on behalf of both 'system' and currently active payment module.
+     * It's needed for general events like: Finalize Checkout, Register Payment, Refund Payment, etc.
+     */
+    public function alert($sAction, $iObjectId, $iSender = false, $aExtras = array())
+    {
+        $sSystem = 'system';
+        $sModule = $this->getName();
+        foreach([$sSystem, $sModule] as $sUnit)
+            bx_alert($sUnit, $sAction, $iObjectId, $iSender, ($sUnit == $sSystem ? array_merge(array('module' => $sModule), $aExtras) : $aExtras));
+    }
+
     public function callGetPaymentData($mixedModule)
     {
     	$sMethod = 'get_payment_data';

+ 2 - 2
modules/boonex/payment/classes/BxPaymentCart.php

@@ -265,7 +265,7 @@ class BxPaymentCart extends BxBaseModPaymentCart
         $aCart['items'] = trim(preg_replace("'" . $this->_oModule->_oConfig->descriptorA2S(array($iSellerId, $iModuleId, $iItemId, '[0-9]+:?')) . "'", "", $aCart['items']), ":");
         $this->_oModule->_oDb->setCartItems($iClientId, $aCart['items'], $aCartCustom);
 
-        bx_alert($this->_oModule->getName(), 'delete_from_cart', 0, 0, array(
+        $this->_oModule->alert('delete_from_cart', 0, 0, array(
             'seller_id' => $iSellerId,
             'module_id' => $iModuleId,
             'item_id' => $iItemId,
@@ -287,7 +287,7 @@ class BxPaymentCart extends BxBaseModPaymentCart
         foreach($aContent as $iSellerId => $aSellerItems)
             $aResult[$iSellerId] = $this->_getInfo($sType, $iUserId, $iSellerId, $aSellerItems);
 
-        bx_alert($this->_oModule->getName(), 'get_cart_info', 0, 0, array(
+        $this->_oModule->alert('get_cart_info', 0, 0, array(
            'type' => $sType,
            'client_id' => $iUserId,
            'seller_id' => $iSellerId,

+ 53 - 55
modules/boonex/payment/classes/BxPaymentJoin.php

@@ -44,7 +44,7 @@ class BxPaymentJoin extends BxBaseModPaymentJoin
     /** 
      * @ref bx_payment-get_block_join "get_block_join"
      */
-	public function serviceGetBlockJoin()
+    public function serviceGetBlockJoin()
     {
     	$sSessionKeyPending = $this->_oModule->_oConfig->getKey('KEY_SESSION_PENDING');
     	$sRequestKeyPending = $this->_oModule->_oConfig->getKey('KEY_REQUEST_PENDING');
@@ -53,83 +53,81 @@ class BxPaymentJoin extends BxBaseModPaymentJoin
     	$iPendingId = (int)$oSession->getValue($sSessionKeyPending);
 
     	if(empty($iPendingId) && bx_get($sRequestKeyPending) !== false) {
-    		$iPendingId = (int)bx_get($sRequestKeyPending);
+            $iPendingId = (int)bx_get($sRequestKeyPending);
 
-    		$oSession->setValue($sSessionKeyPending, $iPendingId);
+            $oSession->setValue($sSessionKeyPending, $iPendingId);
     	}
 
-		if(empty($iPendingId))
-			return array(
-        		'content' => MsgBox(_t($this->_sLangsPrefix . 'err_not_allowed'))
-			);
-
-		$aPending = $this->_oModule->_oDb->getOrderPending(array('type' => 'id', 'id' => $iPendingId));
-	    if(empty($aPending['order']) || (int)$aPending['error_code'] != 1)
-			return array(
-        		'content' => MsgBox(_t($this->_sLangsPrefix . 'err_not_processed'))
-			);
-
-		if((int)$aPending['processed'] == 1)
-			return array(
-        		'content' => MsgBox(_t($this->_sLangsPrefix . 'err_already_processed'))
-			);
-
-		//--- 'System' -> 'Join after Payment' for Alerts Engine ---//
-		$bOverride = false;
-		$sOverrideError = '';
-
-		bx_alert('system', 'join_after_payment', 0, 0, array('override' => &$bOverride, 'override_error' => &$sOverrideError));
-
+        if(empty($iPendingId))
+            return array(
+                'content' => MsgBox(_t($this->_sLangsPrefix . 'err_not_allowed'))
+            );
+
+        $aPending = $this->_oModule->_oDb->getOrderPending(array('type' => 'id', 'id' => $iPendingId));
+        if(empty($aPending['order']) || (int)$aPending['error_code'] != 1)
+            return array(
+                'content' => MsgBox(_t($this->_sLangsPrefix . 'err_not_processed'))
+            );
+
+        if((int)$aPending['processed'] == 1)
+            return array(
+                'content' => MsgBox(_t($this->_sLangsPrefix . 'err_already_processed'))
+            );
+
+        //--- 'System' -> 'Join after Payment' for Alerts Engine ---//
+        $bOverride = false;
+        $sOverrideError = '';
+        $this->_oModule->alert('join_after_payment', 0, 0, array('override' => &$bOverride, 'override_error' => &$sOverrideError));
         if($bOverride)
-        	return;
-		//--- 'System' -> 'Join after Payment' for Alerts Engine ---//
+            return;
+        //--- 'System' -> 'Join after Payment' for Alerts Engine ---//
 
-    	$sContent = BxDolService::call('system', 'create_account_form', array(array('action' => $this->_oModule->_oConfig->getUrl('URL_JOIN'))), 'TemplServiceAccount');
-    	if(!empty($sOverrideError))
-    		$sContent = MsgBox(_t($sOverrideError)) . $sContent;
+        $sContent = BxDolService::call('system', 'create_account_form', array(array('action' => $this->_oModule->_oConfig->getUrl('URL_JOIN'))), 'TemplServiceAccount');
+        if(!empty($sOverrideError))
+            $sContent = MsgBox(_t($sOverrideError)) . $sContent;
 
-		return array(
-        	'content' => $sContent
-		);
+        return array(
+            'content' => $sContent
+        );
     }
 
-	public function performJoin($iPendingId, $sClientName = '', $sClientEmail = '')
+    public function performJoin($iPendingId, $sClientName = '', $sClientEmail = '')
     {
-		BxDolSession::getInstance()->setValue($this->_oModule->_oConfig->getKey('KEY_SESSION_PENDING'), (int)$iPendingId);
+        BxDolSession::getInstance()->setValue($this->_oModule->_oConfig->getKey('KEY_SESSION_PENDING'), (int)$iPendingId);
 
-		if(!empty($sClientName) && !empty($sClientEmail)) {
-			$aTemplate = BxDolEmailTemplates::getInstance()->parseTemplate($this->_oModule->_oConfig->getPrefix('general') . 'paid_need_join', array(
-				'RealName' => $sClientName,
-				'JoinLink' => $this->_oModule->_oConfig->getUrl('URL_JOIN', array($this->_oModule->_oConfig->getKey('KEY_REQUEST_PENDING') => (int)$iPendingId))
-			));
+        if(!empty($sClientName) && !empty($sClientEmail)) {
+            $aTemplate = BxDolEmailTemplates::getInstance()->parseTemplate($this->_oModule->_oConfig->getPrefix('general') . 'paid_need_join', array(
+                'RealName' => $sClientName,
+                'JoinLink' => $this->_oModule->_oConfig->getUrl('URL_JOIN', array($this->_oModule->_oConfig->getKey('KEY_REQUEST_PENDING') => (int)$iPendingId))
+            ));
 
-			sendMail($sClientEmail, $aTemplate['Subject'], $aTemplate['Body'], 0, array(), BX_EMAIL_SYSTEM);
-		}
+            sendMail($sClientEmail, $aTemplate['Subject'], $aTemplate['Body'], 0, array(), BX_EMAIL_SYSTEM);
+        }
 
-		header('Location: ' . $this->_oModule->_oConfig->getUrl('URL_JOIN'));
-		exit;
-	}
+        header('Location: ' . $this->_oModule->_oConfig->getUrl('URL_JOIN'));
+        exit;
+    }
 
-	public function onProfileJoin($iProfileId)
+    public function onProfileJoin($iProfileId)
     {
     	$sSessionKeyPending = $this->_oModule->_oConfig->getKey('KEY_SESSION_PENDING');
 
     	$oSession = BxDolSession::getInstance();
-		$iPendingId = (int)$oSession->getValue($sSessionKeyPending);
+        $iPendingId = (int)$oSession->getValue($sSessionKeyPending);
 
         if(empty($iProfileId) || empty($iPendingId))
-        	return;
+            return;
  
-		$aPending = $this->_oModule->_oDb->getOrderPending(array('type' => 'id', 'id' => $iPendingId));
-		if(empty($aPending) || (isset($aPending['client_id']) && (int)$aPending['client_id'] != 0))
-			return;
+        $aPending = $this->_oModule->_oDb->getOrderPending(array('type' => 'id', 'id' => $iPendingId));
+        if(empty($aPending) || (isset($aPending['client_id']) && (int)$aPending['client_id'] != 0))
+            return;
 
-		if(!$this->_oModule->_oDb->updateOrderPending($iPendingId, array('client_id' => $iProfileId)))
-			return;
+        if(!$this->_oModule->_oDb->updateOrderPending($iPendingId, array('client_id' => $iProfileId)))
+            return;
 
-		$this->_oModule->registerPayment($iPendingId);
+        $this->_oModule->registerPayment($iPendingId);
 
-		$oSession->unsetValue($sSessionKeyPending);
+        $oSession->unsetValue($sSessionKeyPending);
     }
 }
 

+ 12 - 12
modules/boonex/payment/classes/BxPaymentModule.php

@@ -811,7 +811,7 @@ class BxPaymentModule extends BxBaseModPaymentModule
             }
         }
 
-        bx_alert($this->getName(), 'before_pending', 0, bx_get_logged_profile_id(), array(
+        $this->alert('before_pending', 0, bx_get_logged_profile_id(), array(
             'client_id' => $this->_iUserId,
             'type' => &$sType,
             'provider' => &$sProvider,
@@ -887,7 +887,7 @@ class BxPaymentModule extends BxBaseModPaymentModule
         if(!empty($aResult['paid']) || ($bTypeRecurring && !empty($aResult['trial'])))
             $this->registerPayment($aPending);
 
-        bx_alert($this->getName(), 'finalize_checkout', 0, bx_get_logged_profile_id(), array(
+        $this->alert('finalize_checkout', 0, bx_get_logged_profile_id(), array(
             'pending' => $aPending,
             'transactions' => $this->_oDb->getOrderProcessed(array('type' => 'pending_id', 'pending_id' => (int)$aPending['id'])),
             'provider' => $oProvider,
@@ -1215,7 +1215,7 @@ class BxPaymentModule extends BxBaseModPaymentModule
                     $fCommission += (float)$aCommission['installment'];
             }
             
-            bx_alert($this->getName(), 'calculate_commission', 0, 0, array(
+            $this->alert('calculate_commission', 0, 0, array(
                 'vendor' => $aVendor,
                 'commissions' => $aCommissions,
                 'override_result' => &$fCommission,
@@ -1345,7 +1345,7 @@ class BxPaymentModule extends BxBaseModPaymentModule
 
     public function onPaymentRegisterBefore($aPending, $aResult = array())
     {
-        bx_alert('system', 'before_register_payment', 0, $aPending['client_id'], array('pending' => $aPending));
+        $this->alert('before_register_payment', 0, $aPending['client_id'], array('pending' => $aPending));
     }
 
     public function onPaymentRegister($aPending, $aResult = array())
@@ -1358,12 +1358,12 @@ class BxPaymentModule extends BxBaseModPaymentModule
                 $this->isAllowedPurchase(array('module_id' => $aItem['module_id'], 'item_id' => $aItem['item_id']), true);
         }
 
-        bx_alert('system', 'register_payment', 0, $aPending['client_id'], array('pending' => $aPending));
+        $this->alert('register_payment', 0, $aPending['client_id'], array('pending' => $aPending));
     }
 
     public function onPaymentRefund($aPending, $aResult = array())
     {
-        bx_alert('system', 'refund_payment', 0, $aPending['client_id'], array('pending' => $aPending));
+        $this->alert('refund_payment', 0, $aPending['client_id'], array('pending' => $aPending));
     }
 
     public function onSubscriptionCreate($aPending, $aSubscription, $aResult = array())
@@ -1371,7 +1371,7 @@ class BxPaymentModule extends BxBaseModPaymentModule
         $aItems = $this->_oConfig->descriptorsM2A($aPending['items']);
         $this->isAllowedPurchase(array('module_id' => $aItems[0]['module_id'], 'item_id' => $aItems[0]['item_id']), true);
 
-        bx_alert('system', 'create_subscription', 0, $aPending['client_id'], array(
+        $this->alert('create_subscription', 0, $aPending['client_id'], array(
             'pending' => $aPending,
             'subscription' => $aSubscription
         ));
@@ -1379,7 +1379,7 @@ class BxPaymentModule extends BxBaseModPaymentModule
 
     public function onSubscriptionProlong($aPending, $aSubscription, $aResult = array())
     {
-        bx_alert('system', 'prolong_subscription', 0, $aPending['client_id'], array(
+        $this->alert('prolong_subscription', 0, $aPending['client_id'], array(
             'pending' => $aPending,
             'subscription' => $aSubscription
         ));
@@ -1387,7 +1387,7 @@ class BxPaymentModule extends BxBaseModPaymentModule
 
     public function onSubscriptionOverdue($aPending, $aSubscription, $aResult = array())
     {
-        bx_alert('system', 'overdue_subscription', 0, $aPending['client_id'], array(
+        $this->alert('overdue_subscription', 0, $aPending['client_id'], array(
             'pending' => $aPending,
             'subscription' => $aSubscription
         ));
@@ -1395,7 +1395,7 @@ class BxPaymentModule extends BxBaseModPaymentModule
 
     public function onSubscriptionCancel($aPending, $aSubscription, $aResult = array())
     {
-        bx_alert('system', 'cancel_subscription', 0, $aPending['client_id'], array(
+        $this->alert('cancel_subscription', 0, $aPending['client_id'], array(
             'pending' => $aPending,
             'subscription' => $aSubscription
         ));
@@ -1619,7 +1619,7 @@ class BxPaymentModule extends BxBaseModPaymentModule
         if(!$this->_oDb->updateInvoice($iItemId, array('status' => BX_PAYMENT_INV_STATUS_PAID)))
             return array();
 
-        bx_alert($this->getName(), 'invoice_marked_as_paid', 0, false, array(
+        $this->alert('invoice_marked_as_paid', 0, false, array(
             'product_id' => $iItemId,
             'profile_id' => $iClientId,
             'order' => $sOrder,
@@ -1661,7 +1661,7 @@ class BxPaymentModule extends BxBaseModPaymentModule
         if(!$this->_oDb->updateInvoice($iItemId, array('status' => BX_PAYMENT_INV_STATUS_UNPAID)))
             return false;
 
-        bx_alert($this->getName(), 'invoice_marked_as_unpaid', 0, false, array(
+        $this->alert('invoice_marked_as_unpaid', 0, false, array(
             'product_id' => $iItemId,
             'profile_id' => $iClientId,
             'order' => $sOrder,