I am trying to implement Strip payments in my web app. However, when using the sample code, I am getting the js error:
我正在尝试在我的web应用程序中实现脱衣舞付款,但是在使用示例代码时,我得到了js错误:
Uncaught ReferenceError: StripeCheckout is not defined
未捕获的ReferenceError:没有定义StripeCheckout
The code is like so:
代码是这样的:
<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
<script>
Stripe.setPublishableKey('pk_test_HnjFihOWwYTWnnsTLnZTmbgv');
var handler = StripeCheckout.configure({
key: 'pk_test_HnjFihOWwYTWnnsTLnZTmbgv',
image: '/img/documentation/checkout/marketplace.png',
token: function(token) {
// Use the token to create the charge with a server-side script.
// You can access the token ID with `token.id`
}
});
$('#customButton').on('click', function(e) {
// Open Checkout with further options
handler.open({
name: 'Demo Site',
description: '2 widgets',
amount: 2000
});
e.preventDefault();
});
// Close Checkout on page navigation
$(window).on('popstate', function() {
handler.close();
});
</script>
Any idea why I'm getting the error? Thank you.
知道我为什么会出错吗?谢谢你!
2 个解决方案
#1
7
StripeCheckout is built on top of Stripe. You need to include the js file that defines StripeCheckout.
条纹检验是建立在条纹的顶部。您需要包含定义StripeCheckout的js文件。
<script src="https://checkout.stripe.com/checkout.js"></script>
See the documentation here: https://stripe.com/docs/checkout#integration-custom
请参阅这里的文档:https://stripe.com/docs/checkout#integration-custom
#2
2
The publishable key line should only be executed once the checkout.js file has been downloaded and your javascript file is compiled, for my project this works
可发布的密钥行应该只在签出之后执行。js文件已被下载,您的javascript文件已被编译,对于我的项目来说,这是可行的
<script type="text/javascript" src="https://js.stripe.com/v2/">
$(function(){
Stripe.setPublishableKey('<%= Rails.configuration.stripe[:PUBLISHABLE_KEY] %>');
});
</script>
To test this open a console using developer tools in your browser and after the page has loaded, paste $('#payment-form') if the console returns a reference to the form in your page then its working.
要在浏览器中使用开发人员工具来测试这一打开控制台,并且在页面加载后,如果控制台在您的页面中返回对表单的引用,那么它的工作就会被粘贴$('# pay- form')。
I have put this in the form page in my app and it solved this error, when it was included in my javascript file even wrapped in the on ready event it caused the same error as you experienced
我把它放到app的表单页面中,它解决了这个错误,当它被包含在javascript文件中,甚至被包装在on ready事件中,它导致了和你所经历的相同的错误
#1
7
StripeCheckout is built on top of Stripe. You need to include the js file that defines StripeCheckout.
条纹检验是建立在条纹的顶部。您需要包含定义StripeCheckout的js文件。
<script src="https://checkout.stripe.com/checkout.js"></script>
See the documentation here: https://stripe.com/docs/checkout#integration-custom
请参阅这里的文档:https://stripe.com/docs/checkout#integration-custom
#2
2
The publishable key line should only be executed once the checkout.js file has been downloaded and your javascript file is compiled, for my project this works
可发布的密钥行应该只在签出之后执行。js文件已被下载,您的javascript文件已被编译,对于我的项目来说,这是可行的
<script type="text/javascript" src="https://js.stripe.com/v2/">
$(function(){
Stripe.setPublishableKey('<%= Rails.configuration.stripe[:PUBLISHABLE_KEY] %>');
});
</script>
To test this open a console using developer tools in your browser and after the page has loaded, paste $('#payment-form') if the console returns a reference to the form in your page then its working.
要在浏览器中使用开发人员工具来测试这一打开控制台,并且在页面加载后,如果控制台在您的页面中返回对表单的引用,那么它的工作就会被粘贴$('# pay- form')。
I have put this in the form page in my app and it solved this error, when it was included in my javascript file even wrapped in the on ready event it caused the same error as you experienced
我把它放到app的表单页面中,它解决了这个错误,当它被包含在javascript文件中,甚至被包装在on ready事件中,它导致了和你所经历的相同的错误