fix: improve Google Pay handling with additional status checks, robust data extraction, and a fallback verification button

This commit is contained in:
2026-05-01 09:27:36 -04:00
parent aca21ae115
commit 290498c728
2 changed files with 48 additions and 7 deletions
@@ -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;
+34 -2
View File
@@ -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 = `<strong>Payment Error:</strong> ${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 = `
<p class="text-muted">Already completed your payment but still on this page?</p>
<a href="/north/verify/${bidderId}?sessionToken=${sessionToken}" class="btn btn-info">Verify Payment Status</a>
`;
document.querySelector('.panel-body').appendChild(fallbackDiv);
}, 5000);
} catch (error) {
console.error('Checkout Error:', error);