PayPal REST API DotNet SDK 1.9.1 - URI 端点在哪里?

PayPal REST API DotNet SDK 1.9.1 - where is the URI endpoint?

我将 PayPal Dotnet REST SDK 1.9.1 安装到测试应用程序中,一切正常(完全没有问题)。但是注意到没有指定端点(我也不需要指定它),所以我认为它存储在某个地方(paypal.dll?)。

运行 SDK 代码示例(取自 PayPal 的开发者网站)似乎自动生成了 3 个链接。

我是否需要担心 URI 嵌入到 dll 某处?

有什么理由要改吗?

***** 编辑 ******* 这是我用来获取 APIContext 的代码——有人看到这段代码有问题吗?无论我为端点(或模式,或你有什么)输入什么,SDK 始终使用沙盒端点。这里真正的疯狂是它正在接受 LIVE ClientId 和 Secret(因此它肯定连接到 LIVE 端点),但任何进一步的请求总是到沙箱端点。注意:此函数仅调用一次,上下文仅传递给其他 functions/calls/what-have-you。我什至将其设置为通过引用传递,但没有任何乐趣。

public static PayPal.Api.APIContext GetPaypalRestAPIContext()
{
    try
    {
        Dictionary<string, string> config = null;
        if (WebAppSettings.PaypalMode.ToLower != "live")
        {
            config = new Dictionary<string, string>()
            {
                {"mode", WebAppSettings.PaypalMode.ToLower},
                {"clientId", WebAppSettings.PaypalTestClientId},
                {"clientSecret", WebAppSettings.PaypalTestClientSecret},
                {"endpoint", "https://api.sandbox.paypal.com/"}
            };
        }
        else
        {
            config = new Dictionary<string, string>()
            {
                {"mode", WebAppSettings.PaypalMode.ToLower},
                {"clientId", WebAppSettings.PaypalClientId},
                {"clientSecret", WebAppSettings.PaypalClientSecret},
                {"endpoint", "https://api.paypal.com/"}
            };
        }

        string accessToken = (new PayPal.Api.OAuthTokenCredential(config)).GetAccessToken();
        PayPal.Api.APIContext apiContext = new PayPal.Api.APIContext(accessToken);

        return apiContext;
    }
    catch (Exception ex)
    {
        EventLog.LogEvent("Paypal APIContext", "PaypalRestAPIContext has failed.", EventLogSeverity.Warning);
        return null;
    }

}

我觉得我在这里遗漏了一些东西或者失去了理智。

根据 API reference documentation

The URL to the API service

  • Sandbox. https://api.sandbox.paypal.com
  • Live. https://api.paypal.com

这些相同的 URL 在 BaseConstants class 的 GitHub Repository of the SDK 中找到,这意味着它们实际上在 SDK 中 embedded/Hard-coded

/// <summary>
/// Sandbox REST API endpoint
/// </summary>
public const string RESTSandboxEndpoint = "https://api.sandbox.paypal.com/";

/// <summary>
/// Live REST API endpoint
/// </summary>
public const string RESTLiveEndpoint = "https://api.paypal.com/";

/// <summary>
/// Security Test Sandbox REST API endpoint
/// </summary>
public const string RESTSecurityTestSandoxEndpoint = "https://test-api.sandbox.paypal.com/";

这将证实 SDK 正在 “生成” 3 个链接的观察结果。

文档中也有提及。

In order to use the PayPal .NET SDK with your application, you will need to first configure your application. By default, the SDK will attempt to look for PayPal-specific settings in your application's web.config or app.config file.

PayPal Config Settings

The following is a sample config file containing the configuration sections that are required in order for the settings to be used with this SDK:

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

mode: Determines which PayPal endpoint URL will be used with your application. Possible values are live or sandbox.

所以看起来设置中的 mode 将决定在向 API 发出请求时 SDK 调用哪个端点 URL。

回答您的问题。

Do I need to worry that the URI is embedded in the dll somewhere?

没有

Would there be any reason to change it?

它们允许工具更改代码在设置中 运行ning 的模式,以便它在执行时使用适当的 enpoint URL。这意味着如果您想 运行 针对沙箱进行测试,只需更改应用程序的模式设置即可。