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

@ -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;
}
}