RazorPay表单在页面加载时自动加载,而无需单击“立即付款”按钮

我正在尝试将Razorpay集成到我的应用程序中。下面是一个代码,用于控制单击“立即付款”按钮时加载付款模型。我想使页面加载上的模式加载而不是按钮单击。我尝试通过javascript提交表单,看看是否加载了模式,但这不起作用。


代码如下:


<form action="verify.php" method="POST" id="gateway">

  <script

    src="https://checkout.razorpay.com/v1/checkout.js"

    data-key="<?php echo $data['key']?>"

    data-amount="<?php echo $data['amount']?>"

    data-currency="INR"

    data-name="<?php echo $data['name']?>"

    data-image="<?php echo $data['image']?>"

    data-description="<?php echo $data['description']?>"

    data-prefill.name="<?php echo $data['prefill']['name']?>"

    data-prefill.email="<?php echo $data['prefill']['email']?>"

    data-prefill.contact="<?php echo $data['prefill']['contact']?>"

    data-notes.shopping_order_id="3456"

    data-order_id="<?php echo $data['order_id']?>"

    <?php if ($displayCurrency !== 'INR') { ?> data-display_amount="<?php echo $data['display_amount']?>" <?php } ?>

    <?php if ($displayCurrency !== 'INR') { ?> data-display_currency="<?php echo $data['display_currency']?>" <?php } ?>

  >

    document.getElementById("gateway").submit(); // Not working

  </script>

  <!-- Any extra fields to be submitted with the form but not sent to Razorpay -->

  <input type="hidden" name="shopping_order_id" value="3456">

</form>

但是,我也注意到表单操作到页面,因此如果表单提交,它将转到我只想加载付款模式的页面。因此,我所尝试的不可能是解决方案。verify.php


Cats萌萌
浏览 66回答 3
3回答

慕盖茨4494581

我找到了解决方案。发布,因为它可能对将来的某个人有所帮助:在开始元素之后放置此位置:razorpay/checkout/automatic.php (or manual.php)<form><script>&nbsp; $(window).on('load', function() {&nbsp; &nbsp; $('.razorpay-payment-button').click();&nbsp; });</script>

慕运维8079593

将 onload 事件附加到脚本并在处理程序中模拟单击<script>&nbsp; function loadPaymentModal() {&nbsp; &nbsp; const elem = document.getElementsByClassName('razorpay-payment-button')[0];&nbsp; &nbsp; elem.click();&nbsp; }</script><form action="verify.php" method="POST" id="gateway">&nbsp; <script onLoad="loadPaymentModal()" src="https://checkout.razorpay.com/v1/checkout.js"&nbsp; &nbsp; data-key="<?php echo $data['key']?>"&nbsp;&nbsp; &nbsp; data-amount="<?php echo $data['amount']?>"&nbsp;&nbsp; &nbsp; data-currency="INR"&nbsp; &nbsp; data-name="<?php echo $data['name']?>"&nbsp; &nbsp; data-image="<?php echo $data['image']?>"&nbsp; &nbsp; data-description="<?php echo $data['description']?>"&nbsp;&nbsp; &nbsp; data-prefill.name="<?php echo $data['prefill']['name']?>"&nbsp; &nbsp; data-prefill.email="<?php echo $data['prefill']['email']?>"&nbsp; &nbsp; data-prefill.contact="<?php echo $data['prefill']['contact']?>"&nbsp;&nbsp; &nbsp; data-notes.shopping_order_id="3456"&nbsp; &nbsp; data-order_id="<?php echo $data['order_id']?>"&nbsp; &nbsp; <?php if ($displayCurrency !=='INR' ) { ?> data - display_amount="<?php echo $data['display_amount']?>" <? php } ?>&nbsp; &nbsp; <? php if ($displayCurrency !== 'INR') { ?> data - display_currency="<?php echo $data['display_currency']?>" <? php } ?>&nbsp; >&nbsp; &nbsp; </script>&nbsp; <!-- Any extra fields to be submitted with the form but not sent to Razorpay -->&nbsp; <input type="hidden" name="shopping_order_id" value="3456"></form>

犯罪嫌疑人X

<script src="{{url('/')}}/frontendtheme/js/plugins/jquery-3.3.1.min.js"></script><script>&nbsp; &nbsp; $(window).on('load', function() {&nbsp; &nbsp; &nbsp; &nbsp; jQuery('#gateway').submit();&nbsp; &nbsp; });</script>注意:在脚本源上使用最小.js文件夹
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript