Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live environment fails when test customer is used #311

Closed
ryssbowh opened this issue Sep 13, 2024 · 6 comments
Closed

Live environment fails when test customer is used #311

ryssbowh opened this issue Sep 13, 2024 · 6 comments

Comments

@ryssbowh
Copy link

ryssbowh commented Sep 13, 2024

Description

We have a website just gone live (migrated from Craft 3) where payments are failing for admin users. Those users have been making payments on the dev version of the website and in Stripe they are linked to a test environment. Stripe complains :

Could not fetch Stripe customer: No such customer: 'cus_Ge1tS7lpPzAWCK'; a similar object exists in test mode, but a live mode key was used to make this request

The only thing I can do is deleting the record in the stripe_customers table and it fixes the issue.

Shouldn't stripe customers be environment aware ? or should we have a way to delete those references in Craft itself ?

Thank you

Steps to reproduce

  1. Make a payment on a dev site in a Stripe test environment
  2. Make a payment on the live version of the dev site in a Stripe production environment

Additional info

  • Craft CMS version: 4.12.1
  • Stripe for Craft Commerce version: 4.1.5
  • PHP version: 8.2
  • Database driver & version:
  • Plugins & versions:
Copy link

linear bot commented Sep 13, 2024

@ryssbowh
Copy link
Author

ryssbowh commented Oct 7, 2024

This is also an issue when trying to save payment methods using craft\commerce\controllers\PaymentSourcesController::actionAdd

@sm9
Copy link

sm9 commented Nov 12, 2024

Hi, we have also just run into this issue. We're using Craft 4.10.2, Commerce 4.6.4, Stripe for Craft Commerce 4.1.5, and PHP 8.1.29.

User accounts that have placed orders on the staging site and Stripe test mode previously are showing the error that @ryssbowh has reported above on the live site in Stripe live mode.

Is carrying out the suggested fix above safe, and also what @lukeholder recommends doing as a workaround for now? Or is a proper fix imminent?

The only thing I can do is deleting the record in the stripe_customers table and it fixes the issue.

Thanks,

Stephen

@teachmeter
Copy link

This is also an issue when you remove the customers from the test environment on Stripe and using Live Keys.
The error then becomes No such customer: 'cus_AABBCCDDEE'

I think a simple solution would be to store in the stripe_customers table some kind of md5 with the keys used which could be quickly calculated before getting the information from the db.
THis would allow to have multiple identity per keypair for a user aka env switch.

Switching then back and forth would also not require any adjustments in the stripe environment.

@nfourtythree
Copy link
Contributor

Hi all

This is a common issue with carrying over test data into the live environment as the data that is stored in Stripe is completely separate.

If you are importing data into your production site when you are about to go live it is wise to use the craft commerce-stripe/reset-data data command to remove all Stripe references to the test environment.

This is also a useful command when pulling a production DB to work on locally, you can run the command on your local dev to remove the references to the live Stripe environment.

Hope this helps, thanks!

@sm9
Copy link

sm9 commented Jan 29, 2025

Hi Nathaniel, thanks for posting back about this.

What is the best way to remove test Stripe data from a live database, without wiping live data? As an example, we have a client that had a front-end rebuild and was using a private 'beta' version of the website for testing, prior to launch. We weren't aware of the craft commerce-stripe/reset-data command at that time. So we've ended up in a situation where we're running into this error when the client uses their own account on the live site (as they used their own account when testing the private beta).

The original poster said in the first message:

The only thing I can do is deleting the record in the stripe_customers table and it fixes the issue.

Is this the best workaround to use in our situation? I just wanted to double-check before deleting anything from the database, in case there were any knock-on effects to this that we weren't aware of.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants