forked from TFMM/silent-auction
fix: improve API request headers and error reporting for session creation and verification
This commit is contained in:
@@ -50,6 +50,8 @@ class NorthCheckoutController extends Controller
|
|||||||
|
|
||||||
$response = Http::withHeaders([
|
$response = Http::withHeaders([
|
||||||
'Authorization' => 'Bearer ' . $apiKey,
|
'Authorization' => 'Bearer ' . $apiKey,
|
||||||
|
'Accept' => 'application/json',
|
||||||
|
'Content-Type' => 'application/json',
|
||||||
])->post('https://checkout.north.com/api/sessions', [
|
])->post('https://checkout.north.com/api/sessions', [
|
||||||
'checkoutId' => $checkoutId,
|
'checkoutId' => $checkoutId,
|
||||||
'profileId' => $profileId,
|
'profileId' => $profileId,
|
||||||
@@ -58,10 +60,24 @@ class NorthCheckoutController extends Controller
|
|||||||
|
|
||||||
if ($response->failed()) {
|
if ($response->failed()) {
|
||||||
Log::error('North Session Creation Failed: ' . $response->status() . ' ' . $response->body());
|
Log::error('North Session Creation Failed: ' . $response->status() . ' ' . $response->body());
|
||||||
return response()->json(['error' => 'Failed to create checkout session: ' . ($response->json('message') ?? 'Unknown error')], 500);
|
return response()->json([
|
||||||
|
'error' => 'Failed to create checkout session: ' . ($response->json('message') ?? 'Unknown error'),
|
||||||
|
'status' => $response->status(),
|
||||||
|
'body' => $response->body()
|
||||||
|
], 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $response->json();
|
$data = $response->json();
|
||||||
|
|
||||||
|
// If json() is null but body is not empty, it might be a parsing error
|
||||||
|
if (is_null($data) && !empty($response->body())) {
|
||||||
|
Log::error('North Session Response is not JSON: ' . $response->body());
|
||||||
|
return response()->json([
|
||||||
|
'error' => 'Response from North is not valid JSON.',
|
||||||
|
'raw_body' => $response->body()
|
||||||
|
], 500);
|
||||||
|
}
|
||||||
|
|
||||||
$token = $data['token'] ??
|
$token = $data['token'] ??
|
||||||
$data['sessionToken'] ??
|
$data['sessionToken'] ??
|
||||||
$data['id'] ??
|
$data['id'] ??
|
||||||
@@ -72,7 +88,8 @@ class NorthCheckoutController extends Controller
|
|||||||
Log::error('North Session Token Missing in Response: ' . json_encode($data));
|
Log::error('North Session Token Missing in Response: ' . json_encode($data));
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'error' => 'Session token not found in API response.',
|
'error' => 'Session token not found in API response.',
|
||||||
'debug_response' => $data
|
'debug_response' => $data,
|
||||||
|
'raw_body' => $response->body()
|
||||||
], 500);
|
], 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,15 +105,20 @@ class NorthCheckoutController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$apiKey = config('services.north.private_api_key');
|
$apiKey = config('services.north.private_api_key');
|
||||||
|
$checkoutId = config('services.north.checkout_id');
|
||||||
|
$profileId = config('services.north.profile_id');
|
||||||
|
|
||||||
$response = Http::withHeaders([
|
$response = Http::withHeaders([
|
||||||
'Authorization' => 'Bearer ' . $apiKey,
|
'Authorization' => 'Bearer ' . $apiKey,
|
||||||
])->get('https://checkout.north.com/api/sessions/status', [
|
'SessionToken' => $sessionToken,
|
||||||
'sessionToken' => $sessionToken,
|
'CheckoutId' => $checkoutId,
|
||||||
]);
|
'ProfileId' => $profileId,
|
||||||
|
'Accept' => 'application/json',
|
||||||
|
])->get('https://checkout.north.com/api/sessions/status');
|
||||||
|
|
||||||
if ($response->failed()) {
|
if ($response->failed()) {
|
||||||
Log::error('North Session Verification Failed: ' . $response->body());
|
Log::error('North Session Verification Failed: ' . $response->status() . ' ' . $response->body());
|
||||||
return redirect('/mywinnings?bidder_number=' . $bidder->bidder_assigned_number)->with('error', 'Failed to verify payment status.');
|
return redirect('/mywinnings?bidder_number=' . $bidder->bidder_assigned_number)->with('error', 'Failed to verify payment status. Status: ' . $response->status());
|
||||||
}
|
}
|
||||||
|
|
||||||
$status = $response->json();
|
$status = $response->json();
|
||||||
|
|||||||
Reference in New Issue
Block a user