简体   繁体   English

条纹jQuery验证-如何验证输入优惠券的有效性?

[英]Stripe jQuery validation - how to verify a validate of an entered coupon?

I am about to implement coupons to Stripe checkout and thinking whether there's a way to validate whether the entered coupon is still valid. 我即将对Stripe Checkout实施优惠券,并思考是否有一种方法可以验证输入的优惠券是否仍然有效。

Stripe released a jQuery library for checkouts ( https://github.com/stripe/jquery.payment ), but there's no mention about coupons. Stripe发布了一个用于结帐的jQuery库( https://github.com/stripe/jquery.payment ),但是没有提及优惠券。

Any ideas how to verify if the entered coupon is valid? 有什么想法如何验证输入的优惠券是否有效?

Thank you 谢谢

On your server side, you could include something like the following. 在服务器端,您可以包含以下内容。 This assumes your coupon codes are in your server/database in the coupon.rb model. 假设您的优惠券代码在coupon.rb模型中的服务器/数据库中。

# order creation controller
def create
  codes = Coupon.all.pluck(:code)
  code = params[:entered_code]

  begin
    raise "error" if codes.include? code
    # create
  rescue
    flash[:error] = "Coupon code is not valid"
    render 'new' # or something
  end
end

Client side validations would be more complicated. 客户端验证将更加复杂。 You wouldn't want to put all the coupon codes on the client for security reasons, but you could initiate an ajax call that checks the server side records for validation. 出于安全原因,您不希望将所有优惠券代码放在客户端上,但是您可以发起一个ajax调用来检查服务器端记录以进行验证。

Stripe currently only allow the use of coupons for Stripe Connect subscriptions. Stripe当前仅允许将优惠券用于Stripe Connect订阅。

Coupons are not valid for direct charges, and you have to implement your own reduction system yourself, before actually charging your customer. 优惠券不适用于直接收费,您必须在实际向客户收费之前自行实施自己的减免系统。

https://stripe.com/docs/recipes/coupons-for-charges https://stripe.com/docs/recipes/coupons-for-charges

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM