dscrn1974 2014-11-17 09:23
浏览 54
已采纳

将jQuery变量解析为PHP表单到PSP购物卡

I have to parse this jQuery output <span id="chargetotal" class="chargetotal">Amount</strong></span> to a PSP shopping card page.

From this page i try to parse the 'Total amount' (Quantity * Value), and the rest of the form variables to the PSP shopping card page (https://test.ipg-online.com/connect/gateway/processing).

On the voucher page i include ipg-util.php which look like this:

<?php
$dateTime = date("Y:m:d-H:i:s");
    function getDateTime() {
        global $dateTime;
        return $dateTime;
    }
    function createHash($chargetotal, $currency) {
        $storeId = "XXX storeId XXX";
        $sharedSecret = "XXX sharedSecret XXX";
        $stringToHash = $storeId . getDateTime() . $chargetotal .
        $currency . $sharedSecret;
        $ascii = bin2hex($stringToHash);
        return sha1($ascii);
    }
?>

In this instruction i setup 3.3 PHP Example

The form look like this:

        <form method="post" action="https://test.ipgonline.com/connect/gateway/processing">

            <input type="hidden" name="txntype" value="sale">
            <input type="hidden" name="timezone" value="GMT"/>
            <input type="hidden" name="txndatetime" value="<?php echo getDateTime() ?>"/>
            <input type="hidden" name="hash" value="<?php echo createHash( "13.00","978" ) ?>"/>
            <input type="hidden" name="storename" value="XXX My store id XXX"/>
            <input type="hidden" name="mode" value="fullpay"/>
            <input type="text" name="chargetotal" value="13.00"/>
            <input type="hidden" name="currency" value="978"/>
            <input type="hidden" name="responseSuccessURL" value="http://www.abbeyglen.ie/abbeyglen-castle-hotel/voucher-succes.html"/>
            <input type="hidden" name="responseFailURL" value="http://www.abbeyglen.ie/abbeyglen-castle-hotel/voucher-failure.html"/>
            <input type="submit" value="Submit">
        </form>

My problem is that in the above form example they use a strict value of 13.00 for <input type="text" name="chargetotal" value="13.00"/> to create the hash 'form variable'.

But in my case chargetotal is the 'Total amount' of the jQuery function in this HTML <span id="chargetotal" class="chargetotal">Amount</strong></span> .

See below, the jQuery script to get the 'Total amount'.

                 <script type="text/javascript">
                        $(document).ready(function(){

                        update_amounts();
                        $('.qty').change(function() {
                            update_amounts();
                        });
                    });

                    function update_amounts()
                    {
                        var chargetotal = 0;
                        var sum = 0.0;
                        $(function () {
                            var qty = $(this).find('.qty').val();
                            var price = $(this).find('.price').val();
                            var chargetotal = (qty*price)
                            sum+=chargetotal;
                            $(this).find('.chargetotal').text(''+chargetotal);
                        });

                    }
                </script>

How do i translate the jQuery 'Total amount' to a <input type="text" name="chargetotal">?

Thanks!

  • 写回答

1条回答 默认 最新

  • du4629 2014-11-17 10:56
    关注

    Add

    <input type="hidden" name="chargetotal" id="chargetotal" value=""/>
    

    to your form. Remove id="chargetotal" from

    <span class="chargetotal" id="chargetotal"></span>
    

    Add

    $('#chargetotal').val(chargetotal);
    

    after

    $(this).find('.chargetotal').text(''+chargetotal);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line