I am using the stripe gem for rails and I am trying to check if a user's coupon code is invalid. If the code is invalid, then the user is redirected to users/show.html.haml
Here is my code
if Stripe::Coupon.retrieve(current_user.coupon_code) == nil
redirect_to user_path(current_user)
end
I thought that retrieving the code from Stripe and checking whether or not the value is nil
would work but the error message I get is:
Stripe::InvalidRequestError in SubscribersController#new
No such coupon: *Whatever the invalid coupon name is (ex. "ASDF")*
Any idea as to what is going on here? I looked through the Stripe documentation for Ruby and didn't see any info on how to check if a code is invalid. Is there another way to check if a code is equal or not equal to nil
?