Documentation

UpdateAccount

Description and parameters

int
CSaleUserAccount::UpdateAccount(
 int userID, 
 double sum, 
 string currency[, 
 string description = ""[,
 int orderID = 0[,
 string notes = ""]]]
);

Method updates amount at the user's account with userID. Static method.

Call parameters

ParameterDescription
userID User ID.
sum Updated amount at the account. To increase the account amount, the value must have "+" character or without it. To decrease - with "-".  character;
currency Amount currency.
description Description with reason for amount updates.
orderID Order code, if amount update is related to order.
notes Arbitrary text description.

Returned values

Method returns user account ID or false in case of error.

Notes:
  • Money is deducted only from the account with the same currency, passed by parameter into the method. User accounts in another currency are not affected.
  • In case the user didn't have an account in this currency previously, it will be created automatically (and created account ID will be returned).

Examples

<?
// Write callback function to be called on updated flag
// "Delivery permitted" for order and deposit (or deduct) 100 USD to the account

function MyDeliveryOrderCallback($productID, $userID, $bPaid, $orderID)
{
    global $DB;

    // Process the input parameters
    $productID = IntVal($productID);    // Ordered product code
    $userID = IntVal($userID);  // Buyer user code
    $bPaid = ($bPaid ? True : False);   // Sets or removes delivery flag
    $orderID = IntVal($orderID);    // Order code

    if ($userID <= 0)
        return False;

    if ($orderID <= 0)
        return False;

    // Deposit (deduct) money to the account
    if (!CSaleUserAccount::UpdateAccount(
            $userID,
            ($bPaid ? 100 : -100),
            "USD",
            "MANUAL",
            $orderID
        ))
        return False;

    return True;
}
?>

© «Bitrix24», 2001-2024
Up