【问题标题】:Stripe jQuery validation - how to verify a validate of an entered coupon?Stripe jQuery 验证 - 如何验证输入的优惠券的验证?
【发布时间】:2014-09-10 09:26:26
【问题描述】:

我即将在 Stripe 结帐中实施优惠券,并考虑是否有办法验证输入的优惠券是否仍然有效。

Stripe 发布了一个用于结账的 jQuery 库 (https://github.com/stripe/jquery.payment),但没有提及优惠券。

任何想法如何验证输入的优惠券是否有效?

谢谢

【问题讨论】:

    标签: javascript jquery ruby-on-rails stripe-payments coupon


    【解决方案1】:

    Stripe 目前只允许使用优惠券订阅 Stripe Connect。

    优惠券不适用于直接收费,在实际向客户收费之前,您必须自己实施自己的折扣系统。

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

    【讨论】:

      【解决方案2】:

      在您的服务器端,您可以包含以下内容。这假设您的优惠券代码位于 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
      

      客户端验证会更复杂。出于安全原因,您不希望将所有优惠券代码都放在客户端上,但您可以发起一个 ajax 调用来检查服务器端记录以进行验证。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-06-14
        • 2023-01-17
        • 2021-01-19
        • 1970-01-01
        • 2022-01-16
        • 1970-01-01
        • 2021-06-12
        • 2017-09-26
        相关资源
        最近更新 更多