gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 15:39:46 25 4
gpt4 key购买 nike

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

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

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

是否有任何理由改变它?

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

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

GitHub Repository of the SDK 中可以找到这些相同的 URL在 BaseConstants 类中,这意味着它们实际上嵌入/硬编码在 SDK 中

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

因此看起来设置中的模式将决定在向 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?

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

关于asp.net - PayPal REST API DotNet SDK 1.9.1 - URI 端点在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50497792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com