Skip to Content
Menu
This question has been flagged
1 Reply
7848 Views

Hi I’m working on integration with an online payment gateway in POS

After QR code is need scanned and amount sent, I have to call an API to get the payment response or status… After payment sent successfully the API call failed

Here is the code I made:


            var url = "https://api.test-paymentgateway.com/web/v1/merchant/transaction/check-status";
            var hashedString = $("#hashedString").val();
            var data2 = {merchant_id: this.props.merchantId,reference_id: this.props.referenceNumber,};

            var requestString2 = $.map(data2, function(v, k) {return k + "=\"" + v + "\"";}).join(',');

            var hash = CryptoJS.HmacSHA256(requestString2, this.props.authorizationToken);
            var signature = CryptoJS.enc.Base64.stringify(hash);
            console.log("signature: " + signature);
            $.support.cors = true;
            $.ajax(
            {
            url : url,
            type: "POST",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            crossDomain: true,
            headers:
                {
                    'Access-Control-Allow-Origin': window.location.origin,
                    'Access-Control-Allow-Methods': 'POST, GET, OPTIONS',
                    'X-FOO-Signature': signature,
                    'X-CLIENT-ID': this.props.appId,
                },
            data :
                {
                    'merchant_id': this.props.merchantId,
                    'reference_id': this.props.referenceNumber,
                },
            success: function(data)
                {
                    var jsonData = JSON.stringify(data);
                    var objData = $.parseJSON(jsonData);
                    console.log(objData);
                },
            error: function(xhr)
                {
                    alert('error :' + xhr.responseText);
                }
            });

After calling this API, I got this error



Access to XMLHttpRequest at 
'https://api.test-paymentgateway.com/web/v1/merchant/transaction/check-status'
from origin 'https://somedomain.com' has been blocked by CORS policy: Response
to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin'
header is present on the requested resource.    

I dont know how to solve this error and how to enable CORS

Can someone please help me on enabling the CORS in odoo-bitnami version?

I am using odoo 14.0
Avatar
Discard
Best Answer

you can add cors="*" in your controller file like this :

@http.route(['/get'], type='json', auth="user",cors="*")


Avatar
Discard
Related Posts Replies Views Activity
1
Nov 24
105
4
Oct 24
1421
0
Oct 22
4146
0
Sep 22
38
1
Mar 15
5870