Paypal Express Checkout window keeps loading

南楼画角 提交于 2021-01-28 05:20:48

问题


I'm trying to integrate the PayPal button to execute a simple payment to a new Paypal account I just created. Following the guide I rendered the button, but when I click on it and the new window shows up, nothing happens. The "loading lock" keeps spinning, but no errors are shown in the new window, nor in my page. No calls to "onError()" function are executed. I don't know what's wrong! I followed the instruction of the guide!

Navigating other websites I saw that in the new window, while loading (and the "loading lock" spins) some get/post are executed, nothing is executed in my case.

This is my HTML and related .js file (well, part of them)

//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>
    [...]

Do I need to do something more? Do I need to add code? Am I doing something wrong? Why is paypal documentation so poor?


回答1:


You need to return the promise to payment() -- return fetch("/getOldAmount").then(...



来源:https://stackoverflow.com/questions/47445047/paypal-express-checkout-window-keeps-loading

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!