Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paypal c# REST API asks for an undocumented configuration section

I'm hacking hard at Battle Hack London and I've stumbled in an annoying problem. The PayPal SDK for c# doesn't seem to work quite right.

I'm trying to do my first transaction and here's my code (which I put together fixing the broken online docs:

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);

This results in

Cannot parse *.Config file. Ensure you have configured the 'paypal' section correctly.

which I've traced down to this line of code but I don't know how to configure that section correctly and I can't find the correct documentation.

How is tthe csharp REST SDK supposed to be configured?

like image 430
Sklivvz Avatar asked Dec 04 '22 09:12

Sklivvz


2 Answers

I was running into this same error. I tried Skliwz's solution but it did not work for me.

Instead I was able to get a result by passing a dictionary object with the call.

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

Still working on get my Log In to work...

like image 119
GeoffW Avatar answered Dec 31 '22 18:12

GeoffW


I've worked this out with the support of a PayPal dev. One needs to add:

<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>

where xxx, yyy, zzz you are values that you get from the "Account details" of your main sandbox test account.

like image 37
Sklivvz Avatar answered Dec 31 '22 17:12

Sklivvz