在 Accept Hosted 方法中将 showReceipt 设置为 false 时无交易响应 (Authorize.net)

No transaction response when showReceipt is set to false in Accept Hosted approach (Authorize.net)

我正在尝试在 SAP Hybris 中使用 iframe 方法集成 authorize.net 接受托管页面。根据文档,当 showReceipt 设置为 false 时,iframe 应该发回响应。但是现在点击支付按钮后似乎卡住了。

我一直在尝试文档中的方法。然后尝试 How to implement Authorize.NET Hosted Payments iFrame & Laravel 中的解决方案。

这是 iframe 显示的 hostedOrderPage:

<script type="text/javascript">

$(document).ready(function(){

    window.CommunicationHandler = {};

    function parseQueryString(str) {
        var vars = [];
        var arr = str.split('&');
        var pair;
        for (var i = 0; i < arr.length; i++) {
            pair = arr[i].split('=');
            vars[pair[0]] = unescape(pair[1]);
        }
        return vars;
    }

    window.CommunicationHandler.onReceiveCommunication = function (argument) {

        console.log('communication handler enter');

        var params = parseQueryString(argument.qstr)

        switch(params['action']){

            case "cancel"           :

                console.log('cancel'); break;

            case "transactResponse" :

                console.log("transaction response received");
                console.log(transResponse.totalAmount);

        }
    }

    //send the token
    $('#send_hptoken').submit();


});

</script>

<div id="item_container_holder">

    <div class="item_container">
    <div id="iframe_holder" class="center-block" style="width:90%;max-width: 1000px" data-mediator="payment-form-loader">
        <iframe id="load_payment" class="embed-responsive-item" name="load_payment" width="750" height="900" frameborder="0" scrolling="no">
            </iframe>
                <form:form id="send_hptoken" action="https://test.authorize.net/payment/payment" method="post" target="load_payment">
        <input type="hidden" name="token" value="${token}" />
            </form:form>

    </div>
    </div>
</div>

这是 iframecommunicator:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>IFrame Communicator</title>
    <script type="text/javascript">

    function callParentFunction(str) {

        if (str && str.length > 0 && window.parent.parent
            && window.parent.parent.CommunicationHandler && window.parent.parent.CommunicationHandler.onReceiveCommunication) {

            var referrer = document.referrer;
            window.parent.parent.CommunicationHandler.onReceiveCommunication({qstr : str , parent : referrer});

        }

    }

    function receiveMessage(event) {

        if (event && event.data) {
            callParentFunction(event.data);
        }

    }

    if (window.addEventListener) {

        window.addEventListener("message", receiveMessage, false);

    } else if (window.attachEvent) {

        window.attachEvent("onmessage", receiveMessage);

    }

    if (window.location.hash && window.location.hash.length > 1) {

        callParentFunction(window.location.hash.substring(1));

    }

</script>
</head>
<body></body>
</html>

似乎没有任何内容登录到控制台。如果有响应,它应该在 hostedOrderPage 中输入 switch case 'transactResponse' 并将其记录到控制台。

我遇到了类似的问题。首先确保沙盒帐户的测试模式处于关闭状态。此外,我相信我必须为所有相关域添加 Content-Security-Policy 加上 frame-ancestors 'self' 到表单的 Header。我为本地域和远程域构建了一个字符串,在我的例子中是 test.authorize.net,并将其添加为属性。我动态构建表单。

有关 CSC 问题的详细信息,请参阅开发表单中的 this link