cancel
Showing results for 
Search instead for 
Did you mean: 

How introduce Authorization header in Nodejs

Member

How introduce Authorization header in Nodejs

Hi, i have a problem with the SDK, it return me this JSON:

{"name":"AUTHENTICATION_FAILURE","message":"Authentication failed due to invalid authentication credentials or a missing Authorization header.","links":[{"href":"https://developer.paypal.com/docs/api/overview/#error","rel":"information_link"}]}

i want know how introduce the Authorization headers  in nodejs, here is my code:

if (msg.metodoPago === '  Paypal') {
            var payReq = JSON.stringify({

                "intent": "sale",
                "payer": {
                    "payment_method": "paypal"
                },
                "redirect_urls": {
                    "return_url": "https://www.paypal.com",
                    "cancel_url": "https://www.paypal.com",
                },
                "transactions": [{
                    "item_list": {
                        "items": [{
                            "name": "tacos",
                            "sku": "001",
                            "price": "20.00",
                            "currency": "MXN",
                            "quantity": 1
                        }]
                    },
                    "amount": {
                        "currency": "MXN",
                        "total": "20.00"
                    },
                    "description": "This is the payment description."
                }]
            });

            paypal.payment.create(payReq, async function(error, payment) {
                var links = {};

                if (error) {
                    console.error(JSON.stringify(error));
                } else {
                    // Capture HATEOAS links
                    console.log(payment)
                    payment.links.forEach(async function(linkObj) {
                        links[linkObj.rel] = await {
                            href: linkObj.href,
                            method: linkObj.method
                        };
                    })

                    // If the redirect URL is present, redirect the customer to that URL
                    if (links.hasOwnProperty('approval_url')) {
                        // Redirect the customer to links['approval_url'].href
                    } else {
                        console.error('no redirect URI present');
                    }
                }
            });
        }

thanks!!!!!