【发布时间】:2019-07-13 19:02:45
【问题描述】:
我想为我的landing page 的移动网站添加第二个 Stripe Checkout 按钮,但尽管我的放置方式与我放置第一个按钮的方式相同(请参阅主站点顶部的“Suscríbete”),当你点击它时它什么也不做。新按钮位于您在移动视图中加载我的网站时出现的导航菜单上。
HTML 代码:
<button class="btn btn--secondary" id="checkout-button-sku_FQdLfDQeVmuBwR" role="link">Suscríbete</button>
我已经加载了:
<script>
var stripe = Stripe('pk_live_3ASoXZAFAaRMXuoCshu9gGSO00Jvx2IR2u');
var checkoutButton = document.getElementById('checkout-button-sku_FQdLfDQeVmuBwR');
checkoutButton.addEventListener('click', function() {
// When the customer clicks on the button, redirect
// them to Checkout.
stripe.redirectToCheckout({
items: [{
sku: 'sku_FQdLfDQeVmuBwR',
quantity: 1
}],
// Do not rely on the redirect to the successUrl for fulfilling
// purchases, customers may not always reach the success_url after
// a successful payment.
// Instead use one of the strategies described in
// https://stripe.com/docs/payments/checkout/fulfillment
successUrl: 'http://liderplay.es/success',
cancelUrl: 'http://liderplay.es/canceled',
})
.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>
和
<script src="https://js.stripe.com/v3"></script>
【问题讨论】:
-
您的意思是发布您的 API 密钥吗?
-
点击按钮会发生什么?
-
这个密钥是公开的,所以不用担心。
标签: javascript html stripe-payments