function OrderDelivery($orderID, $bPaid, $recurringID = 0) { global $DB, $APPLICATION; $orderID = IntVal($orderID); if ($orderID <= 0) { return False; } $bPaid = $bPaid ? True : False; $recurringID = IntVal($recurringID); $arOrder = CSaleOrder::GetByID($orderID); if ($arOrder) { $dbBasketList = CSaleBasket::GetList(array("NAME" => "ASC"), array("ORDER_ID" => $orderID)); while ($arBasket = $dbBasketList->Fetch()) { if (strlen($arBasket["PAY_CALLBACK_FUNC"]) > 0 || strlen($arBasket["PRODUCT_PROVIDER_CLASS"]) > 0) { if ($bPaid) { /** @var $productProvider IBXSaleProductProvider */ if ($productProvider = CSaleBasket::GetProductProvider($arBasket)) { $arFields = $productProvider::DeliverProduct(array("PRODUCT_ID" => $arBasket["PRODUCT_ID"], "USER_ID" => $arOrder["USER_ID"], "PAID" => $bPaid, "ORDER_ID" => $orderID, 'BASKET_ID' => $arBasket['ID'])); } else { $arFields = CSaleBasket::ExecuteCallbackFunction($arBasket["PAY_CALLBACK_FUNC"], $arBasket["MODULE"], $arBasket["PRODUCT_ID"], $arOrder["USER_ID"], $bPaid, $orderID, $arBasket["QUANTITY"]); } if ($arFields && is_array($arFields) && count($arFields) > 0) { $arFields["ORDER_ID"] = $orderID; $arFields["REMAINING_ATTEMPTS"] = Defined("SALE_PROC_REC_ATTEMPTS") ? SALE_PROC_REC_ATTEMPTS : 3; $arFields["SUCCESS_PAYMENT"] = "Y"; if ($recurringID > 0) { CSaleRecurring::Update($recurringID, $arFields); } else { CSaleRecurring::Add($arFields); } } elseif ($recurringID > 0) { CSaleRecurring::Delete($recurringID); } } else { /** @var $productProvider IBXSaleProductProvider */ if ($productProvider = CSaleBasket::GetProductProvider($arBasket)) { $productProvider::DeliverProduct(array("PRODUCT_ID" => $arBasket["PRODUCT_ID"], "USER_ID" => $arOrder["USER_ID"], "PAID" => $bPaid, "ORDER_ID" => $orderID, 'BASKET_ID' => $arBasket['ID'])); } else { CSaleBasket::ExecuteCallbackFunction($arBasket["PAY_CALLBACK_FUNC"], $arBasket["MODULE"], $arBasket["PRODUCT_ID"], $arOrder["USER_ID"], $bPaid, $orderID, $arBasket["QUANTITY"]); } $dbRecur = CSaleRecurring::GetList(array(), array("USER_ID" => $arOrder["USER_ID"], "PRODUCT_ID" => $arBasket["PRODUCT_ID"], "MODULE" => $arBasket["MODULE"])); while ($arRecur = $dbRecur->Fetch()) { CSaleRecurring::Delete($arRecur["ID"]); } } } } } }
$REMAINING_ATTEMPTS = IntVal($REMAINING_ATTEMPTS); $SUCCESS_PAYMENT = $SUCCESS_PAYMENT == "Y" ? "Y" : "N"; $arFields = array("CANCELED" => $CANCELED, "PRIOR_DATE" => strlen($PRIOR_DATE) > 0 ? $PRIOR_DATE : False, "NEXT_DATE" => $NEXT_DATE, "DESCRIPTION" => strlen($DESCRIPTION) > 0 ? $DESCRIPTION : False, "CANCELED_REASON" => strlen($CANCELED_REASON) > 0 ? $CANCELED_REASON : False, "ORDER_ID" => $ORDER_ID, "REMAINING_ATTEMPTS" => $REMAINING_ATTEMPTS, "SUCCESS_PAYMENT" => $SUCCESS_PAYMENT); if ($saleModulePermissions >= "W") { $arFields["USER_ID"] = $USER_ID; $arFields["MODULE"] = $MODULE; $arFields["PRODUCT_ID"] = $PRODUCT_ID; $arFields["PRODUCT_NAME"] = $PRODUCT_NAME; $arFields["PRODUCT_URL"] = $PRODUCT_URL; $arFields["CALLBACK_FUNC"] = $CALLBACK_FUNC; $arFields["PRODUCT_PROVIDER_CLASS"] = $PRODUCT_PROVIDER_CLASS; } if ($ID > 0) { $res = CSaleRecurring::Update($ID, $arFields); } else { $ID = CSaleRecurring::Add($arFields); $res = $ID > 0; } if (!$res) { $bVarsFromForm = true; if ($ex = $APPLICATION->GetException()) { $errorMessage .= $ex->GetString() . ".<br>"; } else { $errorMessage .= GetMessage("SRE_ERROR_SAVING") . ".<br>"; } } else { if (strlen($apply) <= 0) { LocalRedirect("/bitrix/admin/sale_recurring_admin.php?lang=" . LANGUAGE_ID . GetFilterParams("filter_", false)); } } } else {