0

i am creating one payment module,
i want to send data to api

but when ajax call from js file it give error

"Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://migs.mastercard.com.au/vpcdps. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing)."

my ajax code is like below

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

<?php
$title = 'ANZ Payment';
$vpcURL = 'https://migs.mastercard.com.au/vpcdps';


$data = array("vpc_Version" => 1,
    "vpc_Command" => 'pay',
    "vpc_AccessCode" => '6447E199',
    "vpc_MerchTxnRef" => '100001',
    "vpc_Merchant" => 'TESTANZTEST3',
    "vpc_OrderInfo" => 'VPC Example',
    "vpc_Amount" => 100,
    "vpc_CardNum" => '5123456789012346',
    "vpc_CardExp" => '2105',
    "vpc_CardSecurityCode" => '123',
    "vpc_TicketNo" => '',
);

?>

<button id="payment" style="margin: 100px;font-size: 100px">
    PAY NOW
</button>


<script>
    $(document).ready(function(){
        $("#payment").click(function(){

            var transactionPayload = {
                "vpc_Version": 1,
                "vpc_Command": 'pay',
                "vpc_AccessCode": '6447E199',
                "vpc_MerchTxnRef": '100001',
                "vpc_Merchant": 'TESTANZTEST3',
                "vpc_OrderInfo": 'VPC Example',
                "vpc_Amount": 100,
                "vpc_CardNum": '5123456789012346',
                "vpc_CardExp": '0521',
                "vpc_CardSecurityCode": '123',
                "vpc_TicketNo": ''
            };
            vpcURL = 'https://migs.mastercard.com.au/vpcdps';


            console.log(vpcURL);
            console.log(transactionPayload);

            $.ajax({
                type: 'POST',
                data: transactionPayload,
                url: vpcURL,
                dataType: "text",
                crossDomain: true,
                async: false,
                success: function (response) {
                    alert('success');
                    alert(response);

                },
                error: function (err) {
                    alert('error');
                    console.log(err);
                    messageContainer.addErrorMessage({message: 'An error occurred on the server. Please try to place the order again.'});
                    fullScreenLoader.stopLoader(true);
                }
            });


        });
    });
</script>
4

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.