简体   繁体   中英

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 released a jQuery library for checkouts ( https://github.com/stripe/jquery.payment ), but there's no mention about coupons.

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.

# 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.

Stripe currently only allow the use of coupons for Stripe Connect subscriptions.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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