在Web.config之外存储Paypal Payments Pro帐户信息

时间:2012-10-26 23:59:16

标签: asp.net web-config paypal

我正在使用the .NET SDK for Paypal Payments Pro。示例应用程序将API帐户凭据存储在网站的Web.config文件中。我希望能够从数据库中提取这些凭据。

有些搜索出现了这个条目,它提出了同样的问题:Edit Settings in web.config。不幸的是,接受的答案并没有解决如何在其他地方存储凭证的问题;相反,它显示了如何以编程方式修改Web.config文件。

有没有办法以编程方式指定Paypal Payments Pro API凭证?

由于

3 个答案:

答案 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>");

您只需要填充uservendorpartnerpassword,因此我认为您无法将这些内容存储在数据库中并将其检索为必要的。

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配置。