Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PayPal REST API DotNet SDK 1.9.1 - where is the URI endpoint?

I installed the PayPal Dotnet REST SDK 1.9.1 into a test application and got everything working just fine (no problems at all). But noticed that the endpoint isn't specified (nor did I need to specify it), so I presume it is stored somewhere (the paypal.dll?).

Running the SDK code example (taken from PayPal's developer site) appears to generate 3 links automatically.

Do I need to worry that the URI is embedded in the dll somewhere?

Would there be any reason to change it?

***** EDIT ******* Here is the code I use to get the APIContext - Does anyone see a problem with this code? No matter what I put in for the endpoint (or mode, or what-have-you), the SDK always uses the sandbox endpoint. The real madness here is that it is accepting the LIVE ClientId and Secret (so it is connecting to the LIVE endpoint, for sure), but any further requests are ALWAYS to the sandbox endpoint. NOTE: This function is only called once and the Context is merely passed to other functions/calls/what-have-you. I even set it up to pass by reference with no joy.

public static PayPal.Api.APIContext GetPaypalRestAPIContext()
{
    try
    {
        Dictionary<string, string> config = null;
        if (WebAppSettings.PaypalMode.ToLower != "live")
        {
            config = new Dictionary<string, string>()
            {
                {"mode", WebAppSettings.PaypalMode.ToLower},
                {"clientId", WebAppSettings.PaypalTestClientId},
                {"clientSecret", WebAppSettings.PaypalTestClientSecret},
                {"endpoint", "https://api.sandbox.paypal.com/"}
            };
        }
        else
        {
            config = new Dictionary<string, string>()
            {
                {"mode", WebAppSettings.PaypalMode.ToLower},
                {"clientId", WebAppSettings.PaypalClientId},
                {"clientSecret", WebAppSettings.PaypalClientSecret},
                {"endpoint", "https://api.paypal.com/"}
            };
        }

        string accessToken = (new PayPal.Api.OAuthTokenCredential(config)).GetAccessToken();
        PayPal.Api.APIContext apiContext = new PayPal.Api.APIContext(accessToken);

        return apiContext;
    }
    catch (Exception ex)
    {
        EventLog.LogEvent("Paypal APIContext", "PaypalRestAPIContext has failed.", EventLogSeverity.Warning);
        return null;
    }

}

I feel like I'm missing something here or losing my mind.

like image 420
MC9000 Avatar asked May 23 '18 21:05

MC9000


1 Answers

According to the API reference documentation

The URL to the API service

  • Sandbox. https://api.sandbox.paypal.com
  • Live. https://api.paypal.com

These same URLs are found in the GitHub Repository of the SDK in the BaseConstants class which would mean that they are in fact embedded/Hard-coded in the SDK

/// <summary>
/// Sandbox REST API endpoint
/// </summary>
public const string RESTSandboxEndpoint = "https://api.sandbox.paypal.com/";

/// <summary>
/// Live REST API endpoint
/// </summary>
public const string RESTLiveEndpoint = "https://api.paypal.com/";

/// <summary>
/// Security Test Sandbox REST API endpoint
/// </summary>
public const string RESTSecurityTestSandoxEndpoint = "https://test-api.sandbox.paypal.com/";

Which would confirm the observation of 3 links being "generated" by the SDK.

There is also mention in the documentation.

In order to use the PayPal .NET SDK with your application, you will need to first configure your application. By default, the SDK will attempt to look for PayPal-specific settings in your application's web.config or app.config file.

PayPal Config Settings

The following is a sample config file containing the configuration sections that are required in order for the settings to be used with this SDK:

<configuration>
  <configSections>
    <section name="paypal" type="PayPal.SDKConfigHandler, PayPal" />
  </configSections>

  <!-- PayPal SDK settings -->
  <paypal>
    <settings>
      <add name="mode" value="sandbox"/>
      <add name="clientId" value="_client_Id_"/>
      <add name="clientSecret" value="_client_secret_"/>
    </settings>
  </paypal>
</configuration>

mode: Determines which PayPal endpoint URL will be used with your application. Possible values are live or sandbox.

So it looks like the mode in the settings will determine which endpoint URL is called by the SDK when requests are made to the API.

To answer your questions.

Do I need to worry that the URI is embedded in the dll somewhere?

No.

Would there be any reason to change it?

They allow the facility to change the mode the code is running in setting so that it will use the appropriate enpoint URL when executing. That means that if you want to run test against the sandbox then simply change the mode setting of the application.

like image 114
Nkosi Avatar answered Nov 13 '22 22:11

Nkosi