subscription.plan is nil error on update_subscription_quantity.rb? #858
Unanswered
WillNigel23
asked this question in
Q&A
Replies: 1 comment
-
This means your subscription's plan association isn't returning the plan. You'll need to make sure you have a plan with |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
On my accounts.rb I have an after create callback
def set_fake_trial
set_payment_processor(:fake_processor, allow_fake: true)
if users.any?(&:admin?)
payment_processor.subscribe
else
payment_processor.subscribe(trial_ends_at: 14.days.from_now, ends_at: 14.days.from_now)
end
end
I get an error:
NoMethodError: undefined method `charge_per_unit?' for nil:NilClass
As a workaround, I tried adding
return unless subscription&.active? && subscription.plan&.charge_per_unit?
to bypass the plan is nil error. But doing this causes further errors along the road, like for example my user is currently subscribed to the trial plan and wants to upgrade to a stripe plan, I get errors regarding subscription.plan is nil on some other functions as well.This error does not happen to a user if I don't subscribe them to a fake trial. They can go straight to subscribing to stripe no problem. I need the fake trial to work tho so I can give users access without asking for their credit card.
Beta Was this translation helpful? Give feedback.
All reactions