1
0
Fork 0
mirror of synced 2025-04-20 01:21:01 +00:00

add confirmation bonus adding

This commit is contained in:
Sergey Chazov 2020-10-20 17:52:32 +03:00
parent 498d93108a
commit fa8163a4ce
4 changed files with 78 additions and 1 deletions

View file

@ -16,6 +16,46 @@ if ($arParams["SET_TITLE"] == "Y")
<? if (!empty($arResult["ORDER"])): ?>
<?php
$order = Bitrix\Sale\Order::load($arResult["ORDER"]['ID']);
$paymentCollection = $order->getPaymentCollection();
/** @var \Bitrix\Sale\Payment $payment */
foreach ($paymentCollection as $payment) {
$isPaid = $payment->isPaid();
try {
$paySystemAction = \Intaro\RetailCrm\Repository\PaySystemActionRepository::getFirstByWhere(
['*'],
[
[
'ID',
'=',
$payment->getField('PAY_SYSTEM_ID'),
],
]
);
} catch (\Bitrix\Main\ObjectPropertyException | \Bitrix\Main\ArgumentException | \Bitrix\Main\SystemException $e) {
}
//если есть бонусная оплата и она не оплачена, то отрисовываем форму введения кода верификации
$isPaid=false;//TODO заглушка - убрать после теста
if ($paySystemAction->get('CODE') === 'INTARO_BONUS' && !$isPaid) {
?>
<div id="orderConfirm">
<b><?= GetMessage('CONFIRM_MESSAGE')?></b><br>
<div id="orderVerificationCodeBlock" style="display: none;">
<b><?= GetMessage('SEND_VERIFICATION_CODE')?></b><br>
<input type="text" id="orderVerificationCode" placeholder="<?= GetMessage('VERIFICATION_CODE')?>">
<input type="button" onclick="sendVerificationCode()" value="<?= GetMessage('SEND')?>"/>
</div>
<div id="msg"></div>
</div>
<?php
}
}
?>
<table class="sale_order_full_table">
<tr>
<td>

View file

@ -142,4 +142,5 @@ $MESS["HOW_MANY_BONUSES_TO_SPEND"] = 'Сколько бонусов потрат
$MESS["BONUS_TOTAL"] = 'Всего бонусов:';
$MESS["YOU_CAN_SPEND"] = 'Можно потратить:';
$MESS["CALCULATION_ERROR"] = 'Не удалось рассчитать количество доступных бонусов.';
$MESS["CONFIRM_MESSAGE"] = 'Для завершения процедуры списания бонусов, введите код верификации';

View file

@ -20,3 +20,29 @@ $(document).ready(function() {
$('#bonus-input').on('keydown', _.debounce(makeAjaxRequest, 1000));
});
function sendVerificationCode() {
const verificationCode = $('#orderVerificationCode').val();
BX.ajax.runAction('intaro:retailcrm.api.loyalty.register.sendVerificationCode',
{
data: {
sessid: BX.bitrix_sessid(),
code: verificationCode
}
}
).then(
function(response) {
if (response.data.status === 'error' && response.data.msg !== undefined) {
const msg = response.data.msg;
$('#msg').text(msg);
}
if (response.data.status === 'activate') {
const msgBlock = $('#orderConfirm');
msgBlock.text(response.data.msg);
msgBlock.css('color', response.data.msgColor);
}
}
)
}

View file

@ -176,7 +176,17 @@ class EventsHandlers
$newPayment = $paymentCollection->createItem($service);
$newPayment->setField('SUM', $bonusCount);
$newPayment->setPaid('Y');
//если верификация необходима, но не пройдена
if (isset($response->verification) && !isset($response->verification->verifiedAt)) {
$newPayment->setPaid('N');
}
//если верификация не нужна
if (!isset($response->verification)) {
$newPayment->setPaid('Y');
}
$order->save();
}
} catch (ObjectPropertyException | ArgumentException | SystemException | Exception $e) {