Skip to content
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

Feat - Add stripe processing page #89

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 6 additions & 2 deletions app/Livewire/CheckoutPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,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
36 changes: 36 additions & 0 deletions app/Livewire/CheckoutProcessing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Livewire;

use Illuminate\Http\Request;
use Livewire\Component;
use Lunar\Models\Cart;

class CheckoutProcessing extends Component
{
public string $paymentIntent;

public function mount(Request $request)
{
$this->paymentIntent = $request->get('payment_intent');
}

public function hydrate()
{
if ($this->cart->completedOrder) {
to_route('checkout-success.view', [
'cartId' => $this->cart->id,
]);
}
}

public function getCartProperty()
{
return Cart::where('meta->payment_intent', '=', $this->paymentIntent)->first();
}

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'));

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' => [
'payment_intent' => 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>
<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');