Undefined index: transaction_id

Undefined index: transaction_id
#0 C:appHttpControllersSendMoneyController.php(190): IlluminateFoundationBootstrapHandleExceptions->handleError(8,
‘Undefined index…’, ‘C:\…’, 190, Array)

Can someone help me, I encounter this error.

This is where the error comes from 'transaction_id' => $transactionResponse['transaction_id']

public function submitPaymentMethod ( Request $request )
    // we'll get all the data we need for us to be able to use the transactionService
    $paymentMethodId = $request->input('payment_method_id');        
    $recipientId = $request->input('recipient_id');
    $countryFromId = $request->input('country_from_id');
    $countryToId = $request->input('country_to_id');
    $amountSend = $request->input('sent_amount');
    $payOutNetworkId = $request->input('pay_out_network_id');
    $userCurrencyCode = $request->input('user_currency_code');
    $recipientCurrencyCode = $request->input('recipient_currency_code');
    $countryNameTo = $request->input('user_country_name');
    $countryNameFrom = $request->input('recipient_country_name');
    $countryPayOutNetworkId = $request->input('country_pay_out_networks_id');
    $stripeToken = $request->input('stripe_token');

    // we'll use the newly make service transactionService that will handle all transaction related
    // such as handling in stripe and saving in db, then pass it to a variable
    $transactionResponse = $this->transactionService->submitPayment( $stripeToken, $paymentMethodId, $recipientId, $countryFromId, $countryToId, $amountSend, $payOutNetworkId, $userCurrencyCode, $recipientCurrencyCode, $countryNameTo, $countryNameFrom, $countryPayOutNetworkId );
    // we'll then return that transactionService return for us to display in front
    return response()->json([
        'success' => $transactionResponse['success'],
        'message' => $transactionResponse['message'],
        'transaction_id' => $transactionResponse['transaction_id']
    ], 200);

Why the error is undefined index? Thank you


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

This is a pretty basic error to track down. undefined index means you are trying to access an index of an array which does not exist. Which means you are not even checking the response before handing it off.

        return response()->json([
            'success' => isset($transactionResponse['success']) ? $transactionResponse['success'] : false,
            'message' => isset($transactionResponse['message']) ? $transactionResponse['message'] : '',
            'transaction_id' => isset($transactionResponse['transaction_id']) ? $transactionResponse['transaction_id'] : null
        ], 200);

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x