Giter Site home page Giter Site logo

rest-api-sdk-java's Introduction

PayPal REST API Java SDK Build Status

This repository contains Java SDK and samples for REST API.

Prerequisites:

SDK Core Dependency:

To build sdk and samples:

  • Run mvn install to build sdk jar and sample war files.

SDK Integration:

  • 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>0.7.1</version>
    </dependency>
    

To make an API call:

  • Import stub classes into your code. For example,

    import com.paypal.api.payments.*
  • Copy the configuration file sdk_config.properties in rest-api-sample/src/test/resources folder to your application src/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 accesstoken from clientID and clientSecret using OAuthTokenCredential

    String accessToken = new OAuthTokenCredential(clientID, clientSecret).getAccessToken();
  • Depending on the context of API calls, calling method may be static or non-static (For example, most GET http methods are created as static methods within the resource). In all API calls, we need to pass accessToken created 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);

SDK Configuration:

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

rest-api-sdk-java's People

Contributors

prannamalai avatar kumaravel-jayakumar avatar lvairamani avatar aydiv avatar lathavairamani avatar

Watchers

Phuc Huynh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.