Paypal Java script integration

假如想象 提交于 2019-12-08 21:05:31

after a series of try and fail I found the correct AJAX call:

$.ajax({
        headers: {
             "Accept": "application/json",
             "Accept-Language": "en_US",
             "Authorization": "Basic "+btoa("**<Client ID>:<Secret>**")
        },
        url: "https://api.sandbox.paypal.com/v1/oauth2/token",
        type: "POST",
            data: "grant_type=client_credentials",
        complete: function(result) {
            alert(JSON.stringify(result));
        },
});

You need to replace Client ID:Secret with the one that you find on your Developer Dashboard, for example AxxhGDh:hudh-X-h8qi

Above example doesn't works, below works for me:

var parameter = {
    "grant_type": "client_credentials",
    "username": "<username>",
    "password": "<password>"
}

$.ajax({
    headers: {
        "Accept": "application/json",
        "Accept-Language": "en_US",
        "Authorization": "Basic <your auth key>"
    },
    url: "https://api.sandbox.paypal.com/v1/oauth2/token",
    type: "POST",
    data: parameter,
    complete: function (result) {
        alert(JSON.stringify(result));
    },
})
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!