首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何将优惠券添加到条带结账

如何将优惠券添加到条带结账
EN

Stack Overflow用户
提问于 2020-08-28 14:07:23
回答 1查看 1.3K关注 0票数 1

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

代码语言: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上,但仍然不能工作,我还会遗漏什么呢?

代码语言:javascript
运行
复制
<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>
EN

回答 1

Stack Overflow用户

发布于 2020-08-28 14:20:57

这是不可能使用优惠券订阅在客户端唯一的结帐。您必须在传递优惠券ID:https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-subscription_data-coupon的服务器上创建一个结帐会话

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63628351

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档