Documentation

Withdraw

Description and parameters

double
CSaleUserAccount::Withdraw(
 int userID,
 double paySum,
 string payCurrency[,
 int orderID = 0]
);

Method deducts a specified amount from the user's internal account. In case the internal account doesn't have sufficient funds, deducts only the maximum available amount (i. e. all available funds). Non-static method.

Call parameters

ParameterDescription
userID User code.
paySum Deducted amount.
payCurrency Deducted amount currency.
orderID Order ID, if deducted amount is not associated with the order.

Returned values

Method returns an actually deducted amount from the account or false in case of error.

Note: money are deducted only from the account with the same currency, passed by the parameters to the method. User accounts in another currency are not affected.

Examples

<?
// Pay fully or partially for the order No. 21 from the user's account

$arOrder = CSaleOrder::GetByID(21);

$withdrawSum = CSaleUserAccount::Withdraw(
        $arOrder["USER_ID"],
        $arOrder["PRICE"],
        $arOrder["CURRENCY"],
        $arOrder["ID"]
    );

if ($withdrawSum > 0)
{
    $arFields = array(
            "SUM_PAID" => $withdrawSum,
            "USER_ID" => $arOrder["USER_ID"]
        );
    CSaleOrder::Update($arOrder["ID"], $arFields);

    if ($withdrawSum == $arOrder["PRICE"])
        CSaleOrder::PayOrder($arOrder["ID"], "Y", False, False);
}
?>

© «Bitrix24», 2001-2024
Up