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

wkinne's avatar

Laravel Cashier Stripe Tokens

Hi,

I keep getting this error when trying to test Stripe subscriptions.

"a similar object exists in test mode, but a live mode key was used to make this request."

In my .env file I have both my live and test keys stored.

In my service.php I am referencing both my Test Key and Secret Test Key.

But in the error I got it still shows Cashier and Token.php referencing my live key. I even tried deleting my stripe reference all together from service.php and the same error came up. Does laravel cashier store these keys anywhere else that it may be stored.

Also on the front end I am just using the basic JS that is referenced in the stripe documentation. Here it is:

jQuery(document).ready(function($) { Stripe.setPublishableKey('pk_test_OVtP7wR47ry9b3szLbmAd9e8'); $('#payment-form').submit(function(event) { event.preventDefault(); console.log('testing'); var $form = $(this); $form.find('button').prop('disabled', true); Stripe.card.createToken($form, stripeResponseHandler); return false; });

function stripeResponseHandler(status, response) { var $form = $('#payment-form'); if (response.error) { $form.find('.payment-errors').text(response.error.message); $form.find('button').prop('disabled', false); } else { var token = response.id; $form.append($('').val(token)); $form.get(0).submit(); } }; });

0 likes
1 reply
wkinne's avatar
wkinne
OP
Best Answer
Level 5

I was able to find the issue.

I create a STRIPE_KEY_TEST in my .env file and then references it in my service.php file liek this:

'stripe' => [ 'model' => App\User::class, 'key' => env('STRIPE_KEY_TEST'), 'secret' => env('STRIPE_SECRET_TEST'), ],

But as dug around I found that in Billable.php there is this function: public static function getStripeKey() { return static::$stripeKey ?: getenv('STRIPE_SECRET'); }

and that references the env name STRIPE_SECRET. This was causing the issue if anyone else runs into this.

Please or to participate in this conversation.