[14.x] Fix deletion of subscription items in swap() #1509
Merged
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.
This pull request fixes an issue in
Subscription::swap()
where subscription item models created using inline prices (viaprice_data
) instead of an existing Stripe price are immediately deleted after creation:Items using inline price data will not be keyed by
price
inparseSwapPrices()
, meaning they will not be found by$items->pluck('price')
. This change simply uses the item data returned by the updated Stripe subscription object as the source of truth instead of the array that is initially passed toswap()
. FWIW, I considered adding post-creation/swapping item relation counts to the feature tests relating to inline prices but saw that you weren't testing for such things anywhere else, so I'll keep them to my local branch for now.Presumably this hasn't been much of an issue for people who have followed the docs during initial setup, as the deleted items are re-created almost immediately via the
customer.subscription.updated
webhook (I initially started looking into this as I thought I was experiencing some sort of odd race condition in my site's codebase).This is my first-ever PR, so if I've mucked anything up or can otherwise be of assistance please let me know! 馃槃