Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

shifoodew's avatar

Stripe Error: Invalid token id: tok_visa

Hi, I'm new to stripe and I encountered this error in the Live server.

Card type: Mastercard

I tested this card in my local development 5555555555554444 Mastercard but I don't encounter an error

but in the live server, I encountered this error using an actual card (Card type: Mastercard )

Invalid token id: tok_visa {"exception":"[object] (Stripe\Error\InvalidRequest(code: 0): Invalid token id: tok_visa

this is my local and live code

$customer= Customer::create([
                                'email'    => request('stripeEmail'),
                                'source'  => request('stripeToken')
                            ]);

$charge_customer= Charge::create([
                // 'customer'          => $customer_card,
                'source'            => 'tok_visa',
                'description'       => $product_data->name. 'x'.$qty,
                // 'description'       => $product->name. ' x'.$qty,
                'amount'            => round($total_amount * 100), //Cents format
                'currency'          => 'aud',
                'receipt_email'     => $email,
                'metadata'          => array(
                                            "product_id"        => $product_data->id, 
                                            "product_name"      => $product_data->name,
                                            "quantity"          => (int)$qty,
                                            "product_type"      => $product_type,
                                            "sub_type"          => $subtype,
                                            "user_id"           => $student_data->id,
                                            "fullname"          => $student_data->first_name." ".$student_data->last_name,
                                            "email"             => $email,
                                            "Payment made"      => "Thru Stripe using Whitebelt App"
                                        ),
                'application_fee' => round($platform_fee * 100), //Cents format
                ], array('stripe_account' => $CONNECTED_STRIPE_ACCOUNT_ID ) );

what should I do to fix and avoid that error?

    catch(\Stripe\Error\Card $e){
        return['error' => $e];
    }catch (\Stripe\Error\RateLimit $e) {
       return['error' => $e];
    } catch (\Stripe\Error\InvalidRequest $e) {
       return['error' => $e];
    } catch (\Exception $e) {
       return['error' => $e];
    }

and what test card should I used to generate that error?

I already tested this card number

4000000000000341

Attaching this card to a Customer object succeeds, but attempts to charge the customer fail.

any help will do.

0 likes
6 replies
shifoodew's avatar

@martinbean I mean when I'm testing my code at local it working fine. but in the live mode, we actually used an actual card. but generated an error.

martinbean's avatar

@shifoodew Look at your Charge::create() code. You have hard-coded tok_visa in there. tok_visa is a test token.

shifoodew's avatar

should I use the $request->stripeToken instead of tok_visa?

Please or to participate in this conversation.