mirror of
https://github.com/myronblair/tomsjavajive
synced 2026-07-28 01:02:35 -05:00
11edf3394f
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.
247 lines
11 KiB
PHP
247 lines
11 KiB
PHP
<?php
|
|
ob_start();
|
|
/**
|
|
* Tom's Java Jive - Admin Payment Settings
|
|
*/
|
|
|
|
$pageTitle = 'Payment Settings';
|
|
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']),
|
|
'test_mode' => isset($_POST['stripe_test_mode']),
|
|
'publishable_key' => trim($_POST['stripe_publishable_key'] ?? ''),
|
|
'secret_key' => trim($_POST['stripe_secret_key'] ?? ''),
|
|
'webhook_secret' => trim($_POST['stripe_webhook_secret'] ?? '')
|
|
]);
|
|
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']),
|
|
'cash' => isset($_POST['method_cash']),
|
|
'wallet' => isset($_POST['method_wallet']),
|
|
'gift_card' => isset($_POST['method_gift_card'])
|
|
]);
|
|
setFlash('success', 'Payment methods updated');
|
|
}
|
|
|
|
header('Location: /admin/payments.php');
|
|
exit;
|
|
}
|
|
|
|
$stripe = getSetting('payment_stripe', [
|
|
'enabled' => true,
|
|
'test_mode' => true,
|
|
'publishable_key' => '',
|
|
'secret_key' => '',
|
|
'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,
|
|
'wallet' => true,
|
|
'gift_card' => true
|
|
]);
|
|
?>
|
|
|
|
<div class="page-header">
|
|
<h1 class="page-title">Payment Settings</h1>
|
|
</div>
|
|
|
|
<?php if (hasFlash('success')): ?>
|
|
<div class="alert alert-success"><i class="fas fa-check-circle"></i> <?= getFlash('success') ?></div>
|
|
<?php endif; ?>
|
|
|
|
<div style="display: grid; grid-template-columns: 200px 1fr; gap: 1.5rem;">
|
|
<div>
|
|
<div class="admin-card">
|
|
<div class="admin-card-body" style="padding: 0.5rem;">
|
|
<a href="/admin/settings.php" class="nav-item"><i class="fas fa-store"></i> General</a>
|
|
<a href="/admin/shipping.php" class="nav-item"><i class="fas fa-truck"></i> Shipping</a>
|
|
<a href="/admin/payments.php" class="nav-item active"><i class="fas fa-credit-card"></i> Payments</a>
|
|
<a href="/admin/emails.php" class="nav-item"><i class="fas fa-envelope"></i> Emails</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<!-- 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 <small class="text-muted">(legacy)</small></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="stripe_enabled" <?= $stripe['enabled'] ? 'checked' : '' ?>>
|
|
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']) ?>"
|
|
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']) ?>"
|
|
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']) ?>"
|
|
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">
|
|
<div class="admin-card">
|
|
<div class="admin-card-header">
|
|
<h3 class="admin-card-title">POS Payment Methods</h3>
|
|
</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>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|