stockpile-co / api

The API for Stockpile, an app that manages stuff for organizations.
0 stars 1 forks source link

Make subscription creation atomic #283

Closed AdamVig closed 6 years ago

AdamVig commented 7 years ago

As a Stockpile owner, I want to make sure that no partially-created subscriptions exist so that I can more easily troubleshoot subscription problems.

When a subscription is created, it carries out the following steps:

  1. Create Stripe customer
  2. Create Stockpile organization
  3. Create Stockpile user in that organization

If any of the steps fail, all the steps after it will not be completed. This means:

The whole operation should be atomic: if any part of it fails, then the whole thing is rolled back. This will require maintaining the IDs of each of the created entities in a way that can be accessed by the .catch() on the promise chain, so that the entities can be safely deleted. It will also require a way to determine which entity prompted the error that the .catch() is handling.