Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
60f4968
Wip
lguichard Jan 24, 2024
7efaaa7
Remove nginx, add Caddy and fix entrypoint
lguichard Feb 14, 2024
5b427ca
Cleaning
lguichard Feb 15, 2024
9b18d0e
Wip
lguichard Feb 15, 2024
affe2a1
Refresh config default config Lunar
lguichard Feb 15, 2024
0accf9b
Update default migrations
lguichard Feb 15, 2024
d95457e
Add support of automatic Lunar install
lguichard Feb 15, 2024
0822d67
Add support of Meilisearch
lguichard Feb 15, 2024
63cff30
Add support of Mailpit
lguichard Feb 15, 2024
49d1f46
Merge remote-tracking branch 'upstream/main' into 1.x
lguichard Feb 15, 2024
2b3cbc6
Update Docker output
lguichard Feb 16, 2024
94f0ee4
Fix images import on Seeder
lguichard Feb 16, 2024
fd21565
Cleaning types
lguichard Feb 16, 2024
d331cf0
Remove webpack, add Vite
lguichard Feb 16, 2024
6478204
Register ShippingPlugin
lguichard Feb 16, 2024
1a56bd1
Enable legacy model binding
lguichard Feb 16, 2024
296af4e
Add wire:navigate
lguichard Feb 17, 2024
0cb8838
Update lando support
lguichard Feb 17, 2024
6e91773
Wip
lguichard Feb 18, 2024
7c1b85d
Update docs
lguichard Mar 1, 2024
206df78
Update README.md
lguichard Mar 1, 2024
bc9698d
Update DB Seeders for shipping plugin
alecritson Mar 4, 2024
14c9262
Opt to keep shipping modifier bits
alecritson Mar 4, 2024
1a5ee98
Update seeders
alecritson Apr 10, 2024
164836d
Fix composer
alecritson Apr 10, 2024
ea45592
Update Home.php
alecritson Jul 5, 2024
53254c2
Add squeeze page for processing stripe payments
alecritson Jul 12, 2024
1085820
Merge branch 'main' of github.com:lunarphp/livewire-starter-kit into …
alecritson Nov 6, 2025
647896a
Tweaks to processing page
alecritson Nov 6, 2025
04c09a1
Remove migration
alecritson Nov 6, 2025
d522d46
Tweaks
alecritson Nov 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions app/Livewire/CheckoutPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,6 @@ public function mount(): void
return;
}

if ($this->payment_intent) {
$payment = Payments::driver($this->paymentType)->cart($this->cart)->withData([
'payment_intent_client_secret' => $this->payment_intent_client_secret,
'payment_intent' => $this->payment_intent,
])->authorize();

if ($payment->success) {
redirect()->route('checkout-success.view');

return;
}
}

// Do we have a shipping address?
$this->shipping = $this->cart->shippingAddress ?: new CartAddress;

Expand Down Expand Up @@ -252,12 +239,16 @@ public function checkout()
])->authorize();

if ($payment->success) {
redirect()->route('checkout-success.view');
redirect()->route('checkout-success.view', [
'cartId' => $this->cart->id,
]);

return;
}

return redirect()->route('checkout-success.view');
return redirect()->route('checkout-success.view', [
'cartId' => $this->cart->id,
]);
}

/**
Expand Down
69 changes: 69 additions & 0 deletions app/Livewire/CheckoutProcessing.php
Copy link

@virtruvio virtruvio Nov 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alex --- this worked for me, too. Thanks for taking the time to show me exactly what you were thinking.
Did make one edit here due to an error thrown due to a call to a method on null at line 28:
if ($this->cart === null || !$this->cart->completedOrder()->exists()) {

Same issue on line 36 where we need if ($this->cart !== null && $this->cart->completedOrder()->exists()

Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace App\Livewire;

use Illuminate\Http\Request;
use Livewire\Component;
use Lunar\Facades\Payments;
use Lunar\Models\Cart;
use Lunar\Stripe\Models\StripePaymentIntent;

class CheckoutProcessing extends Component
{

public StripePaymentIntent $paymentIntent;

public string $paymentIntentClientSecret;

public int $tries = 0;

public function mount(Request $request)
{
$this->paymentIntent = StripePaymentIntent::where('intent_id', $request->get('payment_intent'))->firstOrFail();
$this->paymentIntentClientSecret = $request->get('payment_intent_client_secret');
}

public function checkStatus(): void
{
if (! $this->cart?->completedOrder()->exists()) {
$this->tries++;
}

if ($this->tries >= 5) {
$this->manuallyProcessOrder();
}

Comment on lines +33 to +35
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Race condition: Multiple simultaneous requests could increment $this->tries and call manuallyProcessOrder() multiple times before the order completes. Add a check after manuallyProcessOrder() to verify the order was created, or add locking to prevent duplicate manual processing.

Suggested change
$this->manuallyProcessOrder();
}
// Double-check to avoid duplicate processing
if (! $this->cart?->completedOrder()->exists()) {
$this->manuallyProcessOrder();
}
}
// Check again after manual processing

Copilot uses AI. Check for mistakes.
if ($this->cart?->completedOrder()->exists()) {
to_route('checkout-success.view', [
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing return statement: The to_route() helper should be used with return to actually perform the redirect. Without it, execution continues and the component re-renders.

Suggested change
to_route('checkout-success.view', [
return to_route('checkout-success.view', [

Copilot uses AI. Check for mistakes.
'cartId' => $this->cart->id,
]);
}
}
Comment on lines +26 to +41
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The $this->cart?->completedOrder()->exists() check is duplicated. Consider storing the result in a variable to avoid redundant database queries and improve readability.

Copilot uses AI. Check for mistakes.

protected function manuallyProcessOrder(): void
{
$this->paymentIntent->update([
'processing_at' => now(),
]);

Payments::driver('stripe')->cart($this->cart)->withData([
'payment_intent_client_secret' => $this->paymentIntentClientSecret,
'payment_intent' => $this->paymentIntent->intent_id,
])->authorize();
Comment on lines +45 to +52
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The processing_at timestamp is set before authorize() completes. If authorization fails or throws an exception, the timestamp remains set, potentially blocking retries. Consider setting this timestamp after successful authorization or wrapping in a try-catch block.

Suggested change
$this->paymentIntent->update([
'processing_at' => now(),
]);
Payments::driver('stripe')->cart($this->cart)->withData([
'payment_intent_client_secret' => $this->paymentIntentClientSecret,
'payment_intent' => $this->paymentIntent->intent_id,
])->authorize();
try {
Payments::driver('stripe')->cart($this->cart)->withData([
'payment_intent_client_secret' => $this->paymentIntentClientSecret,
'payment_intent' => $this->paymentIntent->intent_id,
])->authorize();
$this->paymentIntent->update([
'processing_at' => now(),
]);
} catch (\Exception $e) {
// Optionally log the error or handle it as needed
// logger()->error('Payment authorization failed: ' . $e->getMessage());
}

Copilot uses AI. Check for mistakes.
}

public function hydrate()
{
$this->checkStatus();
}

public function getCartProperty()
{
return $this->paymentIntent->cart;
}

public function render()
{
return view('livewire.checkout-processing');
}
}
6 changes: 4 additions & 2 deletions app/Livewire/CheckoutSuccessPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Livewire;

use Illuminate\Http\Request;
use Illuminate\View\View;
use Livewire\Component;
use Lunar\Facades\CartSession;
Expand All @@ -14,9 +15,10 @@ class CheckoutSuccessPage extends Component

public Order $order;

public function mount(): void
public function mount(Request $request): void
{
$this->cart = CartSession::current();
$this->cart = Cart::find($request->get('cartId'));
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing import: The Cart model is used but not imported. Add use Lunar\Models\Cart; to the imports.

Copilot uses AI. Check for mistakes.

if (! $this->cart || ! $this->cart->completedOrder) {
$this->redirect('/');

Expand Down
3 changes: 3 additions & 0 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
'stripe' => [
'public_key' => env('STRIPE_KEY'),
'key' => env('STRIPE_SECRET'),
'webhooks' => [
'lunar' => env('STRIPE_SIGNING_SECRET'),
]
],

];
19 changes: 19 additions & 0 deletions resources/views/livewire/checkout-processing.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<section class="bg-white">
<div class="max-w-screen-xl px-4 py-32 mx-auto sm:px-6 lg:px-8 lg:py-48" wire:poll.1s>
<div class="max-w-xl mx-auto text-center">
<h1 class="mt-8 text-3xl font-extrabold sm:text-5xl">
<span class="block"
role="img">
</span>

<span class="block mt-1 text-blue-500">
Processing your order...
</span>

</h1>
<p class="mt-2">Behind the scenes we are checking to see if Lunar has processed the Stripe webhook...</p>

</div>
</div>
</section>
2 changes: 1 addition & 1 deletion resources/views/partials/checkout/payment.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

@if ($paymentType == 'card')
<livewire:stripe.payment :cart="$cart"
:returnUrl="route('checkout.view')" />
:returnUrl="route('checkout.processing')" />
@endif

@if ($paymentType == 'cash-in-hand')
Expand Down
2 changes: 2 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@

Route::get('checkout', CheckoutPage::class)->name('checkout.view');

Route::get('checkout/processing', \App\Livewire\CheckoutProcessing::class)->name('checkout.processing');

Route::get('checkout/success', CheckoutSuccessPage::class)->name('checkout-success.view');