Add PayPal webhook handling

This commit is contained in:
Codex Agent
2026-02-04 14:23:07 +01:00
parent 66c7131d79
commit 5c78ac00dd
12 changed files with 676 additions and 7 deletions

View File

@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use App\Models\CheckoutSession;
use App\Services\Checkout\CheckoutAssignmentService;
use App\Services\Checkout\CheckoutSessionService;
use App\Services\Coupons\CouponRedemptionService;
use App\Services\PayPal\Exceptions\PayPalException;
use App\Services\PayPal\PayPalOrderService;
use Illuminate\Http\RedirectResponse;
@@ -18,6 +19,7 @@ class PayPalReturnController extends Controller
private readonly PayPalOrderService $orders,
private readonly CheckoutSessionService $sessions,
private readonly CheckoutAssignmentService $assignment,
private readonly CouponRedemptionService $couponRedemptions,
) {}
public function __invoke(Request $request): RedirectResponse
@@ -57,6 +59,7 @@ class PayPalReturnController extends Controller
]);
$this->sessions->markFailed($session, 'paypal_capture_failed');
$this->couponRedemptions->recordFailure($session, 'paypal_capture_failed');
return redirect()->to($this->resolveSafeRedirect($cancelUrl, $fallback));
}
@@ -89,11 +92,13 @@ class PayPalReturnController extends Controller
]);
$this->sessions->markCompleted($session, now());
$this->couponRedemptions->recordSuccess($session, $capture);
return redirect()->to($this->resolveSafeRedirect($successUrl, $fallback));
}
$this->sessions->markFailed($session, 'paypal_'.$status);
$this->couponRedemptions->recordFailure($session, 'paypal_'.$status);
return redirect()->to($this->resolveSafeRedirect($cancelUrl, $fallback));
}