简体   繁体   English

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

[英]Store Paypal Payments Pro account information outside of Web.config

I am using the .NET SDK for Paypal Payments Pro . 我正在将.NET SDK用于Paypal Payments Pro The sample application stores the API account credentials in the website's Web.config file. 该示例应用程序将API帐户凭据存储在网站的Web.config文件中。 I'd like to be able to pull these credentials from the database, instead. 我希望能够从数据库中提取这些凭据。

Some searching turned up this entry, which asks the same question: Edit Settings in web.config . 一些搜索打开了此条目,它提出了相同的问题: 在web.config中编辑设置 Unfortunately, the accepted answer didn't address how to store the credentials elsewhere; 不幸的是,被接受的答案并没有解决如何将凭证存储在其他地方。 instead, it showed how to programmatically modify the Web.config file. 而是显示了如何以编程方式修改Web.config文件。

Is there any way to specify the Paypal Payments Pro API credentials programmatically? 有什么方法可以通过编程方式指定Paypal Payments Pro API凭据?

Thanks 谢谢

UDPATE UDPATE

You should be able to re-write the ConfigManager class and the SDKConfigHandler class to retrieve the values from a database (not web.config ). 您应该能够重新编写ConfigManager类和SDKConfigHandler类,以从数据库(不是web.config )中检索值。

ConfigManager retrieves the data and uses the SDKConfigHandler class to structure the data so other methods and classes can use it. ConfigManager检索数据,并使用SDKConfigHandler类构造数据,以便其他方法和类都可以使用它。

You'll find both classes in \\PayPal_Merchant_SDK\\Manager\\ . 您可以在\\PayPal_Merchant_SDK\\Manager\\找到这两个类。

ORIGINAL After reviewing the SDK , it looks like all you have to do is specify the credentials with a new UserInfo object: 原始人在查看SDK之后 ,您似乎要做的就是用新的UserInfo对象指定凭据:

UserInfo User = new UserInfo("<user>", "<vendor>", "<partner>", "<password>");

You just need to populate user , vendor , partner , and password , so I see no reason why you cannot store those in a database and retrieve them as necessary. 您只需要填充uservendorpartnerpassword ,所以我看不出您为什么不能将它们存储在数据库中并根据需要检索它们的原因。

The UserInfo object is passed as a parameter to the SaleTransaction constructor. UserInfo对象作为参数传递给SaleTransaction构造函数。

SaleTransaction Trans = new SaleTransaction(User, Connection, Inv, Card, RequestID);

It would seem that as long as you re-instantiate both the UserInfo object and the the SaleTransaction object after switching credentials, you should be fine. 看起来,只要您在切换凭据后重新实例化UserInfo对象和SaleTransaction对象,就可以了。

The PayflowUtility.AppSettings seems to merely be a helper method for retrieving the values from app.config . PayflowUtility.AppSettings似乎只是从app.config检索值的辅助方法。 From Line 87 of DOSaleComplete.cs : DOSaleComplete.cs第87 DOSaleComplete.cs

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

Right now, PayPal .NET SDKs are designed to pick the API account credentials only from the configuration file. 目前,PayPal .NET SDK设计为仅从配置文件中选择API帐户凭据。 Perhaps, future version will support dynamic authentication. 也许将来的版本将支持动态身份验证。

Thanks 谢谢

Someone's forked the project at github to use a hashtable instead of web.config https://github.com/paypal/sdk-core-dotnet/pull/2 有人在github上分叉了该项目以使用哈希表而不是web.config https://github.com/paypal/sdk-core-dotnet/pull/2

This changeset allows for passing the PayPal configuration in hashtable form to the PayPalAPIInterfaceServiceService. 此变更集允许将哈希表形式的PayPal配置传递给PayPalAPIInterfaceServiceService。 This grants the ability to store config data in an external config file or database rather than forcing the use of an app/web.config file. 这样可以将配置数据存储在外部配置文件或数据库中,而不是强制使用app / web.config文件。 This is especially useful for shared class libraries that perform PayPal SDK operations which are utilized by multiple calling applications; 这对于执行由多个调用应用程序使用的PayPal SDK操作的共享类库特别有用。 also the ability to store a large number of accounts in a database rather than a config file is advantageous. 在数据库中而不是在配置文件中存储大量帐户的能力也是有利的。 Backwards compatibility for existing app/web.config configurations is supported. 支持现有app / web.config配置的向后兼容性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM