Просмотр исходного кода

Ticket #4069 - Credits: Negative balance should not be allowed and Subscription shouldn't be continued and processed when there is low balance.

AntonLV 4 лет назад
Родитель
Сommit
aafae35af6

+ 5 - 1
modules/boonex/payment/classes/BxPaymentModule.php

@@ -1598,8 +1598,12 @@ class BxPaymentModule extends BxBaseModPaymentModule
                 continue;
             }
 
+            $this->_oDb->updateSubscription(['pay_attempts' => (int)$aSubscription['pay_attempts'] + 1], ['id' => $aSubscription['id']]);
+
             if(($mixedResult = $oProvider->makePayment($aPending)) !== true) {
-                $this->log($aSubscription, 'Time Tracker', 'Payment cannot be processed.' . (!empty($mixedResult['message']) ? ' ' . $mixedResult['message'] : ''));
+                $this->_oDb->updateSubscription(['status' => BX_PAYMENT_SBS_STATUS_UNPAID], ['id' => $aSubscription['id']]);
+
+                $this->log($aSubscription, 'Time Tracker', 'Payment cannot be processed (code: ' . (!empty($mixedResult['code']) ? (int)$mixedResult['code'] : 0) . ').');
                 continue;
             }
 

+ 21 - 1
modules/boonex/payment/classes/BxPaymentProviderCredits.php

@@ -132,8 +132,28 @@ class BxPaymentProviderCredits extends BxBaseModPaymentProvider implements iBxBa
 
         $fAmount = (float)$mixedPending['amount'];
         $fClientBalance = bx_srv($this->_sModuleCredits, 'get_profile_balance', [$iClient]);
-        if($fAmount > $fClientBalance)
+        if($fAmount > $fClientBalance) {
+            $aSubscription = $this->_oModule->_oDb->getSubscription([
+                'type' => 'pending_id', 
+                'pending_id' => $mixedPending['id']
+            ]);
+
+            if(!empty($aSubscription) && is_array($aSubscription)) {
+                $aTemplate = BxDolEmailTemplates::getInstance()->parseTemplate($this->_oModule->_oConfig->getPrefix('general') . 'wrong_balance', [
+                    'profile_name' => $oClient->getDisplayName(),
+                    'profile_link' => $oClient->getUrl(),
+                    'sibscription_id' => $aSubscription['subscription_id'],
+                    'sibscription_customer' => $aSubscription['customer_id'],
+                    'sibscription_provider' => _t('_bx_payment_txt_name_' . $mixedPending['provider']),
+                    'sibscription_date' => bx_time_js($aSubscription['date_add'], BX_FORMAT_DATE, true)
+                ], 0, $iClient);
+
+                if($aTemplate !== false)
+                    sendMail($oClient->getAccountObject()->getEmail(), $aTemplate['Subject'], $aTemplate['Body'], 0, [], BX_EMAIL_SYSTEM);
+            }
+
             return ['code' => 4, 'message' => $this->_sLangsPrefix . 'cdt_err_wrong_balance'];
+        }
 
         if(!bx_srv($this->_sModuleCredits, 'make_payment', [$iClient, $fAmount, $iSeller, $mixedPending['order']]))
             return ['code' => 5, 'message' => $this->_sLangsPrefix . 'err_cannot_perform'];

+ 8 - 0
modules/boonex/payment/install/langs/en.xml

@@ -337,6 +337,14 @@
 <p>{items}</p>
 <p>Amount: {amount}<br />Date: {date}</p>
 <p>Go to the <a href="{pending_orders_link}">pending orders page</a> to process the order once the payment is received.</p>
+{email_footer}]]></string>
+
+    <string name="_bx_payment_et_txt_name_wrong_balance"><![CDATA[Insufficient funds to write off.]]></string>
+    <string name="_bx_payment_et_txt_subject_wrong_balance"><![CDATA[Insufficient funds to write off.]]></string>
+    <string name="_bx_payment_et_txt_body_wrong_balance"><![CDATA[{email_header}
+<p>Hello,</p>
+<p>You have insufficient funds to write off for paying a subscription.</p>
+<p>Subscription info:<br />ID: {sibscription_id}<br />Customer: {sibscription_customer}<br />Payment provider: {sibscription_provider}<br />Date: {sibscription_date}</p>
 {email_footer}]]></string>
 
     <!-- MESSAGES, WARNINGS and ERRORS -->

+ 2 - 1
modules/boonex/payment/install/sql/enable.sql

@@ -186,7 +186,8 @@ INSERT INTO `sys_email_templates` (`Module`, `NameSystem`, `Name`, `Subject`, `B
 (@sName, '_bx_payment_et_txt_name_expiration_notification_client', 'bx_payment_expiration_notification_client', '_bx_payment_et_txt_subject_expiration_notification_client', '_bx_payment_et_txt_body_expiration_notification_client'),
 (@sName, '_bx_payment_et_txt_name_expiring_notification_committent', 'bx_payment_expiring_notification_committent', '_bx_payment_et_txt_subject_expiring_notification_committent', '_bx_payment_et_txt_body_expiring_notification_committent'),
 (@sName, '_bx_payment_et_txt_name_overdue_notification_committent', 'bx_payment_overdue_notification_committent', '_bx_payment_et_txt_subject_overdue_notification_committent', '_bx_payment_et_txt_body_overdue_notification_committent'),
-(@sName, '_bx_payment_et_txt_name_checkout_offline', 'bx_payment_checkout_offline', '_bx_payment_et_txt_subject_checkout_offline', '_bx_payment_et_txt_body_checkout_offline');
+(@sName, '_bx_payment_et_txt_name_checkout_offline', 'bx_payment_checkout_offline', '_bx_payment_et_txt_subject_checkout_offline', '_bx_payment_et_txt_body_checkout_offline'),
+(@sName, '_bx_payment_et_txt_name_wrong_balance', 'bx_payment_wrong_balance', '_bx_payment_et_txt_subject_wrong_balance', '_bx_payment_et_txt_body_wrong_balance');
 
 
 -- CRON

+ 8 - 0
modules/boonex/russian/data/langs/bx_payment/ru.xml

@@ -340,6 +340,14 @@
 <p>Перейдите на <a href="{pending_orders_link}">страницу неоплаченных заказов</a> для обработки заказа, когда оплата будет получена.</p>
 {email_footer}]]></string>
 
+    <string name="_bx_payment_et_txt_name_wrong_balance"><![CDATA[Недостаточно средств для списания.]]></string>
+    <string name="_bx_payment_et_txt_subject_wrong_balance"><![CDATA[Недостаточно средств для списания.]]></string>
+    <string name="_bx_payment_et_txt_body_wrong_balance"><![CDATA[{email_header}
+<p>Привет,</p>
+<p>У вас недостаточно средств для списания на оплату подписки.</p>
+<p>Информация о подписке:<br />ID: {sibscription_id}<br />Клиент: {sibscription_customer}<br />Система оплаты: {sibscription_provider}<br />Дата: {sibscription_date}</p>
+{email_footer}]]></string>
+
 
     <!-- MESSAGES, WARNINGS and ERRORS -->
     <string name="_bx_payment_msg_no_results"><![CDATA[Пусто]]></string>