Tot funcionant al 100% i amb Looker
This commit is contained in:
+1383
-36
File diff suppressed because it is too large
Load Diff
+56
-2
@@ -11,8 +11,8 @@ return [
|
||||
// Moneda
|
||||
'currency' => 'eur',
|
||||
|
||||
// On guardar les comandes provisionals
|
||||
'orders_storage_dir' => __DIR__ . '/data',
|
||||
// On guardar les comandes i logs
|
||||
'orders_storage_dir' => dirname(__DIR__) . '/data',
|
||||
|
||||
// URLs públiques
|
||||
'success_url' => 'https://kapvoe-portfoli.treblarella.org/checkout/payment-success.php',
|
||||
@@ -20,4 +20,58 @@ return [
|
||||
|
||||
'stock_sync_url' => 'https://script.google.com/macros/s/AKfycbyH6PuQPR342mwSiKCkYZ1lOnn1VccqzFO-ScbhwjvJoABU3LqVNJcS3gtPE5ZuT0JyvQ/exec',
|
||||
'stock_sync_token' => 'kapvoe_stock_2026_x7F9mQpL2vN8rT4sZ1kW',
|
||||
|
||||
'catalog_api_url' => 'https://kapvoe-portfoli.treblarella.org/api/products.php',
|
||||
|
||||
// Tracking i analytics per Google Sheets / Looker Studio
|
||||
'analytics_enabled' => true,
|
||||
'analytics_sync_url' => 'https://script.google.com/macros/s/AKfycbyyK8fAytZcPHuJKn-LVItMC8BAyTz0jzHml47vvfOHsTwhetCITND_-_yNd7HqickQ/exec',
|
||||
'analytics_sync_token' => 'kapvoe_analitycs_2026_x7F9mQpL2vN8rT4sZ1kW',
|
||||
'analytics_timeout' => 10,
|
||||
|
||||
// Correu sortint
|
||||
// Si vols dependre nomes de la Synology, fes servir 'smtp'.
|
||||
// Opcions: auto | mail | smtp | resend
|
||||
'mail_transport' => 'smtp',
|
||||
'mail_from_email' => 'pedidos@bloodbros.store',
|
||||
'mail_from_name' => 'Blood Bros Sports',
|
||||
'mail_reply_to' => 'pedidos@bloodbros.store',
|
||||
|
||||
// API HTTP de correu. Recomanat si el hosting falla amb mail() o SMTP.
|
||||
// Amb Resend nomes cal una API key i el domini verificat.
|
||||
'resend_api_key' => '',
|
||||
'resend_api_url' => 'https://api.resend.com/emails',
|
||||
|
||||
// AvÃs intern de noves comandes
|
||||
// SMTP sortint. Activa-ho si el servidor no envia be amb mail().
|
||||
// SMTP sortint. Idealment apunta al servidor SMTP de la teva Synology.
|
||||
// Exemples habituals:
|
||||
// - NAS mateixa maquina: 127.0.0.1
|
||||
// - NAS a la LAN: 192.168.x.x
|
||||
'smtp_enabled' => true,
|
||||
'smtp_host' => 'mail.bloodbros.store',
|
||||
'smtp_port' => 587,
|
||||
'smtp_encryption' => 'tls',
|
||||
'smtp_username' => 'pedidos@bloodbros.store',
|
||||
'smtp_password' => '2%0Jx5zv',
|
||||
'smtp_timeout' => 15,
|
||||
// Prova de compatibilitat TLS per hostings/PHPs restrictius.
|
||||
// Activa-ho nomes per provar si el problema es la validacio del certificat.
|
||||
'smtp_allow_invalid_certificates' => true,
|
||||
|
||||
// Avis intern per correu
|
||||
'admin_notification_email' => 'pedidos@bloodbros.store',
|
||||
|
||||
// Avis intern independent del correu.
|
||||
// Si poses un webhook intern de la Synology, es cridara per cada compra pagada.
|
||||
// Si ho deixes buit, es guardara a data/internal-notifications.log
|
||||
'internal_notification_enabled' => true,
|
||||
'internal_notification_webhook_url' => '',
|
||||
'internal_notification_webhook_token' => '',
|
||||
'internal_notification_timeout' => 10,
|
||||
'internal_notification_log_path' => dirname(__DIR__) . '/data/internal-notifications.log',
|
||||
|
||||
// Token per eines internes com el test de correu.
|
||||
// Posa-hi un valor llarg i privat abans d'usar test-mail.php
|
||||
'admin_tools_token' => 'kapvoe-test-2026-9xF2mL7qP4sT8vN1',
|
||||
];
|
||||
|
||||
@@ -3,65 +3,108 @@ declare(strict_types=1);
|
||||
|
||||
require __DIR__ . '/common.php';
|
||||
|
||||
const KAPVOE_SHIPPING_PRICE = 7.99;
|
||||
|
||||
kapvoe_require_post();
|
||||
$config = kapvoe_load_config();
|
||||
$data = kapvoe_json_input();
|
||||
|
||||
$required = [
|
||||
'product_code',
|
||||
'product_name',
|
||||
'price',
|
||||
'quantity',
|
||||
'customer_name',
|
||||
'address',
|
||||
'postal_code',
|
||||
'city',
|
||||
'province',
|
||||
'phone',
|
||||
'email',
|
||||
];
|
||||
|
||||
$errors = kapvoe_validate_required($data, $required);
|
||||
|
||||
if (!filter_var((string)($data['email'] ?? ''), FILTER_VALIDATE_EMAIL)) {
|
||||
$errors['email'] = 'Correu electrònic invàlid';
|
||||
}
|
||||
if (!preg_match('/^\d{5}$/', (string)($data['postal_code'] ?? ''))) {
|
||||
$errors['postal_code'] = 'Codi postal invàlid';
|
||||
}
|
||||
|
||||
if (!preg_match('/^[0-9+\s]{8,20}$/', (string)($data['phone'] ?? ''))) {
|
||||
$errors['phone'] = 'Telèfon invàlid';
|
||||
}
|
||||
|
||||
$price = (float)str_replace(',', '.', (string)$data['price']);
|
||||
$quantity = max(1, (int)$data['quantity']);
|
||||
$quantity = max(1, (int)($data['quantity'] ?? 1));
|
||||
|
||||
if ($price <= 0) {
|
||||
$errors['price'] = 'Preu invàlid';
|
||||
$productCode = trim((string)($data['product_code'] ?? ''));
|
||||
$shippingMethod = ((string)($data['shipping_method'] ?? 'pickup') === 'shipping') ? 'shipping' : 'pickup';
|
||||
$shippingCost = $shippingMethod === 'shipping' ? KAPVOE_SHIPPING_PRICE : 0.0;
|
||||
|
||||
$address = trim((string)($data['address'] ?? ''));
|
||||
$postalCode = trim((string)($data['postal_code'] ?? ''));
|
||||
$city = trim((string)($data['city'] ?? ''));
|
||||
$province = trim((string)($data['province'] ?? ''));
|
||||
|
||||
if ($shippingMethod === 'shipping') {
|
||||
if ($address === '') {
|
||||
$errors['address'] = 'Adreça obligatòria si hi ha enviament';
|
||||
}
|
||||
if (!preg_match('/^\d{5}$/', $postalCode)) {
|
||||
$errors['postal_code'] = 'Codi postal invàlid';
|
||||
}
|
||||
if ($city === '') {
|
||||
$errors['city'] = 'Ciutat obligatòria si hi ha enviament';
|
||||
}
|
||||
if ($province === '') {
|
||||
$errors['province'] = 'Província obligatòria si hi ha enviament';
|
||||
}
|
||||
}
|
||||
|
||||
if ($errors) {
|
||||
kapvoe_json_response(['ok' => false, 'errors' => $errors], 422);
|
||||
}
|
||||
|
||||
$orderId = 'ORD-' . date('Ymd-His') . '-' . substr(bin2hex(random_bytes(3)), 0, 6);
|
||||
$unitAmountCents = (int)round($price * 100);
|
||||
|
||||
$payload = [
|
||||
'order_id' => $orderId,
|
||||
'product_code' => trim((string)$data['product_code']),
|
||||
'product_name' => trim((string)$data['product_name']),
|
||||
'unit_amount_cents' => $unitAmountCents,
|
||||
'quantity' => $quantity,
|
||||
'customer_name' => trim((string)$data['customer_name']),
|
||||
'address' => trim((string)$data['address']),
|
||||
'postal_code' => trim((string)$data['postal_code']),
|
||||
'city' => trim((string)$data['city']),
|
||||
'province' => trim((string)$data['province']),
|
||||
'phone' => trim((string)$data['phone']),
|
||||
'email' => trim((string)$data['email']),
|
||||
];
|
||||
|
||||
try {
|
||||
$catalogProduct = kapvoe_get_catalog_product_by_code($config, $productCode);
|
||||
|
||||
$realPrice = (float)($catalogProduct['europe_price_number'] ?? 0);
|
||||
if ($realPrice <= 0) {
|
||||
throw new RuntimeException("El producte {$productCode} no té un preu vàlid");
|
||||
}
|
||||
|
||||
$productName = trim((string)($catalogProduct['product_code'] ?? $productCode));
|
||||
$productImageUrl = trim((string)($catalogProduct['image_url'] ?? ''));
|
||||
|
||||
$orderId = 'ORD-' . date('Ymd-His') . '-' . substr(bin2hex(random_bytes(3)), 0, 6);
|
||||
|
||||
$unitAmountCents = (int)round($realPrice * 100);
|
||||
$subtotalCents = $unitAmountCents * $quantity;
|
||||
$shippingCostCents = (int)round($shippingCost * 100);
|
||||
$totalAmountCents = $subtotalCents + $shippingCostCents;
|
||||
|
||||
$payload = [
|
||||
'order_id' => $orderId,
|
||||
'product_code' => $productCode,
|
||||
'product_name' => $productName,
|
||||
'unit_amount_cents' => $unitAmountCents,
|
||||
'quantity' => $quantity,
|
||||
'customer_name' => trim((string)$data['customer_name']),
|
||||
'phone' => trim((string)$data['phone']),
|
||||
'email' => trim((string)$data['email']),
|
||||
'analytics_session_id' => trim((string)($data['analytics_session_id'] ?? '')),
|
||||
'analytics_page_url' => trim((string)($data['analytics_page_url'] ?? '')),
|
||||
'analytics_referrer' => trim((string)($data['analytics_referrer'] ?? '')),
|
||||
'analytics_user_agent' => trim((string)($data['analytics_user_agent'] ?? '')),
|
||||
'analytics_utm_source' => trim((string)($data['analytics_utm_source'] ?? '')),
|
||||
'analytics_utm_medium' => trim((string)($data['analytics_utm_medium'] ?? '')),
|
||||
'analytics_utm_campaign' => trim((string)($data['analytics_utm_campaign'] ?? '')),
|
||||
'analytics_device_type' => trim((string)($data['analytics_device_type'] ?? '')),
|
||||
'analytics_page_type' => trim((string)($data['analytics_page_type'] ?? 'catalog')),
|
||||
|
||||
'shipping_method' => $shippingMethod,
|
||||
'shipping_cost_cents' => $shippingCostCents,
|
||||
'subtotal_cents' => $subtotalCents,
|
||||
'total_amount_cents' => $totalAmountCents,
|
||||
|
||||
'address' => $address,
|
||||
'postal_code' => $postalCode,
|
||||
'city' => $city,
|
||||
'province' => $province,
|
||||
];
|
||||
|
||||
$session = kapvoe_create_checkout_session($config, $payload);
|
||||
|
||||
kapvoe_append_order($config, [
|
||||
@@ -69,8 +112,13 @@ try {
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'product_code' => $payload['product_code'],
|
||||
'product_name' => $payload['product_name'],
|
||||
'unit_price' => $price,
|
||||
'product_image_url' => $productImageUrl,
|
||||
'unit_price' => number_format($realPrice, 2, '.', ''),
|
||||
'quantity' => $quantity,
|
||||
'subtotal' => number_format($subtotalCents / 100, 2, '.', ''),
|
||||
'shipping_method' => $shippingMethod,
|
||||
'shipping_cost' => number_format($shippingCostCents / 100, 2, '.', ''),
|
||||
'total_amount' => number_format($totalAmountCents / 100, 2, '.', ''),
|
||||
'customer_name' => $payload['customer_name'],
|
||||
'address' => $payload['address'],
|
||||
'postal_code' => $payload['postal_code'],
|
||||
@@ -78,9 +126,24 @@ try {
|
||||
'province' => $payload['province'],
|
||||
'phone' => $payload['phone'],
|
||||
'email' => $payload['email'],
|
||||
'analytics_session_id' => $payload['analytics_session_id'],
|
||||
'analytics_page_url' => $payload['analytics_page_url'],
|
||||
'analytics_referrer' => $payload['analytics_referrer'],
|
||||
'analytics_user_agent' => $payload['analytics_user_agent'],
|
||||
'analytics_utm_source' => $payload['analytics_utm_source'],
|
||||
'analytics_utm_medium' => $payload['analytics_utm_medium'],
|
||||
'analytics_utm_campaign' => $payload['analytics_utm_campaign'],
|
||||
'analytics_device_type' => $payload['analytics_device_type'],
|
||||
'analytics_page_type' => $payload['analytics_page_type'],
|
||||
'payment_status' => 'pending',
|
||||
'stripe_session_id' => $session['id'] ?? '',
|
||||
'payment_intent_id' => '',
|
||||
'stock_updated' => '0',
|
||||
'stock_updated_at' => '',
|
||||
'webhook_processed_at' => '',
|
||||
'customer_email_sent' => '0',
|
||||
'admin_email_sent' => '0',
|
||||
'email_notifications_sent_at' => '',
|
||||
]);
|
||||
|
||||
kapvoe_json_response([
|
||||
|
||||
+154
-11
@@ -1,20 +1,163 @@
|
||||
<!doctype html>
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="ca">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>Pagament cancel·lat</title>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Pagament cancel·lat · Blood Bros Sports</title>
|
||||
<link rel="icon" type="image/png" href="/assets/logo/bloodbros-sports-logo.png">
|
||||
<style>
|
||||
body{font-family:Arial,Helvetica,sans-serif;background:#081221;color:#fff;margin:0;padding:40px}
|
||||
.box{max-width:780px;margin:auto;background:#0f1d34;border:1px solid rgba(255,255,255,.12);border-radius:24px;padding:32px}
|
||||
a{color:#7dd3fc}
|
||||
:root{
|
||||
--bg-1:#040b16;
|
||||
--bg-2:#071425;
|
||||
--bg-3:#091a30;
|
||||
--text:#f4f7fb;
|
||||
--muted:#9fb0ca;
|
||||
--shadow:0 16px 44px rgba(0,0,0,.34);
|
||||
}
|
||||
|
||||
*{box-sizing:border-box}
|
||||
html,body{margin:0;padding:0}
|
||||
body{
|
||||
font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
|
||||
color:var(--text);
|
||||
background:
|
||||
radial-gradient(circle at 12% 10%, rgba(52,122,255,.18), transparent 24%),
|
||||
radial-gradient(circle at 82% 12%, rgba(100,196,255,.12), transparent 24%),
|
||||
linear-gradient(180deg, var(--bg-1) 0%, var(--bg-2) 38%, var(--bg-3) 100%);
|
||||
min-height:100vh;
|
||||
}
|
||||
|
||||
.wrap{
|
||||
max-width:900px;
|
||||
margin:0 auto;
|
||||
padding:48px 18px;
|
||||
}
|
||||
|
||||
.card{
|
||||
border-radius:32px;
|
||||
border:1px solid rgba(255,255,255,.10);
|
||||
background:
|
||||
radial-gradient(circle at 75% 15%, rgba(104,133,255,.18), transparent 28%),
|
||||
linear-gradient(180deg, rgba(17,29,52,.95), rgba(12,20,36,.98));
|
||||
box-shadow:var(--shadow);
|
||||
padding:28px;
|
||||
}
|
||||
|
||||
.head{
|
||||
display:flex;
|
||||
align-items:center;
|
||||
gap:18px;
|
||||
margin-bottom:18px;
|
||||
}
|
||||
|
||||
.logo-wrap{
|
||||
width:84px;
|
||||
height:84px;
|
||||
border-radius:24px;
|
||||
background:linear-gradient(135deg, rgba(255,255,255,.08), rgba(255,255,255,.03));
|
||||
border:1px solid rgba(255,255,255,.10);
|
||||
display:flex;
|
||||
align-items:center;
|
||||
justify-content:center;
|
||||
overflow:hidden;
|
||||
flex:0 0 auto;
|
||||
}
|
||||
|
||||
.logo-wrap img{
|
||||
max-width:82%;
|
||||
max-height:82%;
|
||||
object-fit:contain;
|
||||
display:block;
|
||||
}
|
||||
|
||||
h1{
|
||||
margin:0 0 6px;
|
||||
font-size:24px;
|
||||
font-weight:1000;
|
||||
}
|
||||
|
||||
p{
|
||||
margin:0;
|
||||
color:var(--muted);
|
||||
font-size:16px;
|
||||
line-height:1.5;
|
||||
}
|
||||
|
||||
.actions{
|
||||
display:flex;
|
||||
gap:12px;
|
||||
flex-wrap:wrap;
|
||||
margin-top:26px;
|
||||
}
|
||||
|
||||
.btn{
|
||||
min-height:52px;
|
||||
padding:0 20px;
|
||||
border-radius:999px;
|
||||
border:1px solid rgba(255,255,255,.10);
|
||||
text-decoration:none;
|
||||
display:inline-flex;
|
||||
align-items:center;
|
||||
justify-content:center;
|
||||
font-weight:900;
|
||||
color:#fff;
|
||||
background:rgba(255,255,255,.05);
|
||||
}
|
||||
|
||||
.btn-primary{
|
||||
background:linear-gradient(180deg, rgba(93,154,255,.34), rgba(52,115,214,.28));
|
||||
border-color:rgba(100,196,255,.24);
|
||||
}
|
||||
|
||||
@media (max-width:640px){
|
||||
.head{
|
||||
align-items:flex-start;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="box">
|
||||
<h1>Pagament cancel·lat</h1>
|
||||
<p>No s'ha completat el pagament. Pots tornar al catàleg i provar-ho de nou.</p>
|
||||
<p><a href="https://kapvoe-portfoli.treblarella.org/">Torna al catàleg</a></p>
|
||||
<div class="wrap">
|
||||
<div class="card">
|
||||
<div class="head">
|
||||
<div class="logo-wrap">
|
||||
<img src="/assets/logo/bloodbros-sports-logo.png" alt="Blood Bros Sports">
|
||||
</div>
|
||||
<div>
|
||||
<h1>Pagament cancel·lat</h1>
|
||||
<p>No s'ha completat la compra. Si vols, pots tornar al catàleg i reprendre la comanda quan et vagi bé.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<a class="btn btn-primary" href="/">Torna al catàleg</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
(function () {
|
||||
try {
|
||||
var key = 'kapvoe_session_id';
|
||||
var sessionId = localStorage.getItem(key) || '';
|
||||
fetch('/api/track-event.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
keepalive: true,
|
||||
body: JSON.stringify({
|
||||
event_type: 'payment_cancel',
|
||||
session_id: sessionId,
|
||||
page_url: window.location.href,
|
||||
referrer: document.referrer || '',
|
||||
user_agent: navigator.userAgent || '',
|
||||
device_type: /mobile|android|iphone|ipod/i.test(navigator.userAgent || '') ? 'mobile' : 'desktop',
|
||||
page_type: 'checkout'
|
||||
})
|
||||
});
|
||||
} catch (e) {}
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+458
-15
@@ -1,26 +1,469 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
$sessionId = htmlspecialchars($_GET['session_id'] ?? '', ENT_QUOTES, 'UTF-8');
|
||||
?><!doctype html>
|
||||
|
||||
require_once __DIR__ . '/common.php';
|
||||
|
||||
$config = kapvoe_load_config();
|
||||
$sessionId = trim((string)($_GET['session_id'] ?? ''));
|
||||
$order = null;
|
||||
$product = null;
|
||||
$error = '';
|
||||
$catalogProductMissing = false;
|
||||
$mailRetryResult = null;
|
||||
|
||||
if ($sessionId === '') {
|
||||
$error = 'Falta el codi de sessió de Stripe.';
|
||||
} else {
|
||||
$order = kapvoe_get_order_by_session_id($config, $sessionId);
|
||||
|
||||
if (!$order) {
|
||||
$error = 'No s\'ha trobat la comanda associada a aquesta sessió.';
|
||||
} else {
|
||||
try {
|
||||
$product = kapvoe_get_catalog_product_by_code(
|
||||
$config,
|
||||
(string)($order['product_code'] ?? '')
|
||||
);
|
||||
} catch (Throwable $e) {
|
||||
$product = null;
|
||||
$catalogProductMissing = true;
|
||||
}
|
||||
|
||||
if ((string)($order['payment_status'] ?? '') === 'paid') {
|
||||
try {
|
||||
$mailRetryResult = kapvoe_send_order_notifications($config, $order, $sessionId);
|
||||
$order = kapvoe_get_order_by_session_id($config, $sessionId) ?? $order;
|
||||
} catch (Throwable $e) {
|
||||
$mailRetryResult = [
|
||||
'error' => $e->getMessage(),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function kapvoe_find_local_product_image_url(string $productCode): string {
|
||||
$productCode = trim($productCode);
|
||||
if ($productCode === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
foreach (['png', 'jpg', 'jpeg', 'webp'] as $ext) {
|
||||
$absolutePath = dirname(__DIR__) . "/assets/products/{$productCode}.{$ext}";
|
||||
if (is_file($absolutePath)) {
|
||||
return "/assets/products/{$productCode}.{$ext}";
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
function e(?string $value): string {
|
||||
return htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
function fmt_eur($value): string {
|
||||
$n = (float)$value;
|
||||
return number_format($n, 2, ',', '.') . ' €';
|
||||
}
|
||||
|
||||
$productCode = (string)($order['product_code'] ?? '');
|
||||
$imageUrl = trim((string)($order['product_image_url'] ?? ''));
|
||||
if ($imageUrl === '') {
|
||||
$imageUrl = (string)($product['image_url'] ?? '');
|
||||
}
|
||||
if ($imageUrl === '') {
|
||||
$imageUrl = kapvoe_find_local_product_image_url($productCode);
|
||||
}
|
||||
$shippingMethod = (string)($order['shipping_method'] ?? 'pickup');
|
||||
$subtotal = (string)($order['subtotal'] ?? $order['unit_price'] ?? '0.00');
|
||||
$shippingCost = (string)($order['shipping_cost'] ?? '0.00');
|
||||
$totalAmount = (string)($order['total_amount'] ?? $order['unit_price'] ?? '0.00');
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="ca">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>Pagament correcte</title>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Compra confirmada · Blood Bros Sports</title>
|
||||
<link rel="icon" type="image/png" href="/assets/logo/bloodbros-sports-logo.png">
|
||||
<style>
|
||||
body{font-family:Arial,Helvetica,sans-serif;background:#081221;color:#fff;margin:0;padding:40px}
|
||||
.box{max-width:780px;margin:auto;background:#0f1d34;border:1px solid rgba(255,255,255,.12);border-radius:24px;padding:32px}
|
||||
a{color:#7dd3fc}
|
||||
:root{
|
||||
--bg-1:#040b16;
|
||||
--bg-2:#071425;
|
||||
--bg-3:#091a30;
|
||||
--card:#0d1729;
|
||||
--line:rgba(255,255,255,.10);
|
||||
--text:#f4f7fb;
|
||||
--muted:#9fb0ca;
|
||||
--accent:#64c4ff;
|
||||
--green:#28d267;
|
||||
--shadow:0 16px 44px rgba(0,0,0,.34);
|
||||
--radius-xl:30px;
|
||||
--radius-lg:24px;
|
||||
--radius-md:18px;
|
||||
}
|
||||
|
||||
*{box-sizing:border-box}
|
||||
html,body{margin:0;padding:0}
|
||||
body{
|
||||
font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
|
||||
color:var(--text);
|
||||
background:
|
||||
radial-gradient(circle at 12% 10%, rgba(52,122,255,.18), transparent 24%),
|
||||
radial-gradient(circle at 82% 12%, rgba(100,196,255,.12), transparent 24%),
|
||||
linear-gradient(180deg, var(--bg-1) 0%, var(--bg-2) 38%, var(--bg-3) 100%);
|
||||
min-height:100vh;
|
||||
}
|
||||
|
||||
.wrap{
|
||||
max-width:980px;
|
||||
margin:0 auto;
|
||||
padding:38px 18px 42px;
|
||||
}
|
||||
|
||||
.card{
|
||||
border-radius:32px;
|
||||
border:1px solid rgba(255,255,255,.10);
|
||||
background:
|
||||
radial-gradient(circle at 75% 15%, rgba(104,133,255,.18), transparent 28%),
|
||||
linear-gradient(180deg, rgba(17,29,52,.95), rgba(12,20,36,.98));
|
||||
box-shadow:var(--shadow);
|
||||
overflow:hidden;
|
||||
}
|
||||
|
||||
.head{
|
||||
display:flex;
|
||||
align-items:center;
|
||||
gap:18px;
|
||||
padding:28px 28px 10px;
|
||||
}
|
||||
|
||||
.logo-wrap{
|
||||
width:84px;
|
||||
height:84px;
|
||||
border-radius:24px;
|
||||
background:linear-gradient(135deg, rgba(255,255,255,.08), rgba(255,255,255,.03));
|
||||
border:1px solid rgba(255,255,255,.10);
|
||||
display:flex;
|
||||
align-items:center;
|
||||
justify-content:center;
|
||||
overflow:hidden;
|
||||
flex:0 0 auto;
|
||||
}
|
||||
|
||||
.logo-wrap img{
|
||||
max-width:82%;
|
||||
max-height:82%;
|
||||
object-fit:contain;
|
||||
display:block;
|
||||
}
|
||||
|
||||
.head-copy h1{
|
||||
margin:0 0 6px;
|
||||
font-size:24px;
|
||||
font-weight:1000;
|
||||
}
|
||||
|
||||
.head-copy p{
|
||||
margin:0;
|
||||
color:var(--muted);
|
||||
font-size:16px;
|
||||
line-height:1.45;
|
||||
}
|
||||
|
||||
.ok-badge{
|
||||
margin:0 28px 22px;
|
||||
display:inline-flex;
|
||||
align-items:center;
|
||||
gap:10px;
|
||||
min-height:40px;
|
||||
padding:0 16px;
|
||||
border-radius:999px;
|
||||
background:rgba(40,210,103,.14);
|
||||
border:1px solid rgba(40,210,103,.28);
|
||||
color:#c8ffd9;
|
||||
font-weight:900;
|
||||
}
|
||||
|
||||
.content{
|
||||
padding:0 28px 30px;
|
||||
display:grid;
|
||||
gap:18px;
|
||||
}
|
||||
|
||||
.summary-card{
|
||||
display:grid;
|
||||
grid-template-columns:120px 1fr;
|
||||
gap:18px;
|
||||
align-items:center;
|
||||
border:1px solid rgba(255,255,255,.08);
|
||||
background:rgba(255,255,255,.04);
|
||||
border-radius:24px;
|
||||
padding:18px;
|
||||
}
|
||||
|
||||
.summary-media{
|
||||
width:120px;
|
||||
height:120px;
|
||||
border-radius:18px;
|
||||
background:rgba(255,255,255,.92);
|
||||
display:flex;
|
||||
align-items:center;
|
||||
justify-content:center;
|
||||
overflow:hidden;
|
||||
}
|
||||
|
||||
.summary-media img{
|
||||
width:100%;
|
||||
height:100%;
|
||||
object-fit:contain;
|
||||
display:block;
|
||||
}
|
||||
|
||||
.summary-placeholder{
|
||||
color:#0b1630;
|
||||
font-size:12px;
|
||||
font-weight:900;
|
||||
text-align:center;
|
||||
padding:8px;
|
||||
}
|
||||
|
||||
.summary-info h2{
|
||||
margin:0 0 6px;
|
||||
font-size:38px;
|
||||
line-height:1;
|
||||
font-weight:1000;
|
||||
letter-spacing:-.04em;
|
||||
}
|
||||
|
||||
.summary-info .meta{
|
||||
color:var(--muted);
|
||||
font-size:15px;
|
||||
line-height:1.5;
|
||||
}
|
||||
|
||||
.grid{
|
||||
display:grid;
|
||||
grid-template-columns:1fr 1fr;
|
||||
gap:18px;
|
||||
}
|
||||
|
||||
.box{
|
||||
border:1px solid rgba(255,255,255,.08);
|
||||
background:rgba(255,255,255,.04);
|
||||
border-radius:24px;
|
||||
padding:18px;
|
||||
}
|
||||
|
||||
.box-title{
|
||||
margin:0 0 14px;
|
||||
color:var(--muted);
|
||||
font-size:12px;
|
||||
text-transform:uppercase;
|
||||
letter-spacing:.16em;
|
||||
font-weight:900;
|
||||
}
|
||||
|
||||
.line{
|
||||
display:flex;
|
||||
justify-content:space-between;
|
||||
gap:14px;
|
||||
padding:8px 0;
|
||||
color:#eef4ff;
|
||||
font-size:15px;
|
||||
border-bottom:1px solid rgba(255,255,255,.06);
|
||||
}
|
||||
|
||||
.line:last-child{
|
||||
border-bottom:none;
|
||||
}
|
||||
|
||||
.line.total{
|
||||
font-size:18px;
|
||||
font-weight:1000;
|
||||
padding-top:12px;
|
||||
}
|
||||
|
||||
.contact-item{
|
||||
display:grid;
|
||||
gap:4px;
|
||||
padding:10px 0;
|
||||
border-bottom:1px solid rgba(255,255,255,.06);
|
||||
}
|
||||
|
||||
.contact-item:last-child{
|
||||
border-bottom:none;
|
||||
}
|
||||
|
||||
.contact-item strong{
|
||||
font-size:12px;
|
||||
color:var(--muted);
|
||||
text-transform:uppercase;
|
||||
letter-spacing:.12em;
|
||||
}
|
||||
|
||||
.contact-item span{
|
||||
color:#eef4ff;
|
||||
font-size:15px;
|
||||
line-height:1.45;
|
||||
word-break:break-word;
|
||||
}
|
||||
|
||||
.actions{
|
||||
display:flex;
|
||||
gap:12px;
|
||||
flex-wrap:wrap;
|
||||
margin-top:6px;
|
||||
}
|
||||
|
||||
.btn{
|
||||
min-height:52px;
|
||||
padding:0 20px;
|
||||
border-radius:999px;
|
||||
border:1px solid rgba(255,255,255,.10);
|
||||
text-decoration:none;
|
||||
display:inline-flex;
|
||||
align-items:center;
|
||||
justify-content:center;
|
||||
font-weight:900;
|
||||
color:#fff;
|
||||
background:rgba(255,255,255,.05);
|
||||
}
|
||||
|
||||
.btn-primary{
|
||||
background:linear-gradient(180deg, rgba(93,154,255,.34), rgba(52,115,214,.28));
|
||||
border-color:rgba(100,196,255,.24);
|
||||
}
|
||||
|
||||
.error-box{
|
||||
margin:28px;
|
||||
padding:20px;
|
||||
border-radius:22px;
|
||||
border:1px solid rgba(255,90,98,.20);
|
||||
background:rgba(255,90,98,.08);
|
||||
color:#ffd9dc;
|
||||
}
|
||||
|
||||
@media (max-width:780px){
|
||||
.summary-card{
|
||||
grid-template-columns:1fr;
|
||||
}
|
||||
.summary-media{
|
||||
width:100%;
|
||||
height:220px;
|
||||
}
|
||||
.grid{
|
||||
grid-template-columns:1fr;
|
||||
}
|
||||
.head{
|
||||
align-items:flex-start;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="box">
|
||||
<h1>Pagament correcte</h1>
|
||||
<p>Hem rebut la teva compra. En breu revisarem la comanda i t'avisarem.</p>
|
||||
<?php if ($sessionId): ?>
|
||||
<p><strong>Stripe session:</strong> <?= $sessionId ?></p>
|
||||
<?php endif; ?>
|
||||
<p><a href="https://kapvoe-portfoli.treblarella.org/">Torna al catàleg</a></p>
|
||||
<div class="wrap">
|
||||
<div class="card">
|
||||
<div class="head">
|
||||
<div class="logo-wrap">
|
||||
<img src="/assets/logo/bloodbros-sports-logo.png" alt="Blood Bros Sports">
|
||||
</div>
|
||||
<div class="head-copy">
|
||||
<h1>Pagament correcte</h1>
|
||||
<p>Hem rebut la teva compra. Aquí tens un resum de la comanda confirmada.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($error !== ''): ?>
|
||||
<div class="error-box">
|
||||
<strong>No hem pogut carregar el resum de la comanda.</strong><br><br>
|
||||
<?= e($error) ?>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="ok-badge">✅ Compra confirmada</div>
|
||||
|
||||
<div class="content">
|
||||
<div class="summary-card">
|
||||
<div class="summary-media">
|
||||
<?php if ($imageUrl !== ''): ?>
|
||||
<img src="<?= e($imageUrl) ?>" alt="<?= e($productCode) ?>">
|
||||
<?php else: ?>
|
||||
<div class="summary-placeholder">Sense imatge</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="summary-info">
|
||||
<h2><?= e($productCode) ?></h2>
|
||||
<div class="meta">
|
||||
Sessió Stripe: <strong><?= e($sessionId) ?></strong><br>
|
||||
Mètode: <strong><?= e($shippingMethod === 'shipping' ? 'Enviament' : 'Entrega en persona') ?></strong>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid">
|
||||
<div class="box">
|
||||
<div class="box-title">Resum econòmic</div>
|
||||
|
||||
<div class="line">
|
||||
<span>Subtotal producte</span>
|
||||
<strong><?= fmt_eur($subtotal) ?></strong>
|
||||
</div>
|
||||
|
||||
<div class="line">
|
||||
<span>Enviament</span>
|
||||
<strong><?= fmt_eur($shippingCost) ?></strong>
|
||||
</div>
|
||||
|
||||
<div class="line total">
|
||||
<span>Total</span>
|
||||
<strong><?= fmt_eur($totalAmount) ?></strong>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="box">
|
||||
<div class="box-title">Dades de contacte</div>
|
||||
|
||||
<div class="contact-item">
|
||||
<strong>Nom</strong>
|
||||
<span><?= e((string)($order['customer_name'] ?? '')) ?></span>
|
||||
</div>
|
||||
|
||||
<div class="contact-item">
|
||||
<strong>Telèfon</strong>
|
||||
<span><?= e((string)($order['phone'] ?? '')) ?></span>
|
||||
</div>
|
||||
|
||||
<div class="contact-item">
|
||||
<strong>Correu electrònic</strong>
|
||||
<span><?= e((string)($order['email'] ?? '')) ?></span>
|
||||
</div>
|
||||
|
||||
<?php if ($shippingMethod === 'shipping'): ?>
|
||||
<div class="contact-item">
|
||||
<strong>Adreça d'enviament</strong>
|
||||
<span>
|
||||
<?= e((string)($order['address'] ?? '')) ?><br>
|
||||
<?= e((string)($order['postal_code'] ?? '')) ?> <?= e((string)($order['city'] ?? '')) ?><br>
|
||||
<?= e((string)($order['province'] ?? '')) ?>
|
||||
</span>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="contact-item">
|
||||
<strong>Entrega</strong>
|
||||
<span>Quedarem amb tu per WhatsApp per entregar-te les ulleres en persona a Lleida o Mollerussa.</span>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<a class="btn btn-primary" href="/">Torna al catàleg</a>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -34,6 +34,8 @@ if (!is_array($event)) {
|
||||
$type = (string)($event['type'] ?? '');
|
||||
$object = $event['data']['object'] ?? null;
|
||||
|
||||
error_log('[KAPVOE WEBHOOK] event_type=' . $type);
|
||||
|
||||
if (!is_array($object)) {
|
||||
http_response_code(400);
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
@@ -51,6 +53,8 @@ try {
|
||||
$paymentIntentId = (string)($object['payment_intent'] ?? '');
|
||||
$paymentStatus = (string)($object['payment_status'] ?? '');
|
||||
|
||||
error_log('[KAPVOE WEBHOOK] checkout.session.completed session_id=' . $sessionId . ' payment_status=' . $paymentStatus);
|
||||
|
||||
if ($sessionId === '') {
|
||||
throw new RuntimeException('Falta session id');
|
||||
}
|
||||
@@ -70,6 +74,8 @@ try {
|
||||
|
||||
$alreadyUpdated = (string)($order['stock_updated'] ?? '') === '1';
|
||||
$stockResult = null;
|
||||
$mailResult = null;
|
||||
$analyticsResult = null;
|
||||
|
||||
if ($paymentStatus === 'paid' && !$alreadyUpdated) {
|
||||
$stockResult = kapvoe_decrement_sheet_stock($config, $order, $sessionId);
|
||||
@@ -82,6 +88,15 @@ try {
|
||||
$alreadyUpdated = true;
|
||||
}
|
||||
|
||||
if ($paymentStatus === 'paid') {
|
||||
$order = kapvoe_get_order_by_session_id($config, $sessionId) ?? $order;
|
||||
error_log('[KAPVOE WEBHOOK] sending_order_notifications session_id=' . $sessionId . ' customer_email=' . (string)($order['email'] ?? ''));
|
||||
$mailResult = kapvoe_send_order_notifications($config, $order, $sessionId);
|
||||
error_log('[KAPVOE WEBHOOK] mail_result session_id=' . $sessionId . ' result=' . json_encode($mailResult, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
||||
$analyticsResult = kapvoe_track_analytics_event($config, kapvoe_build_payment_success_event($order, $sessionId));
|
||||
error_log('[KAPVOE WEBHOOK] analytics_result session_id=' . $sessionId . ' result=' . ($analyticsResult ? '1' : '0'));
|
||||
}
|
||||
|
||||
http_response_code(200);
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
echo json_encode([
|
||||
@@ -90,7 +105,9 @@ try {
|
||||
'session_id' => $sessionId,
|
||||
'payment_intent_id' => $paymentIntentId,
|
||||
'already_updated' => $alreadyUpdated,
|
||||
'stock_result' => $stockResult
|
||||
'stock_result' => $stockResult,
|
||||
'mail_result' => $mailResult,
|
||||
'analytics_result' => $analyticsResult,
|
||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
exit;
|
||||
|
||||
@@ -104,6 +121,7 @@ try {
|
||||
exit;
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
error_log('[KAPVOE WEBHOOK] ERROR ' . $e->getMessage());
|
||||
http_response_code(500);
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
echo json_encode([
|
||||
@@ -111,4 +129,4 @@ try {
|
||||
'error' => $e->getMessage()
|
||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/common.php';
|
||||
|
||||
$config = kapvoe_load_config();
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
$configuredToken = trim((string)($config['admin_tools_token'] ?? ''));
|
||||
$providedToken = trim((string)($_GET['key'] ?? ''));
|
||||
|
||||
if ($configuredToken === '') {
|
||||
http_response_code(403);
|
||||
echo json_encode([
|
||||
'ok' => false,
|
||||
'error' => 'Falta configurar admin_tools_token a config.php',
|
||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!hash_equals($configuredToken, $providedToken)) {
|
||||
http_response_code(403);
|
||||
echo json_encode([
|
||||
'ok' => false,
|
||||
'error' => 'Token invalid',
|
||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
exit;
|
||||
}
|
||||
|
||||
$defaultRecipient = trim((string)($config['admin_notification_email'] ?? ''));
|
||||
$toEmail = trim((string)($_GET['to'] ?? $defaultRecipient));
|
||||
|
||||
if ($toEmail === '' || !filter_var($toEmail, FILTER_VALIDATE_EMAIL)) {
|
||||
http_response_code(400);
|
||||
echo json_encode([
|
||||
'ok' => false,
|
||||
'error' => 'Cal una adreca de correu valida',
|
||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
exit;
|
||||
}
|
||||
|
||||
$transport = strtolower(trim((string)($config['mail_transport'] ?? 'auto')));
|
||||
$smtpHost = trim((string)($config['smtp_host'] ?? ''));
|
||||
$smtpPort = (int)($config['smtp_port'] ?? 0);
|
||||
|
||||
$subject = 'Prova SMTP Blood Bros Sports';
|
||||
$htmlBody = '<!DOCTYPE html>
|
||||
<html lang="ca">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Prova SMTP</title>
|
||||
</head>
|
||||
<body style="margin:0;padding:24px;background:#081221;font-family:Arial,Helvetica,sans-serif;color:#f4f7fb;">
|
||||
<div style="max-width:720px;margin:0 auto;border-radius:24px;border:1px solid rgba(255,255,255,.10);background:linear-gradient(180deg,#172544 0%,#0f1b32 100%);padding:24px;">
|
||||
<h1 style="margin:0 0 12px;font-size:28px;">Prova d\'enviament correcta</h1>
|
||||
<p style="margin:0 0 14px;line-height:1.6;color:#d8e3f3;">Aquest correu s\'ha enviat des de <strong>test-mail.php</strong> per comprovar la configuracio SMTP del projecte.</p>
|
||||
<div style="padding:16px;border-radius:16px;background:rgba(255,255,255,.05);line-height:1.7;">
|
||||
<div><strong>Data:</strong> ' . htmlspecialchars(date('Y-m-d H:i:s'), ENT_QUOTES, 'UTF-8') . '</div>
|
||||
<div><strong>Destinatari:</strong> ' . htmlspecialchars($toEmail, ENT_QUOTES, 'UTF-8') . '</div>
|
||||
<div><strong>Transport:</strong> ' . htmlspecialchars($transport, ENT_QUOTES, 'UTF-8') . '</div>
|
||||
<div><strong>SMTP host:</strong> ' . htmlspecialchars($smtpHost !== '' ? $smtpHost : '(buit)', ENT_QUOTES, 'UTF-8') . '</div>
|
||||
<div><strong>SMTP port:</strong> ' . htmlspecialchars((string)$smtpPort, ENT_QUOTES, 'UTF-8') . '</div>
|
||||
<div><strong>Servidor:</strong> ' . htmlspecialchars((string)($_SERVER['HTTP_HOST'] ?? 'localhost'), ENT_QUOTES, 'UTF-8') . '</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>';
|
||||
|
||||
$sent = kapvoe_send_html_email($config, $toEmail, $subject, $htmlBody);
|
||||
|
||||
echo json_encode([
|
||||
'ok' => $sent,
|
||||
'to' => $toEmail,
|
||||
'subject' => $subject,
|
||||
'transport' => $transport,
|
||||
'smtp_host' => $smtpHost,
|
||||
'smtp_port' => $smtpPort,
|
||||
'mail_log' => kapvoe_mail_log_path($config),
|
||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
Reference in New Issue
Block a user