This repository contains Java SDK and samples for REST API. For PayPal mobile(Android) SDK, please go to PayPal Android SDK
- Java JDK-1.5 or higher
- Apache Maven 3 or higher
- Please refer http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html for any help in Maven.
- Source code for core files are present at https://github.com/paypal/sdk-core-java.
- Run
mvn installto build sdk jar and sample war files.
-
Create a new maven application.
-
Add dependency to sdk in your application's pom.xml as below.
<dependency> <groupId>com.paypal.sdk</groupId> <artifactId>rest-api-sdk</artifactId> <version>LATEST</version> </dependency>
-
Import stub classes into your code. For example,
import com.paypal.api.payments.*
-
Copy the configuration file
sdk_config.propertiesinrest-api-sample/src/test/resourcesfolder to your applicationsrc/main/resources. And load it as a classloader resource,InputStream is = PaymentWithCreditCardServlet.class.getResourceAsStream("/sdk_config.properties");
-
Or load config file from any custom location using absolute path with the below method calls as required,
Payment.initConfig(new File("../sdk_config.properties")); Or Payment.initConfig(new InputStream(new File("../sdk_config.properties"))); Or Payment.initConfig(new Properties().load(new InputStream(new File("../sdk_config.properties"))));
-
Create
accesstokenfromclientIDandclientSecretusingOAuthTokenCredentialString accessToken = new OAuthTokenCredential(clientID, clientSecret).getAccessToken();
-
Depending on the context of API calls, calling method may be static or non-static (For example, most
GEThttp methods are created asstaticmethods within the resource). In all API calls, we need to passaccessTokencreated above as argument as shown below,-
If it is static, invoke it as a class method as like
Payment.get(accessToken, paymentID);
-
If it is non-static, invoke it using resource object as like below. The API call takes a APIContext object in the place of AccessToken, APIContext object encapsulates Access Token and Request ID (used for idempotency).
APIContext apiContext = new APIContext(accessToken); (OR) APIContext apiContext = new APIContext(accessToken, requestId); Payment payment = new Payment(); payment.setIntent("sale"); ... payment.create(apiContext);
-
-
Future Payments sample is available here for executing future payments for a customer who has granted consent on a mobile device.
-
For Invoicing, check out the samples to see how you can use the node sdk to create, send and manage invoices.
The SDK uses Java properties format configuration file. Sample of this file is at
rest-api-sample/src/test/resources/. You can use the sdk_config.properties configuration file to configure
-
HTTP connection parameters.
-
Service configuration.
-
Credentials


