prepare('SELECT * FROM gift_codes WHERE stripe_checkout_session_id = ?'); $stmt->execute([$stripe_checkout_session_id]); $gift_code_entry = $stmt->fetch(); if ($gift_code_entry) { $gift_code = $gift_code_entry['code']; } else { // Generate a unique gift code $gift_code = 'GIFT-' . strtoupper(bin2hex(random_bytes(8))); $package_id = $session->metadata->package_id; $stmt = db()->prepare('INSERT INTO gift_codes (code, package_id, stripe_checkout_session_id) VALUES (?, ?, ?)'); $stmt->execute([$gift_code, $package_id, $stripe_checkout_session_id]); } ?>
Thank you for your purchase. Here is your gift code. Share it with the recipient!
= htmlspecialchars($gift_code) ?>