mirror of
https://github.com/myronblair/tomsjavajive
synced 2026-07-28 09:12:36 -05:00
Add Square payment processor, gated behind PAYMENT_PROCESSOR flag (default: stripe)
Consolidates payment processing onto the same Square account already used by tomtomgames.com and parkerslingshotrentals.com. Collapses the two prior parallel Stripe flows (hosted Checkout + embedded Elements) into a single Square Web Payments SDK flow, since Payments API is synchronous and removes the original reason for two paths. - includes/square.php: squareApi() cURL helper (mirrors the pattern already used on parkerslingshotrentals.com), markSquarePaymentResult() as the single source of truth for order completion shared by the sync response, webhook, and reconciliation poll - fixes a pre-existing bug where loyalty points were only ever awarded from the polling endpoint, never from the webhook. - api/create-square-payment.php replaces api/create-payment-intent.php; api/create-checkout-session.php deleted (no Square equivalent - single flow). - api/webhook.php rewritten for Squares signature scheme and event types. - api/payment-status.php repurposed to reconciliation-only fallback. - payment.php branches on PAYMENT_PROCESSOR so Stripe and Square code coexist deployed while dormant - flipping one config constant is the cutover/rollback. - admin/payments.php: added a Square settings card alongside the existing (now legacy-labeled) Stripe card. - db/schema.sql + live DB: added square_payment_id/square_order_id columns, stripe_* columns kept for historical orders. Not yet cut over - PAYMENT_PROCESSOR still defaults to stripe in config-secrets.php (outside this repo). Sandbox testing still needed before flipping to square/production.
This commit is contained in:
+100
-23
@@ -9,7 +9,7 @@ require_once __DIR__ . '/includes/header.php';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$section = $_POST['section'] ?? '';
|
||||
|
||||
|
||||
if ($section === 'stripe') {
|
||||
setSetting('payment_stripe', [
|
||||
'enabled' => isset($_POST['stripe_enabled']),
|
||||
@@ -20,7 +20,19 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
]);
|
||||
setFlash('success', 'Stripe settings updated');
|
||||
}
|
||||
|
||||
|
||||
if ($section === 'square') {
|
||||
setSetting('payment_square', [
|
||||
'enabled' => isset($_POST['square_enabled']),
|
||||
'sandbox' => isset($_POST['square_sandbox']),
|
||||
'app_id' => trim($_POST['square_app_id'] ?? ''),
|
||||
'location_id' => trim($_POST['square_location_id'] ?? ''),
|
||||
'access_token' => trim($_POST['square_access_token'] ?? ''),
|
||||
'webhook_signature_key' => trim($_POST['square_webhook_signature_key'] ?? '')
|
||||
]);
|
||||
setFlash('success', 'Square settings updated');
|
||||
}
|
||||
|
||||
if ($section === 'methods') {
|
||||
setSetting('payment_methods', [
|
||||
'card' => isset($_POST['method_card']),
|
||||
@@ -30,7 +42,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
]);
|
||||
setFlash('success', 'Payment methods updated');
|
||||
}
|
||||
|
||||
|
||||
header('Location: /admin/payments.php');
|
||||
exit;
|
||||
}
|
||||
@@ -43,6 +55,15 @@ $stripe = getSetting('payment_stripe', [
|
||||
'webhook_secret' => ''
|
||||
]);
|
||||
|
||||
$square = getSetting('payment_square', [
|
||||
'enabled' => defined('PAYMENT_PROCESSOR') && PAYMENT_PROCESSOR === 'square',
|
||||
'sandbox' => defined('SQUARE_ENV') && SQUARE_ENV === 'sandbox',
|
||||
'app_id' => defined('SQUARE_APP_ID') ? SQUARE_APP_ID : '',
|
||||
'location_id' => defined('SQUARE_LOCATION_ID') ? SQUARE_LOCATION_ID : '',
|
||||
'access_token' => defined('SQUARE_ACCESS_TOKEN') ? SQUARE_ACCESS_TOKEN : '',
|
||||
'webhook_signature_key' => defined('SQUARE_WEBHOOK_SIGNATURE_KEY') ? SQUARE_WEBHOOK_SIGNATURE_KEY : ''
|
||||
]);
|
||||
|
||||
$methods = getSetting('payment_methods', [
|
||||
'card' => true,
|
||||
'cash' => true,
|
||||
@@ -70,14 +91,70 @@ $methods = getSetting('payment_methods', [
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div>
|
||||
<!-- Stripe Settings -->
|
||||
<!-- Square Settings -->
|
||||
<form method="POST">
|
||||
<input type="hidden" name="section" value="square">
|
||||
<div class="admin-card">
|
||||
<div class="admin-card-header">
|
||||
<h3 class="admin-card-title"><i class="fas fa-square" style="color: #006AFF;"></i> Square</h3>
|
||||
</div>
|
||||
<div class="admin-card-body">
|
||||
<div class="form-group">
|
||||
<label style="display: flex; align-items: center; gap: 0.5rem; cursor: pointer;">
|
||||
<input type="checkbox" name="square_enabled" <?= $square['enabled'] ? 'checked' : '' ?>>
|
||||
Enable Square payments
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label style="display: flex; align-items: center; gap: 0.5rem; cursor: pointer;">
|
||||
<input type="checkbox" name="square_sandbox" <?= $square['sandbox'] ? 'checked' : '' ?>>
|
||||
Sandbox mode (use sandbox app/location/token)
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label">Application ID</label>
|
||||
<input type="text" name="square_app_id" class="form-input"
|
||||
value="<?= htmlspecialchars($square['app_id']) ?>"
|
||||
placeholder="sq0idp-...">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label">Location ID</label>
|
||||
<input type="text" name="square_location_id" class="form-input"
|
||||
value="<?= htmlspecialchars($square['location_id']) ?>"
|
||||
placeholder="L...">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label">Access Token</label>
|
||||
<input type="password" name="square_access_token" class="form-input"
|
||||
value="<?= htmlspecialchars($square['access_token']) ?>"
|
||||
placeholder="EAAA...">
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-0">
|
||||
<label class="form-label">Webhook Signature Key</label>
|
||||
<input type="password" name="square_webhook_signature_key" class="form-input"
|
||||
value="<?= htmlspecialchars($square['webhook_signature_key']) ?>"
|
||||
placeholder="...">
|
||||
<small class="text-muted">From the Square Developer Dashboard's webhook subscription for this site</small>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary mt-2">Save Square Settings</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<!-- Stripe Settings (legacy) -->
|
||||
<form method="POST">
|
||||
<input type="hidden" name="section" value="stripe">
|
||||
<div class="admin-card">
|
||||
<div class="admin-card-header">
|
||||
<h3 class="admin-card-title"><i class="fab fa-stripe" style="color: #635BFF;"></i> Stripe</h3>
|
||||
<h3 class="admin-card-title"><i class="fab fa-stripe" style="color: #635BFF;"></i> Stripe <small class="text-muted">(legacy)</small></h3>
|
||||
</div>
|
||||
<div class="admin-card-body">
|
||||
<div class="form-group">
|
||||
@@ -86,41 +163,41 @@ $methods = getSetting('payment_methods', [
|
||||
Enable Stripe payments
|
||||
</label>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label style="display: flex; align-items: center; gap: 0.5rem; cursor: pointer;">
|
||||
<input type="checkbox" name="stripe_test_mode" <?= $stripe['test_mode'] ? 'checked' : '' ?>>
|
||||
Test mode (use test keys)
|
||||
</label>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label">Publishable Key</label>
|
||||
<input type="text" name="stripe_publishable_key" class="form-input"
|
||||
value="<?= htmlspecialchars($stripe['publishable_key']) ?>"
|
||||
<input type="text" name="stripe_publishable_key" class="form-input"
|
||||
value="<?= htmlspecialchars($stripe['publishable_key']) ?>"
|
||||
placeholder="pk_test_... or pk_live_...">
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label">Secret Key</label>
|
||||
<input type="password" name="stripe_secret_key" class="form-input"
|
||||
value="<?= htmlspecialchars($stripe['secret_key']) ?>"
|
||||
<input type="password" name="stripe_secret_key" class="form-input"
|
||||
value="<?= htmlspecialchars($stripe['secret_key']) ?>"
|
||||
placeholder="sk_test_... or sk_live_...">
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group mb-0">
|
||||
<label class="form-label">Webhook Secret</label>
|
||||
<input type="password" name="stripe_webhook_secret" class="form-input"
|
||||
value="<?= htmlspecialchars($stripe['webhook_secret']) ?>"
|
||||
<input type="password" name="stripe_webhook_secret" class="form-input"
|
||||
value="<?= htmlspecialchars($stripe['webhook_secret']) ?>"
|
||||
placeholder="whsec_...">
|
||||
<small class="text-muted">Get this from your Stripe webhook settings</small>
|
||||
</div>
|
||||
|
||||
|
||||
<button type="submit" class="btn btn-primary mt-2">Save Stripe Settings</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
|
||||
<!-- POS Payment Methods -->
|
||||
<form method="POST">
|
||||
<input type="hidden" name="section" value="methods">
|
||||
@@ -130,35 +207,35 @@ $methods = getSetting('payment_methods', [
|
||||
</div>
|
||||
<div class="admin-card-body">
|
||||
<p class="text-muted" style="margin-bottom: 1rem;">Select which payment methods are available in the Point of Sale system.</p>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label style="display: flex; align-items: center; gap: 0.5rem; cursor: pointer;">
|
||||
<input type="checkbox" name="method_card" <?= $methods['card'] ? 'checked' : '' ?>>
|
||||
<i class="fas fa-credit-card"></i> Card (Terminal)
|
||||
</label>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label style="display: flex; align-items: center; gap: 0.5rem; cursor: pointer;">
|
||||
<input type="checkbox" name="method_cash" <?= $methods['cash'] ? 'checked' : '' ?>>
|
||||
<i class="fas fa-money-bill"></i> Cash
|
||||
</label>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label style="display: flex; align-items: center; gap: 0.5rem; cursor: pointer;">
|
||||
<input type="checkbox" name="method_wallet" <?= $methods['wallet'] ? 'checked' : '' ?>>
|
||||
<i class="fas fa-wallet"></i> Customer Wallet
|
||||
</label>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group mb-0">
|
||||
<label style="display: flex; align-items: center; gap: 0.5rem; cursor: pointer;">
|
||||
<input type="checkbox" name="method_gift_card" <?= $methods['gift_card'] ? 'checked' : '' ?>>
|
||||
<i class="fas fa-gift"></i> Gift Card
|
||||
</label>
|
||||
</div>
|
||||
|
||||
|
||||
<button type="submit" class="btn btn-primary mt-2">Save Payment Methods</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user