Skip to content

Simplify subscription creation #590

@begedin

Description

@begedin

Problem

Right now, this is how the creation of a subscription record works:

  • We get the quantity and the current user
  • We do a store.createRecord using quantity and current user.
  • We call save, with an adapterOptions parameter hash, containing a projectId key
subscription.save({ adapterOptions: { projectId: currentProjectId} })

The adapterOptions hash is handled during serialization and the project id is added as a plain JSON API attribute to the payload.

Then, on the API side, the controller receives the request and passes the parameters into StripeService.StripeConnectSubscription.find_or_create/2, which, during a long process, loads the project and the plan for that project, then assigns the plan to the subscription during creation.

My guess is, this was done when we didn't yet have a stripe connect plan relationship with the project on ember side. It's needlessly complicated.

I propose that we do the following:

In Ember we simply

  • fetch the user, quantity and stripeConnectPlan
  • create and save a stripeConnectSubscription record using those properties
  • get rid of the whole adapterOptions logic
  • get rid of the projectId virtual attribute

In API we

  • expect the find_or_create request to receive a plan id
  • rework project loading to load by associated plan id (we still need the project to validate that it is ready to accept donations)
  • everything else remains the same
  • clean up subscription controller tests. they do not need the custom payloads anymore

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions