Solved

Paypal RESTful API ASP.NET C#

Posted on 2014-03-02
2
2,989 Views
Last Modified: 2016-03-24
I am trying to implement the Paypal RESTful API to be able to receive payments on my website. At this stage I have been able to make the sample code work.

More specifically I have created a brand new application in VS2013 and copy pasted the following files from the sample API's: PaymentWithCreditCard.aspx, Response.aspx and Configuration.cs. The result is that I can successfully post payments to the sandbox and get a response of an approved payment. So far so good.

Problem N1 - retrieving an access token

I have replaced in the configuration class file the sample standard access token:

        private static string GetAccessToken()
        {
OAuthTokenCredential("EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM", "EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM", GetConfig()).GetAccessToken();
            return accessToken;
        }

Open in new window


with the following:

        private static string GetAccessToken()
        {
            var clientId = System.Configuration.ConfigurationManager.AppSettings["clientId"];
            var secretToken = System.Configuration.ConfigurationManager.AppSettings["secretToken"];
            var config = new Dictionary<string, string> { { "mode", "sandbox" } };

            OAuthTokenCredential tokenCredential = new OAuthTokenCredential(clientId, secretToken, config);
            string accessToken = tokenCredential.GetAccessToken();
            return accessToken;
        }

Open in new window


and i have also added in web.config the following:

  <configSections>
    <section name="paypal" type="PayPal.Manager.SDKConfigHandler, PayPalCoreSDK"/>
  </configSections>
  <paypal>
    <accounts>
      <account apiUsername="" apiPassword="" applicationId="" apiSignature="" />
    </accounts>
    <settings>
      <add name="mode" value="sandbox" />
    </settings>
  </paypal>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <appSettings>
    <add key="clientId" value="***********" />
    <add key="secretToken" value="***********" />
  </appSettings>
</configuration>

Open in new window


however I get a

Exception in HttpConnection Execute: Invalid HTTP response The remote server returned an error: (401) Unauthorized.

Open in new window


The sample files are from
https://github.com/paypal/rest-api-sdk-dotnet/tree/master/Samples/RestApiSample
0
Comment
Question by:Lambru
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 39898973
Nothing immediately stands out. Have you debugged through your code to ensure that lines 3 and 4 actually have the correct values?
0
 

Author Closing Comment

by:Lambru
ID: 39981505
Issue sorted, was using wrong client id client secret.
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The viewer will learn how to count occurrences of each item in an array.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question