55
66The Square Java library provides convenient access to the Square APIs from Java.
77
8+ ## Table of Contents
9+
10+ - [ Requirements] ( #requirements )
11+ - [ Installation] ( #installation )
12+ - [ Usage] ( #usage )
13+ - [ Instantiation] ( #instantiation )
14+ - [ Enums] ( #enums )
15+ - [ Versioning] ( #versioning )
16+ - [ Automatic Pagination] ( #automatic-pagination )
17+ - [ Retries] ( #retries )
18+ - [ Timeouts] ( #timeouts )
19+ - [ Environments] ( #environments )
20+ - [ Base Url] ( #base-url )
21+ - [ Exception Handling] ( #exception-handling )
22+ - [ Webhook Signature Verification] ( #webhook-signature-verification )
23+ - [ Reference] ( #reference )
24+ - [ Legacy Sdk] ( #legacy-sdk )
25+ - [ Advanced] ( #advanced )
26+ - [ Custom Client] ( #custom-client )
27+ - [ Retries] ( #retries )
28+ - [ Timeouts] ( #timeouts )
29+ - [ Custom Headers] ( #custom-headers )
30+ - [ Access Raw Response Data] ( #access-raw-response-data )
31+ - [ Contributing] ( #contributing )
32+
833## Requirements
934
1035Use of the Square Java SDK requires:
@@ -31,7 +56,7 @@ Add the dependency in your `pom.xml` file:
3156<dependency >
3257 <groupId >com.squareup</groupId >
3358 <artifactId >square</artifactId >
34- <version >45.1.0.20251016 </version >
59+ <version >0.0.540 </version >
3560</dependency >
3661```
3762
@@ -278,9 +303,9 @@ When the API returns a non-success status code (4xx or 5xx response), an API exc
278303``` java
279304import com.squareup.square.core.SquareApiException ;
280305
281- try {
306+ try {
282307 client. payments(). create(... );
283- } catch (SquareApiException e) {
308+ } catch (SquareApiException e){
284309 // Do something with the API exception...
285310}
286311```
@@ -336,8 +361,8 @@ Gradle:
336361
337362``` groovy
338363dependencies {
339- implementation 'com.squareup:square:45.1.0.20251016 '
340- implementation 'com.squareup:square-legacy:45.1.0.20251016 '
364+ implementation 'com.squareup:square:0.0.540 '
365+ implementation 'com.squareup:square-legacy:0.0.540 '
341366}
342367```
343368
@@ -347,12 +372,12 @@ Maven:
347372<dependency >
348373 <groupId >com.squareup</groupId >
349374 <artifactId >square</artifactId >
350- <version >45.1.0.20251016 </version >
375+ <version >0.0.540 </version >
351376</dependency >
352377<dependency >
353378 <groupId >com.squareup</groupId >
354379 <artifactId >square-legacy</artifactId >
355- <version >45.1.0.20251016 </version >
380+ <version >0.0.540 </version >
356381</dependency >
357382```
358383
@@ -364,7 +389,7 @@ Maven:
364389
365390### Custom Client
366391
367- This SDK is built to work with any instance of ` OkHttpClient ` . By default, if no client is provided, the SDK will construct one.
392+ This SDK is built to work with any instance of ` OkHttpClient ` . By default, if no client is provided, the SDK will construct one.
368393However, you can pass your own client like so:
369394
370395``` java
@@ -383,7 +408,9 @@ SquareClient client = SquareClient
383408
384409The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
385410as the request is deemed retryable and the number of retry attempts has not grown larger than the configured
386- retry limit (default: 2).
411+ retry limit (default: 2). Before defaulting to exponential backoff, the SDK will first attempt to respect
412+ the ` Retry-After ` header (as either in seconds or as an HTTP date), and then the ` X-RateLimit-Reset ` header
413+ (as a Unix timestamp in epoch seconds); failing both of those, it will fall back to exponential backoff.
387414
388415A request is deemed retryable when any of the following HTTP status codes is returned:
389416
@@ -452,6 +479,19 @@ client.payments().create(
452479);
453480```
454481
482+ ### Access Raw Response Data
483+
484+ The SDK provides access to raw response data, including headers, through the ` withRawResponse() ` method.
485+ The ` withRawResponse() ` method returns a raw client that wraps all responses with ` body() ` and ` headers() ` methods.
486+ (A normal client's ` response ` is identical to a raw client's ` response.body() ` .)
487+
488+ ``` java
489+ CreateHttpResponse response = client. payments(). withRawResponse(). create(... );
490+
491+ System . out. println(response. body());
492+ System . out. println(response. headers(). get(" X-My-Header" ));
493+ ```
494+
455495## Contributing
456496
457497While we value open-source contributions to this SDK, this library is generated programmatically.
0 commit comments