Javascript 继续https://api.stripe.com/v1/payment_pages 使用stripe.redirectToCheckout()时为400“”
我有这个:Javascript 继续https://api.stripe.com/v1/payment_pages 使用stripe.redirectToCheckout()时为400“”,javascript,stripe-payments,Javascript,Stripe Payments,我有这个: <script> var stripe = Stripe('pk_test_51Gv0ngD3zt5RrIg0XQiKHaK7TOAqzju9yps8jJB2Gch6ksmG4FSnqgyWLv3Qld2EkNHgAb30PLKduYGBuYtZe71A0066dp27DB'); var elements = stripe.elements(); // Custom styling can be passed to options when creating an Ele
<script>
var stripe = Stripe('pk_test_51Gv0ngD3zt5RrIg0XQiKHaK7TOAqzju9yps8jJB2Gch6ksmG4FSnqgyWLv3Qld2EkNHgAb30PLKduYGBuYtZe71A0066dp27DB');
var elements = stripe.elements();
// Custom styling can be passed to options when creating an Element.
var style = {
base: {
// Add your base input styles here. For example:
fontSize: '16px',
color: '#32325d',
},
};
// Create an instance of the card Element.
var card = elements.create('card', {
hidePostalCode: true, style: style });
// Add an instance of the card Element into the `card-element` <div>.
card.mount('#card-element');
$(document).on("click", "#subpay", function () {
stripe
.redirectToCheckout({
lineItems: [
// Replace with the ID of your price
{ price: '1000', quantity: 1 },
],
mode: 'payment',
successUrl: 'https://your-website.com/success',
cancelUrl: 'https://your-website.com/canceled',
})
.then(function (result) {
// If `redirectToCheckout` fails due to a browser or network
// error, display the localized error message to your customer
// using `result.error.message`
alert(result);
});
return false;
})
</script>
我在localhost http下运行它。price是price API对象的ID,而不是您想要收取的金额。请看这里:
另请参见此处的文档:
您可以在后端或仪表板上设置实际收费金额,如果您可以在客户端上设置,那么恶意用户就很容易更改价格并为您销售的任何产品支付他们想要的费用。400是错误请求的http代码,你确定你正在以他们期望的方式向API提交有效负载吗?@BenNelson:我不确定我是条带新手我需要更多说明我发现API引用对我一点都不好
<form id="payment-form">
<div class="form-row">
<label for="card-element">
Credit or debit card
</label>
<div id="card-element">
<!-- A Stripe Element will be inserted here. -->
</div>
<!-- Used to display Element errors. -->
<div id="card-errors" role="alert"></div>
</div>
<button id="subpay">Submit Payment</button>
</form>
POST https://api.stripe.com/v1/payment_pages 400