dongmiao260399 2018-07-08 13:43
浏览 64
已采纳

在同一页面上显示条纹模式,而不是在“https://checkout.stripe.com/v3/...”中显示模式

I have a form for a user do a payment using Stripe and the jQuery below.

But when the user clicks in the "Pay" buton instead of the Stripe modal opens on the page the user is redirected to "https://checkout.stripe.com/v3/....html?distinct_id=..." and the Stripe modal appears on that page.

Do you know why the Stripe modal is not appearing in the current page?

 <form action="{{ route('payment.chargeStripe') }}" method="post" id="paymentForm">
    {{csrf_field()}}
    <div id="credit_card_section">  
        <div class="alert alert-info" role="alert">
            <strong><i class="fa fa-info" aria-hidden="true"></i></strong>
            Click in "Pay" to pay.
        </div>
        <input type="hidden" name="stripeToken" id="stripeToken"/>
        <input type="submit" href="" id="payment" class="btn btn-primary" value=" Pay"/>
    </div>
</form>

jQuery:

<script src="https://js.stripe.com/v3/"></script>
<script src="https://checkout.stripe.com/checkout.js"></script>


<script>
$(function () {
    let stripe = StripeCheckout.configure({
        key: "{{config('services.stripe.key')}}",
        image: "",
        locale: "auto",
        token: (token) => {
            document.querySelector('#stripeToken').value = token.id;
            document.querySelector('#paymentForm').submit();
        }
    });

    document.getElementById('payment').addEventListener('click', function(e){

        stripe.open({
            name: 'test',
            description: '{{session('conference_name')}}',
            amount: '{{session('total') * 100}}',
            currency: 'eur'

        });
        e.preventDefault();
    });

    // Close Checkout on page navigation:
    window.addEventListener('popstate', function() {
        handler.close();
    });
    </script>
  • 写回答

1条回答 默认 最新

  • doulangxun7769 2018-07-08 14:12
    关注
    $(function () {
        let stripe = StripeCheckout.configure({
            key: "{{YOUR_STRIPE_PUBLIC_KEY}}",
            image: "",
            locale: "auto",
            token: (token) => {
                document.querySelector('#stripeToken').value = token.id;
                document.querySelector('#paymentForm').submit();
            }
        });
        document.getElementById('payment').addEventListener('click', function(e){
            stripe.open({
                name: 'test',
                description: '{{YOUR_DESCRIPTION}}',
                amount: '12',
                currency: 'eur'
            });
            e.preventDefault();
        });
    
        // Close Checkout on page navigation:
        window.addEventListener('popstate', function() {
            handler.close();
        });
    });
    

    From the code you have posted, it seems it working fine, but its missing function closing parentheses and a bracket. See last line of my code. Once i fixed this one i can able to see the checkout popup in my current page itself.

    Also check in browser console, to make sure there is not js error.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵