-
-
Notifications
You must be signed in to change notification settings - Fork 64
Stripe processing squeeze page #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
60f4968
7efaaa7
5b427ca
9b18d0e
affe2a1
0accf9b
d95457e
0822d67
63cff30
49d1f46
2b3cbc6
94f0ee4
fd21565
d331cf0
6478204
1a56bd1
296af4e
0cb8838
6e91773
7c1b85d
206df78
bc9698d
14c9262
1a5ee98
164836d
ea45592
53254c2
1085820
647896a
04c09a1
d522d46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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
|
||||||||||||||||||||||||||||||||||||||||||||
| $this->manuallyProcessOrder(); | |
| } | |
| // Double-check to avoid duplicate processing | |
| if (! $this->cart?->completedOrder()->exists()) { | |
| $this->manuallyProcessOrder(); | |
| } | |
| } | |
| // Check again after manual processing |
Copilot
AI
Nov 10, 2025
There was a problem hiding this comment.
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.
| to_route('checkout-success.view', [ | |
| return to_route('checkout-success.view', [ |
Copilot
AI
Nov 10, 2025
There was a problem hiding this comment.
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
AI
Nov 10, 2025
There was a problem hiding this comment.
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.
| $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()); | |
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| namespace App\Livewire; | ||
|
|
||
| use Illuminate\Http\Request; | ||
| use Illuminate\View\View; | ||
| use Livewire\Component; | ||
| use Lunar\Facades\CartSession; | ||
|
|
@@ -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')); | ||
|
||
|
|
||
| if (! $this->cart || ! $this->cart->completedOrder) { | ||
| $this->redirect('/'); | ||
|
|
||
|
|
||
| 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> |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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()