46

I'm familiar with the process of clearing test data via the dashboard in Stripe (as per the image).

For testing purposes, I would like to clear the test data as part of the tear down process of our unit tests - to have a clean state at the end of each test cycle.

The API documentation doesn't mention anything, so is there an undocumented way to clear the test data?

Just a note, in the new dashboard, test data deletion lives on the Developers tab:

enter image description here

koopajah
  • 23,792
  • 9
  • 78
  • 104
Chris
  • 54,599
  • 30
  • 149
  • 186
  • Careful with undocumented features--they're prone to change without warning! – Evan Dec 23 '15 at 06:10
  • Agreed. For the sake of unit testing (ie not operating against prod) and the fallback of going back to manual,(our current process) I happy to take said risk – Chris Dec 23 '15 at 06:11
  • I hear that. Anything to speed up tests! (without detracting from the validity of those tests, that is) – Evan Dec 23 '15 at 06:12
  • This is a very old question, but the first one I found via Google. For any future readers, it's best to keep track of all created objects during unit testing, then delete them after the test is done. All stripe objects have a delete function, so whether you have to query your database for tokens, or query each stripe module to retrieve all objects, I think that's the preferred action. Bonus: make the tear down a test itself - make sure your delete calls actually delete the objects. – Polosky Oct 11 '18 at 04:02
  • @Hondros Hmm, I'm on the fence about your comment. I understand what you are saying, but manually deleting means your tests are subject to error - you don't know that a delete is the exact opposite of a create (ie, you can't predict the side effects of the create, so how can you guarantee a clean slate?) – Chris Mar 05 '19 at 02:35
  • @Chris Calling the delete function on a Stripe object doesn't just manually remove a reference. It will (should, at least in my experience) delete any objects that was created during it's own creation. For example, say there was an associated user created with a token via token.create({userstuffhere}) and it returns token 't'. Calling 't.delete()' "should" delete both token 't' as well as the user. However, that being said, I do like to be verbose in my tests and manually create/delete all required artifacts so I haven't run into that issue. – Polosky Mar 05 '19 at 15:05
  • @Hondros I understand what you mean, and have had similar experience. There are some things not stricken from the record, like payouts, logs and a few other bits and bobs. It really depends on the use case at the end of the day and what you are testing, and for 99% of the typical things that might be tested, what you said is probably suffificent – Chris Mar 05 '19 at 23:07
  • @Ywain not sure if you work at stripe but an api endpoint for deleting test data would be a great feature to add. I already update webhook urls via the api & it saves valuable time. – tinmac Nov 23 '19 at 16:34

4 Answers4

40

No, it isn't possible to clean all test data via the API -- only via the dashboard. Sorry!

In the Dashboard, the option now lives at the bottom of the Developers page

koopajah
  • 23,792
  • 9
  • 78
  • 104
Ywain
  • 16,854
  • 4
  • 51
  • 67
  • 6
    Curious if there was been an update on this over the last 12 months? I had forgotten about it - but its still getting upvotes. Does stripe have a recommend way of testing on this front? – Chris Jan 16 '17 at 02:21
  • How to do it from dashboard? I found no such option in strip on current date. – Curious Developer Jun 08 '18 at 12:21
  • 1
    I used the option and our test data has been deleting for over an hour. Is this normally a long process? – Graymatter Oct 02 '18 at 22:19
  • @Graymatter Unfortunately, yes, the process can be quite long depending on the quantity of test data. – Ywain Oct 03 '18 at 11:53
  • 2
    @Ywain Was this ever added to Stripe? It still seems to get upvotes to this day (5 years later) – Chris Jan 21 '20 at 13:10
  • @Chris It still isn't possible to trigger this via the API, but we've recently made big improvements to the overall speed of the process. It can still take a long time depending on how much test data there is, but the process should take 10-20x less time than before. – Ywain Jan 22 '20 at 01:49
  • 2
    Why would you still not implement this? – Stephan-v May 05 '20 at 08:16
  • 1
    @Ywain yeah, how come this is not relevant to stripe? I mean I got thousands of dead and outdated test objecty lying around since I cannot delete them easily and want some pieces of test data regarding prices and products to remain... And I guess I am not the only one.... – TomFree Feb 14 '23 at 15:59
  • 1
    @TomFree I no longer work at Stripe. My best advice is to provide your feedback via the Stripe Developers Discord (https://stripe.com/go/developer-chat). – Ywain Feb 15 '23 at 16:58
  • This really sucks. I don't want to delete all my test products because I use the 'copy to live' function. I only want to delete mess created by the stripe_cli testing. – Dirk R Mar 13 '23 at 10:35
7

The dashboard has changed once again. You can now find it by clicking "Settings" in the lower left-hand corner. Then scroll down to the "Compliance and reporting" section. Click Data. Here you will find the "Delete all test data..." button

Burton
  • 821
  • 8
  • 16
5

The Dashboard appears to again have changed for me at least. I don't have the Data section under Compliance & Reporting, however in their search menu if you type "Data" and then select the "Developer" option that appears, that page will give you the option to remove the data.

Alec Weekes
  • 61
  • 1
  • 2
3

In the latest update of stripe you can find the action button for removing test data in

https://dashboard.stripe.com/test/developers