我正在使用rails的條紋寶石,我試圖檢查用戶的優惠券代碼是否無效。如果代碼是無效的,那麼用戶會被重定向到users/show.html.haml
檢查條紋優惠券是否無效
這裏是我的代碼
if Stripe::Coupon.retrieve(current_user.coupon_code) == nil
redirect_to user_path(current_user)
end
我認爲檢索從條紋的代碼,並確認是否值nil
會工作,但錯誤我得到的消息是:
Stripe::InvalidRequestError in SubscribersController#new
No such coupon: *Whatever the invalid coupon name is (ex. "ASDF")*
關於這裏發生了什麼的任何想法?我查看了Ruby的Stripe文檔,並沒有看到關於如何檢查代碼是否無效的任何信息。是否有另一種方法來檢查代碼是否等於或不等於nil
?
https://stripe.com/docs/api #errors –