简体   繁体   English

Paypal c#REST API要求提供未记录的配置部分

[英]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. 我正在努力攻击伦敦Battle Hack ,我偶然发现了一个恼人的问题。 The PayPal SDK for c# doesn't seem to work quite right. 用于c#的PayPal SDK似乎不能正常工作。

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. 无法解析* .Config文件。 Ensure you have configured the 'paypal' section correctly. 确保您已正确配置'paypal'部分。

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? 如何配置csharp REST SDK?

I was running into this same error. 我遇到了同样的错误。 I tried Skliwz's solution but it did not work for me. 我尝试了Skliwz的解决方案,但它对我不起作用。

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... 仍在努力让我的登录工作......

I've worked this out with the support of a PayPal dev. 我在PayPal开发人员的支持下完成了这项工作。 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 . 其中xxxyyyzzz是您从主沙箱测试帐户的“帐户详细信息”中获得的值。

If you're using PayPal .Net SDK (mine is version 1.3.0) you just need the following: 如果您使用的是PayPal .Net SDK(我的版本是1.3.0),您只需要以下内容:

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

If you're like me, and don't want to store the client information in the *.config file (web.config, app.config) I've found you can specify it in a Dictionary which you have to pass-in to OAuthTokenCredential AND assigned to the APIContext.Config (key to working): 如果您像我一样,并且不想将客户端信息存储在* .config文件(web.config,app.config)中,我发现您可以在字典中指定它,您必须传入到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;

Seems a bit redundant to have to pass it into OAuthTokenCredential and set it to apiContext.Config, but that's what works for me. 看起来有点多余,必须将其传递到OAuthTokenCredential并将其设置为apiContext.Config,但这对我有用。

Just for future reference, the available config settings for the PayPal .NET SDK are now provided on the SDK's GitHub wiki . 仅供将来参考,现在可以在SDK的GitHub wiki上提供PayPal .NET SDK的可用配置设置。 This includes information on what all the supported PayPal config settings are and their default values. 这包括有关所有支持的PayPal配置设置及其默认值的信息。

The wiki also includes information on how to (optionally) setup log4net in the config if you'd like to enable logging with your application. 如果您希望使用您的应用程序启用日志记录,该Wiki还包括有关如何(可选)在配置中设置log4net的信息。

If any information is missing or needs clarification, or if you'd like to request support for more config settings, please don't hesitate to let me know here or on GitHub . 如果缺少任何信息或需要澄清,或者您想要请求支持更多配置设置,请不要犹豫,在这里或GitHub告诉我。

var config = ConfigManager.Instance.GetProperties();

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

Web config: 网络配置:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM