简体   繁体   English

分条付款,无任何按钮

[英]Stripe payment without any button

Currently I'm using a stripe payment button as a way to charge users. 目前,我正在使用条纹付款按钮作为向用户收费的方式。 however, the process for this is: 但是,此过程是:

they get an email, the email has a pay button. 他们收到一封电子邮件,该电子邮件具有“付款”按钮。 once you press the button, the button launches a page with a stripe pay button. 按下按钮后,该按钮将启动带有条纹付款按钮的页面。 pressing the stripe pay button opens the card payment. 按“条纹支付”按钮可打开卡支付。

I'd like to be able go straight from the user pressing the email's pay button to the card payment page opening up, instead of them having to press another button. 我希望能够从用户直接按电子邮件的“付款”按钮转到打开的“卡付款”页面,而不必再按另一个按钮。

I've been using https://stripe.com/docs/checkout . 我一直在使用https://stripe.com/docs/checkout I think that calling the stripecheckout.open directly would do the trick, however, I'm not sure how to format this call correctly with javascript. 我认为直接调用stripecheckout.open可以解决问题,但是,我不确定如何使用javascript正确格式化此调用。

For example, when the email pay button is pressed, the stripe pay button is generated like this 例如,当按下电子邮件付款按钮时,将生成条带付款按钮,如下所示

res.write('<script ');
res.write('src="https://checkout.stripe.com/v2/checkout.js" class="stripe-button"');
res.write('data-key="' + body[0].data_key + '"');
res.write('data-amount="' + body[0].data_amount +'"');
res.write('data-name="' + body[0].data_name + '"');
data_desc_string = body[0].data_description;
data_desc_short = data_desc_string.substring(7);
res.write('data-description="' + data_desc_short + '"');
res.write('data-currency="usd">');
res.write('</script>');

I'm not sure how I should rewrite it just for the stripecheckout.open . 我不知道该如何只为stripecheckout.open重写它。

The Custom Buttons section of the Checkout docs details how to call StripeCheckout.open() . Checkout文档的Custom Buttons部分详细介绍了如何调用StripeCheckout.open()

In your case, you simply call StripeCheckout.open() once the page has loaded (because you want it to appear immediately) instead of in response to a button click (as in the example). 在您的情况下,只需在页面加载后调用StripeCheckout.open() (因为您希望它立即显示),而不是响应单击按钮(如示例中所示)。

How exactly you'd go about that would vary with the JS framework you're using. 根据使用的JS框架,具体实现方式会有所不同。 Using jQuery as in their example code, you'd bind to $(document).ready() : 使用jQuery作为示例代码,您将绑定到$(document).ready()

  <script src="https://checkout.stripe.com/v2/checkout.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js"></script>

  <button id="customButton">Purchase</button>

  <script>
    $(document).ready(function(){
      var token = function(res){
        var $input = $('<input type=hidden name=stripeToken />').val(res.id);
        $('form').append($input).submit();
      };

      StripeCheckout.open({
        key:         'pk_test_czwzkTp2tactuLOEOqbMTRzG',
        address:     true,
        amount:      5000,
        currency:    'usd',
        name:        'Joes Pistachios',
        description: 'A bag of Pistachios',
        panelLabel:  'Checkout',
        token:       token
      });

      return false;
    });
  </script>

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

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