Paypal C # REST API asks for undocumented section configuration

I hack into Battle Hack London a lot and I stumbled upon an annoying problem. PayPal SDK for C # doesn't seem to work correctly.

I am trying to complete my first transaction, and here is my code (which I put together to fix broken online documents :

var tokenCredential = new OAuthTokenCredential(something, someother);
var accessToken = tokenCredential.GetAccessToken();
Payment createdPayment = new Payment
{
  intent = "sale",
  transactions = new List<Transaction>
  {
    new Transaction
    {
      amount = new Amount
      {
        total = value.ToString("R"), 
        currency = "GBP"
      },
      description = forWhat
    }
  }
}.Create(accessToken);

The result is

Unable to parse * .Config file. Make sure you have configured the "paypal" section correctly.

which I traced to this line of code , but I don’t know how to properly configure this section, and I can’t find the correct documentation.

How should tsh cparp REST SDK be configured?

+4
6

PayPal. :

<configSections>
  <section name="paypal" type="PayPal.Manager.SDKConfigHandler, PayPalCoreSDK"/>
</configSections>
<paypal>
  <accounts>
    <account apiUsername="xxx"
             apiPassword="yyy"
             applicationId="APP-80W284485P519543T"
             apiSignature="zzz"
             />
  </accounts>
  <settings>
    <add name="mode" value="sandbox"/>
  </settings>
</paypal>

xxx, yyy, zzz , " " sandbox.

+5

. Skliwz, .

, .

Dictionary<string, string> payPalConfig = new Dictionary<string, string>();
        payPalConfig.Add("mode", "sandbox");
OAuthTokenCredential tokenCredential = new AuthTokenCredential("myCliedId", "myClientSecret", payPalConfig);
string accessToken = tokenCredential.GetAccessToken();

- , ...

+8

PayPal.Net SDK ( 1.3.0), :

<configSections>
    <section name="paypal" type="PayPal.SDKConfigHandler, PayPal" />
</configSections>
<paypal>
    <settings>
       <add name="mode" value="sandbox" />
    </settings>
</paypal>
+2

*.config(web.config, app.config), , , . pass-in OAuthTokenCredential APIContext.Config( ):

var clientId = "___REPLACE_WITH_CLIENTID___";
var clientSecret = "___REPLACE_WITH_CLIENTSECRET___";            
var sdkConfig = new Dictionary<string, string> {
   { "mode", "sandbox" },
   { "clientId", clientId },
   { "clientSecret", clientSecret }
};
var accessToken = new OAuthTokenCredential(clientId, clientSecret, sdkConfig).GetAccessToken();
var apiContext = new APIContext(accessToken);
apiContext.Config = sdkConfig;

, OAuthTokenCredential apiContext.Config, , .

+1

PayPal.NET SDK SDK GitHub wiki. , PayPal .

The wiki also contains information on how to (optionally) configure log4net in the configuration if you want to enable logging with your application.

If any information is missing or needs clarification, or if you want to request support for additional configuration settings, please feel free to let me know about it or on GitHub .

0
source
var config = ConfigManager.Instance.GetProperties();

        // Use OAuthTokenCredential to request an access token from PayPal
        var accessToken = new OAuthTokenCredential(config).GetAccessToken();

Network configuration:

    <configuration>
  <configSections>
    <section name="paypal" type="PayPal.SDKConfigHandler, PayPal" />
  </configSections>

  <!-- PayPal SDK settings -->
  <paypal>
    <settings>
      <add name="mode" value="sandbox"/>
      <add name="clientId" value="_client_Id_"/>
      <add name="clientSecret" value="_client_secret_"/>
    </settings>
  </paypal>
</configuration>
0
source

All Articles