Why can a seller withdraw an amount larger than what is in his account?
Since there could be a situation when seller can withdraw the amount larger than this vendor’s balance
The marketplace administrator may also deny such a request or block access to the vendor panel for a vendor whose balance has become negative.
I think I posted this similar concern. Please elaborate a situation where the vendor would need to withdraw more than what is owed to them as shown in their account?
why don’t add option to active/disable withdraw larger amount!!
It is possible that this will be added in future versions.
can you help me to find the related code of request withdrawel,
i would try to add some snippet
The amount for withdrawal is being filled in the following template:
design/backend/templates/views/companies/components/balance_new_payment.tpl
In case you wish to change the backend as well, you need to check the app/controllers/backend/companies.php controller and its payouts_add
mode.
I 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
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('page_name'); // Replace 'page_name' with the actual URL to your withdrawal form
} else {
fn_companies_add_payout($_REQUEST['payment']);
}
}
$suffix = '.balance';
}
now i would might define the getAvailableBalance() function:
like:
// Create a custom add-on or include this in your own custom PHP file
function getAvailableBalance($vendorId) {
// Replace this code with your actual logic to retrieve the available balance from your data source
// You may need to query your database or fetch the balance based on the vendor's ID
$availableBalance = 0; // Replace with the actual available balance
return $availableBalance;
}
Try this one:
$vendor_payouts = \Tygh\VendorPayouts::instance(['vendor' => $vendorId]);
list($balance, ) = $vendor_payouts->getBalance();
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”
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.
That’s great!
However I strongly recommend to make these changes via add-on. For example create a pre controller with similar code.
Also some recommendations on how to improve this code:
- Instead of adding the function into the controller it will be better to add it to the func.php of this add-on.
- Instead of using
fn_redirect
function, in this controller simply return the array:
return [CONTROLLER_STATUS_REDIRECT, 'companies.balance'];
- Since this will be the pre controller, there is no need to duplicate call of the
fn_companies_add_payout
function, simply add the return withCONTROLLER_STATUS_REDIRECT
if the withdrawal amount exceeds the current balance.