Remove Static payment processing fees from database and update field hints with useful info when adding / editing payment provider

This commit is contained in:
johnnyq
2026-07-22 17:32:01 -04:00
parent 8ee780566e
commit 5402578ce6
7 changed files with 166 additions and 77 deletions

View File

@@ -4394,10 +4394,16 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) {
}
// if (CURRENT_DATABASE_VERSION == '2.4.4') {
// // Insert queries here required to update to DB version 2.4.5
// // Then, update the database to the next sequential version
// mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '2.4.5'");
if (CURRENT_DATABASE_VERSION == '2.4.4') {
// Gateway fee expense now uses the actual fee from Stripe's balance transaction
mysqli_query($mysqli, "ALTER TABLE `payment_providers` DROP `payment_provider_expense_percentage_fee`, DROP `payment_provider_expense_flat_fee`");
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '2.4.5'");
}
// if (CURRENT_DATABASE_VERSION == '2.4.5') {
// // Insert queries here required to update to DB version 2.4.6
// mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '2.4.6'");
// }
} else {

View File

@@ -16,11 +16,6 @@ ob_start();
<div class="modal-body">
<div class="alert alert-info text-center">
<h6>Before Adding a Payment Provider!</h6>
We recommend you add an <strong>Account</strong> and <strong>Vendor</strong> based off the Provider name before continuing eg <strong>Stripe</strong>
</div>
<ul class="nav nav-pills nav-justified mb-3">
<li class="nav-item">
<a class="nav-link active" data-toggle="pill" href="#pills-details">Details</a>
@@ -90,6 +85,7 @@ ob_start();
?>
</select>
</div>
<small class="form-text text-muted">Should havea seperate account created off the payment provider's name e.g. Stripe</small>
</div>
<div class="form-group">
@@ -107,6 +103,10 @@ ob_start();
<div class="tab-pane fade" id="pills-expense">
<div class="alert alert-info text-center">
Payment Processing Fee Expenses get reconciled nighly via the cron
</div>
<div class="form-group">
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" name="enable_expense" checked value="1" id="enableExpenseSwitch">
@@ -136,6 +136,7 @@ ob_start();
?>
</select>
</div>
<small class="form-text text-muted">Payment Privider name e.g. Stripe</small>
</div>
<div class="form-group">
@@ -166,29 +167,8 @@ ob_start();
</button>
</div>
</div>
</div>
<div class="form-group">
<label>Percentage Fee to expense</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" inputmode="decimal" pattern="[0-9]*\.?[0-9]{0,2}" name="percentage_fee" placeholder="Enter Percentage">
</div>
<small class="form-text text-muted">See <a href="https://stripe.com/pricing" target="_blank">here <i class="fas fa-fw fa-external-link-alt"></i></a> for the latest Stripe Fees.</small>
</div>
<div class="form-group">
<label>Flat Fee to expense</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" inputmode="decimal" pattern="[0-9]*\.?[0-9]{0,3}" name="flat_fee" placeholder="0.030">
</div>
<small class="form-text text-muted">See <a href="https://stripe.com/pricing" target="_blank">here <i class="fas fa-fw fa-external-link-alt"></i></a> for the latest Stripe Fees.</small>
</div>
<small class="form-text text-muted">Processing Fee, Credit Card Fee etc</small>
</div>
</div>
</div>

View File

@@ -14,12 +14,11 @@ $account_id = intval($row['payment_provider_account']);
$threshold = floatval($row['payment_provider_threshold']);
$vendor_id = intval($row['payment_provider_expense_vendor']);
$category_id = intval($row['payment_provider_expense_category']);
$percent_fee = floatval($row['payment_provider_expense_percentage_fee']) * 100;
$flat_fee = floatval($row['payment_provider_expense_flat_fee']);
// Generate the HTML form content using output buffering.
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title"><i class="fa fa-fw fa-credit-card mr-2"></i>Editing: <strong><?= $provider_name ?></strong></h5>
<button type="button" class="close text-white" data-dismiss="modal">
@@ -89,6 +88,7 @@ ob_start();
?>
</select>
</div>
<small class="form-text text-muted">Should havea seperate account created off the payment provider's name e.g. Stripe</small>
</div>
<div class="form-group">
@@ -106,6 +106,10 @@ ob_start();
<div class="tab-pane fade" id="pills-expense">
<div class="alert alert-info text-center">
Payment Processing Fee Expenses get reconciled nighly via the cron
</div>
<div class="form-group">
<label>Payment Provider Vendor <strong class="text-danger">*</strong></label>
<div class="input-group">
@@ -130,6 +134,7 @@ ob_start();
?>
</select>
</div>
<small class="form-text text-muted">Payment Privider name e.g. Stripe</small>
</div>
<div class="form-group">
@@ -160,28 +165,7 @@ ob_start();
</button>
</div>
</div>
</div>
<div class="form-group">
<label>Percentage Fee to expense</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" inputmode="decimal" pattern="[0-9]*\.?[0-9]{0,2}" name="percentage_fee" value="<?php echo $percent_fee; ?>" placeholder="Enter Percentage">
</div>
<small class="form-text text-muted">See <a href="https://stripe.com/pricing" target="_blank">here <i class="fas fa-fw fa-external-link-alt"></i></a> for the latest Stripe Fees.</small>
</div>
<div class="form-group">
<label>Flat Fee to expense</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" inputmode="decimal" pattern="[0-9]*\.?[0-9]{0,3}" name="flat_fee" value="<?php echo $flat_fee; ?>" placeholder="0.030">
</div>
<small class="form-text text-muted">See <a href="https://stripe.com/pricing" target="_blank">here <i class="fas fa-fw fa-external-link-alt"></i></a> for the latest Stripe Fees.</small>
<small class="form-text text-muted">Processing Fee, Credit Card Fee etc</small>
</div>
</div>
</div>

View File

@@ -54,9 +54,6 @@ $num_rows = mysqli_num_rows($sql);
Expense Category <?php if ($sort == 'category_name') { echo $order_icon; } ?>
</a>
</th>
<th>
<a class="text-dark">Expensed Fee</a>
</th>
<th class="text-center">
<a class="text-dark">Saved Payment Methods</a>
</th>
@@ -72,10 +69,13 @@ $num_rows = mysqli_num_rows($sql);
$provider_description = escapeHtml($row['payment_provider_description']);
$account_name = escapeHtml($row['account_name']);
$threshold = floatval($row['payment_provider_threshold']);
if (!$threshold) {
$threshold = "Not Enforced";
} else {
$threshold = numfmt_format_currency($currency_format, $threshold, $session_company_currency);
}
$vendor_name = escapeHtml($row['vendor_name'] ?? "Expense Disabled");
$category = escapeHtml($row['category_name']);
$percent_fee = floatval($row['payment_provider_expense_percentage_fee']) * 100;
$flat_fee = floatval($row['payment_provider_expense_flat_fee']);
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('saved_payment_id') AS saved_payment_count FROM client_saved_payment_methods WHERE saved_payment_provider_id = $provider_id"));
$saved_payment_count = intval($row['saved_payment_count']);
@@ -90,10 +90,9 @@ $num_rows = mysqli_num_rows($sql);
<span class="text-secondary"><?php echo $provider_description; ?></span>
</td>
<td><?php echo $account_name; ?></td>
<td><?php echo numfmt_format_currency($currency_format, $threshold, $session_company_currency); ?></td>
<td><?= $threshold ?></td>
<td><?php echo $vendor_name; ?></td>
<td><?php echo $category; ?></td>
<td><?php echo $percent_fee; ?>% + <?php echo numfmt_format_currency($currency_format, $flat_fee, $session_company_currency); ?></td>
<td class="text-center">
<a class="badge badge-dark badge-pill p-2" href="saved_payment_methods.php"><?= $saved_payment_count ?></a>
</td>

View File

@@ -17,8 +17,6 @@ if (isset($_POST['add_payment_provider'])) {
$account = intval($_POST['account']);
$expense_vendor = intval($_POST['expense_vendor']) ?? 0;
$expense_category = intval($_POST['expense_category']) ?? 0;
$percentage_fee = floatval($_POST['percentage_fee']) / 100 ?? 0;
$flat_fee = floatval($_POST['flat_fee']) ?? 0;
// Check to ensure provider isn't added twice
$sql = mysqli_query($mysqli, "SELECT 1 FROM payment_providers WHERE payment_provider_name = '$provider' LIMIT 1");
@@ -27,7 +25,7 @@ if (isset($_POST['add_payment_provider'])) {
redirect();
}
mysqli_query($mysqli,"INSERT INTO payment_providers SET payment_provider_name = '$provider', payment_provider_public_key = '$public_key', payment_provider_private_key = '$private_key', payment_provider_threshold = $threshold, payment_provider_account = $account, payment_provider_expense_vendor = $expense_vendor, payment_provider_expense_category = $expense_category, payment_provider_expense_percentage_fee = $percentage_fee, payment_provider_expense_flat_fee = $flat_fee");
mysqli_query($mysqli,"INSERT INTO payment_providers SET payment_provider_name = '$provider', payment_provider_public_key = '$public_key', payment_provider_private_key = '$private_key', payment_provider_threshold = $threshold, payment_provider_account = $account, payment_provider_expense_vendor = $expense_vendor, payment_provider_expense_category = $expense_category");
$provider_id = mysqli_insert_id($mysqli);
@@ -51,10 +49,8 @@ if (isset($_POST['edit_payment_provider'])) {
$account = intval($_POST['account']);
$expense_vendor = intval($_POST['expense_vendor']) ?? 0;
$expense_category = intval($_POST['expense_category']) ?? 0;
$percentage_fee = floatval($_POST['percentage_fee']) / 100;
$flat_fee = floatval($_POST['flat_fee']);
mysqli_query($mysqli,"UPDATE payment_providers SET payment_provider_public_key = '$public_key', payment_provider_private_key = '$private_key', payment_provider_threshold = $threshold, payment_provider_account = $account, payment_provider_expense_vendor = $expense_vendor, payment_provider_expense_category = $expense_category, payment_provider_expense_percentage_fee = $percentage_fee, payment_provider_expense_flat_fee = $flat_fee WHERE payment_provider_id = $provider_id");
mysqli_query($mysqli,"UPDATE payment_providers SET payment_provider_public_key = '$public_key', payment_provider_private_key = '$private_key', payment_provider_threshold = $threshold, payment_provider_account = $account, payment_provider_expense_vendor = $expense_vendor, payment_provider_expense_category = $expense_category WHERE payment_provider_id = $provider_id");
logAudit("Payment Provider", "Edit", "$session_name edited Payment Provider $provider");
@@ -71,7 +67,7 @@ if (isset($_GET['delete_payment_provider'])) {
$provider_id = intval($_GET['delete_payment_provider']);
// When deleted it cascades deletes
// all Recurring paymentes related to payment provider
// all Recurring payments related to payment provider
// Delete all Saved Cards related
// Delete Client Payment Provider Releation

134
db.sql
View File

@@ -1,9 +1,9 @@
/*M!999999\- enable the sandbox mode */
-- MariaDB dump 10.19 Distrib 10.11.14-MariaDB, for debian-linux-gnu (x86_64)
-- MariaDB dump 10.19 Distrib 10.11.18-MariaDB, for debian-linux-gnu (x86_64)
--
-- Host: localhost Database: itflow_dev
-- ------------------------------------------------------
-- Server version 10.11.14-MariaDB-0+deb12u2
-- Server version 10.11.18-MariaDB-0+deb12u1
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
@@ -962,6 +962,132 @@ CREATE TABLE `custom_fields` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `custom_hosting_api_keys`
--
DROP TABLE IF EXISTS `custom_hosting_api_keys`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `custom_hosting_api_keys` (
`api_key_id` int(11) NOT NULL AUTO_INCREMENT,
`api_key_name` varchar(200) NOT NULL,
`api_key_url` varchar(250) NOT NULL,
`api_key_token_id` varchar(200) NOT NULL,
`api_key_token_secret` varchar(250) NOT NULL,
`api_key_created_at` datetime NOT NULL DEFAULT current_timestamp(),
PRIMARY KEY (`api_key_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `custom_hosting_networks`
--
DROP TABLE IF EXISTS `custom_hosting_networks`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `custom_hosting_networks` (
`network_id` int(11) NOT NULL AUTO_INCREMENT,
`network_name` varchar(200) NOT NULL,
`network` varchar(100) NOT NULL,
`network_mask` varchar(100) NOT NULL,
`gateway` varchar(100) NOT NULL,
`network_start` varchar(100) NOT NULL,
`network_end` varchar(100) NOT NULL,
PRIMARY KEY (`network_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `custom_hosting_plans`
--
DROP TABLE IF EXISTS `custom_hosting_plans`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `custom_hosting_plans` (
`plan_id` int(11) NOT NULL AUTO_INCREMENT,
`plan_name` varchar(250) NOT NULL,
`plan_description` text NOT NULL,
`plan_created_at` datetime NOT NULL DEFAULT current_timestamp(),
PRIMARY KEY (`plan_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `custom_hosting_regions`
--
DROP TABLE IF EXISTS `custom_hosting_regions`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `custom_hosting_regions` (
`region_id` int(11) NOT NULL AUTO_INCREMENT,
`region_name` varchar(200) NOT NULL,
`region_created_at` datetime NOT NULL DEFAULT current_timestamp(),
PRIMARY KEY (`region_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `custom_hosting_servers`
--
DROP TABLE IF EXISTS `custom_hosting_servers`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `custom_hosting_servers` (
`server_id` int(11) NOT NULL AUTO_INCREMENT,
`server_node` varchar(200) NOT NULL,
`server_storage` varchar(200) NOT NULL,
`server_created_at` datetime NOT NULL DEFAULT current_timestamp(),
`server_region_id` int(11) NOT NULL,
`server_api_key_id` varchar(200) NOT NULL,
PRIMARY KEY (`server_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `custom_hosting_vm_templates`
--
DROP TABLE IF EXISTS `custom_hosting_vm_templates`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `custom_hosting_vm_templates` (
`template_id` int(11) NOT NULL AUTO_INCREMENT,
`template_name` varchar(200) NOT NULL,
`vcpus` int(11) NOT NULL,
`memory` int(11) NOT NULL,
`disk` int(11) NOT NULL,
`template_created_at` datetime NOT NULL DEFAULT current_timestamp(),
`template_plan_id` int(11) NOT NULL,
PRIMARY KEY (`template_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `custom_hosting_vms`
--
DROP TABLE IF EXISTS `custom_hosting_vms`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `custom_hosting_vms` (
`vm_id` int(11) NOT NULL AUTO_INCREMENT,
`vm_hostname` varchar(200) NOT NULL,
`vm_ip` varchar(100) NOT NULL,
`vm_created_at` datetime NOT NULL DEFAULT current_timestamp(),
`vm_network_id` int(11) NOT NULL,
`vm_server_id` int(11) NOT NULL,
`vm_template_id` int(11) NOT NULL,
`vm_recurring_invoice_id` int(11) DEFAULT NULL,
`vm_client_id` int(11) NOT NULL,
PRIMARY KEY (`vm_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `custom_links`
--
@@ -1508,8 +1634,6 @@ CREATE TABLE `payment_providers` (
`payment_provider_account` int(11) NOT NULL,
`payment_provider_expense_vendor` int(11) NOT NULL DEFAULT 0,
`payment_provider_expense_category` int(11) NOT NULL DEFAULT 0,
`payment_provider_expense_percentage_fee` decimal(4,4) DEFAULT NULL,
`payment_provider_expense_flat_fee` decimal(15,2) DEFAULT NULL,
`payment_provider_created_at` datetime NOT NULL DEFAULT current_timestamp(),
`payment_provider_updated_at` datetime DEFAULT NULL ON UPDATE current_timestamp(),
PRIMARY KEY (`payment_provider_id`)
@@ -2997,4 +3121,4 @@ CREATE TABLE `vendors` (
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2026-04-04 18:13:53
-- Dump completed on 2026-07-22 17:26:08

View File

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