static function DoPayOrderFromAccount($userId, $currency, $orderId, $orderSum, $arOptions, &$arErrors) { if (!array_key_exists("ONLY_FULL_PAY_FROM_ACCOUNT", $arOptions)) { $arOptions["ONLY_FULL_PAY_FROM_ACCOUNT"] = COption::GetOptionString("sale", "ONLY_FULL_PAY_FROM_ACCOUNT", "N"); } $dbUserAccount = CSaleUserAccount::GetList(array(), array("USER_ID" => $userId, "CURRENCY" => $currency)); $arUserAccount = $dbUserAccount->Fetch(); if (!$arUserAccount) { return false; } if ($arUserAccount["CURRENT_BUDGET"] <= 0) { return false; } if ($arOptions["ONLY_FULL_PAY_FROM_ACCOUNT"] == "Y" && doubleval($arUserAccount["CURRENT_BUDGET"]) < doubleval($orderSum)) { return false; } $withdrawSum = CSaleUserAccount::Withdraw($userId, $orderSum, $currency, $orderId); if ($withdrawSum > 0) { $arFields = array("SUM_PAID" => $withdrawSum, "USER_ID" => $userId); CSaleOrder::Update($orderId, $arFields); if ($withdrawSum == $orderSum) { CSaleOrder::PayOrder($orderId, "Y", False, False); } return true; } return false; }
$arFields["AFFILIATE_ID"] = $affiliateID; } } else { $arFields["AFFILIATE_ID"] = false; } $arResult["ORDER_ID"] = CSaleOrder::DoSaveOrder($arOrderDat, $arFields, 0, $arResult["ERROR"]); $arResult["ORDER_ID"] = IntVal($arResult["ORDER_ID"]); if ($arResult["ORDER_ID"] > 0 && empty($arResult["ERROR"])) { $arOrder = CSaleOrder::GetByID($arResult["ORDER_ID"]); CSaleBasket::OrderBasket($arResult["ORDER_ID"], CSaleBasket::GetBasketUserID(), SITE_ID, false); $arResult["ACCOUNT_NUMBER"] = $arResult["ORDER_ID"] <= 0 ? $arResult["ORDER_ID"] : $arOrder["ACCOUNT_NUMBER"]; } $withdrawSum = 0.0; if (empty($arResult["ERROR"])) { if ($arResult["PAY_FROM_ACCOUNT"] == "Y" && $arUserResult["PAY_CURRENT_ACCOUNT"] == "Y" && ($arParams["ONLY_FULL_PAY_FROM_ACCOUNT"] == "Y" && DoubleVal($arResult["USER_ACCOUNT"]["CURRENT_BUDGET"]) >= DoubleVal($orderTotalSum) || $arParams["ONLY_FULL_PAY_FROM_ACCOUNT"] != "Y")) { $withdrawSum = CSaleUserAccount::Withdraw($USER->GetID(), $orderTotalSum, $arResult["BASE_LANG_CURRENCY"], $arResult["ORDER_ID"]); if ($withdrawSum > 0) { $arFields = array("SUM_PAID" => $withdrawSum, "USER_ID" => $USER->GetID()); CSaleOrder::Update($arResult["ORDER_ID"], $arFields); if ($withdrawSum == $orderTotalSum) { CSaleOrder::PayOrder($arResult["ORDER_ID"], "Y", False, False); } } } if ($arResult["HAVE_PREPAYMENT"]) { if ($psPreAction && $psPreAction->IsAction()) { $psPreAction->orderId = $arResult["ORDER_ID"]; $psPreAction->orderAmount = $orderTotalSum; $psPreAction->deliveryAmount = $arResult["DELIVERY_PRICE"]; $psPreAction->taxAmount = $arResult["TAX_PRICE"]; $orderData = array();