Add More Configurable variabled for Stripe including such as Flat Rate and Percent Fees, expense vendor and expense category update guest stripe pay to take advantage of these vars and updated settings

This commit is contained in:
johnnyq 2024-01-28 00:00:28 -05:00
parent 777637277b
commit b986f04a0c
7 changed files with 112 additions and 35 deletions

View File

@ -1559,14 +1559,26 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) {
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.0.2'");
}
if (CURRENT_DATABASE_VERSION == '1.0.2') {
//Insert queries here required to update to DB version 1.0.3
mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_stripe_expense_vendor` INT(11) NOT NULL DEFAULT 0 AFTER `config_stripe_account`");
mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_stripe_expense_category` INT(11) NOT NULL DEFAULT 0 AFTER `config_stripe_expense_vendor`");
mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_stripe_percentage_fee` DECIMAL(4,4) NOT NULL DEFAULT 0.029 AFTER `config_stripe_expense_category`");
mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_stripe_flat_fee` DECIMAL(15,2) NOT NULL DEFAULT 0.30 AFTER `config_stripe_percentage_fee`");
mysqli_query($mysqli, "ALTER TABLE `settings` CHANGE `config_stripe_account` `config_stripe_account` INT(11) NOT NULL DEFAULT 0");
//Then, update the database to the next sequential version
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.0.3'");
}
// Be sure to change database_version.php to reflect the version you are updating to here
// Please add this same comment block to the bottom of this file, and update the version number.
// Uncomment Below Lines, to add additional database updates
//
// if (CURRENT_DATABASE_VERSION == '1.0.2') {
// // Insert queries here required to update to DB version 1.0.3
// if (CURRENT_DATABASE_VERSION == '1.0.3') {
// // Insert queries here required to update to DB version 1.0.4
// // Then, update the database to the next sequential version
// mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.0.3'");
// mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.0.4'");
// }
} else {

View File

@ -5,5 +5,5 @@
* It is used in conjunction with database_updates.php
*/
DEFINE("LATEST_DATABASE_VERSION", "1.0.2");
DEFINE("LATEST_DATABASE_VERSION", "1.0.3");

8
db.sql
View File

@ -1270,7 +1270,11 @@ CREATE TABLE `settings` (
`config_stripe_enable` tinyint(1) NOT NULL DEFAULT 0,
`config_stripe_publishable` varchar(255) DEFAULT NULL,
`config_stripe_secret` varchar(255) DEFAULT NULL,
`config_stripe_account` tinyint(1) NOT NULL DEFAULT 0,
`config_stripe_account` int(11) NOT NULL DEFAULT 0,
`config_stripe_expense_vendor` int(11) NOT NULL DEFAULT 0,
`config_stripe_expense_category` int(11) NOT NULL DEFAULT 0,
`config_stripe_percentage_fee` decimal(4,4) NOT NULL DEFAULT 0.0290,
`config_stripe_flat_fee` decimal(15,2) NOT NULL DEFAULT 0.30,
`config_stripe_client_pays_fees` tinyint(1) NOT NULL DEFAULT 0,
`config_azure_client_id` varchar(200) DEFAULT NULL,
`config_azure_client_secret` varchar(200) DEFAULT NULL,
@ -1756,4 +1760,4 @@ CREATE TABLE `vendors` (
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2024-01-15 13:07:46
-- Dump completed on 2024-01-27 23:58:10

View File

@ -79,11 +79,15 @@ $config_enable_alert_domain_expire = intval($row['config_enable_alert_domain_exp
$config_send_invoice_reminders = intval($row['config_send_invoice_reminders']);
$config_invoice_overdue_reminders = intval($row['config_invoice_overdue_reminders']);
// Online Payment
// Online Stripe Payment
$config_stripe_enable = intval($row['config_stripe_enable']);
$config_stripe_publishable = $row['config_stripe_publishable'];
$config_stripe_secret = $row['config_stripe_secret'];
$config_stripe_account = $row['config_stripe_account'];
$config_stripe_account = intval($row['config_stripe_account']);
$config_stripe_expense_vendor = intval($row['config_stripe_expense_vendor']);
$config_stripe_expense_category = intval($row['config_stripe_expense_category']);
$config_stripe_percentage_fee = floatval($row['config_stripe_percentage_fee']);
$config_stripe_flat_fee = floatval($row['config_stripe_flat_fee']);
$config_stripe_client_pays_fees = intval($row['config_stripe_client_pays_fees']);
// Modules

View File

@ -15,11 +15,15 @@ function log_to_console($message)
DEFINE("WORDING_PAYMENT_FAILED", "<br><h2>There was an error verifying your payment. Please contact us for more information.</h2>");
// Setup Stripe
$stripe_vars = mysqli_fetch_array(mysqli_query($mysqli, "SELECT config_stripe_enable, config_stripe_publishable, config_stripe_secret, config_stripe_account, config_stripe_client_pays_fees FROM settings WHERE company_id = 1"));
$stripe_vars = mysqli_fetch_array(mysqli_query($mysqli, "SELECT config_stripe_enable, config_stripe_publishable, config_stripe_secret, config_stripe_account, config_stripe_expense_vendor, config_stripe_expense_category, config_stripe_percentage_fee, config_stripe_flat_fee, config_stripe_client_pays_fees FROM settings WHERE company_id = 1"));
$config_stripe_enable = intval($stripe_vars['config_stripe_enable']);
$config_stripe_publishable = nullable_htmlentities($stripe_vars['config_stripe_publishable']);
$config_stripe_secret = nullable_htmlentities($stripe_vars['config_stripe_secret']);
$config_stripe_account = intval($stripe_vars['config_stripe_account']);
$config_stripe_expense_vendor = intval($row['config_stripe_expense_vendor']);
$config_stripe_expense_category = intval($row['config_stripe_expense_category']);
$config_stripe_percentage_fee = floatval($row['config_stripe_percentage_fee']);
$config_stripe_flat_fee = floatval($row['config_stripe_flat_fee']);
$config_stripe_client_pays_fees = intval($stripe_vars['config_stripe_client_pays_fees']);
// Check Stripe is configured
@ -85,10 +89,8 @@ if (isset($_GET['invoice_id'], $_GET['url_key']) && !isset($_GET['payment_intent
// Check config to see if client pays fees is enabled
if ($config_stripe_client_pays_fees == 1) {
$balance_before_fees = $balance_to_pay;
$percentage_fee = 0.029;
$flat_fee = 0.30;
// Calculate the amount to charge the client
$balance_to_pay = ($balance_to_pay + $flat_fee) / (1 - $percentage_fee);
$balance_to_pay = ($balance_to_pay + $config_stripe_flat_fee) / (1 - $config_stripe_percentage_fee);
// Calculate the fee amount
$gateway_fee = round($balance_to_pay - $balance_before_fees, 2);
@ -279,10 +281,8 @@ if (isset($_GET['invoice_id'], $_GET['url_key']) && !isset($_GET['payment_intent
// Check config to see if client pays fees is enabled
if ($config_stripe_client_pays_fees == 1) {
$percentage_fee = 0.029;
$flat_fee = 0.30;
// Calculate the amount to charge the client
$balance_to_pay = ($balance_to_pay + $flat_fee) / (1 - $percentage_fee);
$balance_to_pay = ($balance_to_pay + $config_stripe_flat_fee) / (1 - $config_stripe_percentage_fee);
}
// Round balance to pay to 2 decimal places

View File

@ -373,8 +373,13 @@ if (isset($_POST['edit_online_payment_settings'])) {
$config_stripe_publishable = sanitizeInput($_POST['config_stripe_publishable']);
$config_stripe_secret = sanitizeInput($_POST['config_stripe_secret']);
$config_stripe_account = intval($_POST['config_stripe_account']);
$config_stripe_expense_vendor = intval($_POST['config_stripe_expense_vendor']);
$config_stripe_expense_category = intval($_POST['config_stripe_expense_category']);
$config_stripe_percentage_fee = floatval($_POST['config_stripe_percentage_fee']);
$config_stripe_flat_fee = floatval($_POST['config_stripe_flat_fee']);
$config_stripe_client_pays_fees = intval($_POST['config_stripe_client_pays_fees']);
mysqli_query($mysqli,"UPDATE settings SET config_stripe_enable = $config_stripe_enable, config_stripe_publishable = '$config_stripe_publishable', config_stripe_secret = '$config_stripe_secret', config_stripe_account = $config_stripe_account WHERE company_id = 1");
mysqli_query($mysqli,"UPDATE settings SET config_stripe_enable = $config_stripe_enable, config_stripe_publishable = '$config_stripe_publishable', config_stripe_secret = '$config_stripe_secret', config_stripe_account = $config_stripe_account, config_stripe_expense_vendor = $config_stripe_expense_vendor, config_stripe_expense_category = $config_stripe_expense_category, config_stripe_percentage_fee = $config_stripe_percentage_fee, config_stripe_flat_fee = $config_stripe_flat_fee, config_stripe_client_pays_fees = $config_stripe_client_pays_fees WHERE company_id = 1");
//Logging
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Settings', log_action = 'Modify', log_description = '$session_name modified online payment settings', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id");
@ -889,19 +894,3 @@ if (isset($_GET['update_db'])) {
header("Location: " . $_SERVER["HTTP_REFERER"]);
}
if (isset($_POST['config_stripe_client_pays_fees'])) {
validateAdminRole();
$config_stripe_client_pays_fees = intval($_POST['config_stripe_client_pays_fees']);
mysqli_query($mysqli,"UPDATE settings SET config_stripe_client_pays_fees = $config_stripe_client_pays_fees WHERE company_id = 1");
//Logging
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Settings', log_action = 'Modify', log_description = '$session_name modified stripe client pays fees', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id");
$_SESSION['alert_message'] = "Stripe client pays fees updated";
header("Location: " . $_SERVER["HTTP_REFERER"]);
}

View File

@ -21,7 +21,8 @@ require_once "inc_all_settings.php";
</div>
</div>
<?php if ($config_stripe_enable == 1) { ?>
<div class="<?php if ($config_stripe_enable == 0) { echo "d-none"; } ?>">
<div class="form-group">
<label>Publishable</label>
@ -44,7 +45,7 @@ require_once "inc_all_settings.php";
</div>
<div class="form-group">
<label>Account</label>
<label>Expense / Income Account</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-fw fa-piggy-bank"></i></span>
@ -65,15 +66,82 @@ require_once "inc_all_settings.php";
</select>
</div>
</div>
<div class="form-group">
<label>Expense Vendor <strong class="text-danger">*</strong></label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-building"></i></span>
</div>
<select class="form-control select2" name="config_stripe_expense_vendor" required>
<?php
$sql_select = mysqli_query($mysqli, "SELECT vendor_id, vendor_name FROM vendors WHERE vendor_client_id = 0 AND vendor_template = 0 AND vendor_archived_at IS NULL ORDER BY vendor_name ASC");
while ($row = mysqli_fetch_array($sql_select)) {
$vendor_id = intval($row['vendor_id']);
$vendor_name = nullable_htmlentities($row['vendor_name']);
?>
<option <?php if ($config_stripe_expense_vendor == $vendor_id) { ?> selected <?php } ?> value="<?php echo $vendor_id; ?>"><?php echo $vendor_name; ?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="form-group">
<label>Expense Category <strong class="text-danger">*</strong></label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-list"></i></span>
</div>
<select class="form-control select2" name="config_stripe_expense_category" required>
<?php
$sql_select = mysqli_query($mysqli, "SELECT category_id, category_name FROM categories WHERE category_type = 'Expense' AND category_archived_at IS NULL ORDER BY category_name ASC");
while ($row = mysqli_fetch_array($sql_select)) {
$category_id = intval($row['category_id']);
$category_name = nullable_htmlentities($row['category_name']);
?>
<option <?php if ($config_stripe_expense_category == $category_id) { ?> selected <?php } ?> value="<?php echo $category_id; ?>"><?php echo $category_name; ?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="form-group">
<label>Client Pays Fees</label>
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" name="config_stripe_client_pays_fees" <?php if ($config_stripe_client_pays_fees == 1) { echo "checked"; } ?> value="1" id="clientPaysFeesSwitch">
<label class="custom-control-label" for="clientPaysFeesSwitch">Enable</label>
</div>
</div>
<div class="form-group">
<label>Percentage Fee</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-percent"></i></span>
</div>
<input type="text" class="form-control" name="config_stripe_percentage_fee" placeholder="Enter a %" value="<?php echo $config_stripe_percentage_fee; ?>">
</div>
</div>
<?php } ?>
<div class="form-group">
<label>Flat Fee</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-shopping-cart"></i></span>
</div>
<input type="text" class="form-control" name="config_stripe_flat_fee" placeholder="0.030" value="<?php echo $config_stripe_flat_fee; ?>">
</div>
</div>
</div>
<hr>