diff --git a/resources/js/app.js b/resources/js/app.js index 208402a..a6bc8de 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -231,6 +231,21 @@ Alpine.data('miniPaymentLanding', (config = {}) => ({ } }, + accessCodeFromCheckoutUrl(url) { + if (!url) return ''; + try { + const u = new URL(url, window.location.href); + const host = u.hostname.toLowerCase(); + if (host !== 'checkout.paystack.com' && !host.endsWith('.paystack.com')) { + return ''; + } + const code = u.pathname.replace(/^\/+/, '').split('/')[0] || ''; + return /^[A-Za-z0-9_-]{6,}$/.test(code) ? code : ''; + } catch (e) { + return ''; + } + }, + openInlineCheckout(data = {}) { // Never navigate to checkout.paystack.com. Same-origin MoMo waiting can navigate. if (data.provider === 'mtn_momo' && this.isSameOrigin(data.checkout_url)) { @@ -238,8 +253,14 @@ Alpine.data('miniPaymentLanding', (config = {}) => ({ return false; } - this.checkoutUrl = data.checkout_url || ''; - this.accessCode = data.access_code || ''; + const checkoutUrl = data.checkout_url || ''; + let accessCode = data.access_code || ''; + if (!accessCode) { + accessCode = this.accessCodeFromCheckoutUrl(checkoutUrl); + } + + this.checkoutUrl = checkoutUrl; + this.accessCode = accessCode; this.publicKey = data.public_key || ''; this.returnUrl = data.callback_url || ''; this.showSheet = true; @@ -259,8 +280,8 @@ Alpine.data('miniPaymentLanding', (config = {}) => ({ this.accessCode = ''; this.publicKey = ''; this.returnUrl = ''; - // Keep sheet closed until we have a checkout payload so Inline syncs once with access_code. - this.showSheet = false; + // Open bottomsheet/modal immediately so payment feels in-app while checkout starts. + this.showSheet = true; const controller = new AbortController(); const timer = setTimeout(() => controller.abort(), 45000); diff --git a/resources/views/partials/paystack-sheet.blade.php b/resources/views/partials/paystack-sheet.blade.php index e5dfd9a..ecdef88 100644 --- a/resources/views/partials/paystack-sheet.blade.php +++ b/resources/views/partials/paystack-sheet.blade.php @@ -296,124 +296,118 @@ ); } " - @keydown.escape.window="if (showSheet && $store.ladillPayCheckout && ($store.ladillPayCheckout.frameable || $store.ladillPayCheckout.error || $store.ladillPayCheckout.launching)) showSheet = false" + @keydown.escape.window="if (showSheet) showSheet = false" @ladill-pay-cancelled.window="showSheet = false" - class="fixed inset-0 z-[9999]" - :class="($store.ladillPayCheckout && $store.ladillPayCheckout.inline && !$store.ladillPayCheckout.launching && !$store.ladillPayCheckout.error && !$store.ladillPayCheckout.frameable) ? 'pointer-events-none' : ''" + class="fixed inset-0 z-[9999] flex items-end justify-center md:items-center md:p-6" role="dialog" aria-modal="true" :aria-hidden="(!showSheet).toString()" aria-label="{{ $sheetAria }}"> - {{-- Brief loader only — then Paystack Inline is the sole payment UI (avoids double modal). --}} -
Opening payment…
-{{ $sheetTitle }}
- @if (! empty($sheetSubtitle)) -{{ $sheetSubtitle }}
- @endif -{{ $sheetTitle }}
+ @if (! empty($sheetSubtitle)) +{{ $sheetSubtitle }}
+ @endifCheckout unavailable
- -- {{ $sheetFooter }} -
- @endif+ {{ $sheetFooter }} +
+ @endif