使用MYR货币进行Paypal结帐

时间:2019-04-10 08:25:36

标签: javascript php paypal currency data-conversion

我正在尝试使用MYR货币实施Paypal。但是,我收到一条错误消息,该消息未批准用户的卡。

消息是“很抱歉,但是您的Visa x-xxxx被拒绝了。您可以选择付款方式完成购买,或者选择其他付款方式。”

有人遇到/已经解决了这个问题吗?

<script src="https://www.paypalobjects.com/api/checkout.js"></script>

<script>


// Render the PayPal button
paypal.Button.render({
    // Set your environment
    //env: 'sandbox', // sandbox | production
    env: 'production', // sandbox | production

    // Specify the style of the button
    style: {
        layout: 'vertical',  // horizontal | vertical
        size:   'medium',    // medium | large | responsive
        shape:  'rect',      // pill | rect
        color:  'gold'       // gold | blue | silver | white | black
    },

    // Specify allowed and disallowed funding sources
    //
    // Options:
    // - paypal.FUNDING.CARD
    // - paypal.FUNDING.CREDIT
    // - paypal.FUNDING.ELV
    funding: {
        allowed: [
            //paypal.FUNDING.CARD,
            //paypal.FUNDING.CREDIT
        ],
        disallowed: []
    },

    // Enable Pay Now checkout flow (optional)
    commit: true,

    // PayPal Client IDs - replace with your own
    // Create a PayPal app: https://developer.paypal.com/developer/applications/create
    client: {
        //sandbox: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
        production: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    },

    payment: function (data, actions) {
        return actions.payment.create({
            payment: {
            transactions: [
                    {
                        amount: {
                            total: parseFloat(document.querySelector('.custom-modal-data').getAttribute("data-value")),
                            currency: 'MYR'
                            //currency: 'USD'
                        }
                    }
                ]
            }
        });
    },

    /*onAuthorize: function (data, actions) {
        return actions.payment.execute()
        .then(function () {
            window.alert('Payment Complete!');
        });
    },*/
    onAuthorize: function (data, actions) {

      return actions.payment.execute()
        .then(function () {
            return actions.payment.get().then(function(data) {


                //console.log(data);
                //console.log(data.transactions);
                //console.log(data.transactions[0].related_resources[0].sale.id);

                if(data.state == "approved"){

                    var data        = data;
                    var transaction = data.transactions[0];
                    var box         = $('body').find(`[data-chosen="1"]`);
                    var package     = box.find('.top-up-btn').attr('data-package');
                    var action      = 'userTopupPaypal';



                    var collection = {
                        action:action,
                        data:data,
                        transaction:transaction,
                        package:package,

                    }
                    //console.log(collection);

                    var modal = $('#modalTopup');
                    modal.find(".custom-modal-header-title").text("Processing...");


                    $.ajax({
                        type: "POST",
                        url: "submits/submit-topup.php",
                        data:collection,
                        dataType:'JSON', 
                        success: function(result){

                            console.log(result);

                            hideModalTopup();

                            var status = result.status;
                            if(status == 'Success'){
                                Swal.fire(
                                  'Success!',
                                  'Your have successfully topup.',
                                  'success'
                                );

                            } else {
                                Swal.fire(
                                  'Oppps...',
                                  'Something went wrong.',
                                  'error'
                                );
                            }
                        } 
                    });

                }

            });
        });
    }
}, '#paypal-button-container');

0 个答案:

没有答案