Quantcast
Channel: Active questions tagged paypal - Stack Overflow
Viewing all articles
Browse latest Browse all 471

Asp.net MVC Getting Paypal Access Token in Live Mode

$
0
0

I used the following code to get a Paypal token in Sandbox mode, it works fine. However, switching the Live produces not code.

private string GetPaypalAccessToken(){string accessToken = "";string url = PaypalUrl +"/v1/oauth2/token";using (var client = new HttpClient()){    string credentials64 =        Convert.ToBase64String(Encoding.UTF8.GetBytes(PaypalClientId +":" + PaypalSecret));    client.DefaultRequestHeaders.Add("Authorization", "Basic " + credentials64);    var requestMessage = new HttpRequestMessage(HttpMethod.Post, url);    requestMessage.Content = new StringContent("grant_type=client_credentials", null, "application/x-www-form-urlencoded");    var responseTask = client.SendAsync(requestMessage);    responseTask.Wait();    var result = responseTask.Result;    if (result.IsSuccessStatusCode)    {        var readTask = result.Content.ReadAsStringAsync();        readTask.Wait();        var strResponse = readTask.Result;        var jsonResponse = JsonNode.Parse(strResponse);        if (jsonResponse != null)        {            accessToken = jsonResponse["access_token"]?.ToString() ?? "";        }    }}Console.WriteLine("JWT: " + accessToken);return accessToken;

I've tried following the response given in 'How to get access token from PayPal in MVC' a couple of years ago but it is so different from the code I've used I cannot figure out how to modify the above. Can someone give me a simple guide to how to do this? Yes,I have changed the url in appsetting.json to "https://api-m.paypal.com/"


Viewing all articles
Browse latest Browse all 471

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>