paypal / PayPal-NET-SDK

.NET SDK for PayPal's RESTful APIs
https://developer.paypal.com
Other
536 stars 461 forks source link

Using the SDK without dependency on settings in web.config? #11

Closed sfmskywalker closed 10 years ago

sfmskywalker commented 10 years ago

Is there a way to use the REST API SDK without requiring me to configure settings (ClientID, Secret & Endpoint) via web.config? I'd like to store these settings in a database instead (use case: I'm writing an Orchard CMS module).

I could obviously talk with the REST API directly via HttpClient, but it saves a lot of time being able to use your dot net SDK instead.

aydiv commented 10 years ago

You can skip Web.Config altogether. All REST methods in the SDK have a overloaded variant that takes a APIContext object as a argument. See here for an example.

Here's a payment create call that uses web.config

Payment.Create(<access token>);

while here's a call that uses a dynamic config dictionary instead

Dictionary<string, string> config = new Dictionary<string, string>();
config.Add("mode", "sandbox");

APIContext context = new APIContext();
context.Config = config;
context.AccessToken = <accessToken>;

Payment.Create(context);
sfmskywalker commented 10 years ago

That's great. Thanks!

werddomain commented 9 years ago

https://github.com/paypal/rest-api-sdk-dotnet/blob/master/Visual%20Studio%202008/RestApiSDK/PayPal/Api/Payments/Payment.cs#L120 -> 404 context.AccessToken is readonly

jziaja commented 9 years ago

@werddomain APIContext can be found in the sdk-core-dotnet repository.

Here is an updated example of how to use it with a dynamic config dictionary:

var config = new Dictionary<string, string>();
config.Add("mode", "sandbox");

var context = new APIContext(<accessToken>);
context.Config = config;

Payment.Create(context);`