Add thank you page and fix webhook stock update
All checks were successful
Deploy / Deploy to Production (push) Successful in 7s

- Create thank you page template with bilingual content (FR/EN)
- Add automatic redirect to /thanks after successful payment
- Fix webhook: move kirby()->impersonate() before product update
- Add error handling in webhook with try-catch
- Pass order token to thank you page for future enhancements
- Update thank you page styling for better UX

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
isUnknown 2025-12-19 17:37:34 +01:00
parent f7a69482fc
commit 1aa64a7396
9 changed files with 137 additions and 42 deletions

View file

@ -0,0 +1,16 @@
title:
en: Thank you
fr: Merci
icon: check
tabs:
content:
label:
en: Content
fr: Contenu
fields:
text:
label:
en: Message
fr: Message
type: writer

View file

@ -106,12 +106,15 @@ return [
$order = $event['content'] ?? null;
if ($order && isset($order['items'])) {
// Impersonate pour avoir les permissions d'écriture
kirby()->impersonate('kirby');
foreach ($order['items'] as $item) {
$productId = $item['id'] ?? null;
$quantity = $item['quantity'] ?? 0;
if ($productId && $quantity > 0) {
// Trouver le produit par son snipcartId
// Trouver le produit par son slug
$products = site()->index()->filterBy('intendedTemplate', 'product');
foreach ($products as $product) {
@ -120,12 +123,16 @@ return [
$currentStock = (int) $product->stock()->value();
$newStock = max(0, $currentStock - $quantity);
// Mettre à jour le stock dans toutes les langues
$product->update([
'stock' => $newStock
]);
// Mettre à jour le stock
try {
$product->update([
'stock' => $newStock
]);
} catch (Exception $e) {
// Log l'erreur mais continue le traitement
error_log('Webhook stock update error: ' . $e->getMessage());
}
kirby()->impersonate('kirby');
break;
}
}

28
site/templates/thanks.php Normal file
View file

@ -0,0 +1,28 @@
<?php snippet('header', ['title' => $page->title()]) ?>
<main>
<section class="thanks-page">
<div class="thanks-content">
<h1><?= $page->title()->html() ?></h1>
<?php if($page->text()->isNotEmpty()): ?>
<div class="thanks-message">
<?= $page->text()->kt() ?>
</div>
<?php endif ?>
<div class="thanks-actions">
<a href="<?= $site->homePage()->url() ?>" class="btn__default">
<span class="icon">
<svg clip-rule="evenodd" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path d="m9.474 5.209s-4.501 4.505-6.254 6.259c-.147.146-.22.338-.22.53s.073.384.22.53c1.752 1.754 6.252 6.257 6.252 6.257.145.145.336.217.527.217.191 0 .383-.072.53-.221.293-.293.294-.766.004-1.057l-4.976-4.976h14.692c.414 0 .75-.336.75-.75s-.336-.75-.75-.75h-14.692l4.978-4.979c.289-.289.287-.761-.006-1.054-.147-.147-.339-.221-.53-.221-.191 0-.38.071-.525.215z" fill-rule="nonzero" />
</svg>
</span>
<div class="txt"><?= t('backToShop', 'Retour à la boutique') ?></div>
</a>
</div>
</div>
</section>
</main>
<?php snippet('footer') ?>