The seller can withdraw an amount greater than what is in his account

yeah right
it work now
modify payouts_add on app/controllers/backend/companies.php in line 217 to 223

if ($mode == 'payouts_add') {
           if (!empty($_REQUEST['payment']['amount'])) {
               fn_companies_add_payout($_REQUEST['payment']);
           }

           $suffix = '.balance';
       }

to

function getAvailableBalance($vendorId) {
            $vendor_payouts = \Tygh\VendorPayouts::instance(['vendor' => $vendorId]);
            list($balance, ) = $vendor_payouts->getBalance();
        
            return $balance;
        }

       if ($mode == 'payouts_add') {
    if (!empty($_REQUEST['payment']['amount'])) {
            $withdrawalAmount = floatval($_REQUEST['payment']['amount']);
            $vendorId = (int)$_REQUEST['payment']['vendor'];
    
            // Call the function with the vendor ID to get the available balance
            $availableBalance = getAvailableBalance($vendorId);
    
            if ($withdrawalAmount > $availableBalance) {
                // Set an error message and redirect back to the withdrawal form
                fn_set_notification('E', __('error'), __('withdrawal_amount_exceeds_balance'));
                fn_redirect('companies.balance'); // Replace 'page_name' with the actual URL to your withdrawal form
            } else {
                fn_companies_add_payout($_REQUEST['payment']);
            }
        }
    
        $suffix = '.balance';
    }

don’t miss add translated word of error “withdrawal_amount_exceeds_balance”

1 Like