payment fix

This commit is contained in:
elvira
2026-09-15 15:04:40 +03:00
parent 279339a095
commit 1598f053ee
6 changed files with 48 additions and 13 deletions
@@ -62,7 +62,13 @@ public function show(string $locale): View
if ($cart?->shippingAddress) {
$shippingOptions = $this->syncShipping($cart);
$cart->refresh();
// Cart's CachesProperties::refresh() explicitly nulls total/
// subTotal/shippingTotal/etc. back to their defaults — every
// Lunar call site pairs it with recalculate() for exactly that
// reason. Bare refresh() here was leaving $cart->total null on
// reload, which fed a 0 amount straight into the Stripe Element.
$cart->refresh()->recalculate();
}
return view('checkout::page', [
@@ -180,13 +186,22 @@ public function saveAddress(string $locale, Request $request): JsonResponse
$this->checkout->setRecoveryConsent($request->boolean('recovery_consent'));
$rateKeyAfter = $cart->shippingAddress?->only(['postcode', 'state', 'country_id']);
$rateChanged = $rateKeyAfter != $rateKeyBefore;
// Nothing rate-relevant moved — persist and acknowledge, no re-render.
if ($rateKeyAfter == $rateKeyBefore) {
// setShippingAddress() above always deletes and recreates the
// CartAddress row (Lunar's AddAddress action), which drops whatever
// shipping_option was previously selected — regardless of whether the
// rate-determining fields actually changed. So this always has to run
// to restore/re-validate it, even on a save that only touched e.g. the
// phone number. Only the fragment RE-RENDER is skippable when nothing
// rate-relevant moved — the re-select itself is not optional.
$options = $this->syncShipping($cart);
if (! $rateChanged) {
return $this->fragments($cart, null, $errors);
}
return $this->fragments($cart, $this->syncShipping($cart), $errors);
return $this->fragments($cart, $options, $errors);
}
public function selectShippingOption(string $locale, Request $request): JsonResponse