diff --git a/doc/api/apple-pay.md b/doc/api/apple-pay.md index bc8be616..3fcf9d86 100644 --- a/doc/api/apple-pay.md +++ b/doc/api/apple-pay.md @@ -18,8 +18,11 @@ an Apple Pay enabled domain. This endpoint provides an easy way for platform developers to bulk activate Apple Pay on the Web with Square for merchants using their platform. -Note: The SqPaymentForm library is deprecated as of May 13, 2021, and will only receive critical security updates until it is retired on October 31, 2022. -You must migrate your payment form code to the Web Payments SDK to continue using your domain for Apple Pay. For more information on migrating to the Web Payments SDK, see [Migrate to the Web Payments SDK](https://developer.squareup.com/docs/web-payments/migrate). +Note: You will need to host a valid domain verification file on your domain to support Apple Pay. The +current version of this file is always available at https://app.squareup.com/digital-wallets/apple-pay/apple-developer-merchantid-domain-association, +and should be hosted at `.well_known/apple-developer-merchantid-domain-association` on your +domain. This file is subject to change; we strongly recommend checking for updates regularly and avoiding +long-lived caches that might not keep in sync with the correct file version. To learn more about the Web Payments SDK and how to add Apple Pay, see [Take an Apple Pay Payment](https://developer.squareup.com/docs/web-payments/apple-pay). diff --git a/doc/api/invoices.md b/doc/api/invoices.md index 7f638e6d..3bad364e 100644 --- a/doc/api/invoices.md +++ b/doc/api/invoices.md @@ -288,10 +288,10 @@ invoicesApi.getInvoiceAsync(invoiceId).thenAccept(result -> { # Update Invoice -Updates an invoice by modifying fields, clearing fields, or both. For most updates, you can use a sparse -`Invoice` object to add fields or change values and use the `fields_to_clear` field to specify fields to clear. -However, some restrictions apply. For example, you cannot change the `order_id` or `location_id` field and you -must provide the complete `custom_fields` list to update a custom field. Published invoices have additional restrictions. +Updates an invoice. This endpoint supports sparse updates, so you only need +to specify the fields you want to change along with the required `version` field. +Some restrictions apply to updating invoices. For example, you cannot change the +`order_id` or `location_id` field. ```java CompletableFuture updateInvoiceAsync( @@ -321,14 +321,19 @@ UpdateInvoiceRequest body = new UpdateInvoiceRequest.Builder( new InvoicePaymentRequest.Builder() .uid("2da7964f-f3d2-4f43-81e8-5aa220bf3355") .tippingEnabled(false) + .reminders(Arrays.asList( + new InvoicePaymentReminder.Builder() + .build(), + new InvoicePaymentReminder.Builder() + .build(), + new InvoicePaymentReminder.Builder() + .build() + )) .build() )) .build() ) .idempotencyKey("4ee82288-0910-499e-ab4c-5d0071dad1be") -.fieldsToClear(Arrays.asList( - "payments_requests[2da7964f-f3d2-4f43-81e8-5aa220bf3355].reminders" - )) .build(); invoicesApi.updateInvoiceAsync(invoiceId, body).thenAccept(result -> { diff --git a/doc/client.md b/doc/client.md index c18a4445..bdebe964 100644 --- a/doc/client.md +++ b/doc/client.md @@ -5,7 +5,7 @@ The following parameters are configurable for the API Client: | Parameter | Type | Description | | --- | --- | --- | -| `squareVersion` | `String` | Square Connect API versions
*Default*: `"2024-06-04"` | +| `squareVersion` | `String` | Square Connect API versions
*Default*: `"2024-07-17"` | | `customUrl` | `String` | Sets the base URL requests are made to. Defaults to `https://connect.squareup.com`
*Default*: `"https://connect.squareup.com"` | | `environment` | `string` | The API environment.
**Default: `production`** | | `httpClientConfig` | [`Consumer`](http-client-configuration-builder.md) | Set up Http Client Configuration instance. | @@ -19,7 +19,7 @@ The API client can be initialized as follows: SquareClient client = new SquareClient.Builder() .httpClientConfig(configBuilder -> configBuilder .timeout(0)) - .squareVersion("2024-06-04") + .squareVersion("2024-07-17") .bearerAuthCredentials(new BearerAuthModel.Builder( "AccessToken" ) @@ -44,7 +44,7 @@ public class Program { SquareClient client = new SquareClient.Builder() .httpClientConfig(configBuilder -> configBuilder .timeout(0)) - .squareVersion("2024-06-04") + .squareVersion("2024-07-17") .bearerAuthCredentials(new BearerAuthModel.Builder( "AccessToken" ) diff --git a/doc/models/update-invoice-request.md b/doc/models/update-invoice-request.md index 893cc211..14b1a383 100644 --- a/doc/models/update-invoice-request.md +++ b/doc/models/update-invoice-request.md @@ -13,19 +13,17 @@ Describes a `UpdateInvoice` request. | --- | --- | --- | --- | --- | | `Invoice` | [`Invoice`](../../doc/models/invoice.md) | Required | Stores information about an invoice. You use the Invoices API to create and manage
invoices. For more information, see [Invoices API Overview](https://developer.squareup.com/docs/invoices-api/overview). | Invoice getInvoice() | | `IdempotencyKey` | `String` | Optional | A unique string that identifies the `UpdateInvoice` request. If you do not
provide `idempotency_key` (or provide an empty string as the value), the endpoint
treats each request as independent.

For more information, see [Idempotency](https://developer.squareup.com/docs/build-basics/common-api-patterns/idempotency).
**Constraints**: *Maximum Length*: `128` | String getIdempotencyKey() | -| `FieldsToClear` | `List` | Optional | The list of fields to clear.
For examples, see [Update an Invoice](https://developer.squareup.com/docs/invoices-api/update-invoices). | List getFieldsToClear() | +| `FieldsToClear` | `List` | Optional | The list of fields to clear. Although this field is currently supported, we
recommend using null values or the `remove` field when possible. For examples, see
[Update an Invoice](https://developer.squareup.com/docs/invoices-api/update-invoices). | List getFieldsToClear() | ## Example (as JSON) ```json { - "fields_to_clear": [ - "payments_requests[2da7964f-f3d2-4f43-81e8-5aa220bf3355].reminders" - ], "idempotency_key": "4ee82288-0910-499e-ab4c-5d0071dad1be", "invoice": { "payment_requests": [ { + "reminders": null, "tipping_enabled": false, "uid": "2da7964f-f3d2-4f43-81e8-5aa220bf3355" } @@ -47,7 +45,12 @@ Describes a `UpdateInvoice` request. "sublocality": "sublocality6" } } - } + }, + "fields_to_clear": [ + "fields_to_clear1", + "fields_to_clear2", + "fields_to_clear3" + ] } ``` diff --git a/pom.xml b/pom.xml index 47ee194e..579b8a36 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.squareup square - 40.1.0.20240604 + 40.1.1.20240717 jar Square Java client library for the Square API @@ -40,17 +40,17 @@ io.apimatic core-interfaces - [0.3, 0.4) + [0.3.1, 0.4) io.apimatic core - [0.6, 0.7) + [0.6.3, 0.7) io.apimatic okhttp-client-adapter - [0.3, 0.4) + [0.3.1, 0.4) junit diff --git a/src/main/java/com/squareup/square/Configuration.java b/src/main/java/com/squareup/square/Configuration.java index eddc51d4..da821a99 100644 --- a/src/main/java/com/squareup/square/Configuration.java +++ b/src/main/java/com/squareup/square/Configuration.java @@ -70,16 +70,16 @@ public interface Configuration { */ BearerAuthModel getBearerAuthModel(); - /** - * Get base URI by current environment. - * @param server Server for which to get the base URI - * @return Processed base URI - */ - String getBaseUri(Server server); - - /** - * Get base URI by current environment. - * @return Processed base URI - */ - String getBaseUri(); -} + /** + * Get base URI by current environment. + * @param server Server for which to get the base URI + * @return Processed base URI + */ + String getBaseUri(Server server); + + /** + * Get base URI by current environment. + * @return Processed base URI + */ + String getBaseUri(); +} diff --git a/src/main/java/com/squareup/square/Environment.java b/src/main/java/com/squareup/square/Environment.java index dd6d0a8c..eb2a8a0b 100644 --- a/src/main/java/com/squareup/square/Environment.java +++ b/src/main/java/com/squareup/square/Environment.java @@ -40,14 +40,14 @@ public enum Environment { */ @JsonCreator public static Environment constructFromString(String toConvert) throws IOException { - Environment enumValue = fromString(toConvert); - if (enumValue == null) { - throw new IOException("Unable to create enum instance with value: " + toConvert); - } - return enumValue; - } - - /** + Environment enumValue = fromString(toConvert); + if (enumValue == null) { + throw new IOException("Unable to create enum instance with value: " + toConvert); + } + return enumValue; + } + + /** * Returns the enum member associated with the given string value. * @param toConvert String value to get enum member. * @return The enum member against the given string value. diff --git a/src/main/java/com/squareup/square/Server.java b/src/main/java/com/squareup/square/Server.java index 951b6318..825438b7 100644 --- a/src/main/java/com/squareup/square/Server.java +++ b/src/main/java/com/squareup/square/Server.java @@ -32,14 +32,14 @@ public enum Server { */ @JsonCreator public static Server constructFromString(String toConvert) throws IOException { - Server enumValue = fromString(toConvert); - if (enumValue == null) { - throw new IOException("Unable to create enum instance with value: " + toConvert); - } - return enumValue; - } - - /** + Server enumValue = fromString(toConvert); + if (enumValue == null) { + throw new IOException("Unable to create enum instance with value: " + toConvert); + } + return enumValue; + } + + /** * Returns the enum member associated with the given string value. * @param toConvert String value to get enum member. * @return The enum member against the given string value. diff --git a/src/main/java/com/squareup/square/SquareClient.java b/src/main/java/com/squareup/square/SquareClient.java index dcd7e843..b8e4c624 100644 --- a/src/main/java/com/squareup/square/SquareClient.java +++ b/src/main/java/com/squareup/square/SquareClient.java @@ -157,7 +157,7 @@ public final class SquareClient implements SquareClientInterface { private static final CompatibilityFactory compatibilityFactory = new CompatibilityFactoryImpl(); - private static String userAgent = "Square-Java-SDK/40.1.0.20240604 ({api-version}) {engine}/{engine-version} ({os-info}) {detail}"; + private static String userAgent = "Square-Java-SDK/40.1.1.20240717 ({api-version}) {engine}/{engine-version} ({os-info}) {detail}"; /** * Current API environment. @@ -719,27 +719,27 @@ public String getAccessToken() { * @return sdkVersion */ public String getSdkVersion() { - return "40.1.0.20240604"; - } - - /** - * The timeout to use for making HTTP requests. - * @deprecated This method will be removed in a future version. Use - * {@link #getHttpClientConfig()} instead. - * - * @return timeout - */ - @Deprecated - public long timeout() { - return httpClientConfig.getTimeout(); - } - - /** - * Get base URI by current environment. - * @param server Server for which to get the base URI - * @return Processed base URI - */ - public String getBaseUri(Server server) { + return "40.1.1.20240717"; + } + + /** + * The timeout to use for making HTTP requests. + * @deprecated This method will be removed in a future version. Use + * {@link #getHttpClientConfig()} instead. + * + * @return timeout + */ + @Deprecated + public long timeout() { + return httpClientConfig.getTimeout(); + } + + /** + * Get base URI by current environment. + * @param server Server for which to get the base URI + * @return Processed base URI + */ + public String getBaseUri(Server server) { Map> parameters = new HashMap<>(); parameters.put("custom_url", new SimpleEntry(this.customUrl, false)); @@ -753,28 +753,28 @@ public String getBaseUri(Server server) { * @return Processed base URI */ public String getBaseUri() { - return getBaseUri(Server.ENUM_DEFAULT); - } - - - /** - * Get base URI by current environment. - * - * @param server string for which to get the base URI - * @return Processed base URI - */ - public String getBaseUri(String server) { - return getBaseUri(Server.fromString(server)); - } - - - /** - * Base URLs by environment and server aliases. - * @param environment Environment for which to get the base URI - * @param server Server for which to get the base URI - * @return base URL - */ - private static String environmentMapper(Environment environment, Server server) { + return getBaseUri(Server.ENUM_DEFAULT); + } + + + /** + * Get base URI by current environment. + * + * @param server string for which to get the base URI + * @return Processed base URI + */ + public String getBaseUri(String server) { + return getBaseUri(Server.fromString(server)); + } + + + /** + * Base URLs by environment and server aliases. + * @param environment Environment for which to get the base URI + * @param server Server for which to get the base URI + * @return base URL + */ + private static String environmentMapper(Environment environment, Server server) { if (environment.equals(Environment.PRODUCTION)) { if (server.equals(Server.ENUM_DEFAULT)) { return "https://connect.squareup.com"; @@ -832,7 +832,7 @@ public static class Builder { private Environment environment = Environment.PRODUCTION; private String customUrl = "https://connect.squareup.com"; - private String squareVersion = "2024-06-04"; + private String squareVersion = "2024-07-17"; private HttpClient httpClient; private Headers additionalHeaders = new Headers(); private String userAgentDetail = null; @@ -927,54 +927,54 @@ public Builder userAgentDetail(String userAgentDetail) { return this; } - /** - * The timeout to use for making HTTP requests. - * @deprecated This method will be removed in a future version. Use - * {@link #httpClientConfig(Consumer) httpClientConfig} instead. - * @param timeout must be greater then 0. - * @return Builder - */ - @Deprecated - public Builder timeout(long timeout) { - this.httpClientConfigBuilder.timeout(timeout); - return this; - } - - /** - * HttpCallback. - * @param httpCallback Callback to be called before and after the HTTP call. - * @return Builder - */ - public Builder httpCallback(HttpCallback httpCallback) { - this.httpCallback = httpCallback; - return this; - } - - /** - * Setter for the Builder of httpClientConfiguration, takes in an operation to be performed - * on the builder instance of HTTP client configuration. - * - * @param action Consumer for the builder of httpClientConfiguration. - * @return Builder - */ - public Builder httpClientConfig(Consumer action) { - action.accept(httpClientConfigBuilder); - return this; - } - - /** - * Private Setter for the Builder of httpClientConfiguration, takes in an operation to be performed - * on the builder instance of HTTP client configuration. - * - * @param supplier Supplier for the builder of httpClientConfiguration. - * @return Builder - */ - private Builder httpClientConfig(Supplier supplier) { - httpClientConfigBuilder = supplier.get(); - return this; - } - - /** + /** + * The timeout to use for making HTTP requests. + * @deprecated This method will be removed in a future version. Use + * {@link #httpClientConfig(Consumer) httpClientConfig} instead. + * @param timeout must be greater then 0. + * @return Builder + */ + @Deprecated + public Builder timeout(long timeout) { + this.httpClientConfigBuilder.timeout(timeout); + return this; + } + + /** + * HttpCallback. + * @param httpCallback Callback to be called before and after the HTTP call. + * @return Builder + */ + public Builder httpCallback(HttpCallback httpCallback) { + this.httpCallback = httpCallback; + return this; + } + + /** + * Setter for the Builder of httpClientConfiguration, takes in an operation to be performed + * on the builder instance of HTTP client configuration. + * + * @param action Consumer for the builder of httpClientConfiguration. + * @return Builder + */ + public Builder httpClientConfig(Consumer action) { + action.accept(httpClientConfigBuilder); + return this; + } + + /** + * Private Setter for the Builder of httpClientConfiguration, takes in an operation to be performed + * on the builder instance of HTTP client configuration. + * + * @param supplier Supplier for the builder of httpClientConfiguration. + * @return Builder + */ + private Builder httpClientConfig(Supplier supplier) { + httpClientConfigBuilder = supplier.get(); + return this; + } + + /** * Builds a new SquareClient object using the set fields. * @return SquareClient */ diff --git a/src/main/java/com/squareup/square/api/ApplePayApi.java b/src/main/java/com/squareup/square/api/ApplePayApi.java index 8c5ec28c..c54d2204 100644 --- a/src/main/java/com/squareup/square/api/ApplePayApi.java +++ b/src/main/java/com/squareup/square/api/ApplePayApi.java @@ -16,13 +16,14 @@ public interface ApplePayApi { * Activates a domain for use with Apple Pay on the Web and Square. A validation is performed on * this domain by Apple to ensure that it is properly set up as an Apple Pay enabled domain. * This endpoint provides an easy way for platform developers to bulk activate Apple Pay on the - * Web with Square for merchants using their platform. Note: The SqPaymentForm library is - * deprecated as of May 13, 2021, and will only receive critical security updates until it is - * retired on October 31, 2022. You must migrate your payment form code to the Web Payments SDK - * to continue using your domain for Apple Pay. For more information on migrating to the Web - * Payments SDK, see [Migrate to the Web Payments - * SDK](https://developer.squareup.com/docs/web-payments/migrate). To learn more about the Web - * Payments SDK and how to add Apple Pay, see [Take an Apple Pay + * Web with Square for merchants using their platform. Note: You will need to host a valid + * domain verification file on your domain to support Apple Pay. The current version of this + * file is always available at + * https://app.squareup.com/digital-wallets/apple-pay/apple-developer-merchantid-domain-association, + * and should be hosted at `.well_known/apple-developer-merchantid-domain-association` on your + * domain. This file is subject to change; we strongly recommend checking for updates regularly + * and avoiding long-lived caches that might not keep in sync with the correct file version. To + * learn more about the Web Payments SDK and how to add Apple Pay, see [Take an Apple Pay * Payment](https://developer.squareup.com/docs/web-payments/apple-pay). * @param body Required parameter: An object containing the fields to POST for the request. * See the corresponding object definition for field details. @@ -37,13 +38,14 @@ RegisterDomainResponse registerDomain( * Activates a domain for use with Apple Pay on the Web and Square. A validation is performed on * this domain by Apple to ensure that it is properly set up as an Apple Pay enabled domain. * This endpoint provides an easy way for platform developers to bulk activate Apple Pay on the - * Web with Square for merchants using their platform. Note: The SqPaymentForm library is - * deprecated as of May 13, 2021, and will only receive critical security updates until it is - * retired on October 31, 2022. You must migrate your payment form code to the Web Payments SDK - * to continue using your domain for Apple Pay. For more information on migrating to the Web - * Payments SDK, see [Migrate to the Web Payments - * SDK](https://developer.squareup.com/docs/web-payments/migrate). To learn more about the Web - * Payments SDK and how to add Apple Pay, see [Take an Apple Pay + * Web with Square for merchants using their platform. Note: You will need to host a valid + * domain verification file on your domain to support Apple Pay. The current version of this + * file is always available at + * https://app.squareup.com/digital-wallets/apple-pay/apple-developer-merchantid-domain-association, + * and should be hosted at `.well_known/apple-developer-merchantid-domain-association` on your + * domain. This file is subject to change; we strongly recommend checking for updates regularly + * and avoiding long-lived caches that might not keep in sync with the correct file version. To + * learn more about the Web Payments SDK and how to add Apple Pay, see [Take an Apple Pay * Payment](https://developer.squareup.com/docs/web-payments/apple-pay). * @param body Required parameter: An object containing the fields to POST for the request. * See the corresponding object definition for field details. diff --git a/src/main/java/com/squareup/square/api/BaseApi.java b/src/main/java/com/squareup/square/api/BaseApi.java index fdb1119f..0390e893 100644 --- a/src/main/java/com/squareup/square/api/BaseApi.java +++ b/src/main/java/com/squareup/square/api/BaseApi.java @@ -32,20 +32,20 @@ protected BaseApi(GlobalConfiguration globalConfig) { public HttpCallback getHttpCallback() { return (HttpCallback) globalConfig.getHttpCallback(); } - - /** - * Shared instance of the Http client. - * @return The shared instance of the http client - */ - public HttpClient getClientInstance() { - return globalConfig.getHttpClient(); - } - - /** - * Instance of the Global Configuration - * @return The instance of the global configuration - */ - protected GlobalConfiguration getGlobalConfiguration() { - return globalConfig; - } -} + + /** + * Shared instance of the Http client. + * @return The shared instance of the http client + */ + public HttpClient getClientInstance() { + return globalConfig.getHttpClient(); + } + + /** + * Instance of the Global Configuration + * @return The instance of the global configuration + */ + protected GlobalConfiguration getGlobalConfiguration() { + return globalConfig; + } +} diff --git a/src/main/java/com/squareup/square/api/DefaultApplePayApi.java b/src/main/java/com/squareup/square/api/DefaultApplePayApi.java index b968ece7..d3d2f481 100644 --- a/src/main/java/com/squareup/square/api/DefaultApplePayApi.java +++ b/src/main/java/com/squareup/square/api/DefaultApplePayApi.java @@ -32,13 +32,14 @@ public DefaultApplePayApi(GlobalConfiguration globalConfig) { * Activates a domain for use with Apple Pay on the Web and Square. A validation is performed on * this domain by Apple to ensure that it is properly set up as an Apple Pay enabled domain. * This endpoint provides an easy way for platform developers to bulk activate Apple Pay on the - * Web with Square for merchants using their platform. Note: The SqPaymentForm library is - * deprecated as of May 13, 2021, and will only receive critical security updates until it is - * retired on October 31, 2022. You must migrate your payment form code to the Web Payments SDK - * to continue using your domain for Apple Pay. For more information on migrating to the Web - * Payments SDK, see [Migrate to the Web Payments - * SDK](https://developer.squareup.com/docs/web-payments/migrate). To learn more about the Web - * Payments SDK and how to add Apple Pay, see [Take an Apple Pay + * Web with Square for merchants using their platform. Note: You will need to host a valid + * domain verification file on your domain to support Apple Pay. The current version of this + * file is always available at + * https://app.squareup.com/digital-wallets/apple-pay/apple-developer-merchantid-domain-association, + * and should be hosted at `.well_known/apple-developer-merchantid-domain-association` on your + * domain. This file is subject to change; we strongly recommend checking for updates regularly + * and avoiding long-lived caches that might not keep in sync with the correct file version. To + * learn more about the Web Payments SDK and how to add Apple Pay, see [Take an Apple Pay * Payment](https://developer.squareup.com/docs/web-payments/apple-pay). * @param body Required parameter: An object containing the fields to POST for the request. * See the corresponding object definition for field details. @@ -55,13 +56,14 @@ public RegisterDomainResponse registerDomain( * Activates a domain for use with Apple Pay on the Web and Square. A validation is performed on * this domain by Apple to ensure that it is properly set up as an Apple Pay enabled domain. * This endpoint provides an easy way for platform developers to bulk activate Apple Pay on the - * Web with Square for merchants using their platform. Note: The SqPaymentForm library is - * deprecated as of May 13, 2021, and will only receive critical security updates until it is - * retired on October 31, 2022. You must migrate your payment form code to the Web Payments SDK - * to continue using your domain for Apple Pay. For more information on migrating to the Web - * Payments SDK, see [Migrate to the Web Payments - * SDK](https://developer.squareup.com/docs/web-payments/migrate). To learn more about the Web - * Payments SDK and how to add Apple Pay, see [Take an Apple Pay + * Web with Square for merchants using their platform. Note: You will need to host a valid + * domain verification file on your domain to support Apple Pay. The current version of this + * file is always available at + * https://app.squareup.com/digital-wallets/apple-pay/apple-developer-merchantid-domain-association, + * and should be hosted at `.well_known/apple-developer-merchantid-domain-association` on your + * domain. This file is subject to change; we strongly recommend checking for updates regularly + * and avoiding long-lived caches that might not keep in sync with the correct file version. To + * learn more about the Web Payments SDK and how to add Apple Pay, see [Take an Apple Pay * Payment](https://developer.squareup.com/docs/web-payments/apple-pay). * @param body Required parameter: An object containing the fields to POST for the request. * See the corresponding object definition for field details. diff --git a/src/main/java/com/squareup/square/api/DefaultInvoicesApi.java b/src/main/java/com/squareup/square/api/DefaultInvoicesApi.java index cfc3bf3f..59d5d7ae 100644 --- a/src/main/java/com/squareup/square/api/DefaultInvoicesApi.java +++ b/src/main/java/com/squareup/square/api/DefaultInvoicesApi.java @@ -370,12 +370,9 @@ private ApiCall prepareGetInvoiceRequest( } /** - * Updates an invoice by modifying fields, clearing fields, or both. For most updates, you can - * use a sparse `Invoice` object to add fields or change values and use the `fields_to_clear` - * field to specify fields to clear. However, some restrictions apply. For example, you cannot - * change the `order_id` or `location_id` field and you must provide the complete - * `custom_fields` list to update a custom field. Published invoices have additional - * restrictions. + * Updates an invoice. This endpoint supports sparse updates, so you only need to specify the + * fields you want to change along with the required `version` field. Some restrictions apply to + * updating invoices. For example, you cannot change the `order_id` or `location_id` field. * @param invoiceId Required parameter: The ID of the invoice to update. * @param body Required parameter: An object containing the fields to POST for the request. * See the corresponding object definition for field details. @@ -390,12 +387,9 @@ public UpdateInvoiceResponse updateInvoice( } /** - * Updates an invoice by modifying fields, clearing fields, or both. For most updates, you can - * use a sparse `Invoice` object to add fields or change values and use the `fields_to_clear` - * field to specify fields to clear. However, some restrictions apply. For example, you cannot - * change the `order_id` or `location_id` field and you must provide the complete - * `custom_fields` list to update a custom field. Published invoices have additional - * restrictions. + * Updates an invoice. This endpoint supports sparse updates, so you only need to specify the + * fields you want to change along with the required `version` field. Some restrictions apply to + * updating invoices. For example, you cannot change the `order_id` or `location_id` field. * @param invoiceId Required parameter: The ID of the invoice to update. * @param body Required parameter: An object containing the fields to POST for the request. * See the corresponding object definition for field details. diff --git a/src/main/java/com/squareup/square/api/InvoicesApi.java b/src/main/java/com/squareup/square/api/InvoicesApi.java index 54d2f065..3650a512 100644 --- a/src/main/java/com/squareup/square/api/InvoicesApi.java +++ b/src/main/java/com/squareup/square/api/InvoicesApi.java @@ -170,12 +170,9 @@ CompletableFuture getInvoiceAsync( final String invoiceId); /** - * Updates an invoice by modifying fields, clearing fields, or both. For most updates, you can - * use a sparse `Invoice` object to add fields or change values and use the `fields_to_clear` - * field to specify fields to clear. However, some restrictions apply. For example, you cannot - * change the `order_id` or `location_id` field and you must provide the complete - * `custom_fields` list to update a custom field. Published invoices have additional - * restrictions. + * Updates an invoice. This endpoint supports sparse updates, so you only need to specify the + * fields you want to change along with the required `version` field. Some restrictions apply to + * updating invoices. For example, you cannot change the `order_id` or `location_id` field. * @param invoiceId Required parameter: The ID of the invoice to update. * @param body Required parameter: An object containing the fields to POST for the request. * See the corresponding object definition for field details. @@ -188,12 +185,9 @@ UpdateInvoiceResponse updateInvoice( final UpdateInvoiceRequest body) throws ApiException, IOException; /** - * Updates an invoice by modifying fields, clearing fields, or both. For most updates, you can - * use a sparse `Invoice` object to add fields or change values and use the `fields_to_clear` - * field to specify fields to clear. However, some restrictions apply. For example, you cannot - * change the `order_id` or `location_id` field and you must provide the complete - * `custom_fields` list to update a custom field. Published invoices have additional - * restrictions. + * Updates an invoice. This endpoint supports sparse updates, so you only need to specify the + * fields you want to change along with the required `version` field. Some restrictions apply to + * updating invoices. For example, you cannot change the `order_id` or `location_id` field. * @param invoiceId Required parameter: The ID of the invoice to update. * @param body Required parameter: An object containing the fields to POST for the request. * See the corresponding object definition for field details. diff --git a/src/main/java/com/squareup/square/authentication/BearerAuthManager.java b/src/main/java/com/squareup/square/authentication/BearerAuthManager.java index e8faf1fc..95d3d576 100644 --- a/src/main/java/com/squareup/square/authentication/BearerAuthManager.java +++ b/src/main/java/com/squareup/square/authentication/BearerAuthManager.java @@ -21,23 +21,23 @@ public class BearerAuthManager extends HeaderAuth implements BearerAuthCredentia */ public BearerAuthManager(BearerAuthModel authModel) { super(Collections.singletonMap("Authorization", - applyBearerPrefix(authModel.getAccessToken()))); - this.authModel = authModel; - } - - /** - * applies bearer prefix to the access token. - * @param accessToken The actual access token. - * @return The access token with 'Bearer' as prefix. - */ - private static String applyBearerPrefix(String accessToken) { - if (accessToken == null || accessToken == "") { - return null; - } - - return "Bearer " + accessToken; - } - + applyBearerPrefix(authModel.getAccessToken()))); + this.authModel = authModel; + } + + /** + * applies bearer prefix to the access token. + * @param accessToken The actual access token. + * @return The access token with 'Bearer' as prefix. + */ + private static String applyBearerPrefix(String accessToken) { + if (accessToken == null || accessToken == "") { + return null; + } + + return "Bearer " + accessToken; + } + /** * String value for accessToken. * @return accessToken diff --git a/src/main/java/com/squareup/square/exceptions/ApiException.java b/src/main/java/com/squareup/square/exceptions/ApiException.java index b65605a2..f7f8199c 100644 --- a/src/main/java/com/squareup/square/exceptions/ApiException.java +++ b/src/main/java/com/squareup/square/exceptions/ApiException.java @@ -22,63 +22,63 @@ public class ApiException extends CoreApiException { //private fields private Object data; private List errors; - - /** - * Initialization constructor. - * @param reason The reason for throwing exception - */ - public ApiException(String reason) { - super(reason); - // TODO Auto-generated constructor stub - } - - /** - * Initialization constructor. - * @param reason The reason for throwing exception - * @param context The http context of the API exception - */ - public ApiException(String reason, Context context) { - super(reason, context); - try { - // Can throw IOException if input has invalid content type. - JsonNode jsonNode = CoreHelper.getMapper().readTree(context.getResponse().getBody()); - - if (jsonNode.hasNonNull("payment")) { - data = CoreHelper.getMapper().convertValue(jsonNode.get("payment"), Payment.class); - } - if (jsonNode.hasNonNull("errors")) { - errors = Arrays.asList(CoreHelper.getMapper().convertValue( - jsonNode.get("errors"), Error[].class)); - } else { - errors = new ArrayList<>(); - Error.Builder v1ErrorBuilder = new Error.Builder("V1_ERROR", - jsonNode.hasNonNull("type") ? jsonNode.get("type").asText() : null); - if (jsonNode.hasNonNull("message")) { - v1ErrorBuilder.detail(jsonNode.get("message").asText()); - } - errors.add(v1ErrorBuilder.build()); - } - } catch (IOException ioException) { - // Can throw exception while object mapper tries to: - // Deserialize the content as JSON tree. - // Convert results from JSON tree into given value type. - } - } - - /** - * Returns data about the steps that completed successfully before an error was raised. - * This field is currently only populated for the PaymentsApi.createPayment endpoint. - * @return Response from the API call. - */ - public Object getData() { - return data; - } - - /** - * Getter for the list of errors. - * @return A list of errors - */ - public List getErrors() { - return errors; + + /** + * Initialization constructor. + * @param reason The reason for throwing exception + */ + public ApiException(String reason) { + super(reason); + // TODO Auto-generated constructor stub + } + + /** + * Initialization constructor. + * @param reason The reason for throwing exception + * @param context The http context of the API exception + */ + public ApiException(String reason, Context context) { + super(reason, context); + try { + // Can throw IOException if input has invalid content type. + JsonNode jsonNode = CoreHelper.getMapper().readTree(context.getResponse().getBody()); + + if (jsonNode.hasNonNull("payment")) { + data = CoreHelper.getMapper().convertValue(jsonNode.get("payment"), Payment.class); + } + if (jsonNode.hasNonNull("errors")) { + errors = Arrays.asList(CoreHelper.getMapper().convertValue( + jsonNode.get("errors"), Error[].class)); + } else { + errors = new ArrayList<>(); + Error.Builder v1ErrorBuilder = new Error.Builder("V1_ERROR", + jsonNode.hasNonNull("type") ? jsonNode.get("type").asText() : null); + if (jsonNode.hasNonNull("message")) { + v1ErrorBuilder.detail(jsonNode.get("message").asText()); + } + errors.add(v1ErrorBuilder.build()); + } + } catch (IOException ioException) { + // Can throw exception while object mapper tries to: + // Deserialize the content as JSON tree. + // Convert results from JSON tree into given value type. + } } + + /** + * Returns data about the steps that completed successfully before an error was raised. + * This field is currently only populated for the PaymentsApi.createPayment endpoint. + * @return Response from the API call. + */ + public Object getData() { + return data; + } + + /** + * Getter for the list of errors. + * @return A list of errors + */ + public List getErrors() { + return errors; + } } \ No newline at end of file diff --git a/src/main/java/com/squareup/square/http/client/HttpClientConfiguration.java b/src/main/java/com/squareup/square/http/client/HttpClientConfiguration.java index 0e41f0b3..d33e52b2 100644 --- a/src/main/java/com/squareup/square/http/client/HttpClientConfiguration.java +++ b/src/main/java/com/squareup/square/http/client/HttpClientConfiguration.java @@ -110,20 +110,20 @@ public boolean shouldOverrideHttpClientConfigurations() { return configuration.shouldOverrideHttpClientConfigurations(); } - /** - * Returns the ClientConfiguration instance. - * @return ClientConfiguration - */ - public ClientConfiguration getConfiguration() { - return this.configuration; - } - - /** - * Converts this HttpClientConfiguration into string format. - * @return String representation of this class - */ - @Override - public String toString() { + /** + * Returns the ClientConfiguration instance. + * @return ClientConfiguration + */ + public ClientConfiguration getConfiguration() { + return this.configuration; + } + + /** + * Converts this HttpClientConfiguration into string format. + * @return String representation of this class + */ + @Override + public String toString() { return "HttpClientConfiguration [" + "timeout=" + getTimeout() + ", numberOfRetries=" + getNumberOfRetries() + ", backOffFactor=" + getBackOffFactor() + ", retryInterval=" + getRetryInterval() + ", httpStatusCodesToRetry=" @@ -131,17 +131,17 @@ public String toString() { + ", maximumRetryWaitTime=" + getMaximumRetryWaitTime() + ", shouldRetryOnTimeout=" + shouldRetryOnTimeout() + ", httpClientInstance=" + getHttpClientInstance() + ", overrideHttpClientConfigurations=" + shouldOverrideHttpClientConfigurations() - + "]"; - } - - /** - * Builds a new {@link HttpClientConfiguration.Builder} object. Creates the instance with the - * current state. - * - * @return a new {@link HttpClientConfiguration.Builder} object - */ - public Builder newBuilder() { - return new Builder() + + "]"; + } + + /** + * Builds a new {@link HttpClientConfiguration.Builder} object. Creates the instance with the + * current state. + * + * @return a new {@link HttpClientConfiguration.Builder} object + */ + public Builder newBuilder() { + return new Builder() .timeout(getTimeout()) .numberOfRetries(getNumberOfRetries()) .backOffFactor(getBackOffFactor()) diff --git a/src/main/java/com/squareup/square/http/client/HttpContext.java b/src/main/java/com/squareup/square/http/client/HttpContext.java index 2178ba67..82250508 100644 --- a/src/main/java/com/squareup/square/http/client/HttpContext.java +++ b/src/main/java/com/squareup/square/http/client/HttpContext.java @@ -3,47 +3,47 @@ import io.apimatic.coreinterfaces.http.Context; import com.squareup.square.http.request.HttpRequest; -import com.squareup.square.http.response.HttpResponse; - -/** - * Class to wrap the request sent to the server and the response received from the server. - */ -public class HttpContext implements Context { - private HttpRequest request; - private HttpResponse response; - - /** - * Initialization constructor. - * @param request Instance of HttpRequest. - * @param response Instance of HttpResponse. - */ - public HttpContext(HttpRequest request, HttpResponse response) { - this.request = request; - this.response = response; - } - - /** - * Getter for the Http Request. - * @return HttpRequest request. - */ - public HttpRequest getRequest() { - return request; - } - - /** - * Getter for the Http Response. - * @return HttpResponse response. - */ - public HttpResponse getResponse() { - return response; - } - - /** - * Converts this HttpContext into string format. - * @return String representation of this class - */ - @Override - public String toString() { - return "HttpContext [request=" + request + ", response=" + response + "]"; - } +import com.squareup.square.http.response.HttpResponse; + +/** + * Class to wrap the request sent to the server and the response received from the server. + */ +public class HttpContext implements Context { + private HttpRequest request; + private HttpResponse response; + + /** + * Initialization constructor. + * @param request Instance of HttpRequest. + * @param response Instance of HttpResponse. + */ + public HttpContext(HttpRequest request, HttpResponse response) { + this.request = request; + this.response = response; + } + + /** + * Getter for the Http Request. + * @return HttpRequest request. + */ + public HttpRequest getRequest() { + return request; + } + + /** + * Getter for the Http Response. + * @return HttpResponse response. + */ + public HttpResponse getResponse() { + return response; + } + + /** + * Converts this HttpContext into string format. + * @return String representation of this class + */ + @Override + public String toString() { + return "HttpContext [request=" + request + ", response=" + response + "]"; + } } \ No newline at end of file diff --git a/src/main/java/com/squareup/square/http/request/HttpBodyRequest.java b/src/main/java/com/squareup/square/http/request/HttpBodyRequest.java index e234c682..241b21a4 100644 --- a/src/main/java/com/squareup/square/http/request/HttpBodyRequest.java +++ b/src/main/java/com/squareup/square/http/request/HttpBodyRequest.java @@ -2,34 +2,34 @@ package com.squareup.square.http.request; import com.squareup.square.http.Headers; -import java.util.Map; - -/** - * HTTP Request with an explicit body. - */ -public class HttpBodyRequest extends HttpRequest { - - /** - * Create a request with explicit body. - * @param method The HTTP method to use. Can be PUT, POST, DELETE and PATCH - * @param queryUrlBuilder The fully qualified absolute http url to create the HTTP Request. - * @param headers The key-value map of all http headers to be sent - * @param queryParams The query parameters in a key-value map - * @param body The object to be sent as body after serialization - */ - public HttpBodyRequest(HttpMethod method, StringBuilder queryUrlBuilder, Headers headers, - Map queryParams, Object body) { - super(method, queryUrlBuilder, headers, queryParams, body); - } - - /** - * Converts this HttpBodyRequest into string format. - * @return String representation of this class - */ - @Override - public String toString() { - return "HttpBodyRequest [httpMethod=" + getHttpMethod() - + ", headers=" + getHeaders() + ", queryUrlBuilder=" + getQueryUrl() - + ", queryParameters=" + getQueryParameters() + ", body=" + getBody() + "]"; - } -} +import java.util.Map; + +/** + * HTTP Request with an explicit body. + */ +public class HttpBodyRequest extends HttpRequest { + + /** + * Create a request with explicit body. + * @param method The HTTP method to use. Can be PUT, POST, DELETE and PATCH + * @param queryUrlBuilder The fully qualified absolute http url to create the HTTP Request. + * @param headers The key-value map of all http headers to be sent + * @param queryParams The query parameters in a key-value map + * @param body The object to be sent as body after serialization + */ + public HttpBodyRequest(HttpMethod method, StringBuilder queryUrlBuilder, Headers headers, + Map queryParams, Object body) { + super(method, queryUrlBuilder, headers, queryParams, body); + } + + /** + * Converts this HttpBodyRequest into string format. + * @return String representation of this class + */ + @Override + public String toString() { + return "HttpBodyRequest [httpMethod=" + getHttpMethod() + + ", headers=" + getHeaders() + ", queryUrlBuilder=" + getQueryUrl() + + ", queryParameters=" + getQueryParameters() + ", body=" + getBody() + "]"; + } +} diff --git a/src/main/java/com/squareup/square/http/response/HttpStringResponse.java b/src/main/java/com/squareup/square/http/response/HttpStringResponse.java index 46f549d4..e8c637c4 100644 --- a/src/main/java/com/squareup/square/http/response/HttpStringResponse.java +++ b/src/main/java/com/squareup/square/http/response/HttpStringResponse.java @@ -2,31 +2,31 @@ package com.squareup.square.http.response; import com.squareup.square.http.Headers; -import java.io.InputStream; - -/** - * Class to hold response body as string. - */ -public class HttpStringResponse extends HttpResponse { - - /** - * Initialization constructor. - * @param code The HTTP status code - * @param headers The HTTP headers read from response - * @param rawBody The raw data returned in the HTTP response - * @param body String response body - */ - public HttpStringResponse(int code, Headers headers, InputStream rawBody, String body) { - super(code, headers, rawBody, body); - } - - /** - * Converts this HttpStringResponse into string format. - * @return String representation of this class - */ - @Override - public String toString() { - return "HttpStringResponse [statusCode=" + getStatusCode() + ", headers=" + getHeaders() - + ", body=" + getBody() + "]"; - } -} +import java.io.InputStream; + +/** + * Class to hold response body as string. + */ +public class HttpStringResponse extends HttpResponse { + + /** + * Initialization constructor. + * @param code The HTTP status code + * @param headers The HTTP headers read from response + * @param rawBody The raw data returned in the HTTP response + * @param body String response body + */ + public HttpStringResponse(int code, Headers headers, InputStream rawBody, String body) { + super(code, headers, rawBody, body); + } + + /** + * Converts this HttpStringResponse into string format. + * @return String representation of this class + */ + @Override + public String toString() { + return "HttpStringResponse [statusCode=" + getStatusCode() + ", headers=" + getHeaders() + + ", body=" + getBody() + "]"; + } +} diff --git a/src/main/java/com/squareup/square/models/UpdateInvoiceRequest.java b/src/main/java/com/squareup/square/models/UpdateInvoiceRequest.java index f9cac477..4ec1f1a4 100644 --- a/src/main/java/com/squareup/square/models/UpdateInvoiceRequest.java +++ b/src/main/java/com/squareup/square/models/UpdateInvoiceRequest.java @@ -91,7 +91,8 @@ public String getIdempotencyKey() { /** * Internal Getter for FieldsToClear. - * The list of fields to clear. For examples, see [Update an + * The list of fields to clear. Although this field is currently supported, we recommend using + * null values or the `remove` field when possible. For examples, see [Update an * Invoice](https://developer.squareup.com/docs/invoices-api/update-invoices). * @return Returns the Internal List of String */ @@ -104,7 +105,8 @@ protected OptionalNullable> internalGetFieldsToClear() { /** * Getter for FieldsToClear. - * The list of fields to clear. For examples, see [Update an + * The list of fields to clear. Although this field is currently supported, we recommend using + * null values or the `remove` field when possible. For examples, see [Update an * Invoice](https://developer.squareup.com/docs/invoices-api/update-invoices). * @return Returns the List of String */ diff --git a/src/main/java/com/squareup/square/utilities/FileWrapper.java b/src/main/java/com/squareup/square/utilities/FileWrapper.java index 5d442ab7..9acfc506 100644 --- a/src/main/java/com/squareup/square/utilities/FileWrapper.java +++ b/src/main/java/com/squareup/square/utilities/FileWrapper.java @@ -8,38 +8,38 @@ /** * Class to wrap file and contentType to be sent as part of a HTTP request. */ -public class FileWrapper implements CoreFileWrapper { - - @JsonInclude(JsonInclude.Include.NON_NULL) - private File file; - @JsonInclude(JsonInclude.Include.NON_NULL) - private String contentType; - - /** - * Initialization constructor. - * @param file File object to be wrapped - * @param contentType content type of file - */ - public FileWrapper(File file, String contentType) { - this.file = file; - this.contentType = contentType; - } - - /** - * Initialization constructor. - * @param file File object to be wrapped - */ - public FileWrapper(File file) { - this.file = file; - } - - /** - * Getter for file. - * @return File instance - */ - public File getFile() { - return file; - } +public class FileWrapper implements CoreFileWrapper { + + @JsonInclude(JsonInclude.Include.NON_NULL) + private File file; + @JsonInclude(JsonInclude.Include.NON_NULL) + private String contentType; + + /** + * Initialization constructor. + * @param file File object to be wrapped + * @param contentType content type of file + */ + public FileWrapper(File file, String contentType) { + this.file = file; + this.contentType = contentType; + } + + /** + * Initialization constructor. + * @param file File object to be wrapped + */ + public FileWrapper(File file) { + this.file = file; + } + + /** + * Getter for file. + * @return File instance + */ + public File getFile() { + return file; + } /** * Getter for content type. diff --git a/src/main/java/com/squareup/square/utilities/JsonObject.java b/src/main/java/com/squareup/square/utilities/JsonObject.java index c11b75be..e2095d48 100644 --- a/src/main/java/com/squareup/square/utilities/JsonObject.java +++ b/src/main/java/com/squareup/square/utilities/JsonObject.java @@ -5,44 +5,44 @@ import com.fasterxml.jackson.databind.JsonNode; import com.squareup.square.ApiHelper; import io.apimatic.core.utilities.CoreJsonObject; -import java.io.IOException; - -/** - * This is a wrapper class for JSON object. - */ -public class JsonObject extends CoreJsonObject { - - /** - * Initialization private constructor. - * @param jsonNode The JSON of type JsonNode. - */ - @JsonCreator - private JsonObject(JsonNode jsonNode) { - super(jsonNode); - } - - /** - * Initializes JsonObject with provided JSON. - * @param jsonString The JSON string. - * @return The JsonObject instance. - * @throws IOException signals that provided JSON string does not contain a valid JSON object. - */ - public static JsonObject fromJsonString(String jsonString) throws IOException { - if (jsonString == null) { - return new JsonObject(null); - } - JsonNode node = ApiHelper.getMapper().readTree(jsonString); - if (node.isObject()) { - return new JsonObject(node); - } - throw new IOException("Provided JSON string must contain a valid JSON object."); - } - - /** - * Converts the JSON into string. - * @return String representation of JSON - */ - public String toString() { - return super.toString(); - } +import java.io.IOException; + +/** + * This is a wrapper class for JSON object. + */ +public class JsonObject extends CoreJsonObject { + + /** + * Initialization private constructor. + * @param jsonNode The JSON of type JsonNode. + */ + @JsonCreator + private JsonObject(JsonNode jsonNode) { + super(jsonNode); + } + + /** + * Initializes JsonObject with provided JSON. + * @param jsonString The JSON string. + * @return The JsonObject instance. + * @throws IOException signals that provided JSON string does not contain a valid JSON object. + */ + public static JsonObject fromJsonString(String jsonString) throws IOException { + if (jsonString == null) { + return new JsonObject(null); + } + JsonNode node = ApiHelper.getMapper().readTree(jsonString); + if (node.isObject()) { + return new JsonObject(node); + } + throw new IOException("Provided JSON string must contain a valid JSON object."); + } + + /** + * Converts the JSON into string. + * @return String representation of JSON + */ + public String toString() { + return super.toString(); + } } \ No newline at end of file diff --git a/src/test/java/com/squareup/square/api/BaseApiTest.java b/src/test/java/com/squareup/square/api/BaseApiTest.java index fba9f556..39d138ca 100644 --- a/src/test/java/com/squareup/square/api/BaseApiTest.java +++ b/src/test/java/com/squareup/square/api/BaseApiTest.java @@ -19,40 +19,40 @@ public class BaseApiTest { */ public static final int REQUEST_TIMEOUT = 30; - public static final double ASSERT_PRECISION = 0.01; - - /** - * Global rules for tests. - */ - @Rule - public Timeout globalTimeout = Timeout.seconds(REQUEST_TIMEOUT); - - /** - * Test fixtures, - * Used to serve as HttpCallback and to capture request & response. - */ - - protected static HttpCallbackCatcher httpResponse; - - /** - * Setup test. - */ - @BeforeClass - public static void setUp() throws Exception { - httpResponse = new HttpCallbackCatcher(); - } - - /** - * Tear down test. - */ - @AfterClass - public static void tearDown() throws Exception { - httpResponse = null; - } - - /** - * Create test configuration from Environment variables. - */ + public static final double ASSERT_PRECISION = 0.01; + + /** + * Global rules for tests. + */ + @Rule + public Timeout globalTimeout = Timeout.seconds(REQUEST_TIMEOUT); + + /** + * Test fixtures, + * Used to serve as HttpCallback and to capture request & response. + */ + + protected static HttpCallbackCatcher httpResponse; + + /** + * Setup test. + */ + @BeforeClass + public static void setUp() throws Exception { + httpResponse = new HttpCallbackCatcher(); + } + + /** + * Tear down test. + */ + @AfterClass + public static void tearDown() throws Exception { + httpResponse = null; + } + + /** + * Create test configuration from Environment variables. + */ protected static SquareClient createConfigurationFromEnvironment() { SquareClient.Builder builder = new SquareClient.Builder(); diff --git a/src/test/java/com/squareup/square/testing/HttpCallbackCatcher.java b/src/test/java/com/squareup/square/testing/HttpCallbackCatcher.java index 76b030c7..2b192e46 100644 --- a/src/test/java/com/squareup/square/testing/HttpCallbackCatcher.java +++ b/src/test/java/com/squareup/square/testing/HttpCallbackCatcher.java @@ -5,19 +5,19 @@ import com.squareup.square.http.request.HttpRequest; import com.squareup.square.http.response.HttpResponse; import io.apimatic.coreinterfaces.http.request.Request; -import io.apimatic.coreinterfaces.http.Context; - -/** - * An HTTPCallback that captures the request and response for use later. - */ -public class HttpCallbackCatcher implements HttpCallback { - - private HttpRequest request; - private HttpResponse response; - - /** - * Call back executed before the HTTP request is sent. - */ +import io.apimatic.coreinterfaces.http.Context; + +/** + * An HTTPCallback that captures the request and response for use later. + */ +public class HttpCallbackCatcher implements HttpCallback { + + private HttpRequest request; + private HttpResponse response; + + /** + * Call back executed before the HTTP request is sent. + */ public void onBeforeRequest(Request request) { // Nothing to do here } @@ -26,40 +26,40 @@ public void onBeforeRequest(Request request) { * Call back executed after the HTTP response is received * but before the APICallback's handler is called. */ - public void onAfterResponse(Context context) { - setRequest((HttpRequest) context.getRequest()); - setResponse((HttpResponse) context.getResponse()); - } - - /** - * Get the HTTP Request object associated with this API call. - * @return the HTTP Request - */ - public HttpRequest getRequest() { - return request; - } - - /** - * Set the HTTP Request object associated with this API call. - * @param request the HTTP Request - */ - private void setRequest(HttpRequest prequest) { - this.request = prequest; - } - - /** - * Get the HTTP Response object associated with this API call. - * @return the HTTP Response - */ - public HttpResponse getResponse() { - return response; - } - - /** - * Get the HTTP Response object associated with this API call. - * @param httpResponse the HTTP Response - */ - private void setResponse(HttpResponse httpResponse) { - this.response = httpResponse; - } -} + public void onAfterResponse(Context context) { + setRequest((HttpRequest) context.getRequest()); + setResponse((HttpResponse) context.getResponse()); + } + + /** + * Get the HTTP Request object associated with this API call. + * @return the HTTP Request + */ + public HttpRequest getRequest() { + return request; + } + + /** + * Set the HTTP Request object associated with this API call. + * @param request the HTTP Request + */ + private void setRequest(HttpRequest prequest) { + this.request = prequest; + } + + /** + * Get the HTTP Response object associated with this API call. + * @return the HTTP Response + */ + public HttpResponse getResponse() { + return response; + } + + /** + * Get the HTTP Response object associated with this API call. + * @param httpResponse the HTTP Response + */ + private void setResponse(HttpResponse httpResponse) { + this.response = httpResponse; + } +} diff --git a/src/test/java/com/squareup/square/utilities/WebhooksHelperTest.java b/src/test/java/com/squareup/square/utilities/WebhooksHelperTest.java index 2b94d065..1ba42509 100644 --- a/src/test/java/com/squareup/square/utilities/WebhooksHelperTest.java +++ b/src/test/java/com/squareup/square/utilities/WebhooksHelperTest.java @@ -16,6 +16,17 @@ public void testSignatureValidationPass() { Assert.assertTrue(isAuthentic); } + @Test + public void testSignatureValidationEscapedPass() { + String escpaedRequestBody = "{\"data\":{\"type\":\"webhooks\",\"id\":\">id<\"}}"; + String newSignatureHeader = "Cxt7+aTi4rKgcA0bC4g9EHdVtLSDWdqccmL5MvihU4U="; + String signatureKey = "signature-key"; + String url = "https://webhook.site/webhooks"; + + boolean isAuthentic = WebhooksHelper.isValidWebhookEventSignature(escpaedRequestBody, newSignatureHeader, signatureKey, url); + Assert.assertTrue(isAuthentic); + } + @Test public void testSignatureValidationFailUrlMismatch() { boolean isAuthentic = WebhooksHelper.isValidWebhookEventSignature(REQUEST_BODY, SIGNATURE_HEADER, SIGNATURE_KEY, "https://webhook.site/79a4f3a-dcfa-49ee-bac5-9d0edad886b9");