条纹付款没有任何button
目前,我正在使用条形付款button作为向用户收费的方式。 然而,这个过程是:
他们收到一封电子邮件,电子邮件有一个付款button。 一旦你按下button,button将启动一个带有条纹付费button的页面。 按条形支付button打开卡支付。
我希望能够直接从用户按下电子邮件的付款button到卡付款页面开放,而不是他们不得不按下另一个button。
我一直在使用https://stripe.com/docs/checkout 。 我认为,直接调用stripecheckout.open会做的伎俩,但是,我不知道如何使用JavaScript正确格式化此调用。
例如,当按下电子邮件付款button时,就会像这样生成条带付款button
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>');
我不知道我应该如何重写它只为stripecheckout.open
。
Checkout文档的Custom Buttons部分详细说明如何调用StripeCheckout.open()
。
在你的情况下,一旦页面加载(因为你希望它立即出现),而不是响应button点击(如例子),你只需调用StripeCheckout.open()
)。
你会怎么做会随着你使用的JS框架而变化。 使用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>