1️⃣ Register and Log in to a PayPal Business Account
You first need a PayPal Business Account.
Registration URL: paypal.com/business
2️⃣ Access the Developer Dashboard
Open the PayPal Developer Dashboard (developer.paypal.com/developer/applications).
Log in using your business account.
Here, you can manage your REST API apps and Sandbox test accounts.
3️⃣ Create an API App to Obtain Keys
In the Dashboard, select "Apps & Credentials".
Under the "REST API apps" section, you will see the default "Default Application". To create a new one, click "Create App".
Fill in the app name and select the associated PayPal account (can be a Sandbox test account or a Live account for real payments).
After creation, on the app details page, you will see two crucial pieces of information:
Client ID: Used to identify your application.
Secret: Used to authenticate your application. Keep this secure and do not disclose it.
These two pieces of information are your API Keys for integrating PayPal payments.
Mode Explanation:
Sandbox Mode: Uses the api-m.sandbox.paypal.comendpoint for testing payments with simulated funds.
Live Mode: Uses the api-m.paypal.comendpoint for processing real payments. After switching to Live mode, you must securely store the new Client ID and Secret.
4️⃣ Using the API Keys
When integrating via REST API, you do not use the Client ID and Secret directly for API calls. The standard process is as follows:
Obtain an Access Token: Send a request to the PayPal OAuth 2.0 endpoint (/v1/oauth2/token) using your Client ID and Secret for authentication to obtain an Access Token.
Use the Access Token: When making subsequent API calls for payments, creating orders, querying refunds, etc., include this Access Token in the HTTP request's Authorizationheader in the format: Bearer ACCESS-TOKEN.
Token Validity: The Access Token is typically valid for 8-9 hours (e.g., 31668 seconds). You need to request a new one after it expires.
🔗 Official Documentation Links
PayPal REST API Overview: developer.paypal.com/docs/api/overview/
Detailed Guide to Getting an Access Token: developer.paypal.com/docs/api/get-an-access-token/