我正在使用the .NET SDK for Paypal Payments Pro。示例应用程序将API帐户凭据存储在网站的Web.config
文件中。我希望能够从数据库中提取这些凭据。
有些搜索出现了这个条目,它提出了同样的问题:Edit Settings in web.config。不幸的是,接受的答案并没有解决如何在其他地方存储凭证的问题;相反,它显示了如何以编程方式修改Web.config
文件。
有没有办法以编程方式指定Paypal Payments Pro API凭证?
由于
答案 0 :(得分:0)
<强> UDPATE 强>
您应该能够重新编写ConfigManager
类和SDKConfigHandler
类来检索数据库中的值(而不是web.config
)。
ConfigManager
检索数据并使用SDKConfigHandler
类来构造数据,以便其他方法和类可以使用它。
您可以在\PayPal_Merchant_SDK\Manager\
中找到这两个课程。
<强> ORIGINAL 强>
在审核the SDK之后,看起来您只需使用新的UserInfo
对象指定凭据:
UserInfo User = new UserInfo("<user>", "<vendor>", "<partner>", "<password>");
您只需要填充user
,vendor
,partner
和password
,因此我认为您无法将这些内容存储在数据库中并将其检索为必要的。
UserInfo
对象作为参数传递给SaleTransaction
构造函数。
SaleTransaction Trans = new SaleTransaction(User, Connection, Inv, Card, RequestID);
看来只要在切换凭据后重新实例化UserInfo
对象和SaleTransaction
对象,就应该没问题。
PayflowUtility.AppSettings
似乎只是一种帮助方法,用于从app.config
检索值。来自DOSaleComplete.cs
的第87行:
Should you choose to store the login information (Vendor, User, Partner and Password) in
app.config, you can retrieve the data using PayflowUtility.AppSettings.
For Example:
App.Config Entry: <add key="PayflowPartner" value="PayPal"/>
String mUser = PayflowUtility.AppSettings("PayflowUser");
String mVendor = PayflowUtility.AppSettings("PayflowVendor");
String mPartner = PayflowUtility.AppSettings("PayflowPartner");
String mPassword = PayflowUtility.AppSettings("PayflowPassword");
UserInfo User = new UserInfo (mUser, mVendor, mPartner, mPassword);
答案 1 :(得分:0)
目前,PayPal .NET SDK仅用于从配置文件中选择API帐户凭据。也许,未来版本将支持动态身份验证。
由于
答案 2 :(得分:0)
有人在github分叉项目使用哈希表而不是web.config https://github.com/paypal/sdk-core-dotnet/pull/2
此变更集允许传递PayPal配置 哈希表形式到PayPalAPIInterfaceServiceService。这个补助金 能够在外部配置文件中存储配置数据或 数据库而不是强制使用app / web.config文件。这个 对于执行PayPal的共享类库特别有用 多个调用应用程序使用的SDK操作; 还可以在数据库中存储大量帐户 而不是配置文件是有利的。向后兼容性 支持现有的app / web.config配置。