mirror of https://github.com/itflow-org/itflow
Initial work on Adding Payment Methods for Online Payments in Client on Agent Side and initial work on AI Providers with multiple model support assigned to various sections and custom prompts
This commit is contained in:
parent
6bc7862232
commit
9b6be66623
|
|
@ -0,0 +1,130 @@
|
|||
<?php
|
||||
|
||||
require_once "includes/inc_all_client.php";
|
||||
|
||||
// Perms
|
||||
enforceUserPermission('module_sales');
|
||||
|
||||
// Initialize stripe
|
||||
require_once 'plugins/stripe-php/init.php';
|
||||
|
||||
// Get Stripe vars
|
||||
$stripe_vars = mysqli_fetch_array(mysqli_query($mysqli, "SELECT config_stripe_enable, config_stripe_publishable, config_stripe_secret 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']);
|
||||
|
||||
// Get client's StripeID from database
|
||||
$stripe_client_details = mysqli_fetch_array(mysqli_query($mysqli, "SELECT * FROM client_stripe WHERE client_id = $client_id LIMIT 1"));
|
||||
if ($stripe_client_details) {
|
||||
$stripe_id = sanitizeInput($stripe_client_details['stripe_id']);
|
||||
$stripe_pm = sanitizeInput($stripe_client_details['stripe_pm']);
|
||||
}
|
||||
|
||||
// Stripe not enabled in settings
|
||||
if (!$config_stripe_enable || !$config_stripe_publishable || !$config_stripe_secret) {
|
||||
echo "Stripe payment error - Stripe is not enabled, please talk to your helpdesk for further information.";
|
||||
include_once 'includes/footer.php';
|
||||
exit();
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div class="card card-dark">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title"><i class="fa fa-redo-alt mr-2"></i>AutoPay</h3>
|
||||
</div>
|
||||
|
||||
<div class="card-body">
|
||||
<!-- Setup pt1: Stripe ID not found / auto-payment not configured -->
|
||||
<?php if (!$stripe_client_details || empty($stripe_id)) { ?>
|
||||
|
||||
<b>Save card details</b><br>
|
||||
In order to set up automatic payments, you must create a customer record in Stripe.<br>
|
||||
First, you must authorize Stripe to store your card details for the purpose of automatic payment.
|
||||
<br><br>
|
||||
|
||||
<div class="col-5">
|
||||
<form action="post.php" method="POST">
|
||||
|
||||
<div class="form-group">
|
||||
<div class="custom-control custom-checkbox">
|
||||
<input class="custom-control-input" type="checkbox" id="consent" name="consent" value="1" required>
|
||||
<label for="consent" class="custom-control-label">
|
||||
I grant consent for automatic payments
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<button type="submit" class="form-control btn-success" name="create_stripe_customer">Create Stripe Customer Record</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?php }
|
||||
|
||||
// Setup pt2: Stripe ID found / payment may be configured -->
|
||||
elseif (empty($stripe_pm)) { ?>
|
||||
|
||||
<b>Save card details</b><br>
|
||||
Please add the payment details you would like to save.<br>
|
||||
By adding payment details here, you grant consent for future automatic payments of invoices.<br><br>
|
||||
|
||||
<input type="hidden" id="stripe_publishable_key" value="<?php echo $config_stripe_publishable ?>">
|
||||
<script src="https://js.stripe.com/v3/"></script>
|
||||
<script src="js/autopay_setup_stripe.js"></script>
|
||||
<div id="checkout">
|
||||
<!-- Checkout will insert the payment form here -->
|
||||
</div>
|
||||
|
||||
<?php }
|
||||
|
||||
// Manage the saved card
|
||||
else { ?>
|
||||
|
||||
<b>Manage saved payment methods</b>
|
||||
|
||||
<?php
|
||||
|
||||
try {
|
||||
// Initialize
|
||||
$stripe = new \Stripe\StripeClient($config_stripe_secret);
|
||||
|
||||
// Get payment method info (last 4 digits etc)
|
||||
$payment_method = $stripe->customers->retrievePaymentMethod(
|
||||
$stripe_id,
|
||||
$stripe_pm,
|
||||
[]
|
||||
);
|
||||
|
||||
} catch (Exception $e) {
|
||||
$error = $e->getMessage();
|
||||
error_log("Stripe payment error - encountered exception when fetching payment method info for $stripe_pm: $error");
|
||||
logApp("Stripe", "error", "Exception when fetching payment method info for $stripe_pm: $error");
|
||||
}
|
||||
|
||||
$card_name = nullable_htmlentities($payment_method->billing_details->name);
|
||||
$card_brand = nullable_htmlentities($payment_method->card->display_brand);
|
||||
$card_last4 = nullable_htmlentities($payment_method->card->last4);
|
||||
$card_expires = nullable_htmlentities($payment_method->card->exp_month) . "/" . nullable_htmlentities($payment_method->card->exp_year);
|
||||
|
||||
?>
|
||||
|
||||
<ul><li><?php echo "$card_name - $card_brand card ending in $card_last4, expires $card_expires"; ?></li></ul>
|
||||
|
||||
<hr>
|
||||
<b>Actions</b><br>
|
||||
- <a href="post.php?stripe_remove_pm&pm=<?php echo $stripe_pm; ?>">Remove saved payment method</a>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
||||
require_once "includes/footer.php";
|
||||
|
|
@ -3680,10 +3680,35 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) {
|
|||
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '2.2.1'");
|
||||
}
|
||||
|
||||
// if (CURRENT_DATABASE_VERSION == '2.2.1') {
|
||||
// // Insert queries here required to update to DB version 2.2.2
|
||||
if (CURRENT_DATABASE_VERSION == '2.2.1') {
|
||||
mysqli_query($mysqli, "CREATE TABLE `ai_providers` (
|
||||
`ai_provider_id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`ai_provider_name` VARCHAR(200) NOT NULL,
|
||||
`ai_provider_api_url` VARCHAR(200) NOT NULL,
|
||||
`ai_provider_api_key` VARCHAR(200) DEFAULT NULL,
|
||||
`ai_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`ai_updated_at` DATETIME NULL ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`ai_provider_id`)
|
||||
)");
|
||||
|
||||
mysqli_query($mysqli, "CREATE TABLE `ai_provider_models` (
|
||||
`ai_model_provider_id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`ai_model_provider_name` VARCHAR(200) NOT NULL,
|
||||
`ai_model_prompt` TEXT DEFAULT NULL,
|
||||
`ai_model_use_case` VARCHAR(200) DEFAULT NULL,
|
||||
`ai_model_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`ai_model_updated_at` DATETIME NULL ON UPDATE CURRENT_TIMESTAMP,
|
||||
`ai_model_ai_provider_id` INT(11) NOT NULL,
|
||||
PRIMARY KEY (`ai_model_provider_id`)
|
||||
)");
|
||||
|
||||
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '2.2.2'");
|
||||
}
|
||||
|
||||
// if (CURRENT_DATABASE_VERSION == '2.2.2') {
|
||||
// // Insert queries here required to update to DB version 2.2.3
|
||||
// // Then, update the database to the next sequential version
|
||||
// mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '2.2.2'");
|
||||
// mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '2.2.3'");
|
||||
// }
|
||||
|
||||
} else {
|
||||
|
|
|
|||
41
db.sql
41
db.sql
|
|
@ -1,4 +1,4 @@
|
|||
/*M!999999\- enable the sandbox mode */
|
||||
/*M!999999\- enable the sandbox mode */
|
||||
-- MariaDB dump 10.19 Distrib 10.11.11-MariaDB, for debian-linux-gnu (x86_64)
|
||||
--
|
||||
-- Host: localhost Database: itflow_dev
|
||||
|
|
@ -38,6 +38,43 @@ CREATE TABLE `accounts` (
|
|||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `ai_provider_models`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `ai_provider_models`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `ai_provider_models` (
|
||||
`ai_model_provider_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`ai_model_provider_name` varchar(200) NOT NULL,
|
||||
`ai_model_prompt` text DEFAULT NULL,
|
||||
`ai_model_use_case` varchar(200) DEFAULT NULL,
|
||||
`ai_model_created_at` datetime NOT NULL DEFAULT current_timestamp(),
|
||||
`ai_model_updated_at` datetime DEFAULT NULL ON UPDATE current_timestamp(),
|
||||
`ai_model_ai_provider_id` int(11) NOT NULL,
|
||||
PRIMARY KEY (`ai_model_provider_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `ai_providers`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `ai_providers`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `ai_providers` (
|
||||
`ai_provider_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`ai_provider_name` varchar(200) NOT NULL,
|
||||
`ai_provider_api_url` varchar(200) NOT NULL,
|
||||
`ai_provider_api_key` varchar(200) DEFAULT NULL,
|
||||
`ai_created_at` datetime NOT NULL DEFAULT current_timestamp(),
|
||||
`ai_updated_at` datetime DEFAULT NULL ON UPDATE current_timestamp(),
|
||||
PRIMARY KEY (`ai_provider_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `api_keys`
|
||||
--
|
||||
|
|
@ -2591,4 +2628,4 @@ CREATE TABLE `vendors` (
|
|||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||
|
||||
-- Dump completed on 2025-06-21 18:33:02
|
||||
-- Dump completed on 2025-07-04 15:39:35
|
||||
|
|
|
|||
|
|
@ -5,4 +5,4 @@
|
|||
* It is used in conjunction with database_updates.php
|
||||
*/
|
||||
|
||||
DEFINE("LATEST_DATABASE_VERSION", "2.2.1");
|
||||
DEFINE("LATEST_DATABASE_VERSION", "2.2.2");
|
||||
|
|
|
|||
Loading…
Reference in New Issue