代码之家  ›  专栏  ›  技术社区  ›  redoc01

继续前进https://api.stripe.com/v1/payment\u页面使用时为400'条带重定向到checkout()

  •  0
  • redoc01  · 技术社区  · 4 年前

    我有这个:

    <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
    

    我在本地主机http下运行这个。

    0 回复  |  直到 4 年前
        1
  •  1
  •   Paul Asjes    4 年前

    price 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

    你在你的后台(或仪表板)上设置实际收费金额,如果你能在客户端上设置,那么恶意用户就很容易改变价格,并为你出售的任何东西支付他们想要的费用。