所以,我正在使用纯客户端(JS)的Stripe RedirectToCheckout,我一直没有出错,这很好。然而,我决定在我的Web应用程序中使用VueJS。因此,我通过CDN导入VueJS,并像往常一样进行设置。
我已经将stripe checkout功能移到了VueJS方法中。然而,现在当我运行stripe checkout时。它像往常一样重定向我,所有的测试支付都成功了。但我在控制台出现了以下错误。
Unrecognized Content -Security -Policy directive 'worker -src'.
所以有两件事我想知道。
商店.html
<!-- IMPORT STRIPE AND VueJS HERE -->
<div id="app">
<button class="button" v-on:click="redirectToCheckout()">Pay £{{total}}</button>
<div id="error-message"></div>
</div>
<script>
new Vue({
el: '#app',
data: {
total: 2.50
},
methods: {
redirectToCheckout() {
var stripe = Stripe('STRIPE_KEY');
stripe.redirectToCheckout({
items: [
// Add shipping fee
{sku: 'sku_HCLoshvlZRCn7S', quantity: 1}
],
successUrl: 'https://your-website.com/success.html?session_id={CHECKOUT_SESSION_ID}',
cancelUrl: 'https://your-website.com/canceled.html',
})
.then(function (result) {
if (result.error) {
// If `redirectToCheckout` fails due to a browser or network
// error, display the localized error message to your customer.
var displayError = document.getElementById('error-message');
displayError.textContent = result.error.message;
}
});
}
}
})
</script>
非常感谢:)