Skip to content

Commit a3e94d1

Browse files
author
wrongecho
committed
- Finish updating URLs from /portal to /client
- Add a basic Stripe management page to admin settings to remove cards/reset Stripe customer IDs
1 parent 57deea2 commit a3e94d1

10 files changed

+93
-15
lines changed

admin_settings_online_payment.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
<form action="post.php" method="post" autocomplete="off">
1313
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token'] ?>">
1414

15-
<div class="alert alert-secondary">Currently, we only integrate with Stripe. Please see <a href="https://forum.itflow.org/d/439-payment-integrations-megathread" target="_blank">this forum post</a>.</div>
16-
<br>
17-
1815
<div class="form-group">
1916
<div class="custom-control custom-switch">
2017
<input type="checkbox" class="custom-control-input" name="config_stripe_enable" <?php if ($config_stripe_enable == 1) { echo "checked"; } ?> value="1" id="enableStripeSwitch">
@@ -140,6 +137,8 @@
140137

141138
</div>
142139

140+
<div class="alert alert-secondary">Currently, we only integrate with Stripe. Please see <a href="https://forum.itflow.org/d/439-payment-integrations-megathread" target="_blank">this forum post</a>.</div>
141+
143142
</div>
144143

145144
<hr>

admin_settings_online_payment_clients.php

+20
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<th>Client</th>
1919
<th>Stripe Customer ID</th>
2020
<th>Stripe Payment ID</th>
21+
<th>Action</th>
2122
</tr>
2223
</thead>
2324
<tbody>
@@ -35,6 +36,25 @@
3536
<td><?php echo "$client_name ($client_id)" ?></td>
3637
<td><?php echo $stripe_id; ?></td>
3738
<td><?php echo $stripe_pm ?></td>
39+
<td>
40+
<div class="dropdown dropleft text-center">
41+
<button class="btn btn-secondary btn-sm" type="button" data-toggle="dropdown">
42+
<i class="fas fa-ellipsis-h"></i>
43+
</button>
44+
<div class="dropdown-menu">
45+
<?php if (!empty($stripe_pm)) { ?>
46+
<a class="dropdown-item text-danger confirm-link" href="post.php?stripe_remove_pm&client_id=<?php echo $client_id ?>&pm=<?php echo $stripe_pm ?>&csrf_token=<?php echo $_SESSION['csrf_token'] ?>">
47+
<i class="fas fa-fw fa-credit-card mr-2"></i>Delete payment method
48+
</a>
49+
<?php } else { ?>
50+
<a data-toggle="tooltip" data-placement="left" title="May result in duplicate customer records in Stripe" class="dropdown-item text-danger confirm-link" href="post.php?stripe_reset_customer&client_id=<?php echo $client_id ?>&csrf_token=<?php echo $_SESSION['csrf_token'] ?>">
51+
<i class="fas fa-fw fa-trash mr-2"></i>Reset Stripe
52+
</a>
53+
<?php } ?>
54+
</div>
55+
</div>
56+
</td>
57+
3858
</tr>
3959

4060
<?php } ?>

client/autopay.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
// Manage the saved card
8989
else { ?>
9090

91-
<b>Manage saved card details</b>
91+
<b>Manage saved payment methods</b>
9292

9393
<?php
9494

@@ -120,7 +120,7 @@
120120

121121
<hr>
122122
<b>Actions</b><br>
123-
- <a href="post.php?stripe_remove_card&pm=<?php echo $stripe_pm; ?>">Remove saved card</a>
123+
- <a href="post.php?stripe_remove_pm&pm=<?php echo $stripe_pm; ?>">Remove saved payment method</a>
124124

125125
<?php } ?>
126126

client/login_microsoft.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
$client_id = $settings['config_azure_client_id'];
3030
$client_secret = $settings['config_azure_client_secret'];
3131

32-
$redirect_uri = "https://$config_base_url/portal/login_microsoft.php";
32+
$redirect_uri = "https://$config_base_url/client/login_microsoft.php";
3333

3434
# https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow
3535
$auth_code_url = "https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize";

client/post.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -633,15 +633,15 @@
633633
}
634634

635635
// Logging
636-
logAction("Stripe", "Update", "$session_contact_name added saved card ($card_info) for future automatic payments (PM: $payment_method)", $session_client_id, $session_client_id);
636+
logAction("Stripe", "Update", "$session_contact_name saved payment method ($card_info) for future automatic payments (PM: $payment_method)", $session_client_id, $session_client_id);
637637

638638
// Redirect
639-
$_SESSION['alert_message'] = "Card saved - thank you";
639+
$_SESSION['alert_message'] = "Payment method saved - thank you";
640640
header('Location: autopay.php');
641641

642642
}
643643

644-
if (isset($_GET['stripe_remove_card'])) {
644+
if (isset($_GET['stripe_remove_pm'])) {
645645

646646
if ($session_contact_primary == 0 && !$session_contact_is_billing_contact) {
647647
header("Location: post.php?logout");
@@ -678,8 +678,8 @@
678678
mysqli_query($mysqli, "UPDATE client_stripe SET stripe_pm = NULL WHERE client_id = $session_client_id LIMIT 1");
679679

680680
// Logging & Redirect
681-
logAction("Stripe", "Update", "$session_contact_name deleted saved card (PM: $payment_method)", $session_client_id, $session_client_id);
681+
logAction("Stripe", "Update", "$session_contact_name deleted saved Stripe payment method (PM: $payment_method)", $session_client_id, $session_client_id);
682682

683-
$_SESSION['alert_message'] = "Card removed";
683+
$_SESSION['alert_message'] = "Payment method removed";
684684
header('Location: autopay.php');
685685
}

guest/index.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?php
22
// Redirect to the portal
3-
header("Location: ../portal/");
3+
header("Location: ../client/");

includes/admin_side_nav.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
</li>
147147

148148
<!-- SETTINGS Section -->
149-
<li class="nav-item has-treeview mt-2 <?php echo (in_array(basename($_SERVER['PHP_SELF']), ['admin_settings_company.php', 'admin_settings_localization.php', 'admin_settings_theme.php', 'admin_settings_security.php', 'admin_settings_mail.php', 'admin_settings_notification.php', 'admin_settings_default.php', 'admin_settings_invoice.php', 'admin_settings_quote.php', 'admin_settings_online_payment.php', 'admin_settings_project.php', 'admin_settings_ticket.php', 'admin_settings_ai.php', 'admin_settings_integration.php', 'admin_settings_telemetry.php', 'admin_settings_module.php']) ? 'menu-open' : ''); ?>">
149+
<li class="nav-item has-treeview mt-2 <?php echo (in_array(basename($_SERVER['PHP_SELF']), ['admin_settings_company.php', 'admin_settings_localization.php', 'admin_settings_theme.php', 'admin_settings_security.php', 'admin_settings_mail.php', 'admin_settings_notification.php', 'admin_settings_default.php', 'admin_settings_invoice.php', 'admin_settings_quote.php', 'admin_settings_online_payment.php', 'admin_settings_online_payment_clients.php', 'admin_settings_project.php', 'admin_settings_ticket.php', 'admin_settings_ai.php', 'admin_settings_integration.php', 'admin_settings_telemetry.php', 'admin_settings_module.php']) ? 'menu-open' : ''); ?>">
150150
<a href="#" class="nav-link">
151151
<p>
152152
SETTINGS
@@ -214,6 +214,12 @@
214214
<p>Online Payment</p>
215215
</a>
216216
</li>
217+
<li class="nav-item">
218+
<a href="admin_settings_online_payment_clients.php" class="nav-link <?php echo (basename($_SERVER['PHP_SELF']) == 'admin_settings_online_payment_clients.php' ? 'active' : ''); ?>">
219+
<i class="nav-icon far fa-credit-card"></i>
220+
<p>Payment/Stripe Clients</p>
221+
</a>
222+
</li>
217223
<li class="nav-item">
218224
<a href="admin_settings_project.php" class="nav-link <?php echo (basename($_SERVER['PHP_SELF']) == 'admin_settings_project.php' ? 'active' : ''); ?>">
219225
<i class="nav-icon fas fa-project-diagram"></i>

js/autopay_setup_stripe.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ initialize();
66
// Fetch Checkout Session and retrieve the client secret
77
async function initialize() {
88
const fetchClientSecret = async () => {
9-
const response = await fetch("/portal/portal_post.php?create_stripe_checkout", {
9+
const response = await fetch("/client/post.php?create_stripe_checkout", {
1010
method: "POST",
1111
});
1212
const { clientSecret } = await response.json();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
defined('FROM_POST_HANDLER') || die("Direct file access is not allowed");
4+
5+
if (isset($_GET['stripe_remove_pm'])) {
6+
validateCSRFToken($_GET['csrf_token']);
7+
8+
if (!$config_stripe_enable) {
9+
$_SESSION['alert_message'] = "Stripe not enabled";
10+
header("Location: " . $_SERVER["HTTP_REFERER"]);
11+
exit();
12+
}
13+
14+
$client_id = intval($_GET['client_id']);
15+
$payment_method = sanitizeInput($_GET['pm']);
16+
17+
try {
18+
// Initialize stripe
19+
require_once 'vendor/stripe-php-10.5.0/init.php';
20+
$stripe = new \Stripe\StripeClient($config_stripe_secret);
21+
22+
// Detach PM
23+
$stripe->paymentMethods->detach($payment_method, []);
24+
25+
} catch (Exception $e) {
26+
$error = $e->getMessage();
27+
error_log("Stripe payment error - encountered exception when removing payment method info for $payment_method: $error");
28+
logApp("Stripe", "error", "Exception removing payment method for $payment_method: $error");
29+
}
30+
31+
// Remove payment method from ITFlow
32+
mysqli_query($mysqli, "UPDATE client_stripe SET stripe_pm = NULL WHERE client_id = $client_id LIMIT 1");
33+
34+
// Logging & Redirect
35+
logAction("Stripe", "Update", "$session_name deleted saved Stripe payment method (PM: $payment_method)", $client_id);
36+
$_SESSION['alert_message'] = "Payment method removed";
37+
header("Location: " . $_SERVER["HTTP_REFERER"]);
38+
39+
}
40+
41+
if (isset($_GET['stripe_reset_customer'])) {
42+
validateCSRFToken($_GET['csrf_token']);
43+
44+
$client_id = intval($_GET['client_id']);
45+
46+
// Delete the customer id and payment method id stored in ITFlow, allowing the client to set these up again
47+
mysqli_query($mysqli, "DELETE FROM client_stripe WHERE client_id = $client_id");
48+
49+
// Logging
50+
logAction("Stripe", "Delete", "$session_name reset Stripe settings for client", $client_id);
51+
52+
$_SESSION['alert_message'] = "Reset client Stripe settings";
53+
header("Location: " . $_SERVER["HTTP_REFERER"]);
54+
}

post/user/ticket.php

-1
Original file line numberDiff line numberDiff line change
@@ -1757,7 +1757,6 @@
17571757

17581758
// EMAIL
17591759
$subject = "Ticket closed - [$ticket_prefix$ticket_number] - $ticket_subject | (do not reply)";
1760-
//$body = "Hello $contact_name,<br><br>Your ticket regarding \"$ticket_subject\" has been closed. <br><br> We hope the request/issue was resolved to your satisfaction. If you need further assistance, please raise a new ticket using the below details. Please do not reply to this email. <br><br>Ticket: $ticket_prefix$ticket_number<br>Subject: $ticket_subject<br>Portal: https://$config_base_url/portal/ticket.php?id=$ticket_id<br><br>--<br>$company_name - Support<br>$config_ticket_from_email<br>$company_phone";
17611760
$body = "Hello $contact_name,<br><br>Your ticket regarding \"$ticket_subject\" has been closed. <br><br> We hope the request/issue was resolved to your satisfaction, please provide your feedback <a href=\'https://$config_base_url/guest/guest_view_ticket.php?ticket_id=$ticket_id&url_key=$url_key\'>here</a>. <br>If you need further assistance, please raise a new ticket using the below details. Please do not reply to this email. <br><br>Ticket: $ticket_prefix$ticket_number<br>Subject: $ticket_subject<br>Portal: https://$config_base_url/client/ticket.php?id=$ticket_id<br><br>--<br>$company_name - Support<br>$config_ticket_from_email<br>$company_phone";
17621761

17631762
// Check email valid

0 commit comments

Comments
 (0)