Configure your environment

After you install the SDK, you must make the SDK available to your app and configure your environment. Configuration details include the mode, which is sandbox for testing or live for production, and your client ID and secret for your app.

Note: To get a client ID and secret, use the developer dashboard to create a REST API app.

In the directory where you installed the SDK, create a file in your preferred language. In the file, include the following code to make the SDK available, and configure your environment with your application credentials.

var paypal = require('paypal-rest-sdk');

paypal.configure({
  mode: 'sandbox', // Sandbox or live
  client_id: 'YOUR APPLICATION CLIENT ID',
  client_secret: 'YOUR APPLICATION CLIENT SECRET'});
// Autoload SDK package for composer based installations
require 'vendor/autoload.php';

$apiContext = new \PayPal\Rest\ApiContext(
  new \PayPal\Auth\OAuthTokenCredential(
    'YOUR APPLICATION CLIENT ID',
    'YOUR APPLICATION CLIENT SECRET'
  )
);
import paypalrestsdk

paypalrestsdk.configure({
  'mode': 'sandbox', #sandbox or live
  'client_id': 'YOUR APPLICATION CLIENT ID',
  'client_secret': 'YOUR APPLICATION CLIENT SECRET' })
require 'paypal-sdk-rest'
include PayPal::SDK::REST
include PayPal::SDK::Core::Logging

PayPal::SDK.configure(
  :mode => 'sandbox', #sandbox or live
  :client_id => 'YOUR APPLICATION CLIENT ID',
  :client_secret => 'YOUR APPLICATION CLIENT SECRET',
  :ssl_options => { } )
import com.paypal.base.rest.APIContext;
import com.paypal.base.rest.PayPalRESTException;

// Replace with your application client ID and secret
String clientId = "YOUR APPLICATION CLIENT ID";
String clientSecret = "YOUR APPLICATION CLIENT SECRET";

APIContext context = new APIContext(clientId, clientSecret, "sandbox");
// Add to web.config or app.config
<configuration>
  <configSections>
    <section name="paypal" type="PayPal.SDKConfigHandler, PayPal" />
  </configSections>

  <!-- PayPal SDK settings -->
  <paypal>
    <settings>
      <add name="mode" value="sandbox"/>
      <add name="clientId" value="YOUR APPLICATION CLIENT ID"/>
      <add name="clientSecret" value="YOUR APPLICATION CLIENT SECRET"/>
    </settings>
  </paypal>
</configuration>

// Add to code
using PayPal.Api;

// Authenticate with PayPal
var config = ConfigManager.Instance.GetProperties();
var accessToken = new OAuthTokenCredential(config).GetAccessToken();
var apiContext = new APIContext(accessToken);

Next

Additional information