\Bitrix\Main\Loader::includeModule('sale');
$sCoupon = $_REQUEST['COUPON'];
\Bitrix\Sale\DiscountCouponsManager::add($sCoupon);
$oBasket = \Bitrix\Sale\Basket::loadItemsForFUser(
\Bitrix\Sale\Fuser::getId(),
\Bitrix\Main\Context::getCurrent()->getSite()
);
$oDiscounts = \Bitrix\Sale\Discount::loadByBasket($oBasket);
$oBasket->refreshData([ 'PRICE' , 'COUPONS']);
$oDiscounts->calculate();
$result = $oDiscounts->getApplyResult();
$oBasket->save();