Paypal Express Checkout窗口一直在加载

时间:2017-11-22 22:49:01

标签: javascript jquery html paypal express-checkout

我正在尝试集成PayPal按钮,以便对我刚刚创建的新Paypal帐户执行简单付款。 按照指南我渲染了按钮,但当我点击它并显示新窗口时,没有任何反应。 “加载锁定”继续旋转,但新窗口和页面中都没有显示错误。不执行对“onError()”函数的调用。我不知道出了什么问题!我按照指南的指示进行了操作!

浏览其他网站我在新窗口中看到,在加载时(以及“加载锁定”旋转)执行了一些get / post,在我的情况下没有执行任何操作。

这是我的HTML和相关的.js文件(好吧,其中一部分)

//THIS FUNCTION IS CALLED TO DISPLAY A NEW ELEMENT CONTAINING THE BUTTON 
function payment(todelete) {

    destroy(todelete);
    $("#pay").delay(timeFade).fadeIn(timeFade);
    
    paypal.Button.render({
        env: 'sandbox',
        client: {
            sandbox:    'MYKEY',
            production: 'MYKEY'
        },

        commit: true,

        payment: function(data, actions) {
            fetch("/getOldAmount").then(function(res){
                return (res.json());
            }).then(function(data){

                var old_amount = data[0].Donation;
                var amount_tot = $("#amount").val();
                //BUILDING A RANDOM TEST JSON, NOT RELATED TO MY CODE
                var payment_json = {
                        transactions: [
                            {
                                amount: {
                                    total:    '1.00',
                                    currency: 'USD'
                                }
                            }
                        ]
                    };
                if(amount_tot > old_amount){
                //WHEN CLICKING PAYPAL BUTTON I CAN SEE THIS LOG, SO EVERYTHING IS FINE HERE
                    console.log("EXECUTING PAYPAL POST");
                    return actions.payment.create(payment_json);
                } else {
                    console.log("Amount too low to execute transaction");
                }

            });
        },

        onAuthorize: function(data, actions) {
            return actions.payment.execute().then(function(payment) {
                console.log("AUTHORIZED");
            });
        },
        onError: function(data, actions){
            console.log("ERRORRRRRR");
            console.log(data);
        }

    }, '#paypal-button');
    
}
<div class="container pagination-centered" style="display: block">
            <div class="form-group">
                <label class="richest_header" for="amount">ENTER AMOUNT</label>
                <input type="text" class="form-control amount-field" id="amount" placeholder="Amount..." name="amountField">
            </div>
            <div id="paypal-button"></div>
</div>

<!-- HEADER -->
    [...]
<script src="https://www.paypalobjects.com/api/checkout.js">
    <script type="text/javascript" src="assets/script/myscript.js"></script>
    [...]

我还需要做些什么吗? 我需要添加代码吗? 难道我做错了什么? 为什么paypal文档很差?

1 个答案:

答案 0 :(得分:0)

您需要将承诺退回payment() - return fetch("/getOldAmount").then(...