Stop form POSTs from 307ing to ladl.link or redirecting away to checkout.paystack.com, open Paystack Inline with access_code, and use the single-chrome sheet so payment stays on the Mini page.
39 lines
1.2 KiB
PHP
39 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use App\Support\LadillLink;
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class RedirectLegacyQrToLadillLink
|
|
{
|
|
public function handle(Request $request, Closure $next): Response
|
|
{
|
|
if (! preg_match('#^q/[a-z0-9]#i', ltrim($request->path(), '/'))) {
|
|
return $next($request);
|
|
}
|
|
|
|
if (LadillLink::isInternalRequest($request)) {
|
|
return $next($request);
|
|
}
|
|
|
|
// Same-origin pay from Mini-hosted pages (e.g. mini.ladill.com) must hit
|
|
// local /q/{code}/pay — redirecting to ladl.link breaks CORS / form POSTs
|
|
// and used to dump the browser onto checkout.paystack.com.
|
|
if ($request->ajax() || $request->expectsJson() || $request->wantsJson()) {
|
|
return $next($request);
|
|
}
|
|
|
|
// Form POST (and any method) to the Mini pay endpoint stays on Mini so
|
|
// PaymentController can return JSON or flash payload for in-page Inline.
|
|
$path = ltrim($request->path(), '/');
|
|
if (preg_match('#^q/[^/]+/pay(?:/callback)?$#i', $path) === 1) {
|
|
return $next($request);
|
|
}
|
|
|
|
return LadillLink::legacyRedirect($request);
|
|
}
|
|
}
|