Open russdot opened 1 month ago
Continuing to investigate this for my own learning and to help out...
I've been stepping through the code to determine where the session changes and I think I've found it.
In my debug console I was running Lunar\Facades\CartSession::current()->id
to check the output. I noticed it increments by +1 after updating the order within OfflinePayment->authorize()
To illustrate using excerpt from OfflinePayment
, where I've added comments to indicate breakpoint locations and values for the cart ID.
public function authorize(): ?PaymentAuthorize
{
if (! $this->order) {
if (! $this->order = $this->cart->draftOrder()->first()) {
$this->order = $this->cart->createOrder();
}
}
$orderMeta = array_merge(
(array) $this->order->meta,
$this->data['meta'] ?? []
);
$status = $this->data['authorized'] ?? null;
//
// (after executing line above) Lunar\Facades\CartSession::current()->id = N
//
$this->order->update([
'status' => $status ?? ($this->config['authorized'] ?? null),
'meta' => $orderMeta,
'placed_at' => now(),
]);
//
// (after executing line above) Lunar\Facades\CartSession::current()->id = N + 1
// The CartSession ID increments by 1 after updating the order
//
$response = new PaymentAuthorize(
success: true,
orderId: $this->order->id,
paymentType: 'offline',
);
PaymentAttemptEvent::dispatch($response);
return $response;
}
Not sure yet why this is occurring - but wanted to capture my findings. Perhaps this is a bug with Lunar core?
I think the issue here is the Starter kit is quite outdated at this point, we're working on new starter kits for v1 and to bring this back up to speed with the latest beta.
There was a change to the way carts are retrieved from the session after a cart completed an order, so because you're trying to fetch the cart afterwards, it has a completed order and therefore returns a new cart. So, in the case of the offline payment, you would need to pass the cart id to the success page to fetch it that way instead of going through the session manager.
You can see this on this PR which is awaiting review by @glennjacobs https://github.com/lunarphp/livewire-starter-kit/pull/89
I think the issue here is the Starter kit is quite outdated at this point
If I may add my opinion, the Livewire Starter kit works really well except for a few minor issues. The one issue I have is the clever way the shipping and billing details pages have been merged into one. It makes it a bit hard to customize. For example, often a client might want to administer multiple shipping address, and sometimes a client wants the shipping address pre-populated. I feel that combining the login shipping and billing into one broke the single responsibility principle and I'm finding customization hard.
I noticed that when submitting an order, there is no confirmation and it redirects to the main storefront (
/
).After some debugging and tracing, I believe I've tracked down what's happening but I'm not sure why.
CheckoutPage->checkout()
redirects on successful offline payment.CheckoutSuccessPage->mount()
runs, theCartSession::current()
retrieves an apparently new session with an ID=N+1. For example, when the payment succeeds the cart ID might be 8, but inCheckoutSuccessPage
the ID will be 9.completedOrder
to fail, and redirect to the main storefront without displaying thecheckout-success.view