You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you are using Maven, run the tests with below command
46
+
47
+
```sh
48
+
mvn test
46
49
```
47
50
48
-
## API documentation
51
+
## SDK Reference
49
52
50
53
### Payments
51
54
*[Payments]
@@ -124,209 +127,6 @@ If you need to use [List settlements](https://developer.squareup.com/reference/s
124
127
125
128
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).
126
129
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.
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 =newSquareClient.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 =newSquareClient.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 =newSquareClient.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:
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 =newAddress.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`
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`:
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).
0 commit comments