diff --git a/app/Http/Controllers/Pos/RegisterController.php b/app/Http/Controllers/Pos/RegisterController.php index 19e1aa8..26164a9 100644 --- a/app/Http/Controllers/Pos/RegisterController.php +++ b/app/Http/Controllers/Pos/RegisterController.php @@ -235,6 +235,7 @@ class RegisterController extends Controller $result = $this->sales->initiatePayCheckout($sale, $merchant); $checkoutUrl = $result['checkout_url'] ?? null; + $accessCode = $result['access_code'] ?? null; $this->customerDisplays->pushPayment($location, $sale->fresh(['lines']), [ 'checkout_url' => $checkoutUrl, @@ -246,6 +247,7 @@ class RegisterController extends Controller if ($request->expectsJson() || $request->ajax()) { return response()->json([ 'checkout_url' => $checkoutUrl, + 'access_code' => $accessCode, 'sale_id' => $sale->id, ]); } @@ -253,6 +255,7 @@ class RegisterController extends Controller return redirect() ->route('pos.sales.show', $sale) ->with('checkout_url', $checkoutUrl) + ->with('access_code', $accessCode) ->with('success', 'Payment sheet ready — customer screen shows the QR; till sheet is for the operator.'); } catch (RuntimeException $e) { return back()->withInput()->with('error', $e->getMessage()); diff --git a/app/Http/Controllers/Pos/TicketController.php b/app/Http/Controllers/Pos/TicketController.php index 40f7e1a..6efb678 100644 --- a/app/Http/Controllers/Pos/TicketController.php +++ b/app/Http/Controllers/Pos/TicketController.php @@ -230,6 +230,7 @@ class TicketController extends Controller if ($request->expectsJson() || $request->ajax()) { return response()->json([ 'checkout_url' => $result['checkout_url'], + 'access_code' => $result['access_code'] ?? '', 'sale_id' => $sale->id, ]); } @@ -237,6 +238,7 @@ class TicketController extends Controller return redirect() ->route('pos.tickets.show', $sale) ->with('checkout_url', $result['checkout_url']) + ->with('access_code', $result['access_code'] ?? '') ->with('success', 'Payment sheet ready — hand the device to the customer for card or MoMo.'); } catch (RuntimeException $e) { return back()->with('error', $e->getMessage()); diff --git a/app/Services/Payments/MerchantGatewayService.php b/app/Services/Payments/MerchantGatewayService.php index 87717f2..a6a5964 100644 --- a/app/Services/Payments/MerchantGatewayService.php +++ b/app/Services/Payments/MerchantGatewayService.php @@ -132,6 +132,7 @@ class MerchantGatewayService return [ 'checkout_url' => (string) $checkout['checkout_url'], + 'access_code' => (string) ($checkout['access_code'] ?? ''), 'reference' => (string) $checkout['reference'], 'provider' => 'ladill_pay', ]; @@ -186,6 +187,7 @@ class MerchantGatewayService return [ 'checkout_url' => $url, + 'access_code' => (string) ($response->json('data.access_code') ?? ''), 'reference' => (string) ($response->json('data.reference') ?: $reference), 'provider' => PaymentGatewaySetting::PROVIDER_PAYSTACK, ]; diff --git a/app/Services/Pos/PosSaleService.php b/app/Services/Pos/PosSaleService.php index b90d963..8081cab 100644 --- a/app/Services/Pos/PosSaleService.php +++ b/app/Services/Pos/PosSaleService.php @@ -362,7 +362,11 @@ class PosSaleService 'payment_reference' => $checkout['reference'], ])->save(); - return ['payment' => $payment, 'checkout_url' => $checkout['checkout_url']]; + return [ + 'payment' => $payment, + 'checkout_url' => $checkout['checkout_url'], + 'access_code' => (string) ($checkout['access_code'] ?? ''), + ]; } public function completePayPayment(string $reference): PosPayment @@ -577,6 +581,7 @@ class PosSaleService return [ 'sale' => $sale->fresh('lines'), 'checkout_url' => $checkoutUrl, + 'access_code' => (string) ($checkout['access_code'] ?? ''), ]; } diff --git a/resources/js/app.js b/resources/js/app.js index 0fb1976..5053df2 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -21,13 +21,17 @@ document.addEventListener('alpine:init', () => { Alpine.store('paymentCheckout', { isOpen: false, url: '', - open(url) { + accessCode: '', + open(url, accessCode = '') { this.url = url || ''; - this.isOpen = this.url !== ''; + this.accessCode = accessCode || ''; + this.isOpen = this.url !== '' || this.accessCode !== ''; }, close() { this.isOpen = false; this.url = ''; + this.accessCode = ''; + window.LadillPayCheckout?.cancel?.(); }, }); }); diff --git a/resources/views/partials/payment-checkout-host.blade.php b/resources/views/partials/payment-checkout-host.blade.php index 91d2855..f1f23eb 100644 --- a/resources/views/partials/payment-checkout-host.blade.php +++ b/resources/views/partials/payment-checkout-host.blade.php @@ -2,8 +2,9 @@
Opening payment…
+{{ $sheetTitle }}
- @if (! empty($sheetSubtitle)) -{{ $sheetSubtitle }}
- @endif -