diff --git a/web/app/themes/haiku-atelier-2024/page-checkout.php b/web/app/themes/haiku-atelier-2024/page-checkout.php index 1a1f4c58..a8374252 100755 --- a/web/app/themes/haiku-atelier-2024/page-checkout.php +++ b/web/app/themes/haiku-atelier-2024/page-checkout.php @@ -101,14 +101,25 @@ if (empty($methode_livraison['nom'])) { // Sélectionne la clé API Stripe Stripe::setApiKey(Config::get('STRIPE_API_SECRET')); +// TODO: Appliquer le bon calcul pour les montants vs. percentages +function get_discount_amount(WC_Coupon $coupon) { + if ($coupon->get_discount_type() === 'amount_off') { + return $coupon->get_amount() * 100; + } else { + return $coupon->get_amount() * 100; + } +} + + // Met à jour les Codes promos $coupons_stripe = collect(Coupon::all()->data); $coupons_wc = collect(WC()->cart->get_coupons()) ->map(static fn(WC_Coupon $coupon): array => [ + 'currency' => 'EUR', 'duration' => 'forever', + 'fixed_cart' === $coupon->get_discount_type() ? 'amount_off' : 'percent_off' => get_discount_amount($coupon), 'id' => $coupon->get_code(), 'name' => $coupon->get_code(), - 'fixed_cart' === $coupon->get_discount_type() ? 'amount_off' : 'percent_off' => $coupon->get_amount(), ]) ->each(static function (array $item) use ($coupons_stripe): void { // Si le code promo n'existe, le créer