我正在尝试在我的网络应用中实施Strip付款.但是,在使用示例代码时,我收到了js错误:
未捕获的ReferenceError:未定义StripeCheckout
代码是这样的:
<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>
知道我为什么会收到这个错误吗?谢谢.
解决方法
StripeCheckout构建于Stripe之上.您需要包含定义StripeCheckout的js文件.
<script src="https://checkout.stripe.com/checkout.js"></script>
请参阅此处的文档:
https://stripe.com/docs/checkout#integration-custom