![](/img/trans.png)
[英]Stripe redirectToCheckout - “TypeError: stripe.redirectToCheckout is not a function” Rails
[英]Keep getting 'https://api.stripe.com/v1/payment_pages 400' when using stripe.redirectToCheckout()
我有這個:
<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>
和這個:
<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
我在 localhost http 下運行它。
price
是 Price API object 的 ID,不是您要收取的金額。 見這里: https://stripe.com/docs/js/checkout/redirect_to_checkout#stripe_checkout_redirect_to_checkout-options-lineItems-price
另請參閱此處的文檔: https://stripe.com/docs/payments/checkout/client#generate-checkout-button
您在后端(或儀表板)上設置要收取的實際金額,如果您可以在客戶端上設置它,那么惡意用戶很容易更改價格並為您出售的任何商品支付他們想要的費用.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.