forked from TFMM/silent-auction
fix: handle 'Approved' status and extract nested transaction ID from North API response
This commit is contained in:
@@ -131,18 +131,22 @@ class NorthCheckoutController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$status = $response->json();
|
$status = $response->json();
|
||||||
|
$currentStatus = $status['status'] ?? '';
|
||||||
|
|
||||||
// The North API status check might return success/completed.
|
// The North API status check might return Approved, completed, or success.
|
||||||
// Based on docs, we should check status.
|
$successStatuses = ['approved', 'completed', 'success'];
|
||||||
if (isset($status['status']) && ($status['status'] === 'completed' || $status['status'] === 'success')) {
|
|
||||||
|
if (in_array(strtolower($currentStatus), $successStatuses)) {
|
||||||
// Check if already checked out to avoid duplicates
|
// Check if already checked out to avoid duplicates
|
||||||
$existingCheckout = Checkout::where('bidder_num', $bidder->idbidders)->first();
|
$existingCheckout = Checkout::where('bidder_num', $bidder->idbidders)->first();
|
||||||
|
|
||||||
if (!$existingCheckout) {
|
if (!$existingCheckout) {
|
||||||
$winnertotal = $status['amount'] ?? WinningBids::where('winning_bidder_num', $bidder->idbidders)->sum('winning_cost');
|
// According to docs, when status is Approved, transaction details are in 'body'
|
||||||
|
$body = $status['body'] ?? [];
|
||||||
|
$winnertotal = $status['amount'] ?? ($body['amount'] ?? WinningBids::where('winning_bidder_num', $bidder->idbidders)->sum('winning_cost'));
|
||||||
$payment_method = 3; // Credit Card
|
$payment_method = 3; // Credit Card
|
||||||
$cc_transaction = $status['transactionId'] ?? 'NORTH_EC';
|
$cc_transaction = $body['auth_guid'] ?? ($status['transactionId'] ?? 'NORTH_EC');
|
||||||
$cc_amount = $status['amount'] ?? $winnertotal;
|
$cc_amount = $winnertotal;
|
||||||
$check_number = null;
|
$check_number = null;
|
||||||
|
|
||||||
$checkout_id = DB::table('checkout')->insertGetID(
|
$checkout_id = DB::table('checkout')->insertGetID(
|
||||||
|
|||||||
Reference in New Issue
Block a user