MC9*_*000 8 asp.net paypal paypal-rest-sdk
我将PayPal Dotnet REST SDK 1.9.1安装到测试应用程序中并使一切工作正常(完全没有问题).但是注意到端点没有指定(我也不需要指定它),所以我认为它存储在某个地方(paypal.dll?).
运行SDK代码示例(取自PayPal的开发人员站点)似乎会自动生成3个链接.
我是否需要担心URI是否嵌入在某个地方的dll中?
有没有理由改变它?
*****编辑*******这是我用来获取APIContext的代码 - 有没有人看到这段代码的问题?无论我为端点(或模式,或者你有什么)投入什么,SDK总是使用沙箱端点.这里真正的疯狂是它接受了LIVE ClientId和Secret(因此它肯定会连接到LIVE端点),但是任何进一步的请求都始终是沙箱端点.注意:此函数仅调用一次,Context仅传递给其他函数/调用/ 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;
}
}
Run Code Online (Sandbox Code Playgroud)
我觉得我在这里错过了一些东西或者失去了理智.
根据API参考文档
API服务的URL
- 沙箱.
https://api.sandbox.paypal.com
- 生活.
https://api.paypal.com
这些相同的URL可以在类的SDK的GitHub存储库中找到,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/";
Run Code Online (Sandbox Code Playgroud)
这将确认观察到由SDK "生成"的3个链接.
文档中也提到了.
要在您的应用程序中使用PayPal .NET SDK,您需要先配置您的应用程序.默认情况下,SDK将尝试在应用程序的web.config或app.config文件中查找特定于PayPal的设置.
以下是一个示例配置文件,其中包含设置与此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>
Run Code Online (Sandbox Code Playgroud)
mode:确定将与您的应用程序一起使用的PayPal端点URL.可能的值是
live
或sandbox
.
因此,mode
在向API发出请求时,设置中的内容将确定SDK调用哪个端点URL.
回答你的问题.
我是否需要担心URI是否嵌入在某个地方的dll中?
没有.
有没有理由改变它?
它们允许工具在设置中更改代码运行的模式,以便在执行时使用适当的enpoint URL.这意味着如果要对沙箱运行测试,则只需更改应用程序的模式设置即可.
归档时间: |
|
查看次数: |
222 次 |
最近记录: |