Skip to content

Commit 7909e58

Browse files
committed
4.0.0.20191217 release
0 parents  commit 7909e58

File tree

897 files changed

+96408
-0
lines changed

Some content is hidden

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

897 files changed

+96408
-0
lines changed

.gitignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
target/
2+
build/
3+
.gradle/
4+
bin/
5+
*.class
6+
*.jar
7+
*.war
8+
*.ear
9+
*.logs
10+
*.iml
11+
.settings/
12+
.classpath
13+
.project
14+
gradle.properties
15+
build.gradle
16+
gradle/wrapper/gradle-wrapper.properties
17+
gradlew
18+
gradlew.bat
19+
settings.gradle

LICENSE

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Copyright 2019 Square, Inc.
2+
Licensed under the Apache License, Version 2.0 (the "License");
3+
you may not use this file except in compliance with the License.
4+
You may obtain a copy of the License at
5+
https://www.apache.org/licenses/LICENSE-2.0
6+
Unless required by applicable law or agreed to in writing, software
7+
distributed under the License is distributed on an "AS IS" BASIS,
8+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
See the License for the specific language governing permissions and
10+
limitations under the License.

README.md

Lines changed: 302 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,302 @@
1+
![Square logo]
2+
3+
# Square Java SDK
4+
5+
[![Travis status](https://travis-ci.org/square/square-java-sdk.svg?branch=master)](https://travis-ci.org/square/square-java-sdk)
6+
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.squareup/square/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.squareup/square)
7+
[![Apache-2 license](https://img.shields.io/badge/license-Apache2-brightgreen.svg)](https://www.apache.org/licenses/LICENSE-2.0)
8+
9+
Use this library to integrate Square payments into your app and grow your business with Square APIs including Catalog, Customers, Employees, Inventory, Labor, Locations, and Orders.
10+
11+
## Requirements
12+
13+
Use of the Square Java SDK requires:
14+
15+
* Java 8 or better
16+
* Maven or Gradle to build and install the SDK.
17+
18+
## Installation
19+
20+
### Install with Maven
21+
22+
Install the API client library to your local Maven repository:
23+
24+
```
25+
mvn install -DskipTests
26+
```
27+
28+
**OR**
29+
30+
Install the client dynamically by adding a dependency to the POM for your project:
31+
32+
```
33+
<dependency>
34+
<groupId>com.squareup</groupId>
35+
<artifactId>square</artifactId>
36+
<version>4.0.0.20191217</version>
37+
</dependency>
38+
```
39+
40+
### Install with Gradle
41+
42+
Install the client by adding the following dependency to the build file for your project:
43+
44+
```
45+
implementation "com.squareup:square:4.0.0.20191217"
46+
```
47+
48+
49+
## API documentation
50+
51+
### Take Payments
52+
53+
* [Payments]
54+
* [Checkout]
55+
56+
### More Square APIs
57+
58+
* [Catalog]
59+
* [Customers]
60+
* [Employees]
61+
* [Inventory]
62+
* [Labor]
63+
* [Locations]
64+
* [Merchants]
65+
* [Orders]
66+
* [Apple Pay]
67+
* [Refunds]
68+
* [Reporting]
69+
70+
### Authorization APIs
71+
72+
* [Mobile Authorization]
73+
* [O Auth]
74+
75+
### Deprecated APIs
76+
77+
* [V1 Locations]
78+
* [V1 Employees]
79+
* [V1 Transactions]
80+
* [V1 Items]
81+
* [Transactions]
82+
83+
## Usage
84+
85+
First time using Square? Here’s how to get started:
86+
87+
1. **Create a Square account.** If you don’t have one already, [sign up for a developer account].
88+
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.
89+
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.
90+
91+
Now let’s call your first Square API.
92+
93+
```java
94+
import java.util.List;
95+
import java.io.IOException;
96+
97+
import com.squareup.square.Environment;
98+
import com.squareup.square.SquareClient;
99+
import com.squareup.square.exceptions.ApiException;
100+
import com.squareup.square.http.client.HttpContext;
101+
import com.squareup.square.api.LocationsApi;
102+
import com.squareup.square.models.Location;
103+
import com.squareup.square.models.Error;
104+
105+
public class Example {
106+
public static void main(String[] args) {
107+
SquareClient client = new SquareClient.Builder()
108+
.environment(Environment.SANDBOX)
109+
.accessToken("YOUR_SANDBOX_ACCESS_TOKEN")
110+
.build();
111+
112+
LocationsApi api = client.getLocationsApi();
113+
114+
try {
115+
List<Location> locations = api.listLocations().getLocations();
116+
// Your business logic code
117+
System.out.println("calling listLocations successfully");
118+
} catch (ApiException e) {
119+
List<Error> errors = e.getErrors();
120+
int statusCode = e.getResponseCode();
121+
HttpContext httpContext = e.getHttpContext();
122+
123+
// Your error handling code
124+
System.err.println("ApiException when calling API");
125+
e.printStackTrace();
126+
}
127+
catch (IOException e) {
128+
// Your error handling code
129+
System.err.println("IOException when calling API");
130+
e.printStackTrace();
131+
}
132+
}
133+
}
134+
```
135+
136+
Next, get an access token and reference it in your code:
137+
138+
1. Open the Developer Dashboard and select your application. The **Credentials** page for your app opens by default.
139+
1. Set the dashboard mode to **Sandbox Settings** for a sandbox access token.
140+
1. Copy the Access Token in the Credentials section of the page and replace `YOUR_SANDBOX_ACCESS_TOKEN` with the token.
141+
142+
**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.
143+
144+
## SDK patterns
145+
If you know a few patterns, you’ll be able to call any API in the SDK. Here are some important ones:
146+
147+
### Get an access token
148+
149+
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.
150+
Use an access token that is appropriate for your use case. There are two options:
151+
152+
- To manage the resources for your own Square account, use the **Personal Access Token** for the application created in your Square account.
153+
- 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.
154+
155+
**Important** For both use cases, make sure you store and access the tokens securely.
156+
157+
### Import and Instantiate the Client Class
158+
159+
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:
160+
161+
- Initialize the `SquareClient` with environment set to sandbox:
162+
163+
```java
164+
SquareClient client = new SquareClient.Builder()
165+
.environment(Environment.SANDBOX)
166+
.accessToken("SANDBOX ACCESS TOKEN HERE")
167+
.build();
168+
```
169+
170+
- To access production resources, set environment to production:
171+
172+
```java
173+
SquareClient client = new SquareClient.Builder()
174+
.environment(Environment.PRODUCTION)
175+
.accessToken("ACCESS TOKEN HERE")
176+
.build();
177+
```
178+
179+
### Get an Instance of an API object and call its methods
180+
181+
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:
182+
183+
- 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:
184+
185+
```java
186+
CustomersApi api = client.getCustomersApi();
187+
ListCustomersResponse listCustomersRes = api.listCustomers(null, null, null);
188+
```
189+
190+
See the SDK documentation for the list of methods for each API class.
191+
192+
- 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:
193+
194+
```java
195+
CustomersApi api = client.getCustomersApi();
196+
197+
Address address = new Address.Builder()
198+
.addressLine1("1455 Market St")
199+
.addressLine2("San Francisco, CA 94103")
200+
.build();
201+
202+
// Create a unique key(idempotency) for this creation operation so you don't accidentally
203+
// create the customer multiple times if you need to retry this operation.
204+
// For the purpose of example, we mark it as `unique_idempotency_key`
205+
CreateCustomerRequest createCustomerRequest = new CreateCustomerRequest.Builder()
206+
.idempotencyKey("unique_idempotency_key")
207+
.givenName("John")
208+
.familyName("Smith")
209+
.address(address)
210+
.build();
211+
212+
// Call createCustomer method to create a new customer in this Square account
213+
try {
214+
CreateCustomerResponse response = api.createCustomer(createCustomerRequest);
215+
} catch (ApiException e) {
216+
List<Error> errors = e.getErrors();
217+
int statusCode = e.getResponseCode();
218+
HttpContext httpContext = e.getHttpContext();
219+
220+
// Your error handling code
221+
System.err.println("ApiException when calling API");
222+
e.printStackTrace();
223+
}
224+
225+
```
226+
227+
- 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.
228+
- 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.
229+
230+
### Handle the response
231+
232+
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`:
233+
234+
```java
235+
try {
236+
List<Location> locations = api.listLocations().getLocations();
237+
} catch (ApiException e) {
238+
List<Error> errors = e.getErrors();
239+
int statusCode = e.getResponseCode();
240+
HttpContext httpContext = e.getHttpContext();
241+
242+
// Your error handling code
243+
System.err.println("ApiException when calling API");
244+
e.printStackTrace();
245+
}
246+
```
247+
248+
## Tests
249+
250+
First, clone the repo locally and `cd` into the directory.
251+
252+
```sh
253+
git clone https://github.com/square/square-java-sdk.git
254+
cd square-java-sdk
255+
```
256+
257+
Before running the tests, find a sandbox token in your [Developer Dashboard] and set a `SQUARE_ACCESS_TOKEN` environment variable.
258+
259+
```sh
260+
export SQUARE_ENVIRONMENT=sandbox
261+
export SQUARE_ACCESS_TOKEN="YOUR_SANDBOX_ACCESS_TOKEN"
262+
```
263+
264+
If you are using Maven, run the tests with below command
265+
266+
```sh
267+
mvn test
268+
```
269+
270+
## Learn more
271+
272+
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.
273+
274+
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).
275+
276+
277+
[//]: # "Link anchor definitions"
278+
[Square Logo]: https://docs.connect.squareup.com/images/github/github-square-logo.svg
279+
[Developer Dashboard]: https://developer.squareup.com/apps
280+
[Square API]: https://squareup.com/developers
281+
[sign up for a developer account]: https://squareup.com/signup?v=developers
282+
[Client]: doc/client.md
283+
[Payments]: doc/payments.md
284+
[Checkout]: doc/checkout.md
285+
[Catalog]: doc/catalog.md
286+
[Customers]: doc/customers.md
287+
[Employees]: doc/employees.md
288+
[Inventory]: doc/inventory.md
289+
[Labor]: doc/labor.md
290+
[Locations]: doc/locations.md
291+
[Merchants]: doc/merchants.md
292+
[Orders]: doc/orders.md
293+
[Apple Pay]: doc/apple-pay.md
294+
[Refunds]: doc/refunds.md
295+
[Reporting]: doc/reporting.md
296+
[Mobile Authorization]: doc/mobile-authorization.md
297+
[O Auth]: doc/o-auth.md
298+
[V1 Locations]: doc/v1-locations.md
299+
[V1 Employees]: doc/v1-employees.md
300+
[V1 Transactions]: doc/v1-transactions.md
301+
[V1 Items]: doc/v1-items.md
302+
[Transactions]: doc/transactions.md

doc/apple-pay.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Apple Pay
2+
3+
```java
4+
ApplePayApi applePayApi = client.getApplePayApi();
5+
```
6+
7+
## Class Name
8+
9+
`ApplePayApi`
10+
11+
## Register Domain
12+
13+
Activates a domain for use with Web Apple Pay and Square. A validation
14+
will be performed on this domain by Apple to ensure is it properly set up as
15+
an Apple Pay enabled domain.
16+
17+
This endpoint provides an easy way for platform developers to bulk activate
18+
Web Apple Pay with Square for merchants using their platform.
19+
20+
To learn more about Apple Pay on Web see the Apple Pay section in the
21+
[Square Payment Form Walkthrough](https://developer.squareup.com/docs/docs/payment-form/payment-form-walkthrough).
22+
23+
```java
24+
CompletableFuture<RegisterDomainResponse> registerDomainAsync(
25+
final RegisterDomainRequest body
26+
)
27+
```
28+
29+
### Parameters
30+
31+
| Parameter | Type | Tags | Description |
32+
| --- | --- | --- | --- |
33+
| `body` | [`RegisterDomainRequest`](/doc/models/register-domain-request.md) | Body, Required | An object containing the fields to POST for the request.<br><br>See the corresponding object definition for field details. |
34+
35+
### Response Type
36+
37+
[`RegisterDomainResponse`](/doc/models/register-domain-response.md)
38+
39+
### Example Usage
40+
41+
```java
42+
RegisterDomainRequest body = new RegisterDomainRequest.Builder(
43+
"example.com")
44+
.build();
45+
46+
applePayApi.registerDomainAsync(body).thenAccept(result -> {
47+
// TODO success callback handler
48+
}).exceptionally(exception -> {
49+
// TODO failure callback handler
50+
return null;
51+
});
52+
```
53+

0 commit comments

Comments
 (0)