mirror of
https://github.com/myronblair/tomsjavajive
synced 2026-06-30 17:50:32 -05:00
Fix loyalty system: load tiers from DB, award points on payment
- LoyaltyProgram now loads tiers from loyalty_tiers DB table in constructor with fallback to hardcoded defaults if table is empty - awardPoints() accepts order_id param with duplicate-prevention check so points cannot be double-awarded for the same order - Inserts balance_after into loyalty_transactions for accurate history - payment-status.php: award points after Stripe checkout session or PaymentIntent confirmed as paid - create-checkout-session.php: award points in demo mode payment path Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
|
||||
require_once __DIR__ . '/../includes/functions.php';
|
||||
require_once __DIR__ . '/../includes/stripe.php';
|
||||
require_once __DIR__ . '/../includes/loyalty.php';
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
@@ -52,7 +53,16 @@ if (!isStripeConfigured()) {
|
||||
'order_id = :id',
|
||||
['id' => $orderId]
|
||||
);
|
||||
|
||||
|
||||
if (!empty($order['customer_id'])) {
|
||||
loyalty()->awardPoints(
|
||||
$order['customer_id'],
|
||||
(float) $order['total'],
|
||||
'Order #' . $order['order_number'],
|
||||
$orderId
|
||||
);
|
||||
}
|
||||
|
||||
jsonResponse([
|
||||
'demo_mode' => true,
|
||||
'message' => 'Payment simulated (Stripe not configured)',
|
||||
|
||||
+23
-2
@@ -6,6 +6,7 @@
|
||||
|
||||
require_once __DIR__ . '/../includes/functions.php';
|
||||
require_once __DIR__ . '/../includes/stripe.php';
|
||||
require_once __DIR__ . '/../includes/loyalty.php';
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
@@ -75,7 +76,17 @@ try {
|
||||
'order_id = :id',
|
||||
['id' => $order['order_id']]
|
||||
);
|
||||
|
||||
|
||||
// Award loyalty points
|
||||
if (!empty($order['customer_id'])) {
|
||||
loyalty()->awardPoints(
|
||||
$order['customer_id'],
|
||||
(float) $order['total'],
|
||||
'Order #' . $order['order_number'],
|
||||
$order['order_id']
|
||||
);
|
||||
}
|
||||
|
||||
jsonResponse([
|
||||
'status' => 'complete',
|
||||
'payment_status' => 'paid',
|
||||
@@ -104,7 +115,17 @@ try {
|
||||
'order_id = :id',
|
||||
['id' => $order['order_id']]
|
||||
);
|
||||
|
||||
|
||||
// Award loyalty points
|
||||
if (!empty($order['customer_id'])) {
|
||||
loyalty()->awardPoints(
|
||||
$order['customer_id'],
|
||||
(float) $order['total'],
|
||||
'Order #' . $order['order_number'],
|
||||
$order['order_id']
|
||||
);
|
||||
}
|
||||
|
||||
jsonResponse([
|
||||
'status' => 'complete',
|
||||
'payment_status' => 'paid',
|
||||
|
||||
Reference in New Issue
Block a user