MyDaftQuestions
MyDaftQuestions

Reputation: 4691

App.config file not being recognized in by PayPal.Api

I want to eventually set up Paypal payment. Step one though is to have a play. And I have failed on the quick start!

https://github.com/paypal/PayPal-NET-SDK/wiki/Quick-Start shows a code example. It explains that first, I need to download the PayPal .NET SDK package via NuGet. This is great, I'm on .NET Framework (not core). I install it.

Phase 2 gives an entire example. I add some PayPal config settings to the app.config file. Done

Phase 3 is where it is going wrong. I'm referencing PayPal.API in my C# class.

The relevant part of my code is

using PayPal.Api;
using System.Collections.Generic;   

namespace TestProj.Payment
{
    public class PaypalGateway
    {
        public void Sandbox()
        {
            var config = ConfigManager.Instance.GetProperties();// this is the fault
            var accessToken = new OAuthTokenCredential(config).GetAccessToken();

config always has 0 instances

My Project has an App.config file with the correct values

 <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <section name="paypal" type="PayPal.SDKConfigHandler, PayPal" />
  </configSections>
  <paypal>
    <settings>
      <add name="mode" value="sandbox" />
      <add name="clientId" value="***" />
      <add name="clientSecret" value="***" />
    </settings>
  </paypal>

If I rename my App.config file to blah.nonsense then the same issue occurs. It's as if the API is looking for a file else where or that it isn't configured correctly.

Upvotes: 1

Views: 583

Answers (2)

Sanaullah Khan
Sanaullah Khan

Reputation: 1

the same problem was with me, the keyword PayPal must be in small caps like paypal.

<configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <section name="paypal" type="PayPal.SDKConfigHandler, **PayPal**" />
  </configSections>
  <paypal>
    <settings>
      <add name="mode" value="sandbox" />
      <add name="clientId" value="***" />
      <add name="clientSecret" value="***" />
    </settings>
  </paypal>

should be

<configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <section name="paypal" type="PayPal.SDKConfigHandler, **paypal**" />
  </configSections>
  <paypal>
    <settings>
      <add name="mode" value="sandbox" />
      <add name="clientId" value="***" />
      <add name="clientSecret" value="***" />
    </settings>
  </paypal>

Upvotes: 0

Nkosi
Nkosi

Reputation: 246998

This question is tagged with , so the assumption is that this is for a web project

The quick start clearly states

Add the following to your web.config or app.config

web.config should where you place the configuration details if this is in fact a web project.

Even if the referenced code is for another class library in the project, which can use app.config file, all the settings will eventually have to be in the root web.config file of the web project as that is the process that will be running.

Upvotes: 1

Related Questions