【问题标题】:How to add coupons to stripe checkout如何将优惠券添加到条纹结帐
【发布时间】:2020-12-17 01:36:38
【问题描述】:

我在我的 ruby​​ on rails 5 网站上为我的支付网关计划使用条纹。我在客户端使用 api,就像它出现在 this link 中一样。我需要在我的计划中添加优惠券,我可以像计划一样在测试模式的条带仪表板中创建它,但是将 id 添加到代码中不会将我重定向到条带结帐页面。这是我的 javascript 代码:

    <script src="https://js.stripe.com/v3"></script>
    
    <script type="text/javascript">
    
      $(document).ready(function() {
    
        var stripe = Stripe('<%= Rails.configuration.stripe[:publishable_key] %>');
    
        $('.payment-action').on('click', function() {
    
          const data = $(this).data();
          const user_email = '<%= current_user ? current_user.email : ""%>'
          const user = '<%= current_user.id%>'
    
          stripe.redirectToCheckout({
            lineItems: [{
              // Define the product and price in the Dashboard first, and use the price
              // ID in your client-side code. You may also pass a SKU id into the `price`
              // field 
              price: data['plankey'],
              quantity: 1
            }],
            customerEmail: user_email,
            mode: 'subscription',
            subscriptionData: {
              coupon: 'WaS5wFHC'
            },        
            successUrl: 'https://www.my_web.network/success_payment?session_id={CHECKOUT_SESSION_ID}&p_i='+data['plan']+'&us='+user,
            cancelUrl: 'https://www.my_web.network/update_plan'
          });
        });
    
      });
    
    
    </script>

我一直在尝试使用 subscription_data 或 subscriptionData 让它出现在 this page 上,但它仍然不起作用,我可能缺少什么?

<script type="text/javascript">

  $(document).ready(function() {

    var stripe = Stripe('<%= Rails.configuration.stripe[:publishable_key] %>');

    $('.payment-action').on('click', function() {

      const data = $(this).data();
      const user_email = '<%= current_user ? current_user.email : ""%>'
      const user = '<%= current_user.id%>'

      stripe.redirectToCheckout({
        lineItems: [{
          // Define the product and price in the Dashboard first, and use the price
          // ID in your client-side code. You may also pass a SKU id into the `price`
          // field 
          price: data['plankey'],
          quantity: 1
        }],
        customerEmail: user_email,
        mode: 'subscription',
        subscription_data: {
          coupon: 'WaS5wFHC'
        },        
        successUrl: 'https://www.my_web.network/success_payment?session_id={CHECKOUT_SESSION_ID}&p_i='+data['plan']+'&us='+user,
        cancelUrl: 'https://www.my_web.network/update_plan'
      });
    });

  });


</script>

【问题讨论】:

    标签: javascript ruby-on-rails-4 ruby-on-rails-5 stripe-payments coupon


    【解决方案1】:

    无法在仅客户端结帐中使用优惠券进行订阅。您必须在传递优惠券 ID 的服务器上创建结帐会话:https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-subscription_data-coupon

    【讨论】:

      猜你喜欢
      • 2013-08-04
      • 2023-01-17
      • 2019-12-16
      • 2023-04-05
      • 1970-01-01
      • 2016-02-09
      • 1970-01-01
      • 2021-04-18
      • 2014-08-29
      相关资源
      最近更新 更多