2026-04-03

This commit is contained in:
gcch 2026-04-03 08:49:14 +02:00
commit 5f835ca4e6
45 changed files with 819 additions and 626 deletions

View file

@ -1,17 +1,23 @@
<?php
declare(strict_types=1);
/**
* Route pour la préparation du paiement via Stripe (« Checkout »).
*/
declare(strict_types=1);
namespace HaikuAtelier;
use Roots\WPConfig\Config;
use Stripe\BillingPortal\Session;
use Stripe\Checkout\Session;
use Stripe\Coupon;
use Stripe\Product;
use Stripe\Stripe;
use Symfony\Component\Uid\Uuid;
use WC_Cart;
use WC_Coupon;
use WC_Order;
use WC_Session_Handler;
header('Content-Type: application/json; charset=utf-8');
@ -40,7 +46,7 @@ $session_wc = WC()->session;
$urls = [
'accueil' => get_page_link(get_page_by_path('home')),
'succes_commande' => get_page_link(get_page_by_path('successful-order')),
'echec_commande' => get_page_link(get_page_by_path('failed-order'))
'echec_commande' => get_page_link(get_page_by_path('failed-order')),
];
// Redirige à la page d'accueil si le Panier est vide
@ -86,7 +92,7 @@ $articles = collect($panier->get_cart())
. ' ('
. explode(': ', (string) $article_panier['data']?->get_attribute_summary())[1]
. ')',
false => $article_panier['data']?->get_title()
false => $article_panier['data']?->get_title(),
};
return [
@ -94,11 +100,11 @@ $articles = collect($panier->get_cart())
'currency' => 'EUR',
'product_data' => [
'name' => $titre_produit,
'images' => [wp_get_attachment_image_url($article_panier['data']?->get_image_id())]
'images' => [wp_get_attachment_image_url($article_panier['data']?->get_image_id())],
],
'unit_amount' => $article_panier['data']?->get_price() * 100
'unit_amount' => $article_panier['data']?->get_price() * 100,
],
'quantity' => $article_panier['quantity']
'quantity' => $article_panier['quantity'],
];
})
->values()
@ -126,7 +132,7 @@ $coupons_wc = collect(WC()->cart->get_coupons())
'duration' => get_discount_duration($coupon),
'fixed_cart' === $coupon->get_discount_type() ? 'amount_off' : 'percent_off' => get_discount_amount($coupon),
'id' => $coupon->get_code(),
'name' => $coupon->get_code()
'name' => $coupon->get_code(),
])
->each(static function (array $item) use ($coupons_stripe): void {
// Si le code promo n'existe pas, le créer
@ -140,7 +146,7 @@ $reductions_stripe = $coupons_wc
->toArray();
/** @var Session $session_checkout_stripe */
$session_checkout_stripe = \Stripe\Checkout\Session::create([
$session_checkout_stripe = Session::create([
'cancel_url' => $urls['echec_commande'],
'customer_email' => $email_client,
'discounts' => $reductions_stripe,
@ -152,8 +158,8 @@ $session_checkout_stripe = \Stripe\Checkout\Session::create([
'display_name' => $methode_livraison['nom'],
'fixed_amount' => ['amount' => $methode_livraison['cout'], 'currency' => 'EUR'],
'tax_behavior' => 'inclusive',
'type' => 'fixed_amount'
]]]
'type' => 'fixed_amount',
]]],
], ['idempotency_key' => Uuid::v4()]);
// echo json_encode($session_checkout_stripe);
header('HTTP/1.1 303 See Other');