---
# System prepended metadata

title: Northstar Server SDK for Java

---

# Northstar Server SDK for Java

[TOC]

## Description

This SDK acts as library to interact with the PayPal API. It will handle the heavy lifting of managing API calls, so devs can focus on their business logic rather than the low level network details.

The PayPal Orders API is a part of the Checkout workflow. An order represents a payment between two or more parties. This SDK allows user to perform all necessary actions on an order.

HTTP request | Description
------------- | -------------
**POST** /orders/{id}/authorize | Authorize payment for order
**POST** /orders/{id}/capture | Capture payment for order
**POST** /orders/{id}/confirm-payment-source | Confirm the Order
**POST** /orders | Create order
**GET** /orders/{id} | Show order details
**PATCH** /orders/{id} | Update order

## Design
### Class Diagrams
```mermaid
classDiagram
class Configuration {
-environment : string
-clientId : string
-clientSecret : string
+Configuration(clientId : string, clientSecret : string, environment : string)
+baseUrl() string
+getClientId() string
+getClientSecret() string
} 

%% PayPalHttp
class Environment{
 <<External PayPalHttp interface>>
 +baseUrl() string
}

Configuration ..|> Environment : implements

class Base {
#config : Configuration
+Base(config : Configuration)
#execute(request : HttpRequest) HttpResponse
}

class Order {
+Order(config: Configuration)
+authorize(id : string, OrderAuthorizeRequest) OrderAuthorizeResponseJson
+capture(id : string, OrderCaptureRequest) Order
+confirm(id : string, ConfirmOrderRequest) Order
+create(OrderRequest) Order
+retrieve(id : string) Order
+update(Patch[]) int
}

Order --|> Base : extends

class PayPalClient {
-config Configuration
-order Order
+PayPalClient(config : Configuration)
+order() Order
}

PayPalClient "1" --* "1" Configuration : has-a
PayPalClient "1" --* "1" Order : has-a
```

## Setup
### Requirements
1. Java (8+ ?)
2. Maven (3.8.3+) or Gradle (7.2+)

### Installation

#### Maven users

Add this dependency to your project's POM:

```xml
<dependency>
  <groupId>TBD</groupId>
  <artifactId>paypal-java</artifactId>
  <version>1.0</version>
  <scope>compile</scope>
</dependency>
```

#### Gradle users

Add this dependency to your project's build file:

```groovy
dependencies {
    implementation "TBD:paypal-java:1.0"
}
```

## Quick Start
### Initialize SDK with Client ID and Secret
Client id and secret are required for each request to [authenticate](https://developer.paypal.com/api/rest/authentication/) the client.
Login to [PayPal Developer Dashboard](https://developer.paypal.com/developer/applications) to retrieve your client id and secret.

Client sets the environment, client id, and secret prior to initial request.
The environment is sandbox or production.
```java=
import paypal.Configuration;
import paypal.PayPalClient;

// Replace CLIENT_ID and CLIENT_SECRET with non-hard coded values.
Configuration config = new Configuration(CLIENT_ID, CLIENT_SECRET, "sandbox");
PayPalClient client = new PayPalClient(config);
```

### Create New Order
```java=
import ...

// Replace CLIENT_ID and CLIENT_SECRET with non-hard coded values.
Configuration config = new Configuration(CLIENT_ID, CLIENT_SECRET, "sandbox");
PayPalClient client = new PayPalClient(config);

AmountWithBreakdown amount = new AmountWithBreakdown()
        .currencyCode("USD")
        .value("10.00");

PurchaseUnitRequest purchaseUnit = new PurchaseUnitRequest().amount(amount);

OrderRequest orderRequest = new OrderRequest()
        .intent("CAPTURE")
        .addPurchaseUnitsItem(purchaseUnit);

Order response = client.order().create(orderRequest);
```
### Get Existing Order
Shows details for an order, by ID.
```java=
import ...

// Replace CLIENT_ID and CLIENT_SECRET with non-hard coded values.
Configuration config = new Configuration(CLIENT_ID, CLIENT_SECRET, "sandbox");
PayPalClient client = new PayPalClient(config);

// Replace ORDER_ID with actual id.
Order response = client.order().get(ORDER_ID);

String orderStatus = response.getStatus();
String orderId = response.getId();
```

### Authorize Order
Authorizes payment for an order. To successfully authorize payment for an order, the buyer must first approve the order or a valid payment_source must be provided in the request.
```java=
import ...

// Replace CLIENT_ID and CLIENT_SECRET with non-hard coded values.
Configuration config = new Configuration(CLIENT_ID, CLIENT_SECRET, "sandbox");
PayPalClient client = new PayPalClient(config);

// OrderAuthorizeRequestJson is optional
Token token = new Token()
    .setId(PAYPAL_GENERATED_ID)
    .setType("BILLING_AGREEMENT");

PaymentSource paymentSource = new PaymentSource().setToken(token);

OrderAuthorizeRequest orderAuthorizeRequest = new OrderAuthorizeRequest()
    .setPaymentSource(paymentSource);

Order response = client.order().authorize(ORDER_ID, orderAuthorizeRequest);
```

### Capture Order
Captures payment for an order. To successfully capture payment for an order, the buyer must first approve the order or a valid payment_source must be provided in the request.
```java=
import ...

// Replace CLIENT_ID and CLIENT_SECRET with non-hard coded values.
Configuration config = new Configuration(CLIENT_ID, CLIENT_SECRET, "sandbox");
PayPalClient client = new PayPalClient(config);

Token token = new Token()
    .setId(PAYPAL_GENERATED_ID)
    .setType("BILLING_AGREEMENT");

PaymentSource paymentSource = new PaymentSource().setToken(token);

OrderCaptureRequest orderCaptureRequest = new OrderCaptureRequest()
    .setPaymentSource(paymentSource);

Order response = client.order().capture(ORDER_ID, orderCaptureRequest);
```

### Patch Order
Updates an order with a CREATED or APPROVED status. You cannot update an order with the COMPLETED status.

```java=
import ...

// Replace CLIENT_ID and CLIENT_SECRET with non-hard coded values.
Configuration config = new Configuration(CLIENT_ID, CLIENT_SECRET, "sandbox");
PayPalClient client = new PayPalClient(config);

Patch patchRequest = new Patch()
    .setOp(...)
    .setPath(...)
    .setValue(...)
    .setFrom(...);

int response = client.order().patch(ORDER_ID, patchRequest);
```

### Confirm Order
Payer confirms their intent to pay for the the order with the given payment source.

```java=
import ...

// Replace CLIENT_ID and CLIENT_SECRET with non-hard coded values.
Configuration config = new Configuration(CLIENT_ID, CLIENT_SECRET, "sandbox");
PayPalClient client = new PayPalClient(config);

Token token = new Token()
    .setId(PAYPAL_GENERATED_ID)
    .setType("BILLING_AGREEMENT");

PaymentSource paymentSource = new PaymentSource().setToken(token);

ConfirmORderRequest confirmOrderRequest = new ConfirmOrderRequest()
    .setPaymentSource(paymentSource);

Order response = client.order().confirm(ORDER_ID, confirmOrderRequest);
```