Store Paypal Payments Pro account information outs

2019-06-10 12:49发布

I am using the .NET SDK for Paypal Payments Pro. The sample application stores the API account credentials in the website's Web.config file. 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. Unfortunately, the accepted answer didn't address how to store the credentials elsewhere; instead, it showed how to programmatically modify the Web.config file.

Is there any way to specify the Paypal Payments Pro API credentials programmatically?

Thanks

3条回答
beautiful°
2楼-- · 2019-06-10 13:30

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 retrieves the data and uses the SDKConfigHandler class to structure the data so other methods and classes can use it.

You'll find both classes in \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:

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.

The UserInfo object is passed as a parameter to the SaleTransaction constructor.

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.

The PayflowUtility.AppSettings seems to merely be a helper method for retrieving the values from app.config. From Line 87 of 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);
查看更多
做自己的国王
3楼-- · 2019-06-10 13:36

Right now, PayPal .NET SDKs are designed to pick the API account credentials only from the configuration file. Perhaps, future version will support dynamic authentication.

Thanks

查看更多
Rolldiameter
4楼-- · 2019-06-10 13:47

Someone's forked the project at github to use a hashtable instead of 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. 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. This is especially useful for shared class libraries that perform PayPal SDK operations which are utilized by multiple calling applications; 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.

查看更多
登录 后发表回答