-
-
Notifications
You must be signed in to change notification settings - Fork 485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error when creating SubscriptionItems for metered plans #865
Comments
Note: the code below uses the Stripe API alongside dj-stripe, but there is likely a way to do this using just the dj-stripe code/objects as of v2. @therefromhere may be able to tell us, I don't know off the top off my head. Also, I'm just plucking off the first plan from the set Stripe Plans in the example below, be sure to set the subscription to the plan the user actually selected in the subscription form on your end before attempting to use this code. I'm also setting the trial_end parameter, in the event you've a trialing period and just haven't mentioned it yet - this is how you've ensure the trial begins - remove trial_end if the subscription is meant to be paid for, and thus the charge created, immediately upon successful instantiation of the subscription itself.
So the question becomes: You're setting a quantity when creating the subscription, correct? |
Yes, I am setting the quantity for the first subscription item to 0 when I create the subscription. It should be noted that I created the subscription from the Stripe dashboard. So this error is purely happening during the webhooks event callback. |
I've not looked into this deeply but it sounds like this could be a similar case to #773 - fudge the data on the stable 2.0 branch (which we won't allow migrations) using I've a feeling there's a different PR which was more similar but I can't find it right now. |
@jameschristopher - check your setup. I'm not sure why you want to instantiate a tiered subscription with a quantity of 0, but for gits and shiggles I went in and subscribed a customer to a tiered subscription with quantity=0, and the events/webhooks and updates to the application all went through and look fine on my end. Stripe API Version: 2018-11-08 |
Well the issue isn’t with tiered plans it’s with metered plans. |
@therefromhere I’ll give that a shot and update this thread |
Cool. Note that master and stable/2.0 are currently in sync since we didn't add any post-2.0 release breaking changes yet (migrations etc), so this would be a point where they'll diverge. |
It seems that
I also added a similar line to |
@jameschristopher I'm not sure why _manipulate_stripe_object_hook wasn't firing for you, I've gone ahead and implemented the fix as discussed as #866. |
Python==3.7.1
Django==2.1.7
djstripe==2.0.0
The issue seems to arise when processing the
customer.subscription.created
webhook callback. dj-stripe attempts to create theSubscriptionItem
s listed in the Stripe response. The Stripe response forSubscription
items that are on metered plans does not contain thequantity
attribute, thus when dj-stripe ingests that data it fails to create aSubscriptionItem
as thequantity
field does not accept null values nor does it have a default. Here is a snippet copied from my Stripe logs of what was POSTed to my webhook endpoint:You'll see that for the first (metered plan)
SubscriptionItem
thequantity
attribute is missing. I believe this is causing the error I'm seeing:Not entirely sure what the remedy is here, Stripe documentation for SubscriptionItem suggests that this attribute should be a positive integer or 0, but doesn't specify that the attribute is always present. dj-stripe may need to be modified to handle this case?
Everything works fine if I do not include the metered plan in the subscription.
Has anyone else dealt with this issue before?
The text was updated successfully, but these errors were encountered: