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
UDPATE
You should be able to re-write the
ConfigManager
class and theSDKConfigHandler
class to retrieve the values from a database (notweb.config
).ConfigManager
retrieves the data and uses theSDKConfigHandler
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:You just need to populate
user
,vendor
,partner
, andpassword
, 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 theSaleTransaction
constructor.It would seem that as long as you re-instantiate both the
UserInfo
object and the theSaleTransaction
object after switching credentials, you should be fine.The
PayflowUtility.AppSettings
seems to merely be a helper method for retrieving the values fromapp.config
. From Line 87 ofDOSaleComplete.cs
: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
Someone's forked the project at github to use a hashtable instead of web.config https://github.com/paypal/sdk-core-dotnet/pull/2