[英]Stripe payment integration - What is the way to move .js [checkout.js] outside of loop?
I'm creating stripe payment form according to their documentation. 我正在根据他们的文档创建条纹付款表格。 I need to use it in wordpress loop to it looks like: 我需要在wordpress循环中使用它,如下所示:
Start loop:
Item name
Item img
Item desc
etc.
<form action="/charge" method="POST">
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="pk_test_23123123"
data-amount="2000"
data-name="name"
data-description="2 widgets"
data-locale="auto"
data-zip-code="true"
data-currency="eur">
</script>
</form>
Stop loop
But there's a problem - after adding stripe code website works very slow. 但是有一个问题-添加条带代码后,网站工作非常缓慢。 I think it's about loading checkout.js multiple times. 我认为这是关于多次加载checkout.js的问题。 Is there a solution to move .js above the loop? 是否存在将.js移到循环上方的解决方案?
First, please note that Stripe's Checkout form does not process payments by itself -- it only collects a customer's card information and turns it into a token. 首先,请注意,Stripe的Checkout表单本身不会处理付款-它仅收集客户的卡信息并将其转换为令牌。 The token must then be sent to your backend server where it can be used to eg create a charge . 然后必须将令牌发送到您的后端服务器,在该服务器中可以使用它来创建费用 。
You can get around loading Checkout multiple times using a custom integration . 您可以使用自定义集成多次加载Checkout。 This way, Checkout's script would only be loaded once, and you would then call the configure()
and open()
methods on the StripeCheckout
object to open the form with the parameters you want. 这样,Checkout的脚本将只加载一次,然后您将在StripeCheckout
对象上调用configure()
和open()
方法以使用所需的参数打开表单。
Since you're using WordPress, it might be simpler to use an already existing Stripe plugin. 由于您使用的是WordPress,因此使用现有的Stripe插件可能更简单。 You can find some of those plugins here: https://wordpress.org/plugins/search.php?q=stripe 您可以在这里找到其中一些插件: https : //wordpress.org/plugins/search.php?q=stripe
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.