Skip to content

Commit cfbc550

Browse files
authored
Merge pull request #70 from square/release/18.1.0.20220120
Generated PR for Release: 18.1.0.20220120
2 parents da5a3fd + 236a3e2 commit cfbc550

File tree

173 files changed

+2524
-1953
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+2524
-1953
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Change Log
22

3+
For general API and SDK changelogs, see [Square APIs and SDKs Release Notes](https://developer.squareup.com/docs/changelog/connect).
4+
35
## Version 18.0.0.20211215 (2021-12-15)
46
### API updates
57

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2021 Square, Inc.
1+
Copyright 2022 Square, Inc.
22
Licensed under the Apache License, Version 2.0 (the "License");
33
you may not use this file except in compliance with the License.
44
You may obtain a copy of the License at

README.md

Lines changed: 23 additions & 223 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,43 @@ Use this library to integrate Square payments into your app and grow your busine
1212

1313
Use of the Square Java SDK requires:
1414

15-
* Java 8 or better
16-
* Maven or Gradle to build and install the SDK.
15+
* Java 8 or higher
16+
* Maven or Gradle
1717

1818
## Installation
1919

20-
### Install with Maven
20+
For more information, see [Set Up Your Square SDK for a Java Project](https://developer.squareup.com/docs/sdks/java/setup-project).
2121

22-
Install the API client library to your local Maven repository:
22+
## Quickstart
2323

24-
```
25-
mvn install -DskipTests
26-
```
24+
For more information, see [Square Java SDK Quickstart](https://developer.squareup.com/docs/sdks/java/quick-start).
2725

28-
**OR**
26+
## Usage
27+
For more information, see [Using the Square Java SDK](https://developer.com/docs/sdks/java/using-java-sdk).
2928

30-
Install the client dynamically by adding a dependency to the POM for your project:
29+
## Tests
3130

32-
```
33-
<dependency>
34-
<groupId>com.squareup</groupId>
35-
<artifactId>square</artifactId>
36-
<version>18.0.0.20211215</version>
37-
</dependency>
38-
```
31+
First, clone the repo locally and `cd` into the directory.
3932

40-
### Install with Gradle
33+
```sh
34+
git clone https://github.com/square/square-java-sdk.git
35+
cd square-java-sdk
36+
```
4137

42-
Install the client by adding the following dependency to the build file for your project:
38+
Before running the tests, find a sandbox token in your [Developer Dashboard] and set a `SQUARE_ACCESS_TOKEN` environment variable.
4339

40+
```sh
41+
export SQUARE_ENVIRONMENT=sandbox
42+
export SQUARE_ACCESS_TOKEN="YOUR_SANDBOX_ACCESS_TOKEN"
4443
```
45-
implementation "com.squareup:square:18.0.0.20211215"
44+
45+
If you are using Maven, run the tests with below command
46+
47+
```sh
48+
mvn test
4649
```
4750

48-
## API documentation
51+
## SDK Reference
4952

5053
### Payments
5154
* [Payments]
@@ -124,209 +127,6 @@ If you need to use [List settlements](https://developer.squareup.com/reference/s
124127

125128
You'll also need to provide logic to handle paginated results. For more information, see [Pagination in Connect V1](https://developer.squareup.com/docs/working-with-apis/pagination#pagination-in-connect-v1).
126129

127-
## Usage
128-
129-
First time using Square? Here’s how to get started:
130-
131-
1. **Create a Square account.** If you don’t have one already, [sign up for a developer account].
132-
1. **Create an application.** Go to your [Developer Dashboard] and create your first application. All you need to do is give it a name. When you’re doing this for your production application, enter the name as you would want a customer to see it.
133-
1. **Make your first API call.** Almost all Square API calls require a location ID. You’ll make your first call to `listLocations`, which happens to be one of the API calls that don’t require a location ID. For more information about locations, see the [Locations] API documentation.
134-
135-
Now let’s call your first Square API.
136-
137-
```java
138-
import java.util.List;
139-
import java.io.IOException;
140-
141-
import com.squareup.square.Environment;
142-
import com.squareup.square.SquareClient;
143-
import com.squareup.square.exceptions.ApiException;
144-
import com.squareup.square.http.client.HttpContext;
145-
import com.squareup.square.api.LocationsApi;
146-
import com.squareup.square.models.Location;
147-
import com.squareup.square.models.Error;
148-
149-
public class Example {
150-
public static void main(String[] args) {
151-
SquareClient client = new SquareClient.Builder()
152-
.environment(Environment.SANDBOX)
153-
.accessToken("YOUR_SANDBOX_ACCESS_TOKEN")
154-
.build();
155-
156-
LocationsApi api = client.getLocationsApi();
157-
158-
try {
159-
List<Location> locations = api.listLocations().getLocations();
160-
// Your business logic code
161-
System.out.println("calling listLocations successfully");
162-
} catch (ApiException e) {
163-
List<Error> errors = e.getErrors();
164-
int statusCode = e.getResponseCode();
165-
HttpContext httpContext = e.getHttpContext();
166-
167-
// Your error handling code
168-
System.err.println("ApiException when calling API");
169-
e.printStackTrace();
170-
}
171-
catch (IOException e) {
172-
// Your error handling code
173-
System.err.println("IOException when calling API");
174-
e.printStackTrace();
175-
}
176-
}
177-
}
178-
```
179-
180-
Next, get an access token and reference it in your code:
181-
182-
1. Open the Developer Dashboard and select your application. The **Credentials** page for your app opens by default.
183-
1. Set the dashboard mode to **Sandbox Settings** for a sandbox access token.
184-
1. Copy the Access Token in the Credentials section of the page and replace `YOUR_SANDBOX_ACCESS_TOKEN` with the token.
185-
186-
**Important** When you eventually switch from trying things out on sandbox to actually working with your real production resources, you should not embed the access token in your code. Make sure you store and access your production access tokens securely.
187-
188-
## SDK patterns
189-
If you know a few patterns, you’ll be able to call any API in the SDK. Here are some important ones:
190-
191-
### Get an access token
192-
193-
To use the Square API to manage the resources of a Square account (payments, orders, customers, etc.), you need to create an application (or use an existing one) in the Developer Dashboard and get an access token. Access tokens have specific permissions to resources in a specific Square account that can be accessed by a specific application in a specific developer account.
194-
Use an access token that is appropriate for your use case. There are two options:
195-
196-
- To manage the resources for your own Square account, use the **Personal Access Token** for the application created in your Square account.
197-
- To manage resources for other Square accounts, use OAuth to ask owners of the accounts you want to manage so that you can work on their behalf. When you implement OAuth, you ask the Square account holder for permission to manage resources in their account and get an OAuth access token and refresh token for their account. You define the specific resources you want to access as part of the OAuth call.
198-
199-
**Important** For both use cases, make sure you store and access the tokens securely.
200-
201-
### Import and Instantiate the Client Class
202-
203-
To use the Square API, you import the Client class, instantiate a Client object, and initialize it with the appropriate access token. Here’s how:
204-
205-
- Initialize the `SquareClient` with environment set to sandbox:
206-
207-
```java
208-
SquareClient client = new SquareClient.Builder()
209-
.environment(Environment.SANDBOX)
210-
.accessToken("SANDBOX ACCESS TOKEN HERE")
211-
.build();
212-
```
213-
214-
- To access production resources, set environment to production:
215-
216-
```java
217-
SquareClient client = new SquareClient.Builder()
218-
.environment(Environment.PRODUCTION)
219-
.accessToken("ACCESS TOKEN HERE")
220-
.build();
221-
```
222-
223-
- To set a custom environment provide a `customUrl`, and set the environment to `Environment.CUSTOM`:
224-
225-
```java
226-
SquareClient client = new SquareClient.Builder()
227-
.environment(Environment.CUSTOM)
228-
.customUrl("https://your.customdomain.com")
229-
.accessToken("ACCESS TOKEN HERE")
230-
.build();
231-
```
232-
233-
### Get an Instance of an API object and call its methods
234-
235-
Each API is implemented as a class. The Client object instantiates every API class and exposes them as properties so you can easily start using any Square API. You work with an API by calling methods on an instance of an API class. Here’s how:
236-
237-
- Work with an API by calling the methods on the API object. For example, you would call listCustomers to get a list of all customers in the Square account:
238-
239-
```java
240-
CustomersApi api = client.getCustomersApi();
241-
ListCustomersResponse listCustomersRes = api.listCustomers(null, null, null);
242-
```
243-
244-
See the SDK documentation for the list of methods for each API class.
245-
246-
- Pass complex parameters such as create, update, or search as a model. For example, you would pass a model containing the values used to create a new customer using create_customer:
247-
248-
```java
249-
CustomersApi api = client.getCustomersApi();
250-
251-
Address address = new Address.Builder()
252-
.addressLine1("1455 Market St")
253-
.addressLine2("San Francisco, CA 94103")
254-
.build();
255-
256-
// Create a unique key(idempotency) for this creation operation so you don't accidentally
257-
// create the customer multiple times if you need to retry this operation.
258-
// For the purpose of example, we mark it as `unique_idempotency_key`
259-
CreateCustomerRequest createCustomerRequest = new CreateCustomerRequest.Builder()
260-
.idempotencyKey("unique_idempotency_key")
261-
.givenName("John")
262-
.familyName("Smith")
263-
.address(address)
264-
.build();
265-
266-
// Call createCustomer method to create a new customer in this Square account
267-
try {
268-
CreateCustomerResponse response = api.createCustomer(createCustomerRequest);
269-
} catch (ApiException e) {
270-
List<Error> errors = e.getErrors();
271-
int statusCode = e.getResponseCode();
272-
HttpContext httpContext = e.getHttpContext();
273-
274-
// Your error handling code
275-
System.err.println("ApiException when calling API");
276-
e.printStackTrace();
277-
}
278-
279-
```
280-
281-
- Use idempotency for create, update, or other calls that you want to avoid calling twice. To make an idempotent API call, you add the idempotency_key with a unique value in the Hash for the API call’s request.
282-
- Specify a location ID for APIs such as Transactions, Orders, and Checkout that deal with payments. When a payment or order is created in Square, it is always associated with a location.
283-
284-
### Handle the response
285-
286-
If your API call succeeds, Square API returns a response object containing an `HttpContext` that describe both the request and the response. Otherwise, the API throws an `ApiException`:
287-
288-
```java
289-
try {
290-
List<Location> locations = api.listLocations().getLocations();
291-
} catch (ApiException e) {
292-
List<Error> errors = e.getErrors();
293-
int statusCode = e.getResponseCode();
294-
HttpContext httpContext = e.getHttpContext();
295-
296-
// Your error handling code
297-
System.err.println("ApiException when calling API");
298-
e.printStackTrace();
299-
}
300-
```
301-
302-
## Tests
303-
304-
First, clone the repo locally and `cd` into the directory.
305-
306-
```sh
307-
git clone https://github.com/square/square-java-sdk.git
308-
cd square-java-sdk
309-
```
310-
311-
Before running the tests, find a sandbox token in your [Developer Dashboard] and set a `SQUARE_ACCESS_TOKEN` environment variable.
312-
313-
```sh
314-
export SQUARE_ENVIRONMENT=sandbox
315-
export SQUARE_ACCESS_TOKEN="YOUR_SANDBOX_ACCESS_TOKEN"
316-
```
317-
318-
If you are using Maven, run the tests with below command
319-
320-
```sh
321-
mvn test
322-
```
323-
324-
## Learn more
325-
326-
The Square Platform is built on the [Square API]. Square has a number of other SDKs that enable you to securely handle credit card information on both mobile and web so that you can process payments via the Square API.
327-
328-
You can also use the Square API to create applications or services that work with payments, orders, inventory, etc. that have been created and managed in Square’s in-person hardware products (Square Point of Sale and Square Register).
329-
330130

331131
[//]: # "Link anchor definitions"
332132
[Square Logo]: https://docs.connect.squareup.com/images/github/github-square-logo.svg

0 commit comments

Comments
 (0)