Update ManagesCustomer to include optional metadata when creating or syncing a user #1543
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Our
User
model has theBillable
trait applied to it. In order to make it easier to search Stripe for the correct user, we've been syncing the user ID in the metadata. I've noticed this has lead to a decent amount of code duplication.This also means that if someone else is writing code that creates/syncs users in Stripe, they need to 1) know it won't send this metadata over and 2) remember to include it. It would be much easier if I could just define the metadata that should be included once on the
User
model and know that it would be included consistently every time.This PR introduces a
stripeMetadata()
method to theManagesCustomers
concern. By default, it will just send over a null object and not set the metadata. However, if I wanted to specify some custom metadata on myBillable
object, all I would need to do is add:I haven't written any automated tests for this functionality, as I didn't see any for similar methods (e.g.
stripeName()
,stripeEmail()
, etc.). I did manually test it and verified that it worked as expected for when no metadata is specified, and when custom metadata is provided.