From 290498c7283373cdb942e101dbdffa34b23a5d18 Mon Sep 17 00:00:00 2001 From: Russ Long Date: Fri, 1 May 2026 09:27:36 -0400 Subject: [PATCH] fix: improve Google Pay handling with additional status checks, robust data extraction, and a fallback verification button --- .../Controllers/NorthCheckoutController.php | 17 +++++++-- resources/views/north_checkout.blade.php | 38 +++++++++++++++++-- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/NorthCheckoutController.php b/app/Http/Controllers/NorthCheckoutController.php index 2a978e3..71e83a1 100644 --- a/app/Http/Controllers/NorthCheckoutController.php +++ b/app/Http/Controllers/NorthCheckoutController.php @@ -133,8 +133,8 @@ class NorthCheckoutController extends Controller $status = $response->json(); $currentStatus = $status['status'] ?? ''; - // The North API status check might return Approved, completed, or success. - $successStatuses = ['approved', 'completed', 'success']; + // The North API status check might return Approved, completed, success, authorized, or captured. + $successStatuses = ['approved', 'completed', 'success', 'authorized', 'captured']; if (in_array(strtolower($currentStatus), $successStatuses)) { // Check if already checked out to avoid duplicates @@ -142,10 +142,19 @@ class NorthCheckoutController extends Controller if (!$existingCheckout) { // According to docs, when status is Approved, transaction details are in 'body' + // Digital wallets might have these at the top level $body = $status['body'] ?? []; - $winnertotal = $status['amount'] ?? ($body['amount'] ?? WinningBids::where('winning_bidder_num', $bidder->idbidders)->sum('winning_cost')); + $winnertotal = $status['amount'] ?? + ($body['amount'] ?? + ($status['amount_total'] ?? + WinningBids::where('winning_bidder_num', $bidder->idbidders)->sum('winning_cost'))); + $payment_method = 3; // Credit Card - $cc_transaction = $body['auth_guid'] ?? ($status['transactionId'] ?? 'NORTH_EC'); + $cc_transaction = $body['auth_guid'] ?? + ($status['transaction_id'] ?? + ($status['transactionId'] ?? + ($status['id'] ?? 'NORTH_EC'))); + $cc_amount = $winnertotal; $check_number = null; diff --git a/resources/views/north_checkout.blade.php b/resources/views/north_checkout.blade.php index 3e28a64..6a520d9 100644 --- a/resources/views/north_checkout.blade.php +++ b/resources/views/north_checkout.blade.php @@ -65,11 +65,43 @@ console.log('Mounting checkout with token:', sessionToken); await checkout.mount(sessionToken, 'checkout-container'); - // Handle completion - checkout.onPaymentComplete((result) => { + const handleCompletion = (result) => { + console.log('Payment complete event received:', result); // Redirect to verify the payment on the server window.location.href = `/north/verify/${bidderId}?sessionToken=${sessionToken}`; - }); + }; + + // Handle completion + checkout.onPaymentComplete(handleCompletion); + + // Support for possible variations in event names + if (typeof checkout.onPaymentSuccess === 'function') { + checkout.onPaymentSuccess(handleCompletion); + } + + // Handle errors + if (typeof checkout.onPaymentError === 'function') { + checkout.onPaymentError((error) => { + console.error('Payment Error:', error); + // Don't clear the container, just prepend the error + const errorDiv = document.createElement('div'); + errorDiv.className = 'alert alert-danger'; + errorDiv.innerHTML = `Payment Error: ${error.message || 'An error occurred during payment.'}`; + document.querySelector('.panel-body').prepend(errorDiv); + }); + } + + // Show a fallback button after a short delay to allow for manual verification if the redirect fails + setTimeout(() => { + const fallbackDiv = document.createElement('div'); + fallbackDiv.className = 'text-center'; + fallbackDiv.style.marginTop = '20px'; + fallbackDiv.innerHTML = ` +

Already completed your payment but still on this page?

+ Verify Payment Status + `; + document.querySelector('.panel-body').appendChild(fallbackDiv); + }, 5000); } catch (error) { console.error('Checkout Error:', error);