fix: improve Google Pay handling with additional status checks, robust data extraction, and a fallback verification button
This commit is contained in:
@@ -133,8 +133,8 @@ class NorthCheckoutController extends Controller
|
|||||||
$status = $response->json();
|
$status = $response->json();
|
||||||
$currentStatus = $status['status'] ?? '';
|
$currentStatus = $status['status'] ?? '';
|
||||||
|
|
||||||
// The North API status check might return Approved, completed, or success.
|
// The North API status check might return Approved, completed, success, authorized, or captured.
|
||||||
$successStatuses = ['approved', 'completed', 'success'];
|
$successStatuses = ['approved', 'completed', 'success', 'authorized', 'captured'];
|
||||||
|
|
||||||
if (in_array(strtolower($currentStatus), $successStatuses)) {
|
if (in_array(strtolower($currentStatus), $successStatuses)) {
|
||||||
// Check if already checked out to avoid duplicates
|
// Check if already checked out to avoid duplicates
|
||||||
@@ -142,10 +142,19 @@ class NorthCheckoutController extends Controller
|
|||||||
|
|
||||||
if (!$existingCheckout) {
|
if (!$existingCheckout) {
|
||||||
// According to docs, when status is Approved, transaction details are in 'body'
|
// According to docs, when status is Approved, transaction details are in 'body'
|
||||||
|
// Digital wallets might have these at the top level
|
||||||
$body = $status['body'] ?? [];
|
$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
|
$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;
|
$cc_amount = $winnertotal;
|
||||||
$check_number = null;
|
$check_number = null;
|
||||||
|
|
||||||
|
|||||||
@@ -65,11 +65,43 @@
|
|||||||
console.log('Mounting checkout with token:', sessionToken);
|
console.log('Mounting checkout with token:', sessionToken);
|
||||||
await checkout.mount(sessionToken, 'checkout-container');
|
await checkout.mount(sessionToken, 'checkout-container');
|
||||||
|
|
||||||
// Handle completion
|
const handleCompletion = (result) => {
|
||||||
checkout.onPaymentComplete((result) => {
|
console.log('Payment complete event received:', result);
|
||||||
// Redirect to verify the payment on the server
|
// Redirect to verify the payment on the server
|
||||||
window.location.href = `/north/verify/${bidderId}?sessionToken=${sessionToken}`;
|
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) {
|
} catch (error) {
|
||||||
console.error('Checkout Error:', error);
|
console.error('Checkout Error:', error);
|
||||||
|
|||||||
Reference in New Issue
Block a user