Stripe connect checkout session won’t work with connected account on direct charges PHP

I’m having a lot of trouble in getting my stripe checkout sessions working. Previously before making the payment a direct charge to the connected account and taking a fee, everything was working fine. Now with the updated code, everything functions as expected expect for the url when returning.
Which provides a 500 error, due to the checkout session not being recognized I assume.
The current code for creating a checkout session is below.

try {

            // Calculate the amount in Stripe's smallest unit
            $stripeAmount = $this->calculateStripeAmount($request['amounts'][$configItem['currency']]);

            // Calculate the 10% fee
            $feeAmount = $this->calculateFeeAmount($request['amounts'][$configItem['currency']]);

                

            $session = StripeCheckoutSession::create([
                'payment_method_types' => $paymentMethodTypes,
                'customer_email' => $request['payer_email'],
                'client_reference_id' => $request['order_id'],
                'line_items' => [[
                    'price_data' => [
                        'currency' => $configItem['currency'],
                        'unit_amount' => $this->calculateStripeAmount($request['amounts'][$configItem['currency']]),
                        'product_data' => [
                            'name' => $request['item_name'],
                            'description' => $request['description'],
                        ]
                    ],
                    'quantity' => 1,
                ]],
                'mode' => 'payment',


                'success_url' => getAppUrl($configItem['callbackUrl']) . '?stripe_session_id={CHECKOUT_SESSION_ID}' . '&paymentOption=stripe&orderId=' . $request['order_id'],
                'cancel_url' => getAppUrl($configItem['callbackUrl']) . '?stripe_session_id={CHECKOUT_SESSION_ID}' . '&paymentOption=stripe&orderId=' . $request['order_id'],
                'payment_intent_data' => [
                    'application_fee_amount' => $feeAmount,
                        ],
        

                
                 ], ['stripe_account' => $request['stripe_connect_account_id']],
             );
                    
            

              return $session;
        } catch (Exception $e) {
            //if payment failed set failed message
             $errorMessage = [
                'message' => 'failed',
                'errorMessage' => $e->getMessage(),
                'trace' => $e->getTraceAsString() // This will help in debugging
            ];
            return (array) $errorMessage;
        }
    }

 
        /**
         * Retrieve Stripe data by session Id
         *
         * @param string $sessionId
         *
         * request to Stripe checkout
         *---------------------------------------------------------------- */
        public function retrieveStripeData($sessionId)
        {
            try {
                $sessionData = StripeCheckoutSession::retrieve($sessionId);

                if (empty($sessionData)) {
                    throw new Exception("Session data does not exist.");
                }

                $paymentIntentData = StripePaymentIntent::retrieve($sessionData->payment_intent);

                return $paymentIntentData;
            } catch (StripeErrorInvalidRequest $err) {
                //set error message if payment failed
                $errorMessage['errorMessage'] = $err->getMessage();

                //return error message array
                return (array) $errorMessage;
            } catch (StripeErrorCard $err) {
                //set error message if payment failed
                $errorMessage['errorMessage'] = $err->getMessage();

                //return error message array
                return (array) $errorMessage;
            }
        }

Here is the front end in another file, ignore the public key not using the variable as that is on purpose and needs to be removed.

if(payWidth == 'stripe'){
            $(".payment_method_box").css("pointer-events", "auto");
            $(".loaderWrapper").remove();
            //config data For Stripe
            var configData = <?php echo json_encode($PublicConfigs); ?> ,
            configItem = configData['payments']['gateway_configuration']['stripe'],
                userDetails = <?php echo json_encode($DataUserDetails); ?> ,
            stripePublishKey = '';
            //check stripe test or production mode
            if (configItem['testMode'] === 'true') {
                stripePublishKey = '<?php echo $stripePaymentTestPublicKey;?>';
            } else {
                stripePublishKey = '<?php echo $stripePaymentLivePublicKey;?>';
            }
            /*if (configItem['testMode']) {
                stripePublishKey = configItem['stripeTestingPublishKey'];
            } else {
                stripePublishKey = configItem['stripeLivePublishKey'];
            }*/
            userDetails['paymentOption'] = payWidth;
            userDetails['f'] = 'processProduct';
            userDetails['creditPlan'] = planID;
            // Stripe script for send ajax request to server side start
            $.ajax({
                type: 'post', //form method
                context: this,
                url: siteurl + 'requests/request.php', // post data url
                dataType: "JSON",
                data: userDetails, // form serialize data
                error: function(err) {
                    var error = err.responseText
                    string = '';
                    alert(err.responseText);
                },
                success: function(response) {
                    //alert(response.id);
                    var stripe = Stripe('pk_test_51NfvLOJKlCTqPFwWMLFchWWnSWqy8v1JECWnjMSUxaUfomcl1ru5gSpxh3u395GPwDy23oVMK7tFpfAYuhkOkZwl009owSqTbq', {
                        stripeAccount: ('<?php echo $stripeConnectAccountId;?>')
                    });
                    //alert(stripe);
                    stripe.redirectToCheckout({
                        sessionId: response.id,
                    }).then(function(result) {
                        var string = '';
                        alert(result.error.message);
                    });
                }
            });
        }

Aswell as the error provided by stripe logs below. enter image description here

I’m very new to js and php, which may show in the code. I’m aware this is a lot to ask, but if anyone could provide guidance on where the issue may be arising from it would be greatly appreciated.

One idea I’ve had is that the customer might be getting created under the platform, while the checkout session is under the connected account. I’ve attempted to create a customer and use the same line with stripe_account but the result was the same.