From d0f08d3594a380406bc3dbcaf6d7f077538a8616 Mon Sep 17 00:00:00 2001 From: "fern-api[bot]" <115122769+fern-api[bot]@users.noreply.github.com> Date: Fri, 16 Jan 2026 03:05:53 +0000 Subject: [PATCH] SDK regeneration Unable to analyze changes with AI, incrementing PATCH version. --- .fern/metadata.json | 16 - .fernignore | 1 + LICENSE | 2 +- README.md | 53 +- build.gradle | 18 +- changelog.md | 4 + reference.md | 1430 +++-------------- .../squareup/square/AsyncChannelsClient.java | 63 - .../square/AsyncRawApplePayClient.java | 11 +- .../square/AsyncRawBankAccountsClient.java | 52 +- .../square/AsyncRawBookingsClient.java | 119 +- .../squareup/square/AsyncRawCardsClient.java | 42 +- .../square/AsyncRawCatalogClient.java | 110 +- .../square/AsyncRawChannelsClient.java | 244 --- .../square/AsyncRawCheckoutClient.java | 40 +- .../square/AsyncRawCustomersClient.java | 123 +- .../square/AsyncRawDevicesClient.java | 39 +- .../square/AsyncRawDisputesClient.java | 88 +- .../square/AsyncRawEmployeesClient.java | 39 +- .../squareup/square/AsyncRawEventsClient.java | 41 +- .../square/AsyncRawGiftCardsClient.java | 90 +- .../square/AsyncRawInventoryClient.java | 206 +-- .../square/AsyncRawInvoicesClient.java | 129 +- .../squareup/square/AsyncRawLaborClient.java | 115 +- .../square/AsyncRawLocationsClient.java | 53 +- .../square/AsyncRawLoyaltyClient.java | 10 +- .../square/AsyncRawMerchantsClient.java | 39 +- .../squareup/square/AsyncRawMobileClient.java | 10 +- .../squareup/square/AsyncRawOAuthClient.java | 36 +- .../squareup/square/AsyncRawOrdersClient.java | 82 +- .../square/AsyncRawPaymentsClient.java | 90 +- .../square/AsyncRawPayoutsClient.java | 68 +- .../square/AsyncRawRefundsClient.java | 50 +- .../squareup/square/AsyncRawSitesClient.java | 10 +- .../square/AsyncRawSnippetsClient.java | 30 +- .../square/AsyncRawSubscriptionsClient.java | 140 +- .../squareup/square/AsyncRawTeamClient.java | 40 +- .../square/AsyncRawTeamMembersClient.java | 62 +- .../square/AsyncRawTerminalClient.java | 30 +- .../square/AsyncRawTransferOrdersClient.java | 734 --------- .../square/AsyncRawV1TransactionsClient.java | 30 +- .../square/AsyncRawVendorsClient.java | 71 +- .../squareup/square/AsyncSquareClient.java | 14 - .../square/AsyncSquareClientBuilder.java | 177 +- .../square/AsyncTransferOrdersClient.java | 307 ---- .../com/squareup/square/ChannelsClient.java | 61 - .../squareup/square/RawApplePayClient.java | 10 +- .../square/RawBankAccountsClient.java | 33 +- .../squareup/square/RawBookingsClient.java | 109 +- .../com/squareup/square/RawCardsClient.java | 47 +- .../com/squareup/square/RawCatalogClient.java | 96 +- .../squareup/square/RawChannelsClient.java | 191 --- .../squareup/square/RawCheckoutClient.java | 44 +- .../squareup/square/RawCustomersClient.java | 107 +- .../com/squareup/square/RawDevicesClient.java | 26 +- .../squareup/square/RawDisputesClient.java | 75 +- .../squareup/square/RawEmployeesClient.java | 27 +- .../com/squareup/square/RawEventsClient.java | 43 +- .../squareup/square/RawGiftCardsClient.java | 78 +- .../squareup/square/RawInventoryClient.java | 150 +- .../squareup/square/RawInvoicesClient.java | 120 +- .../com/squareup/square/RawLaborClient.java | 111 +- .../squareup/square/RawLocationsClient.java | 52 +- .../com/squareup/square/RawLoyaltyClient.java | 10 +- .../squareup/square/RawMerchantsClient.java | 27 +- .../com/squareup/square/RawMobileClient.java | 10 +- .../com/squareup/square/RawOAuthClient.java | 38 +- .../com/squareup/square/RawOrdersClient.java | 83 +- .../squareup/square/RawPaymentsClient.java | 79 +- .../com/squareup/square/RawPayoutsClient.java | 39 +- .../com/squareup/square/RawRefundsClient.java | 34 +- .../com/squareup/square/RawSitesClient.java | 10 +- .../squareup/square/RawSnippetsClient.java | 32 +- .../square/RawSubscriptionsClient.java | 128 +- .../com/squareup/square/RawTeamClient.java | 41 +- .../squareup/square/RawTeamMembersClient.java | 63 +- .../squareup/square/RawTerminalClient.java | 31 +- .../square/RawTransferOrdersClient.java | 602 ------- .../square/RawV1TransactionsClient.java | 31 +- .../com/squareup/square/RawVendorsClient.java | 73 +- .../com/squareup/square/SquareClient.java | 14 - .../squareup/square/SquareClientBuilder.java | 177 +- .../squareup/square/TransferOrdersClient.java | 299 ---- ...ncRawCustomAttributeDefinitionsClient.java | 52 +- .../AsyncRawCustomAttributesClient.java | 79 +- .../AsyncRawLocationProfilesClient.java | 12 +- .../AsyncRawTeamMemberProfilesClient.java | 22 +- .../RawCustomAttributeDefinitionsClient.java | 53 +- .../bookings/RawCustomAttributesClient.java | 63 +- .../bookings/RawLocationProfilesClient.java | 13 +- .../bookings/RawTeamMemberProfilesClient.java | 23 +- ...kDeleteBookingCustomAttributesRequest.java | 8 +- ...kUpsertBookingCustomAttributesRequest.java | 8 +- .../cashdrawers/AsyncRawShiftsClient.java | 51 +- .../square/cashdrawers/RawShiftsClient.java | 36 +- .../square/catalog/AsyncImagesClient.java | 23 - .../square/catalog/AsyncRawImagesClient.java | 226 +-- .../square/catalog/AsyncRawObjectClient.java | 31 +- .../squareup/square/catalog/ImagesClient.java | 21 - .../square/catalog/RawImagesClient.java | 169 +- .../square/catalog/RawObjectClient.java | 30 +- .../checkout/AsyncRawPaymentLinksClient.java | 72 +- .../checkout/RawPaymentLinksClient.java | 53 +- .../square/core/AsyncCustomPager.java | 164 -- .../com/squareup/square/core/BasePage.java | 16 +- .../square/core/BiDirectionalPage.java | 60 - .../squareup/square/core/ClientOptions.java | 30 +- .../com/squareup/square/core/CustomPager.java | 117 -- .../square/core/NullableNonemptyFilter.java | 5 +- .../squareup/square/core/ObjectMappers.java | 9 - .../squareup/square/core/RequestOptions.java | 2 +- .../square/core/RetryInterceptor.java | 118 +- .../java/com/squareup/square/core/Stream.java | 82 +- .../com/squareup/square/core/SyncPage.java | 4 +- .../square/core/SyncPagingIterable.java | 10 +- .../square/customers/AsyncRawCardsClient.java | 20 +- ...ncRawCustomAttributeDefinitionsClient.java | 62 +- .../AsyncRawCustomAttributesClient.java | 59 +- .../customers/AsyncRawGroupsClient.java | 90 +- .../customers/AsyncRawSegmentsClient.java | 39 +- .../square/customers/RawCardsClient.java | 20 +- .../RawCustomAttributeDefinitionsClient.java | 63 +- .../customers/RawCustomAttributesClient.java | 43 +- .../square/customers/RawGroupsClient.java | 74 +- .../square/customers/RawSegmentsClient.java | 23 +- ...UpsertCustomerCustomAttributesRequest.java | 8 +- .../square/devices/AsyncRawCodesClient.java | 52 +- .../square/devices/RawCodesClient.java | 34 +- .../disputes/AsyncRawEvidenceClient.java | 49 +- .../square/disputes/RawEvidenceClient.java | 33 +- .../giftcards/AsyncRawActivitiesClient.java | 39 +- .../square/giftcards/RawActivitiesClient.java | 26 +- .../labor/AsyncRawBreakTypesClient.java | 74 +- .../labor/AsyncRawEmployeeWagesClient.java | 40 +- .../square/labor/AsyncRawShiftsClient.java | 50 +- .../labor/AsyncRawTeamMemberWagesClient.java | 39 +- .../labor/AsyncRawWorkweekConfigsClient.java | 39 +- .../square/labor/RawBreakTypesClient.java | 57 +- .../square/labor/RawEmployeeWagesClient.java | 23 +- .../square/labor/RawShiftsClient.java | 54 +- .../labor/RawTeamMemberWagesClient.java | 23 +- .../labor/RawWorkweekConfigsClient.java | 23 +- ...ncRawCustomAttributeDefinitionsClient.java | 52 +- .../AsyncRawCustomAttributesClient.java | 79 +- .../locations/AsyncRawTransactionsClient.java | 43 +- .../RawCustomAttributeDefinitionsClient.java | 53 +- .../locations/RawCustomAttributesClient.java | 63 +- .../locations/RawTransactionsClient.java | 40 +- ...DeleteLocationCustomAttributesRequest.java | 8 +- ...UpsertLocationCustomAttributesRequest.java | 8 +- .../loyalty/AsyncRawAccountsClient.java | 50 +- .../loyalty/AsyncRawProgramsClient.java | 30 +- .../square/loyalty/AsyncRawRewardsClient.java | 51 +- .../square/loyalty/RawAccountsClient.java | 51 +- .../square/loyalty/RawProgramsClient.java | 31 +- .../square/loyalty/RawRewardsClient.java | 50 +- .../programs/AsyncRawPromotionsClient.java | 59 +- .../loyalty/programs/RawPromotionsClient.java | 45 +- ...ncRawCustomAttributeDefinitionsClient.java | 52 +- .../AsyncRawCustomAttributesClient.java | 79 +- .../RawCustomAttributeDefinitionsClient.java | 53 +- .../merchants/RawCustomAttributesClient.java | 63 +- ...DeleteMerchantCustomAttributesRequest.java | 8 +- ...UpsertMerchantCustomAttributesRequest.java | 8 +- ...ncRawCustomAttributeDefinitionsClient.java | 52 +- .../AsyncRawCustomAttributesClient.java | 79 +- .../RawCustomAttributeDefinitionsClient.java | 53 +- .../orders/RawCustomAttributesClient.java | 63 +- ...ulkDeleteOrderCustomAttributesRequest.java | 8 +- ...ulkUpsertOrderCustomAttributesRequest.java | 8 +- .../AsyncRawWageSettingClient.java | 21 +- .../teammembers/RawWageSettingClient.java | 20 +- .../terminal/AsyncRawActionsClient.java | 40 +- .../terminal/AsyncRawCheckoutsClient.java | 40 +- .../terminal/AsyncRawRefundsClient.java | 40 +- .../square/terminal/RawActionsClient.java | 40 +- .../square/terminal/RawCheckoutsClient.java | 43 +- .../square/terminal/RawRefundsClient.java | 40 +- .../types/BatchCreateTeamMembersRequest.java | 8 +- .../types/BatchCreateVendorsRequest.java | 8 +- .../BatchDeleteCatalogObjectsRequest.java | 8 +- .../types/BatchGetCatalogObjectsRequest.java | 8 +- .../square/types/BatchGetOrdersRequest.java | 8 +- .../types/BatchUpdateTeamMembersRequest.java | 8 +- .../types/BatchUpdateVendorsRequest.java | 8 +- .../BatchUpsertCatalogObjectsRequest.java | 8 +- .../types/BulkCreateCustomersRequest.java | 8 +- .../types/BulkDeleteCustomersRequest.java | 8 +- ...eleteLocationCustomAttributesResponse.java | 8 +- ...eleteMerchantCustomAttributesResponse.java | 8 +- ...lkDeleteOrderCustomAttributesResponse.java | 8 +- .../BulkPublishScheduledShiftsRequest.java | 8 +- .../types/BulkRetrieveBookingsRequest.java | 8 +- .../types/BulkRetrieveChannelsRequest.java | 106 -- .../types/BulkRetrieveChannelsResponse.java | 139 -- .../types/BulkRetrieveCustomersRequest.java | 8 +- ...rieveTeamMemberBookingProfilesRequest.java | 8 +- .../types/BulkUpdateCustomersRequest.java | 8 +- ...lkUpsertOrderCustomAttributesResponse.java | 8 +- .../types/CancelTransferOrderRequest.java | 199 --- .../types/CancelTransferOrderResponse.java | 133 -- .../square/types/CardPaymentDetails.java | 289 +++- .../CatalogCustomAttributeDefinition.java | 8 +- .../square/types/CatalogObjectBatch.java | 8 +- .../CatalogQueryItemsForModifierList.java | 8 +- .../square/types/CatalogQueryItemsForTax.java | 8 +- .../square/types/CatalogQuerySet.java | 8 +- .../square/types/CatalogQueryText.java | 8 +- .../CatalogSubscriptionPlanVariation.java | 8 +- .../com/squareup/square/types/Channel.java | 351 ---- .../squareup/square/types/ChannelStatus.java | 83 - .../types/CreateSubscriptionRequest.java | 8 +- .../square/types/CreateTransferOrderData.java | 535 ------ .../types/CreateTransferOrderLineData.java | 171 -- .../types/CreateTransferOrderRequest.java | 151 -- .../types/CreateTransferOrderResponse.java | 133 -- .../types/DeleteTransferOrderResponse.java | 102 -- .../types/DeleteTransferOrdersRequest.java | 187 --- .../square/types/DeviceAttributes.java | 12 +- .../types/DeviceAttributesDeviceType.java | 86 - ...DeviceComponentDetailsEthernetDetails.java | 61 +- .../DeviceComponentDetailsMeasurement.java | 6 - .../DeviceComponentDetailsWiFiDetails.java | 57 +- .../squareup/square/types/DeviceStatus.java | 6 +- .../square/types/GetChannelsRequest.java | 113 -- .../types/GetTransferOrdersRequest.java | 113 -- .../squareup/square/types/InvoiceFilter.java | 8 +- .../square/types/ListChannelsRequest.java | 328 ---- .../square/types/ListChannelsResponse.java | 162 -- ...derCustomAttributeDefinitionsResponse.java | 8 +- .../squareup/square/types/LoyaltyAccount.java | 35 +- .../types/LoyaltyEventLocationFilter.java | 8 +- .../square/types/LoyaltyEventTypeFilter.java | 8 +- .../LoyaltyPromotionAvailableTimeData.java | 8 +- .../com/squareup/square/types/Payment.java | 6 +- .../types/ReceiveTransferOrderRequest.java | 231 --- .../types/ReceiveTransferOrderResponse.java | 133 -- .../com/squareup/square/types/Reference.java | 131 -- .../squareup/square/types/ReferenceType.java | 218 --- .../square/types/RetrieveChannelResponse.java | 131 -- .../types/RetrieveTransferOrderResponse.java | 133 -- .../square/types/SearchOrdersStateFilter.java | 8 +- .../types/SearchTransferOrdersRequest.java | 161 -- .../types/SearchTransferOrdersResponse.java | 164 -- .../squareup/square/types/SelectOptions.java | 8 +- .../types/StartTransferOrderRequest.java | 199 --- .../types/StartTransferOrderResponse.java | 133 -- .../squareup/square/types/Subscription.java | 56 +- .../square/types/SubscriptionActionType.java | 10 - .../square/types/SubscriptionStatus.java | 10 - .../squareup/square/types/TransferOrder.java | 714 -------- .../types/TransferOrderCreatedEvent.java | 286 ---- .../types/TransferOrderCreatedEventData.java | 184 --- .../TransferOrderCreatedEventObject.java | 102 -- .../types/TransferOrderDeletedEvent.java | 286 ---- .../types/TransferOrderDeletedEventData.java | 204 --- .../square/types/TransferOrderFilter.java | 229 --- .../types/TransferOrderGoodsReceipt.java | 152 -- .../TransferOrderGoodsReceiptLineItem.java | 343 ---- .../square/types/TransferOrderLine.java | 410 ----- .../square/types/TransferOrderQuery.java | 132 -- .../square/types/TransferOrderSort.java | 136 -- .../square/types/TransferOrderSortField.java | 84 - .../square/types/TransferOrderStatus.java | 114 -- .../types/TransferOrderUpdatedEvent.java | 286 ---- .../types/TransferOrderUpdatedEventData.java | 184 --- .../TransferOrderUpdatedEventObject.java | 102 -- .../types/UpdateItemModifierListsRequest.java | 8 +- .../square/types/UpdateItemTaxesRequest.java | 8 +- .../square/types/UpdateTransferOrderData.java | 394 ----- .../types/UpdateTransferOrderLineData.java | 278 ---- .../types/UpdateTransferOrderRequest.java | 232 --- .../types/UpdateTransferOrderResponse.java | 133 -- .../webhooks/AsyncRawEventTypesClient.java | 10 +- .../webhooks/AsyncRawSubscriptionsClient.java | 89 +- .../square/webhooks/RawEventTypesClient.java | 10 +- .../webhooks/RawSubscriptionsClient.java | 77 +- 277 files changed, 5083 insertions(+), 18350 deletions(-) delete mode 100644 .fern/metadata.json create mode 100644 changelog.md delete mode 100644 src/main/java/com/squareup/square/AsyncChannelsClient.java delete mode 100644 src/main/java/com/squareup/square/AsyncRawChannelsClient.java delete mode 100644 src/main/java/com/squareup/square/AsyncRawTransferOrdersClient.java delete mode 100644 src/main/java/com/squareup/square/AsyncTransferOrdersClient.java delete mode 100644 src/main/java/com/squareup/square/ChannelsClient.java delete mode 100644 src/main/java/com/squareup/square/RawChannelsClient.java delete mode 100644 src/main/java/com/squareup/square/RawTransferOrdersClient.java delete mode 100644 src/main/java/com/squareup/square/TransferOrdersClient.java delete mode 100644 src/main/java/com/squareup/square/core/AsyncCustomPager.java delete mode 100644 src/main/java/com/squareup/square/core/BiDirectionalPage.java delete mode 100644 src/main/java/com/squareup/square/core/CustomPager.java delete mode 100644 src/main/java/com/squareup/square/types/BulkRetrieveChannelsRequest.java delete mode 100644 src/main/java/com/squareup/square/types/BulkRetrieveChannelsResponse.java delete mode 100644 src/main/java/com/squareup/square/types/CancelTransferOrderRequest.java delete mode 100644 src/main/java/com/squareup/square/types/CancelTransferOrderResponse.java delete mode 100644 src/main/java/com/squareup/square/types/Channel.java delete mode 100644 src/main/java/com/squareup/square/types/ChannelStatus.java delete mode 100644 src/main/java/com/squareup/square/types/CreateTransferOrderData.java delete mode 100644 src/main/java/com/squareup/square/types/CreateTransferOrderLineData.java delete mode 100644 src/main/java/com/squareup/square/types/CreateTransferOrderRequest.java delete mode 100644 src/main/java/com/squareup/square/types/CreateTransferOrderResponse.java delete mode 100644 src/main/java/com/squareup/square/types/DeleteTransferOrderResponse.java delete mode 100644 src/main/java/com/squareup/square/types/DeleteTransferOrdersRequest.java delete mode 100644 src/main/java/com/squareup/square/types/DeviceAttributesDeviceType.java delete mode 100644 src/main/java/com/squareup/square/types/GetChannelsRequest.java delete mode 100644 src/main/java/com/squareup/square/types/GetTransferOrdersRequest.java delete mode 100644 src/main/java/com/squareup/square/types/ListChannelsRequest.java delete mode 100644 src/main/java/com/squareup/square/types/ListChannelsResponse.java delete mode 100644 src/main/java/com/squareup/square/types/ReceiveTransferOrderRequest.java delete mode 100644 src/main/java/com/squareup/square/types/ReceiveTransferOrderResponse.java delete mode 100644 src/main/java/com/squareup/square/types/Reference.java delete mode 100644 src/main/java/com/squareup/square/types/ReferenceType.java delete mode 100644 src/main/java/com/squareup/square/types/RetrieveChannelResponse.java delete mode 100644 src/main/java/com/squareup/square/types/RetrieveTransferOrderResponse.java delete mode 100644 src/main/java/com/squareup/square/types/SearchTransferOrdersRequest.java delete mode 100644 src/main/java/com/squareup/square/types/SearchTransferOrdersResponse.java delete mode 100644 src/main/java/com/squareup/square/types/StartTransferOrderRequest.java delete mode 100644 src/main/java/com/squareup/square/types/StartTransferOrderResponse.java delete mode 100644 src/main/java/com/squareup/square/types/TransferOrder.java delete mode 100644 src/main/java/com/squareup/square/types/TransferOrderCreatedEvent.java delete mode 100644 src/main/java/com/squareup/square/types/TransferOrderCreatedEventData.java delete mode 100644 src/main/java/com/squareup/square/types/TransferOrderCreatedEventObject.java delete mode 100644 src/main/java/com/squareup/square/types/TransferOrderDeletedEvent.java delete mode 100644 src/main/java/com/squareup/square/types/TransferOrderDeletedEventData.java delete mode 100644 src/main/java/com/squareup/square/types/TransferOrderFilter.java delete mode 100644 src/main/java/com/squareup/square/types/TransferOrderGoodsReceipt.java delete mode 100644 src/main/java/com/squareup/square/types/TransferOrderGoodsReceiptLineItem.java delete mode 100644 src/main/java/com/squareup/square/types/TransferOrderLine.java delete mode 100644 src/main/java/com/squareup/square/types/TransferOrderQuery.java delete mode 100644 src/main/java/com/squareup/square/types/TransferOrderSort.java delete mode 100644 src/main/java/com/squareup/square/types/TransferOrderSortField.java delete mode 100644 src/main/java/com/squareup/square/types/TransferOrderStatus.java delete mode 100644 src/main/java/com/squareup/square/types/TransferOrderUpdatedEvent.java delete mode 100644 src/main/java/com/squareup/square/types/TransferOrderUpdatedEventData.java delete mode 100644 src/main/java/com/squareup/square/types/TransferOrderUpdatedEventObject.java delete mode 100644 src/main/java/com/squareup/square/types/UpdateTransferOrderData.java delete mode 100644 src/main/java/com/squareup/square/types/UpdateTransferOrderLineData.java delete mode 100644 src/main/java/com/squareup/square/types/UpdateTransferOrderRequest.java delete mode 100644 src/main/java/com/squareup/square/types/UpdateTransferOrderResponse.java diff --git a/.fern/metadata.json b/.fern/metadata.json deleted file mode 100644 index 22890ea6..00000000 --- a/.fern/metadata.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "cliVersion": "2.8.1", - "generatorName": "fernapi/fern-java-sdk", - "generatorVersion": "3.19.0", - "generatorConfig": { - "base-api-exception-class-name": "SquareApiException", - "base-exception-class-name": "SquareException", - "client-class-name": "SquareClient", - "inline-path-parameters": true, - "inline-file-properties": true, - "package-prefix": "com.squareup.square", - "package-layout": "flat", - "enable-forward-compatible-enums": true, - "publish-to": "central" - } -} \ No newline at end of file diff --git a/.fernignore b/.fernignore index 0dce8ae6..71d25ccb 100644 --- a/.fernignore +++ b/.fernignore @@ -6,3 +6,4 @@ src/main/java/com/squareup/square/core/SquareApiException.java src/main/java/com/squareup/square/utilities/WebhooksHelper.java src/test/resources/testdata .github/workflows/ci.yml +changelog.md diff --git a/LICENSE b/LICENSE index f5669d1d..878ffc14 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2025 Square. +Copyright (c) 2026 Square. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 39371ac7..94db2591 100644 --- a/README.md +++ b/README.md @@ -26,8 +26,6 @@ The Square Java library provides convenient access to the Square APIs from Java. - [Custom Client](#custom-client) - [Retries](#retries) - [Timeouts](#timeouts) - - [Custom Headers](#custom-headers) - - [Access Raw Response Data](#access-raw-response-data) - [Contributing](#contributing) ## Requirements @@ -56,7 +54,7 @@ Add the dependency in your `pom.xml` file: com.squareup square - 45.2.0.20251016 + 45.2.1 ``` @@ -303,9 +301,9 @@ When the API returns a non-success status code (4xx or 5xx response), an API exc ```java import com.squareup.square.core.SquareApiException; -try{ +try { client.payments().create(...); -} catch (SquareApiException e){ +} catch (SquareApiException e) { // Do something with the API exception... } ``` @@ -389,7 +387,7 @@ Maven: ### Custom Client -This SDK is built to work with any instance of `OkHttpClient`. By default, if no client is provided, the SDK will construct one. +This SDK is built to work with any instance of `OkHttpClient`. By default, if no client is provided, the SDK will construct one. However, you can pass your own client like so: ```java @@ -408,9 +406,7 @@ SquareClient client = SquareClient The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long as the request is deemed retryable and the number of retry attempts has not grown larger than the configured -retry limit (default: 2). Before defaulting to exponential backoff, the SDK will first attempt to respect -the `Retry-After` header (as either in seconds or as an HTTP date), and then the `X-RateLimit-Reset` header -(as a Unix timestamp in epoch seconds); failing both of those, it will fall back to exponential backoff. +retry limit (default: 2). A request is deemed retryable when any of the following HTTP status codes is returned: @@ -453,45 +449,6 @@ client.payments().create( ); ``` -### Custom Headers - -The SDK allows you to add custom headers to requests. You can configure headers at the client level or at the request level. - -```java -import com.squareup.square.SquareClient; -import com.squareup.square.core.RequestOptions; - -// Client level -SquareClient client = SquareClient - .builder() - .addHeader("X-Custom-Header", "custom-value") - .addHeader("X-Request-Id", "abc-123") - .build(); -; - -// Request level -client.payments().create( - ..., - RequestOptions - .builder() - .addHeader("X-Request-Header", "request-value") - .build() -); -``` - -### Access Raw Response Data - -The SDK provides access to raw response data, including headers, through the `withRawResponse()` method. -The `withRawResponse()` method returns a raw client that wraps all responses with `body()` and `headers()` methods. -(A normal client's `response` is identical to a raw client's `response.body()`.) - -```java -CreateHttpResponse response = client.payments().withRawResponse().create(...); - -System.out.println(response.body()); -System.out.println(response.headers().get("X-My-Header")); -``` - ## Contributing While we value open-source contributions to this SDK, this library is generated programmatically. diff --git a/build.gradle b/build.gradle index f9a4f2c0..31fe999b 100644 --- a/build.gradle +++ b/build.gradle @@ -14,13 +14,12 @@ repositories { } dependencies { - api 'com.squareup.okhttp3:okhttp:5.2.1' - api 'com.fasterxml.jackson.core:jackson-databind:2.18.2' - api 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.18.2' - api 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.18.2' + api 'com.squareup.okhttp3:okhttp:4.12.0' + api 'com.fasterxml.jackson.core:jackson-databind:2.17.2' + api 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.17.2' + api 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.17.2' testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2' testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.8.2' - testImplementation 'org.junit.jupiter:junit-jupiter-params:5.8.2' } @@ -47,7 +46,7 @@ java { group = 'com.squareup' -version = '45.2.0.20251016' +version = '45.2.1' jar { dependsOn(":generatePomFileForMavenPublication") @@ -78,7 +77,7 @@ publishing { maven(MavenPublication) { groupId = 'com.squareup' artifactId = 'square' - version = '45.2.0.20251016' + version = '45.2.1' from components.java pom { name = 'square' @@ -121,10 +120,9 @@ sonatypeCentralUpload { } signing { - def signingKeyId = "$System.env.MAVEN_SIGNATURE_KID" - def signingKey = "$System.env.MAVEN_SIGNATURE_SECRET_KEY" + def signingKeyId = "$System.env.MAVEN_SIGNATURE_SECRET_KEY" def signingPassword = "$System.env.MAVEN_SIGNATURE_PASSWORD" - useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword) + useInMemoryPgpKeys(signingKeyId, signingPassword) sign publishing.publications.maven } diff --git a/changelog.md b/changelog.md new file mode 100644 index 00000000..ca5cd1ed --- /dev/null +++ b/changelog.md @@ -0,0 +1,4 @@ +## 45.2.1 - 2026-01-16 +* SDK regeneration +* Unable to analyze changes with AI, incrementing PATCH version. + diff --git a/reference.md b/reference.md index cad48580..1105700b 100644 --- a/reference.md +++ b/reference.md @@ -474,7 +474,7 @@ client.oAuth().authorize(); ## V1Transactions -
client.v1Transactions.v1ListOrders(locationId) -> List<V1Order> +
client.v1Transactions.v1ListOrders(locationId) -> List&lt;V1Order&gt;
@@ -817,7 +817,7 @@ client.applePay().registerDomain(
## BankAccounts -
client.bankAccounts.list() -> SyncPagingIterable<BankAccount> +
client.bankAccounts.list() -> ListBankAccountsResponse
@@ -1030,7 +1030,7 @@ client.bankAccounts().get(
## Bookings -
client.bookings.list() -> SyncPagingIterable<Booking> +
client.bookings.list() -> ListBookingsResponse
@@ -1340,7 +1340,9 @@ client.bookings().bulkRetrieveBookings( BulkRetrieveBookingsRequest .builder() .bookingIds( - Arrays.asList("booking_ids") + new ArrayList( + Arrays.asList("booking_ids") + ) ) .build() ); @@ -1499,7 +1501,9 @@ client.bookings().bulkRetrieveTeamMemberBookingProfiles( BulkRetrieveTeamMemberBookingProfilesRequest .builder() .teamMemberIds( - Arrays.asList("team_member_ids") + new ArrayList( + Arrays.asList("team_member_ids") + ) ) .build() ); @@ -1759,7 +1763,7 @@ client.bookings().cancel(
## Cards -
client.cards.list() -> SyncPagingIterable<Card> +
client.cards.list() -> ListCardsResponse
@@ -2149,7 +2153,9 @@ client.catalog().batchDelete( BatchDeleteCatalogObjectsRequest .builder() .objectIds( - Arrays.asList("W62UWFY35CWMYGVWK6TWJDNI", "AA27W3M2GGTF3H6AVPNB77CK") + new ArrayList( + Arrays.asList("W62UWFY35CWMYGVWK6TWJDNI", "AA27W3M2GGTF3H6AVPNB77CK") + ) ) .build() ); @@ -2219,7 +2225,9 @@ client.catalog().batchGet( BatchGetCatalogObjectsRequest .builder() .objectIds( - Arrays.asList("W62UWFY35CWMYGVWK6TWJDNI", "AA27W3M2GGTF3H6AVPNB77CK") + new ArrayList( + Arrays.asList("W62UWFY35CWMYGVWK6TWJDNI", "AA27W3M2GGTF3H6AVPNB77CK") + ) ) .includeRelatedObjects(true) .build() @@ -2269,7 +2277,7 @@ Default value: `false`
-**catalogVersion:** `Optional` +**catalogVersion:** `Optional` The specific version of the catalog objects to be included in the response. This allows you to retrieve historical versions of objects. The specified version value is matched against @@ -2351,38 +2359,42 @@ client.catalog().batchUpsert( .builder() .idempotencyKey("789ff020-f723-43a9-b4b5-43b5dc1fa3dc") .batches( - Arrays.asList( - CatalogObjectBatch - .builder() - .objects( - Arrays.asList( - CatalogObject.item( - CatalogObjectItem - .builder() - .id("id") - .build() - ), - CatalogObject.item( - CatalogObjectItem - .builder() - .id("id") - .build() - ), - CatalogObject.item( - CatalogObjectItem - .builder() - .id("id") - .build() - ), - CatalogObject.tax( - CatalogObjectTax - .builder() - .id("id") - .build() + new ArrayList( + Arrays.asList( + CatalogObjectBatch + .builder() + .objects( + new ArrayList( + Arrays.asList( + CatalogObject.item( + CatalogObjectItem + .builder() + .id("id") + .build() + ), + CatalogObject.item( + CatalogObjectItem + .builder() + .id("id") + .build() + ), + CatalogObject.item( + CatalogObjectItem + .builder() + .id("id") + .build() + ), + CatalogObject.tax( + CatalogObjectTax + .builder() + .id("id") + .build() + ) + ) ) ) - ) - .build() + .build() + ) ) ) .build() @@ -2493,7 +2505,7 @@ client.catalog().info();
-
client.catalog.list() -> SyncPagingIterable<CatalogObject> +
client.catalog.list() -> ListCatalogResponse
@@ -2584,7 +2596,7 @@ SUBSCRIPTION_PLAN, ITEM_OPTION, CUSTOM_ATTRIBUTE_DEFINITION, QUICK_AMOUNT_SETTIN
-**catalogVersion:** `Optional` +**catalogVersion:** `Optional` The specific version of the catalog objects to be included in the response. This allows you to retrieve historical versions of objects. The specified version value is matched against @@ -2641,7 +2653,7 @@ client.catalog().search( SearchCatalogObjectsRequest .builder() .objectTypes( - Optional.of( + new ArrayList( Arrays.asList(CatalogObjectType.ITEM) ) ) @@ -2824,29 +2836,29 @@ client.catalog().searchItems( .builder() .textFilter("red") .categoryIds( - Optional.of( + new ArrayList( Arrays.asList("WINE_CATEGORY_ID") ) ) .stockLevels( - Optional.of( + new ArrayList( Arrays.asList(SearchCatalogItemsRequestStockLevel.OUT, SearchCatalogItemsRequestStockLevel.LOW) ) ) .enabledLocationIds( - Optional.of( + new ArrayList( Arrays.asList("ATL_LOCATION_ID") ) ) .limit(100) .sortOrder(SortOrder.ASC) .productTypes( - Optional.of( + new ArrayList( Arrays.asList(CatalogItemProductType.REGULAR) ) ) .customAttributeFilters( - Optional.of( + new ArrayList( Arrays.asList( CustomAttributeFilter .builder() @@ -3023,15 +3035,17 @@ client.catalog().updateItemModifierLists( UpdateItemModifierListsRequest .builder() .itemIds( - Arrays.asList("H42BRLUJ5KTZTTMPVSLFAACQ", "2JXOBJIHCWBQ4NZ3RIXQGJA6") + new ArrayList( + Arrays.asList("H42BRLUJ5KTZTTMPVSLFAACQ", "2JXOBJIHCWBQ4NZ3RIXQGJA6") + ) ) .modifierListsToEnable( - Optional.of( + new ArrayList( Arrays.asList("H42BRLUJ5KTZTTMPVSLFAACQ", "2JXOBJIHCWBQ4NZ3RIXQGJA6") ) ) .modifierListsToDisable( - Optional.of( + new ArrayList( Arrays.asList("7WRC16CJZDVLSNDQ35PP6YAD") ) ) @@ -3118,15 +3132,17 @@ client.catalog().updateItemTaxes( UpdateItemTaxesRequest .builder() .itemIds( - Arrays.asList("H42BRLUJ5KTZTTMPVSLFAACQ", "2JXOBJIHCWBQ4NZ3RIXQGJA6") + new ArrayList( + Arrays.asList("H42BRLUJ5KTZTTMPVSLFAACQ", "2JXOBJIHCWBQ4NZ3RIXQGJA6") + ) ) .taxesToEnable( - Optional.of( + new ArrayList( Arrays.asList("4WRCNHCJZDVLSNDQ35PP6YAD") ) ) .taxesToDisable( - Optional.of( + new ArrayList( Arrays.asList("AQCEGCEBBQONINDOHRGZISEX") ) ) @@ -3179,231 +3195,12 @@ At least one of `taxes_to_enable` or `taxes_to_disable` must be specified.
-
-
-
- -## Channels -
client.channels.list() -> SyncPagingIterable<Channel> -
-
- -#### 📝 Description - -
-
- -
-
- - -
-
-
-
- -#### 🔌 Usage - -
-
- -
-
- -```java -client.channels().list( - ListChannelsRequest - .builder() - .referenceType(ReferenceType.UNKNOWN_TYPE) - .referenceId("reference_id") - .status(ChannelStatus.ACTIVE) - .cursor("cursor") - .limit(1) - .build() -); -``` -
-
-
-
- -#### ⚙️ Parameters - -
-
- -
-
- -**referenceType:** `Optional` — Type of reference associated to channel - -
-
- -
-
- -**referenceId:** `Optional` — id of reference associated to channel - -
-
- -
-
- -**status:** `Optional` — Status of channel - -
-
- -
-
- -**cursor:** `Optional` — Cursor to fetch the next result - -
-
- -
-
- -**limit:** `Optional` - -Maximum number of results to return. -When not provided the returned results will be cap at 100 channels. - -
-
-
-
- - -
-
-
- -
client.channels.bulkRetrieve(request) -> BulkRetrieveChannelsResponse -
-
- -#### 📝 Description - -
-
- -
-
- - -
-
-
-
- -#### 🔌 Usage - -
-
- -
-
- -```java -client.channels().bulkRetrieve( - BulkRetrieveChannelsRequest - .builder() - .channelIds( - Arrays.asList("CH_9C03D0B59", "CH_6X139B5MN", "NOT_EXISTING") - ) - .build() -); -``` -
-
-
-
- -#### ⚙️ Parameters - -
-
- -
-
- -**channelIds:** `List` - -
-
-
-
- - -
-
-
- -
client.channels.get(channelId) -> RetrieveChannelResponse -
-
- -#### 📝 Description - -
-
- -
-
- - -
-
-
-
- -#### 🔌 Usage - -
-
- -
-
- -```java -client.channels().get( - GetChannelsRequest - .builder() - .channelId("channel_id") - .build() -); -``` -
-
-
-
- -#### ⚙️ Parameters - -
-
- -
-
- -**channelId:** `String` — A channel id - -
-
-
-
- -
## Customers -
client.customers.list() -> SyncPagingIterable<Customer> +
client.customers.list() -> ListCustomersResponse
@@ -3897,7 +3694,9 @@ client.customers().bulkDeleteCustomers( BulkDeleteCustomersRequest .builder() .customerIds( - Arrays.asList("8DDA5NZVBZFGAX0V3HPF81HHE0", "N18CPRVXR5214XPBBA6BZQWF3C", "2GYD7WNXF7BJZW1PMGNXZ3Y8M8") + new ArrayList( + Arrays.asList("8DDA5NZVBZFGAX0V3HPF81HHE0", "N18CPRVXR5214XPBBA6BZQWF3C", "2GYD7WNXF7BJZW1PMGNXZ3Y8M8") + ) ) .build() ); @@ -3960,7 +3759,9 @@ client.customers().bulkRetrieveCustomers( BulkRetrieveCustomersRequest .builder() .customerIds( - Arrays.asList("8DDA5NZVBZFGAX0V3HPF81HHE0", "N18CPRVXR5214XPBBA6BZQWF3C", "2GYD7WNXF7BJZW1PMGNXZ3Y8M8") + new ArrayList( + Arrays.asList("8DDA5NZVBZFGAX0V3HPF81HHE0", "N18CPRVXR5214XPBBA6BZQWF3C", "2GYD7WNXF7BJZW1PMGNXZ3Y8M8") + ) ) .build() ); @@ -4124,7 +3925,7 @@ client.customers().search( CustomerCreationSourceFilter .builder() .values( - Optional.of( + new ArrayList( Arrays.asList(CustomerCreationSource.THIRD_PARTY) ) ) @@ -4148,7 +3949,7 @@ client.customers().search( FilterValue .builder() .all( - Optional.of( + new ArrayList( Arrays.asList("545AXB44B4XXWMVQ4W8SBT3HHF") ) ) @@ -4194,7 +3995,7 @@ For more information, see [Pagination](https://developer.squareup.com/docs/build
-**limit:** `Optional` +**limit:** `Optional` The maximum number of results to return in a single page. This limit is advisory. The response might contain more or fewer results. If the specified limit is invalid, Square returns a `400 VALUE_TOO_LOW` or `400 VALUE_TOO_HIGH` error. The default value is 100. @@ -4472,7 +4273,7 @@ format, where `YYYY` is the specified birth year or `0000` if a birth year is no
-**version:** `Optional` +**version:** `Optional` The current version of the customer profile. @@ -4558,7 +4359,7 @@ client.customers().delete(
-**version:** `Optional` +**version:** `Optional` The current version of the customer profile. @@ -4575,7 +4376,7 @@ As a best practice, you should include this parameter to enable [optimistic conc
## Devices -
client.devices.list() -> SyncPagingIterable<Device> +
client.devices.list() -> ListDevicesResponse
@@ -4730,7 +4531,7 @@ client.devices().get(
## Disputes -
client.disputes.list() -> SyncPagingIterable<Dispute> +
client.disputes.list() -> ListDisputesResponse
@@ -5151,7 +4952,7 @@ client.disputes().submitEvidence(
## Employees -
client.employees.list() -> SyncPagingIterable<Employee> +
client.employees.list() -> ListEmployeesResponse
@@ -5521,7 +5322,7 @@ client.events().listEventTypes(
## GiftCards -
client.giftCards.list() -> SyncPagingIterable<GiftCard> +
client.giftCards.list() -> ListGiftCardsResponse
@@ -6215,7 +6016,7 @@ client.inventory().deprecatedBatchChange( .builder() .idempotencyKey("8fc6a5b0-9fe8-4b46-b46b-2ef95793abbe") .changes( - Optional.of( + new ArrayList( Arrays.asList( InventoryChange .builder() @@ -6297,22 +6098,22 @@ client.inventory().deprecatedBatchGetChanges( BatchRetrieveInventoryChangesRequest .builder() .catalogObjectIds( - Optional.of( + new ArrayList( Arrays.asList("W62UWFY35CWMYGVWK6TWJDNI") ) ) .locationIds( - Optional.of( + new ArrayList( Arrays.asList("C6W5YS5QM06F5") ) ) .types( - Optional.of( + new ArrayList( Arrays.asList(InventoryChangeType.PHYSICAL_COUNT) ) ) .states( - Optional.of( + new ArrayList( Arrays.asList(InventoryState.IN_STOCK) ) ) @@ -6378,12 +6179,12 @@ client.inventory().deprecatedBatchGetCounts( BatchGetInventoryCountsRequest .builder() .catalogObjectIds( - Optional.of( + new ArrayList( Arrays.asList("W62UWFY35CWMYGVWK6TWJDNI") ) ) .locationIds( - Optional.of( + new ArrayList( Arrays.asList("59TNP9SA8VGDA") ) ) @@ -6452,7 +6253,7 @@ client.inventory().batchCreateChanges( .builder() .idempotencyKey("8fc6a5b0-9fe8-4b46-b46b-2ef95793abbe") .changes( - Optional.of( + new ArrayList( Arrays.asList( InventoryChange .builder() @@ -6502,7 +6303,7 @@ client.inventory().batchCreateChanges(
-
client.inventory.batchGetChanges(request) -> SyncPagingIterable<InventoryChange> +
client.inventory.batchGetChanges(request) -> BatchGetInventoryChangesResponse
@@ -6540,22 +6341,22 @@ client.inventory().batchGetChanges( BatchRetrieveInventoryChangesRequest .builder() .catalogObjectIds( - Optional.of( + new ArrayList( Arrays.asList("W62UWFY35CWMYGVWK6TWJDNI") ) ) .locationIds( - Optional.of( + new ArrayList( Arrays.asList("C6W5YS5QM06F5") ) ) .types( - Optional.of( + new ArrayList( Arrays.asList(InventoryChangeType.PHYSICAL_COUNT) ) ) .states( - Optional.of( + new ArrayList( Arrays.asList(InventoryState.IN_STOCK) ) ) @@ -6589,7 +6390,7 @@ client.inventory().batchGetChanges(
-
client.inventory.batchGetCounts(request) -> SyncPagingIterable<InventoryCount> +
client.inventory.batchGetCounts(request) -> BatchGetInventoryCountsResponse
@@ -6630,12 +6431,12 @@ client.inventory().batchGetCounts( BatchGetInventoryCountsRequest .builder() .catalogObjectIds( - Optional.of( + new ArrayList( Arrays.asList("W62UWFY35CWMYGVWK6TWJDNI") ) ) .locationIds( - Optional.of( + new ArrayList( Arrays.asList("59TNP9SA8VGDA") ) ) @@ -6854,7 +6655,7 @@ client.inventory().getTransfer(
-
client.inventory.get(catalogObjectId) -> SyncPagingIterable<InventoryCount> +
client.inventory.get(catalogObjectId) -> GetInventoryCountResponse
@@ -6942,7 +6743,7 @@ See the [Pagination](https://developer.squareup.com/docs/working-with-apis/pagin
-
client.inventory.changes(catalogObjectId) -> SyncPagingIterable<InventoryChange> +
client.inventory.changes(catalogObjectId) -> GetInventoryChangesResponse
@@ -7040,7 +6841,7 @@ See the [Pagination](https://developer.squareup.com/docs/working-with-apis/pagin
## Invoices -
client.invoices.list() -> SyncPagingIterable<Invoice> +
client.invoices.list() -> ListInvoicesResponse
@@ -7173,7 +6974,7 @@ client.invoices().create( .build() ) .paymentRequests( - Optional.of( + new ArrayList( Arrays.asList( InvoicePaymentRequest .builder() @@ -7182,7 +6983,7 @@ client.invoices().create( .tippingEnabled(true) .automaticPaymentSource(InvoiceAutomaticPaymentSource.NONE) .reminders( - Optional.of( + new ArrayList( Arrays.asList( InvoicePaymentReminder .builder() @@ -7212,7 +7013,7 @@ client.invoices().create( .build() ) .customFields( - Optional.of( + new ArrayList( Arrays.asList( InvoiceCustomField .builder() @@ -7319,10 +7120,12 @@ client.invoices().search( InvoiceFilter .builder() .locationIds( - Arrays.asList("ES0RJRZYEC39A") + new ArrayList( + Arrays.asList("ES0RJRZYEC39A") + ) ) .customerIds( - Optional.of( + new ArrayList( Arrays.asList("JDKYHBWT1D4F8MFH63DBMEN8Y4") ) ) @@ -7488,7 +7291,7 @@ client.invoices().update( .builder() .version(1) .paymentRequests( - Optional.of( + new ArrayList( Arrays.asList( InvoicePaymentRequest .builder() @@ -8579,7 +8382,7 @@ client.labor().createTimecard( .build() ) .breaks( - Optional.of( + new ArrayList( Arrays.asList( Break .builder() @@ -8869,7 +8672,7 @@ client.labor().updateTimecard( .build() ) .breaks( - Optional.of( + new ArrayList( Arrays.asList( Break .builder() @@ -9216,7 +9019,7 @@ client.locations().update( BusinessHours .builder() .periods( - Optional.of( + new ArrayList( Arrays.asList( BusinessHoursPeriod .builder() @@ -9328,14 +9131,14 @@ client.locations().checkouts( .referenceId("reference_id") .customerId("customer_id") .lineItems( - Optional.of( + new ArrayList( Arrays.asList( OrderLineItem .builder() .quantity("2") .name("Printed T Shirt") .appliedTaxes( - Optional.of( + new ArrayList( Arrays.asList( OrderLineItemAppliedTax .builder() @@ -9345,7 +9148,7 @@ client.locations().checkouts( ) ) .appliedDiscounts( - Optional.of( + new ArrayList( Arrays.asList( OrderLineItemAppliedDiscount .builder() @@ -9390,7 +9193,7 @@ client.locations().checkouts( ) ) .taxes( - Optional.of( + new ArrayList( Arrays.asList( OrderLineItemTax .builder() @@ -9403,7 +9206,7 @@ client.locations().checkouts( ) ) .discounts( - Optional.of( + new ArrayList( Arrays.asList( OrderLineItemDiscount .builder() @@ -9444,7 +9247,7 @@ client.locations().checkouts( ) .redirectUrl("https://merchant.website.com/order-confirm") .additionalRecipients( - Optional.of( + new ArrayList( Arrays.asList( ChargeRequestAdditionalRecipient .builder() @@ -9738,7 +9541,7 @@ For more information, see [Pagination](https://developer.squareup.com/docs/build
## Merchants -
client.merchants.list() -> SyncPagingIterable<Merchant> +
client.merchants.list() -> ListMerchantsResponse
@@ -10145,7 +9948,7 @@ client.orders().create( .locationId("057P5VYJ4A5X1") .referenceId("my-order-001") .lineItems( - Optional.of( + new ArrayList( Arrays.asList( OrderLineItem .builder() @@ -10164,7 +9967,7 @@ client.orders().create( .quantity("2") .catalogObjectId("BEMYCSMIJL46OCDV4KYIKXIB") .modifiers( - Optional.of( + new ArrayList( Arrays.asList( OrderLineItemModifier .builder() @@ -10174,7 +9977,7 @@ client.orders().create( ) ) .appliedDiscounts( - Optional.of( + new ArrayList( Arrays.asList( OrderLineItemAppliedDiscount .builder() @@ -10188,7 +9991,7 @@ client.orders().create( ) ) .taxes( - Optional.of( + new ArrayList( Arrays.asList( OrderLineItemTax .builder() @@ -10201,7 +10004,7 @@ client.orders().create( ) ) .discounts( - Optional.of( + new ArrayList( Arrays.asList( OrderLineItemDiscount .builder() @@ -10296,7 +10099,9 @@ client.orders().batchGet( BatchGetOrdersRequest .builder() .orderIds( - Arrays.asList("CAISEM82RcpmcFBM0TfOyiHV3es", "CAISENgvlJ6jLWAzERDzjyHVybY") + new ArrayList( + Arrays.asList("CAISEM82RcpmcFBM0TfOyiHV3es", "CAISENgvlJ6jLWAzERDzjyHVybY") + ) ) .locationId("057P5VYJ4A5X1") .build() @@ -10373,7 +10178,7 @@ client.orders().calculate( .builder() .locationId("D7AVYMEAPJ3A3") .lineItems( - Optional.of( + new ArrayList( Arrays.asList( OrderLineItem .builder() @@ -10403,7 +10208,7 @@ client.orders().calculate( ) ) .discounts( - Optional.of( + new ArrayList( Arrays.asList( OrderLineItemDiscount .builder() @@ -10597,7 +10402,7 @@ client.orders().search( SearchOrdersRequest .builder() .locationIds( - Optional.of( + new ArrayList( Arrays.asList("057P5VYJ4A5X1", "18YC4JDH91E1H") ) ) @@ -10611,7 +10416,9 @@ client.orders().search( SearchOrdersStateFilter .builder() .states( - Arrays.asList(OrderState.COMPLETED) + new ArrayList( + Arrays.asList(OrderState.COMPLETED) + ) ) .build() ) @@ -10832,7 +10639,7 @@ client.orders().update( .builder() .locationId("location_id") .lineItems( - Optional.of( + new ArrayList( Arrays.asList( OrderLineItem .builder() @@ -10854,7 +10661,7 @@ client.orders().update( .build() ) .fieldsToClear( - Optional.of( + new ArrayList( Arrays.asList("discounts") ) ) @@ -10974,7 +10781,7 @@ client.orders().pay( .orderId("order_id") .idempotencyKey("c043a359-7ad9-4136-82a9-c3f1d66dcbff") .paymentIds( - Optional.of( + new ArrayList( Arrays.asList("EnZdNAlWCmfh6Mt5FMNST1o7taB", "0LRiVlbXVwe8ozu4KbZxd12mvaB") ) ) @@ -11040,7 +10847,7 @@ The payment total must match the order total.
## Payments -
client.payments.list() -> SyncPagingIterable<Payment> +
client.payments.list() -> ListPaymentsResponse
@@ -11108,7 +10915,7 @@ client.payments().list( **beginTime:** `Optional` -Indicates the start of the time range to retrieve payments for, in RFC 3339 format. +Indicates the start of the time range to retrieve payments for, in RFC 3339 format. The range is determined using the `created_at` field for each Payment. Inclusive. Default: The current time minus one year. @@ -11120,7 +10927,7 @@ Inclusive. Default: The current time minus one year. **endTime:** `Optional` -Indicates the end of the time range to retrieve payments for, in RFC 3339 format. The +Indicates the end of the time range to retrieve payments for, in RFC 3339 format. The range is determined using the `created_at` field for each Payment. Default: The current time. @@ -11167,7 +10974,7 @@ for the default (main) location associated with the seller.
-**total:** `Optional` — The exact amount in the `total_money` for a payment. +**total:** `Optional` — The exact amount in the `total_money` for a payment.
@@ -11360,7 +11167,7 @@ This could be a payment token generated by the Web Payments SDK for any of its [supported methods](https://developer.squareup.com/docs/web-payments/overview#explore-payment-methods), including cards, bank transfers, Afterpay or Cash App Pay. If recording a payment that the seller received outside of Square, specify either "CASH" or "EXTERNAL". -For more information, see +For more information, see [Take Payments](https://developer.squareup.com/docs/payments-api/take-payments).
@@ -11448,10 +11255,10 @@ For more information, see [Permissions](https://developer.squareup.com/docs/paym **delayDuration:** `Optional` -The duration of time after the payment's creation when Square automatically -either completes or cancels the payment depending on the `delay_action` field value. -For more information, see -[Time threshold](https://developer.squareup.com/docs/payments-api/take-payments/card-payments/delayed-capture#time-threshold). +The duration of time after the payment's creation when Square automatically +either completes or cancels the payment depending on the `delay_action` field value. +For more information, see +[Time threshold](https://developer.squareup.com/docs/payments-api/take-payments/card-payments/delayed-capture#time-threshold). This parameter should be specified as a time duration, in RFC 3339 format. @@ -11472,8 +11279,8 @@ Default: **delayAction:** `Optional` The action to be applied to the payment when the `delay_duration` has elapsed. The action must be -CANCEL or COMPLETE. For more information, see -[Time Threshold](https://developer.squareup.com/docs/payments-api/take-payments/card-payments/delayed-capture#time-threshold). +CANCEL or COMPLETE. For more information, see +[Time Threshold](https://developer.squareup.com/docs/payments-api/take-payments/card-payments/delayed-capture#time-threshold). Default: CANCEL @@ -11531,7 +11338,7 @@ used. **teamMemberId:** `Optional` -An optional [TeamMember](entity:TeamMember) ID to associate with +An optional [TeamMember](entity:TeamMember) ID to associate with this payment. @@ -11544,7 +11351,7 @@ this payment. A user-defined ID to associate with the payment. -You can use this field to associate the payment to an entity in an external system +You can use this field to associate the payment to an entity in an external system (for example, you might specify an order ID that is generated by a third-party shopping cart). @@ -12038,8 +11845,8 @@ client.payments().complete( **versionToken:** `Optional` -Used for optimistic concurrency. This opaque token identifies the current `Payment` -version that the caller expects. If the server has a different version of the Payment, +Used for optimistic concurrency. This opaque token identifies the current `Payment` +version that the caller expects. If the server has a different version of the Payment, the update fails and a response with a VERSION_MISMATCH error is returned. @@ -12053,7 +11860,7 @@ the update fails and a response with a VERSION_MISMATCH error is returned.
## Payouts -
client.payouts.list() -> SyncPagingIterable<Payout> +
client.payouts.list() -> ListPayoutsResponse
@@ -12248,7 +12055,7 @@ client.payouts().get(
-
client.payouts.listEntries(payoutId) -> SyncPagingIterable<PayoutEntry> +
client.payouts.listEntries(payoutId) -> ListPayoutEntriesResponse
@@ -12347,7 +12154,7 @@ Default: `100`
## Refunds -
client.refunds.list() -> SyncPagingIterable<PaymentRefund> +
client.refunds.list() -> ListPaymentRefundsResponse
@@ -13153,7 +12960,7 @@ client.subscriptions().create( .build() ) .phases( - Optional.of( + new ArrayList( Arrays.asList( Phase .builder() @@ -13237,7 +13044,7 @@ If the cancellation date is earlier than the end date of a subscription cycle, t at the canceled date and the subscriber is sent a prorated invoice at the beginning of the canceled cycle. When the subscription plan of the newly created subscription has a fixed number of cycles and the `canceled_date` -occurs before the subscription plan completes, the specified `canceled_date` sets the date when the subscription +occurs before the subscription plan expires, the specified `canceled_date` sets the date when the subscription stops through the end of the last cycle.
@@ -13459,17 +13266,17 @@ client.subscriptions().search( SearchSubscriptionsFilter .builder() .customerIds( - Optional.of( + new ArrayList( Arrays.asList("CHFGVKYY8RSV93M5KCYTG4PN0G") ) ) .locationIds( - Optional.of( + new ArrayList( Arrays.asList("S8GWD5R9QB376") ) ) .sourceNames( - Optional.of( + new ArrayList( Arrays.asList("My App") ) ) @@ -13912,7 +13719,7 @@ client.subscriptions().cancel(
-
client.subscriptions.listEvents(subscriptionId) -> SyncPagingIterable<SubscriptionEvent> +
client.subscriptions.listEvents(subscriptionId) -> ListSubscriptionEventsResponse
@@ -14066,7 +13873,7 @@ on the starting date of the next billing cycle.
-**pauseCycleDuration:** `Optional` +**pauseCycleDuration:** `Optional` The number of billing cycles the subscription will be paused before it is reactivated. @@ -14228,7 +14035,7 @@ client.subscriptions().swapPlan( .subscriptionId("subscription_id") .newPlanVariationId("FQ7CDXXWSLUJRPM3GFJSJGZ7") .phases( - Optional.of( + new ArrayList( Arrays.asList( PhaseInput .builder() @@ -14337,7 +14144,7 @@ client.teamMembers().create( .builder() .assignmentType(TeamMemberAssignedLocationsAssignmentType.EXPLICIT_LOCATIONS) .locationIds( - Optional.of( + new ArrayList( Arrays.asList("YSGH2WBKG94QZ", "GA2Y9HSJ8KRYT") ) ) @@ -14347,7 +14154,7 @@ client.teamMembers().create( WageSetting .builder() .jobAssignments( - Optional.of( + new ArrayList( Arrays.asList( JobAssignment .builder() @@ -14465,7 +14272,9 @@ client.teamMembers().batchCreate( .assignmentType(Optional.of(TeamMemberAssignedLocationsAssignmentType.EXPLICIT_LOCATIONS)) .locationIds( Optional.of( - Arrays.asList("YSGH2WBKG94QZ", "GA2Y9HSJ8KRYT") + new ArrayList( + Arrays.asList("YSGH2WBKG94QZ", "GA2Y9HSJ8KRYT") + ) ) ) .build() @@ -14615,7 +14424,9 @@ client.teamMembers().batchUpdate( .assignmentType(Optional.of(TeamMemberAssignedLocationsAssignmentType.EXPLICIT_LOCATIONS)) .locationIds( Optional.of( - Arrays.asList("YSGH2WBKG94QZ", "GA2Y9HSJ8KRYT") + new ArrayList( + Arrays.asList("YSGH2WBKG94QZ", "GA2Y9HSJ8KRYT") + ) ) ) .build() @@ -14701,7 +14512,7 @@ client.teamMembers().search( SearchTeamMembersFilter .builder() .locationIds( - Optional.of( + new ArrayList( Arrays.asList("0G5P3VGACMMQZ") ) ) @@ -14867,7 +14678,7 @@ client.teamMembers().update( .builder() .assignmentType(TeamMemberAssignedLocationsAssignmentType.EXPLICIT_LOCATIONS) .locationIds( - Optional.of( + new ArrayList( Arrays.asList("YSGH2WBKG94QZ", "GA2Y9HSJ8KRYT") ) ) @@ -14877,7 +14688,7 @@ client.teamMembers().update( WageSetting .builder() .jobAssignments( - Optional.of( + new ArrayList( Arrays.asList( JobAssignment .builder() @@ -15411,8 +15222,8 @@ client.terminal().dismissTerminalRefund(
-## TransferOrders -
client.transferOrders.create(request) -> CreateTransferOrderResponse +## Vendors +
client.vendors.batchCreate(request) -> BatchCreateVendorsResponse
@@ -15424,26 +15235,7 @@ client.terminal().dismissTerminalRefund(
-Creates a new transfer order in [DRAFT](entity:TransferOrderStatus) status. A transfer order represents the intent -to move [CatalogItemVariation](entity:CatalogItemVariation)s from one [Location](entity:Location) to another. -The source and destination locations must be different and must belong to your Square account. - -In [DRAFT](entity:TransferOrderStatus) status, you can: -- Add or remove items -- Modify quantities -- Update shipping information -- Delete the entire order via [DeleteTransferOrder](api-endpoint:TransferOrders-DeleteTransferOrder) - -The request requires source_location_id and destination_location_id. -Inventory levels are not affected until the order is started via -[StartTransferOrder](api-endpoint:TransferOrders-StartTransferOrder). - -Common integration points: -- Sync with warehouse management systems -- Automate regular stock transfers -- Initialize transfers from inventory optimization systems - -Creates a [transfer_order.created](webhook:transfer_order.created) webhook event. +Creates one or more [Vendor](entity:Vendor) objects to represent suppliers to a seller.
@@ -15458,776 +15250,8 @@ Creates a [transfer_order.created](webhook:transfer_order.created) webhook event
```java -client.transferOrders().create( - CreateTransferOrderRequest - .builder() - .idempotencyKey("65cc0586-3e82-384s-b524-3885cffd52") - .transferOrder( - CreateTransferOrderData - .builder() - .sourceLocationId("EXAMPLE_SOURCE_LOCATION_ID_123") - .destinationLocationId("EXAMPLE_DEST_LOCATION_ID_456") - .expectedAt("2025-11-09T05:00:00Z") - .notes("Example transfer order for inventory redistribution between locations") - .trackingNumber("TRACK123456789") - .createdByTeamMemberId("EXAMPLE_TEAM_MEMBER_ID_789") - .lineItems( - Optional.of( - Arrays.asList( - CreateTransferOrderLineData - .builder() - .itemVariationId("EXAMPLE_ITEM_VARIATION_ID_001") - .quantityOrdered("5") - .build(), - CreateTransferOrderLineData - .builder() - .itemVariationId("EXAMPLE_ITEM_VARIATION_ID_002") - .quantityOrdered("3") - .build() - ) - ) - ) - .build() - ) - .build() -); -``` -
-
- - - -#### ⚙️ Parameters - -
-
- -
-
- -**idempotencyKey:** `String` - -A unique string that identifies this CreateTransferOrder request. Keys can be -any valid string but must be unique for every CreateTransferOrder request. - -
-
- -
-
- -**transferOrder:** `CreateTransferOrderData` — The transfer order to create - -
-
-
-
- - - - -
- -
client.transferOrders.search(request) -> SyncPagingIterable<TransferOrder> -
-
- -#### 📝 Description - -
-
- -
-
- -Searches for transfer orders using filters. Returns a paginated list of matching -[TransferOrder](entity:TransferOrder)s sorted by creation date. - -Common search scenarios: -- Find orders for a source [Location](entity:Location) -- Find orders for a destination [Location](entity:Location) -- Find orders in a particular [TransferOrderStatus](entity:TransferOrderStatus) -
-
-
-
- -#### 🔌 Usage - -
-
- -
-
- -```java -client.transferOrders().search( - SearchTransferOrdersRequest - .builder() - .query( - TransferOrderQuery - .builder() - .filter( - TransferOrderFilter - .builder() - .sourceLocationIds( - Optional.of( - Arrays.asList("EXAMPLE_SOURCE_LOCATION_ID_123") - ) - ) - .destinationLocationIds( - Optional.of( - Arrays.asList("EXAMPLE_DEST_LOCATION_ID_456") - ) - ) - .statuses( - Optional.of( - Arrays.asList(TransferOrderStatus.STARTED, TransferOrderStatus.PARTIALLY_RECEIVED) - ) - ) - .build() - ) - .sort( - TransferOrderSort - .builder() - .field(TransferOrderSortField.UPDATED_AT) - .order(SortOrder.DESC) - .build() - ) - .build() - ) - .cursor("eyJsYXN0X3VwZGF0ZWRfYXQiOjE3NTMxMTg2NjQ4NzN9") - .limit(10) - .build() -); -``` -
-
-
-
- -#### ⚙️ Parameters - -
-
- -
-
- -**query:** `Optional` — The search query - -
-
- -
-
- -**cursor:** `Optional` — Pagination cursor from a previous search response - -
-
- -
-
- -**limit:** `Optional` — Maximum number of results to return (1-100) - -
-
-
-
- - -
-
-
- -
client.transferOrders.get(transferOrderId) -> RetrieveTransferOrderResponse -
-
- -#### 📝 Description - -
-
- -
-
- -Retrieves a specific [TransferOrder](entity:TransferOrder) by ID. Returns the complete -order details including: - -- Basic information (status, dates, notes) -- Line items with ordered and received quantities -- Source and destination [Location](entity:Location)s -- Tracking information (if available) -
-
-
-
- -#### 🔌 Usage - -
-
- -
-
- -```java -client.transferOrders().get( - GetTransferOrdersRequest - .builder() - .transferOrderId("transfer_order_id") - .build() -); -``` -
-
-
-
- -#### ⚙️ Parameters - -
-
- -
-
- -**transferOrderId:** `String` — The ID of the transfer order to retrieve - -
-
-
-
- - -
-
-
- -
client.transferOrders.update(transferOrderId, request) -> UpdateTransferOrderResponse -
-
- -#### 📝 Description - -
-
- -
-
- -Updates an existing transfer order. This endpoint supports sparse updates, -allowing you to modify specific fields without affecting others. - -Creates a [transfer_order.updated](webhook:transfer_order.updated) webhook event. -
-
-
-
- -#### 🔌 Usage - -
-
- -
-
- -```java -client.transferOrders().update( - UpdateTransferOrderRequest - .builder() - .transferOrderId("transfer_order_id") - .idempotencyKey("f47ac10b-58cc-4372-a567-0e02b2c3d479") - .transferOrder( - UpdateTransferOrderData - .builder() - .sourceLocationId("EXAMPLE_SOURCE_LOCATION_ID_789") - .destinationLocationId("EXAMPLE_DEST_LOCATION_ID_101") - .expectedAt("2025-11-10T08:00:00Z") - .notes("Updated: Priority transfer due to low stock at destination") - .trackingNumber("TRACK987654321") - .lineItems( - Optional.of( - Arrays.asList( - UpdateTransferOrderLineData - .builder() - .uid("1") - .quantityOrdered("7") - .build(), - UpdateTransferOrderLineData - .builder() - .itemVariationId("EXAMPLE_NEW_ITEM_VARIATION_ID_003") - .quantityOrdered("2") - .build(), - UpdateTransferOrderLineData - .builder() - .uid("2") - .remove(true) - .build() - ) - ) - ) - .build() - ) - .version(1753109537351L) - .build() -); -``` -
-
-
-
- -#### ⚙️ Parameters - -
-
- -
-
- -**transferOrderId:** `String` — The ID of the transfer order to update - -
-
- -
-
- -**idempotencyKey:** `String` — A unique string that identifies this UpdateTransferOrder request. Keys must contain only alphanumeric characters, dashes and underscores - -
-
- -
-
- -**transferOrder:** `UpdateTransferOrderData` — The transfer order updates to apply - -
-
- -
-
- -**version:** `Optional` — Version for optimistic concurrency - -
-
-
-
- - -
-
-
- -
client.transferOrders.delete(transferOrderId) -> DeleteTransferOrderResponse -
-
- -#### 📝 Description - -
-
- -
-
- -Deletes a transfer order in [DRAFT](entity:TransferOrderStatus) status. -Only draft orders can be deleted. Once an order is started via -[StartTransferOrder](api-endpoint:TransferOrders-StartTransferOrder), it can no longer be deleted. - -Creates a [transfer_order.deleted](webhook:transfer_order.deleted) webhook event. -
-
-
-
- -#### 🔌 Usage - -
-
- -
-
- -```java -client.transferOrders().delete( - DeleteTransferOrdersRequest - .builder() - .transferOrderId("transfer_order_id") - .version(1000000L) - .build() -); -``` -
-
-
-
- -#### ⚙️ Parameters - -
-
- -
-
- -**transferOrderId:** `String` — The ID of the transfer order to delete - -
-
- -
-
- -**version:** `Optional` — Version for optimistic concurrency - -
-
-
-
- - -
-
-
- -
client.transferOrders.cancel(transferOrderId, request) -> CancelTransferOrderResponse -
-
- -#### 📝 Description - -
-
- -
-
- -Cancels a transfer order in [STARTED](entity:TransferOrderStatus) or -[PARTIALLY_RECEIVED](entity:TransferOrderStatus) status. Any unreceived quantities will no -longer be receivable and will be immediately returned to the source [Location](entity:Location)'s inventory. - -Common reasons for cancellation: -- Items no longer needed at destination -- Source location needs the inventory -- Order created in error - -Creates a [transfer_order.updated](webhook:transfer_order.updated) webhook event. -
-
-
-
- -#### 🔌 Usage - -
-
- -
-
- -```java -client.transferOrders().cancel( - CancelTransferOrderRequest - .builder() - .transferOrderId("transfer_order_id") - .idempotencyKey("65cc0586-3e82-4d08-b524-3885cffd52") - .version(1753117449752L) - .build() -); -``` -
-
-
-
- -#### ⚙️ Parameters - -
-
- -
-
- -**transferOrderId:** `String` — The ID of the transfer order to cancel. Must be in STARTED or PARTIALLY_RECEIVED status. - -
-
- -
-
- -**idempotencyKey:** `String` - -A unique string that identifies this UpdateTransferOrder request. Keys can be -any valid string but must be unique for every UpdateTransferOrder request. - -
-
- -
-
- -**version:** `Optional` — Version for optimistic concurrency - -
-
-
-
- - -
-
-
- -
client.transferOrders.receive(transferOrderId, request) -> ReceiveTransferOrderResponse -
-
- -#### 📝 Description - -
-
- -
-
- -Records receipt of [CatalogItemVariation](entity:CatalogItemVariation)s for a transfer order. -This endpoint supports partial receiving - you can receive items in multiple batches. - -For each line item, you can specify: -- Quantity received in good condition (added to destination inventory with [InventoryState](entity:InventoryState) of IN_STOCK) -- Quantity damaged during transit/handling (added to destination inventory with [InventoryState](entity:InventoryState) of WASTE) -- Quantity canceled (returned to source location's inventory) - -The order must be in [STARTED](entity:TransferOrderStatus) or [PARTIALLY_RECEIVED](entity:TransferOrderStatus) status. -Received quantities are added to the destination [Location](entity:Location)'s inventory according to their condition. -Canceled quantities are immediately returned to the source [Location](entity:Location)'s inventory. - -When all items are either received, damaged, or canceled, the order moves to -[COMPLETED](entity:TransferOrderStatus) status. - -Creates a [transfer_order.updated](webhook:transfer_order.updated) webhook event. -
-
-
-
- -#### 🔌 Usage - -
-
- -
-
- -```java -client.transferOrders().receive( - ReceiveTransferOrderRequest - .builder() - .transferOrderId("transfer_order_id") - .idempotencyKey("EXAMPLE_IDEMPOTENCY_KEY_101") - .receipt( - TransferOrderGoodsReceipt - .builder() - .lineItems( - Optional.of( - Arrays.asList( - TransferOrderGoodsReceiptLineItem - .builder() - .transferOrderLineUid("transfer_order_line_uid") - .quantityReceived("3") - .quantityDamaged("1") - .quantityCanceled("1") - .build(), - TransferOrderGoodsReceiptLineItem - .builder() - .transferOrderLineUid("transfer_order_line_uid") - .quantityReceived("2") - .quantityCanceled("1") - .build() - ) - ) - ) - .build() - ) - .version(1753118664873L) - .build() -); -``` -
-
-
-
- -#### ⚙️ Parameters - -
-
- -
-
- -**transferOrderId:** `String` — The ID of the transfer order to receive items for - -
-
- -
-
- -**idempotencyKey:** `String` — A unique key to make this request idempotent - -
-
- -
-
- -**receipt:** `TransferOrderGoodsReceipt` — The receipt details - -
-
- -
-
- -**version:** `Optional` — Version for optimistic concurrency - -
-
-
-
- - -
-
-
- -
client.transferOrders.start(transferOrderId, request) -> StartTransferOrderResponse -
-
- -#### 📝 Description - -
-
- -
-
- -Changes a [DRAFT](entity:TransferOrderStatus) transfer order to [STARTED](entity:TransferOrderStatus) status. -This decrements inventory at the source [Location](entity:Location) and marks it as in-transit. - -The order must be in [DRAFT](entity:TransferOrderStatus) status and have all required fields populated. -Once started, the order can no longer be deleted, but it can be canceled via -[CancelTransferOrder](api-endpoint:TransferOrders-CancelTransferOrder). - -Creates a [transfer_order.updated](webhook:transfer_order.updated) webhook event. -
-
-
-
- -#### 🔌 Usage - -
-
- -
-
- -```java -client.transferOrders().start( - StartTransferOrderRequest - .builder() - .transferOrderId("transfer_order_id") - .idempotencyKey("EXAMPLE_IDEMPOTENCY_KEY_789") - .version(1753109537351L) - .build() -); -``` -
-
-
-
- -#### ⚙️ Parameters - -
-
- -
-
- -**transferOrderId:** `String` — The ID of the transfer order to start. Must be in DRAFT status. - -
-
- -
-
- -**idempotencyKey:** `String` - -A unique string that identifies this UpdateTransferOrder request. Keys can be -any valid string but must be unique for every UpdateTransferOrder request. - -
-
- -
-
- -**version:** `Optional` — Version for optimistic concurrency - -
-
-
-
- - -
-
-
- -## Vendors -
client.vendors.batchCreate(request) -> BatchCreateVendorsResponse -
-
- -#### 📝 Description - -
-
- -
-
- -Creates one or more [Vendor](entity:Vendor) objects to represent suppliers to a seller. -
-
-
-
- -#### 🔌 Usage - -
-
- -
-
- -```java -client.vendors().batchCreate( - BatchCreateVendorsRequest +client.vendors().batchCreate( + BatchCreateVendorsRequest .builder() .vendors( new HashMap() {{ @@ -16249,14 +15273,16 @@ client.vendors().batchCreate( ) .contacts( Optional.of( - Arrays.asList( - VendorContact - .builder() - .ordinal(1) - .name("Joe Burrow") - .emailAddress("joe@joesfreshseafood.com") - .phoneNumber("1-212-555-4250") - .build() + new ArrayList( + Arrays.asList( + VendorContact + .builder() + .ordinal(1) + .name("Joe Burrow") + .emailAddress("joe@joesfreshseafood.com") + .phoneNumber("1-212-555-4250") + .build() + ) ) ) ) @@ -16324,7 +15350,7 @@ client.vendors().batchGet( BatchGetVendorsRequest .builder() .vendorIds( - Optional.of( + new ArrayList( Arrays.asList("INV_V_JDKYHBWT1D4F8MFH63DBMEN8Y4") ) ) @@ -16484,7 +15510,7 @@ client.vendors().create( .build() ) .contacts( - Optional.of( + new ArrayList( Arrays.asList( VendorContact .builder() @@ -16763,7 +15789,7 @@ client.vendors().update(
## Bookings CustomAttributeDefinitions -
client.bookings.customAttributeDefinitions.list() -> SyncPagingIterable<CustomAttributeDefinition> +
client.bookings.customAttributeDefinitions.list() -> ListBookingCustomAttributeDefinitionsResponse
@@ -17343,7 +16369,7 @@ information needed to create or update a custom attribute.
-
client.bookings.customAttributes.list(bookingId) -> SyncPagingIterable<CustomAttribute> +
client.bookings.customAttributes.list(bookingId) -> ListBookingCustomAttributesResponse
@@ -17736,7 +16762,7 @@ definition owner, you must use the qualified key.
## Bookings LocationProfiles -
client.bookings.locationProfiles.list() -> SyncPagingIterable<LocationBookingProfile> +
client.bookings.locationProfiles.list() -> ListLocationBookingProfilesResponse
@@ -17805,7 +16831,7 @@ client.bookings().locationProfiles().list(
## Bookings TeamMemberProfiles -
client.bookings.teamMemberProfiles.list() -> SyncPagingIterable<TeamMemberBookingProfile> +
client.bookings.teamMemberProfiles.list() -> ListTeamMemberBookingProfilesResponse
@@ -17951,7 +16977,7 @@ client.bookings().teamMemberProfiles().get(
## CashDrawers Shifts -
client.cashDrawers.shifts.list() -> SyncPagingIterable<CashDrawerShiftSummary> +
client.cashDrawers.shifts.list() -> ListCashDrawerShiftsResponse
@@ -18131,7 +17157,7 @@ client.cashDrawers().shifts().get(
-
client.cashDrawers.shifts.listEvents(shiftId) -> SyncPagingIterable<CashDrawerShiftEvent> +
client.cashDrawers.shifts.listEvents(shiftId) -> ListCashDrawerShiftEventsResponse
@@ -18514,7 +17540,7 @@ Default value: `false`
-**catalogVersion:** `Optional` +**catalogVersion:** `Optional` Requests objects as of a specific version of the catalog. This allows you to retrieve historical versions of objects. The value to retrieve a specific version of an object can be found @@ -18617,7 +17643,7 @@ catalog item will delete its catalog item variations).
## Checkout PaymentLinks -
client.checkout.paymentLinks.list() -> SyncPagingIterable<PaymentLink> +
client.checkout.paymentLinks.list() -> ListPaymentLinksResponse
@@ -19044,7 +18070,7 @@ client.checkout().paymentLinks().delete(
## Customers CustomAttributeDefinitions -
client.customers.customAttributeDefinitions.list() -> SyncPagingIterable<CustomAttributeDefinition> +
client.customers.customAttributeDefinitions.list() -> ListCustomerCustomAttributeDefinitionsResponse
@@ -19611,7 +18637,7 @@ information needed to create or update a custom attribute.
## Customers Groups -
client.customers.groups.list() -> SyncPagingIterable<CustomerGroup> +
client.customers.groups.list() -> ListCustomerGroupsResponse
@@ -20097,7 +19123,7 @@ client.customers().groups().remove(
## Customers Segments -
client.customers.segments.list() -> SyncPagingIterable<CustomerSegment> +
client.customers.segments.list() -> ListCustomerSegmentsResponse
@@ -20431,7 +19457,7 @@ client.customers().cards().delete(
## Customers CustomAttributes -
client.customers.customAttributes.list(customerId) -> SyncPagingIterable<CustomAttribute> +
client.customers.customAttributes.list(customerId) -> ListCustomerCustomAttributesResponse
@@ -20833,7 +19859,7 @@ definition owner, you must use the qualified key.
## Devices Codes -
client.devices.codes.list() -> SyncPagingIterable<DeviceCode> +
client.devices.codes.list() -> ListDeviceCodesResponse
@@ -21074,7 +20100,7 @@ client.devices().codes().get(
## Disputes Evidence -
client.disputes.evidence.list(disputeId) -> SyncPagingIterable<DisputeEvidence> +
client.disputes.evidence.list(disputeId) -> ListDisputeEvidenceResponse
@@ -21286,7 +20312,7 @@ client.disputes().evidence().delete(
## GiftCards Activities -
client.giftCards.activities.list() -> SyncPagingIterable<GiftCardActivity> +
client.giftCards.activities.list() -> ListGiftCardActivitiesResponse
@@ -21527,7 +20553,7 @@ gift card, the `location_id` where the activity occurred, and the activity `type
## Labor BreakTypes -
client.labor.breakTypes.list() -> SyncPagingIterable<BreakType> +
client.labor.breakTypes.list() -> ListBreakTypesResponse
@@ -21897,7 +20923,7 @@ client.labor().breakTypes().delete(
## Labor EmployeeWages -
client.labor.employeeWages.list() -> SyncPagingIterable<EmployeeWage> +
client.labor.employeeWages.list() -> ListEmployeeWagesResponse
@@ -22105,7 +21131,7 @@ client.labor().shifts().create( .build() ) .breaks( - Optional.of( + new ArrayList( Arrays.asList( Break .builder() @@ -22395,7 +21421,7 @@ client.labor().shifts().update( .build() ) .breaks( - Optional.of( + new ArrayList( Arrays.asList( Break .builder() @@ -22517,7 +21543,7 @@ client.labor().shifts().delete(
## Labor TeamMemberWages -
client.labor.teamMemberWages.list() -> SyncPagingIterable<TeamMemberWage> +
client.labor.teamMemberWages.list() -> ListTeamMemberWagesResponse
@@ -22660,7 +21686,7 @@ client.labor().teamMemberWages().get(
## Labor WorkweekConfigs -
client.labor.workweekConfigs.list() -> SyncPagingIterable<WorkweekConfig> +
client.labor.workweekConfigs.list() -> ListWorkweekConfigsResponse
@@ -22804,7 +21830,7 @@ client.labor().workweekConfigs().get(
## Locations CustomAttributeDefinitions -
client.locations.customAttributeDefinitions.list() -> SyncPagingIterable<CustomAttributeDefinition> +
client.locations.customAttributeDefinitions.list() -> ListLocationCustomAttributeDefinitionsResponse
@@ -23418,7 +22444,7 @@ information needed to create or update a custom attribute.
-
client.locations.customAttributes.list(locationId) -> SyncPagingIterable<CustomAttribute> +
client.locations.customAttributes.list(locationId) -> ListLocationCustomAttributesResponse
@@ -24274,7 +23300,7 @@ client.loyalty().accounts().search( SearchLoyaltyAccountsRequestLoyaltyAccountQuery .builder() .mappings( - Optional.of( + new ArrayList( Arrays.asList( LoyaltyAccountMapping .builder() @@ -25232,7 +24258,7 @@ Keys can be any valid string, but must be unique for every request.
## Loyalty Programs Promotions -
client.loyalty.programs.promotions.list(programId) -> SyncPagingIterable<LoyaltyPromotion> +
client.loyalty.programs.promotions.list(programId) -> ListLoyaltyPromotionsResponse
@@ -25390,7 +24416,9 @@ client.loyalty().programs().promotions().create( LoyaltyPromotionAvailableTimeData .builder() .timePeriods( - Arrays.asList("BEGIN:VEVENT\nDTSTART:20220816T160000\nDURATION:PT2H\nRRULE:FREQ=WEEKLY;BYDAY=TU\nEND:VEVENT") + new ArrayList( + Arrays.asList("BEGIN:VEVENT\nDTSTART:20220816T160000\nDURATION:PT2H\nRRULE:FREQ=WEEKLY;BYDAY=TU\nEND:VEVENT") + ) ) .build() ) @@ -25409,7 +24437,7 @@ client.loyalty().programs().promotions().create( .build() ) .qualifyingCategoryIds( - Optional.of( + new ArrayList( Arrays.asList("XTQPYLR3IIU9C44VRCB3XD12") ) ) @@ -25615,7 +24643,7 @@ promotion that has an `ACTIVE` or `SCHEDULED` status.
## Merchants CustomAttributeDefinitions -
client.merchants.customAttributeDefinitions.list() -> SyncPagingIterable<CustomAttributeDefinition> +
client.merchants.customAttributeDefinitions.list() -> ListMerchantCustomAttributeDefinitionsResponse
@@ -26213,7 +25241,7 @@ information needed to create or update a custom attribute.
-
client.merchants.customAttributes.list(merchantId) -> SyncPagingIterable<CustomAttribute> +
client.merchants.customAttributes.list(merchantId) -> ListMerchantCustomAttributesResponse
@@ -26612,7 +25640,7 @@ definition owner, you must use the qualified key.
## Orders CustomAttributeDefinitions -
client.orders.customAttributeDefinitions.list() -> SyncPagingIterable<CustomAttributeDefinition> +
client.orders.customAttributeDefinitions.list() -> ListOrderCustomAttributeDefinitionsResponse
@@ -27214,7 +26242,7 @@ client.orders().customAttributes().batchUpsert(
-
client.orders.customAttributes.list(orderId) -> SyncPagingIterable<CustomAttribute> +
client.orders.customAttributes.list(orderId) -> ListOrderCustomAttributesResponse
@@ -27728,7 +26756,7 @@ client.teamMembers().wageSetting().update( WageSetting .builder() .jobAssignments( - Optional.of( + new ArrayList( Arrays.asList( JobAssignment .builder() @@ -28780,7 +27808,7 @@ client.webhooks().eventTypes().list(
## Webhooks Subscriptions -
client.webhooks.subscriptions.list() -> SyncPagingIterable<WebhookSubscription> +
client.webhooks.subscriptions.list() -> ListWebhookSubscriptionsResponse
@@ -28918,7 +27946,7 @@ client.webhooks().subscriptions().create( .builder() .name("Example Webhook Subscription") .eventTypes( - Optional.of( + new ArrayList( Arrays.asList("payment.created", "payment.updated") ) ) diff --git a/src/main/java/com/squareup/square/AsyncChannelsClient.java b/src/main/java/com/squareup/square/AsyncChannelsClient.java deleted file mode 100644 index 5d1c9280..00000000 --- a/src/main/java/com/squareup/square/AsyncChannelsClient.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square; - -import com.squareup.square.core.ClientOptions; -import com.squareup.square.core.RequestOptions; -import com.squareup.square.core.SyncPagingIterable; -import com.squareup.square.types.BulkRetrieveChannelsRequest; -import com.squareup.square.types.BulkRetrieveChannelsResponse; -import com.squareup.square.types.Channel; -import com.squareup.square.types.GetChannelsRequest; -import com.squareup.square.types.ListChannelsRequest; -import com.squareup.square.types.RetrieveChannelResponse; -import java.util.concurrent.CompletableFuture; - -public class AsyncChannelsClient { - protected final ClientOptions clientOptions; - - private final AsyncRawChannelsClient rawClient; - - public AsyncChannelsClient(ClientOptions clientOptions) { - this.clientOptions = clientOptions; - this.rawClient = new AsyncRawChannelsClient(clientOptions); - } - - /** - * Get responses with HTTP metadata like headers - */ - public AsyncRawChannelsClient withRawResponse() { - return this.rawClient; - } - - public CompletableFuture> list() { - return this.rawClient.list().thenApply(response -> response.body()); - } - - public CompletableFuture> list(ListChannelsRequest request) { - return this.rawClient.list(request).thenApply(response -> response.body()); - } - - public CompletableFuture> list( - ListChannelsRequest request, RequestOptions requestOptions) { - return this.rawClient.list(request, requestOptions).thenApply(response -> response.body()); - } - - public CompletableFuture bulkRetrieve(BulkRetrieveChannelsRequest request) { - return this.rawClient.bulkRetrieve(request).thenApply(response -> response.body()); - } - - public CompletableFuture bulkRetrieve( - BulkRetrieveChannelsRequest request, RequestOptions requestOptions) { - return this.rawClient.bulkRetrieve(request, requestOptions).thenApply(response -> response.body()); - } - - public CompletableFuture get(GetChannelsRequest request) { - return this.rawClient.get(request).thenApply(response -> response.body()); - } - - public CompletableFuture get(GetChannelsRequest request, RequestOptions requestOptions) { - return this.rawClient.get(request, requestOptions).thenApply(response -> response.body()); - } -} diff --git a/src/main/java/com/squareup/square/AsyncRawApplePayClient.java b/src/main/java/com/squareup/square/AsyncRawApplePayClient.java index c7e7cf02..dd2daec3 100644 --- a/src/main/java/com/squareup/square/AsyncRawApplePayClient.java +++ b/src/main/java/com/squareup/square/AsyncRawApplePayClient.java @@ -93,16 +93,19 @@ public CompletableFuture> regis @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, RegisterDomainResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), RegisterDomainResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/AsyncRawBankAccountsClient.java b/src/main/java/com/squareup/square/AsyncRawBankAccountsClient.java index 94ad3043..f8723ab5 100644 --- a/src/main/java/com/squareup/square/AsyncRawBankAccountsClient.java +++ b/src/main/java/com/squareup/square/AsyncRawBankAccountsClient.java @@ -91,10 +91,9 @@ public CompletableFuture startingAfter = parsedResponse.getCursor(); ListBankAccountsRequest nextRequest = ListBankAccountsRequest.builder() .from(request) @@ -103,22 +102,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO List result = parsedResponse.getBankAccounts().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return list(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return list(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -166,17 +167,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, GetBankAccountByV1IdResponse.class), + responseBody.string(), GetBankAccountByV1IdResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -225,16 +228,19 @@ public CompletableFuture> get( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetBankAccountResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), GetBankAccountResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/AsyncRawBookingsClient.java b/src/main/java/com/squareup/square/AsyncRawBookingsClient.java index 1216b65b..39a41c10 100644 --- a/src/main/java/com/squareup/square/AsyncRawBookingsClient.java +++ b/src/main/java/com/squareup/square/AsyncRawBookingsClient.java @@ -128,10 +128,9 @@ public CompletableFuture>> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListBookingsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListBookingsResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListBookingsResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListBookingsRequest nextRequest = ListBookingsRequest.builder() .from(request) @@ -139,22 +138,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO .build(); List result = parsedResponse.getBookings().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return list(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return list(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -232,16 +233,18 @@ public CompletableFuture> create @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateBookingResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateBookingResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -300,17 +303,19 @@ public CompletableFuture> s @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, SearchAvailabilityResponse.class), + responseBody.string(), SearchAvailabilityResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -369,17 +374,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BulkRetrieveBookingsResponse.class), + responseBody.string(), BulkRetrieveBookingsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -426,17 +433,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, GetBusinessBookingProfileResponse.class), + responseBody.string(), GetBusinessBookingProfileResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -486,17 +495,19 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, RetrieveLocationBookingProfileResponse.class), + responseBody.string(), RetrieveLocationBookingProfileResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -553,17 +564,19 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BulkRetrieveTeamMemberBookingProfilesResponse.class), + responseBody.string(), BulkRetrieveTeamMemberBookingProfilesResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -614,16 +627,18 @@ public CompletableFuture> get( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetBookingResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetBookingResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -686,16 +701,18 @@ public CompletableFuture> update @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateBookingResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UpdateBookingResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -759,16 +776,18 @@ public CompletableFuture> cancel @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CancelBookingResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CancelBookingResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/AsyncRawCardsClient.java b/src/main/java/com/squareup/square/AsyncRawCardsClient.java index b4368aad..26d9f3e3 100644 --- a/src/main/java/com/squareup/square/AsyncRawCardsClient.java +++ b/src/main/java/com/squareup/square/AsyncRawCardsClient.java @@ -106,10 +106,9 @@ public CompletableFuture>> lis @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListCardsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListCardsResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListCardsResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListCardsRequest nextRequest = ListCardsRequest.builder() .from(request) @@ -117,7 +116,7 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO .build(); List result = parsedResponse.getCards().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable(startingAfter.isPresent(), result, parsedResponse, () -> { + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { try { return list(nextRequest, requestOptions) .get() @@ -129,9 +128,12 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -185,16 +187,18 @@ public CompletableFuture> create( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateCardResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateCardResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -241,16 +245,18 @@ public CompletableFuture> get( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetCardResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetCardResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -300,16 +306,18 @@ public CompletableFuture> disable( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, DisableCardResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), DisableCardResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/AsyncRawCatalogClient.java b/src/main/java/com/squareup/square/AsyncRawCatalogClient.java index d65f7705..abf57df2 100644 --- a/src/main/java/com/squareup/square/AsyncRawCatalogClient.java +++ b/src/main/java/com/squareup/square/AsyncRawCatalogClient.java @@ -118,17 +118,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BatchDeleteCatalogObjectsResponse.class), + responseBody.string(), BatchDeleteCatalogObjectsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -193,17 +195,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BatchGetCatalogObjectsResponse.class), + responseBody.string(), BatchGetCatalogObjectsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -281,17 +285,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BatchUpsertCatalogObjectsResponse.class), + responseBody.string(), BatchUpsertCatalogObjectsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -338,16 +344,18 @@ public CompletableFuture> info(Req @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CatalogInfoResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CatalogInfoResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -428,10 +436,9 @@ public CompletableFuture startingAfter = parsedResponse.getCursor(); ListCatalogRequest nextRequest = ListCatalogRequest.builder() .from(request) @@ -439,22 +446,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO .build(); List result = parsedResponse.getObjects().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return list(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return list(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -543,17 +552,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, SearchCatalogObjectsResponse.class), + responseBody.string(), SearchCatalogObjectsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -642,17 +653,19 @@ public CompletableFuture> s @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, SearchCatalogItemsResponse.class), + responseBody.string(), SearchCatalogItemsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -711,17 +724,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpdateItemModifierListsResponse.class), + responseBody.string(), UpdateItemModifierListsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -780,16 +795,19 @@ public CompletableFuture> upda @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateItemTaxesResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), UpdateItemTaxesResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/AsyncRawChannelsClient.java b/src/main/java/com/squareup/square/AsyncRawChannelsClient.java deleted file mode 100644 index 9ca8fc0b..00000000 --- a/src/main/java/com/squareup/square/AsyncRawChannelsClient.java +++ /dev/null @@ -1,244 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.squareup.square.core.ClientOptions; -import com.squareup.square.core.MediaTypes; -import com.squareup.square.core.ObjectMappers; -import com.squareup.square.core.QueryStringMapper; -import com.squareup.square.core.RequestOptions; -import com.squareup.square.core.SquareApiException; -import com.squareup.square.core.SquareClientHttpResponse; -import com.squareup.square.core.SquareException; -import com.squareup.square.core.SyncPagingIterable; -import com.squareup.square.types.BulkRetrieveChannelsRequest; -import com.squareup.square.types.BulkRetrieveChannelsResponse; -import com.squareup.square.types.Channel; -import com.squareup.square.types.GetChannelsRequest; -import com.squareup.square.types.ListChannelsRequest; -import com.squareup.square.types.ListChannelsResponse; -import com.squareup.square.types.RetrieveChannelResponse; -import java.io.IOException; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; -import okhttp3.Call; -import okhttp3.Callback; -import okhttp3.Headers; -import okhttp3.HttpUrl; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.RequestBody; -import okhttp3.Response; -import okhttp3.ResponseBody; -import org.jetbrains.annotations.NotNull; - -public class AsyncRawChannelsClient { - protected final ClientOptions clientOptions; - - public AsyncRawChannelsClient(ClientOptions clientOptions) { - this.clientOptions = clientOptions; - } - - public CompletableFuture>> list() { - return list(ListChannelsRequest.builder().build()); - } - - public CompletableFuture>> list(ListChannelsRequest request) { - return list(request, null); - } - - public CompletableFuture>> list( - ListChannelsRequest request, RequestOptions requestOptions) { - HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("v2/channels"); - if (request.getReferenceType().isPresent()) { - QueryStringMapper.addQueryParameter( - httpUrl, "reference_type", request.getReferenceType().get(), false); - } - if (request.getReferenceId().isPresent()) { - QueryStringMapper.addQueryParameter( - httpUrl, "reference_id", request.getReferenceId().get(), false); - } - if (request.getStatus().isPresent()) { - QueryStringMapper.addQueryParameter( - httpUrl, "status", request.getStatus().get(), false); - } - if (request.getCursor().isPresent()) { - QueryStringMapper.addQueryParameter( - httpUrl, "cursor", request.getCursor().get(), false); - } - if (request.getLimit().isPresent()) { - QueryStringMapper.addQueryParameter( - httpUrl, "limit", request.getLimit().get(), false); - } - Request.Builder _requestBuilder = new Request.Builder() - .url(httpUrl.build()) - .method("GET", null) - .headers(Headers.of(clientOptions.headers(requestOptions))) - .addHeader("Accept", "application/json"); - Request okhttpRequest = _requestBuilder.build(); - OkHttpClient client = clientOptions.httpClient(); - if (requestOptions != null && requestOptions.getTimeout().isPresent()) { - client = clientOptions.httpClientWithTimeout(requestOptions); - } - CompletableFuture>> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { - @Override - public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { - try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - ListChannelsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListChannelsResponse.class); - Optional startingAfter = parsedResponse.getCursor(); - ListChannelsRequest nextRequest = ListChannelsRequest.builder() - .from(request) - .cursor(startingAfter) - .build(); - List result = parsedResponse.getChannels().orElse(Collections.emptyList()); - future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return list(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), - response)); - return; - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); - return; - } catch (IOException e) { - future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); - } - } - - @Override - public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); - } - }); - return future; - } - - public CompletableFuture> bulkRetrieve( - BulkRetrieveChannelsRequest request) { - return bulkRetrieve(request, null); - } - - public CompletableFuture> bulkRetrieve( - BulkRetrieveChannelsRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("v2/channels/bulk-retrieve") - .build(); - RequestBody body; - try { - body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); - } catch (JsonProcessingException e) { - throw new SquareException("Failed to serialize request", e); - } - Request okhttpRequest = new Request.Builder() - .url(httpUrl) - .method("POST", body) - .headers(Headers.of(clientOptions.headers(requestOptions))) - .addHeader("Content-Type", "application/json") - .addHeader("Accept", "application/json") - .build(); - OkHttpClient client = clientOptions.httpClient(); - if (requestOptions != null && requestOptions.getTimeout().isPresent()) { - client = clientOptions.httpClientWithTimeout(requestOptions); - } - CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { - @Override - public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { - try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BulkRetrieveChannelsResponse.class), - response)); - return; - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); - return; - } catch (IOException e) { - future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); - } - } - - @Override - public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); - } - }); - return future; - } - - public CompletableFuture> get(GetChannelsRequest request) { - return get(request, null); - } - - public CompletableFuture> get( - GetChannelsRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("v2/channels") - .addPathSegment(request.getChannelId()) - .build(); - Request.Builder _requestBuilder = new Request.Builder() - .url(httpUrl) - .method("GET", null) - .headers(Headers.of(clientOptions.headers(requestOptions))) - .addHeader("Accept", "application/json"); - Request okhttpRequest = _requestBuilder.build(); - OkHttpClient client = clientOptions.httpClient(); - if (requestOptions != null && requestOptions.getTimeout().isPresent()) { - client = clientOptions.httpClientWithTimeout(requestOptions); - } - CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { - @Override - public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { - try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, RetrieveChannelResponse.class), - response)); - return; - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); - return; - } catch (IOException e) { - future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); - } - } - - @Override - public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); - } - }); - return future; - } -} diff --git a/src/main/java/com/squareup/square/AsyncRawCheckoutClient.java b/src/main/java/com/squareup/square/AsyncRawCheckoutClient.java index ac9c907b..720944b0 100644 --- a/src/main/java/com/squareup/square/AsyncRawCheckoutClient.java +++ b/src/main/java/com/squareup/square/AsyncRawCheckoutClient.java @@ -72,17 +72,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, RetrieveLocationSettingsResponse.class), + responseBody.string(), RetrieveLocationSettingsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -138,17 +140,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpdateLocationSettingsResponse.class), + responseBody.string(), UpdateLocationSettingsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -195,17 +199,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, RetrieveMerchantSettingsResponse.class), + responseBody.string(), RetrieveMerchantSettingsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -260,17 +266,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpdateMerchantSettingsResponse.class), + responseBody.string(), UpdateMerchantSettingsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/AsyncRawCustomersClient.java b/src/main/java/com/squareup/square/AsyncRawCustomersClient.java index 13a0b377..f13859f1 100644 --- a/src/main/java/com/squareup/square/AsyncRawCustomersClient.java +++ b/src/main/java/com/squareup/square/AsyncRawCustomersClient.java @@ -125,10 +125,9 @@ public CompletableFuture>> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListCustomersResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListCustomersResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListCustomersResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListCustomersRequest nextRequest = ListCustomersRequest.builder() .from(request) @@ -136,22 +135,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO .build(); List result = parsedResponse.getCustomers().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return list(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return list(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -239,16 +240,19 @@ public CompletableFuture> creat @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateCustomerResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), CreateCustomerResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -321,17 +325,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BulkCreateCustomersResponse.class), + responseBody.string(), BulkCreateCustomersResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -388,17 +394,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BulkDeleteCustomersResponse.class), + responseBody.string(), BulkDeleteCustomersResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -455,17 +463,19 @@ public CompletableFuture @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BulkRetrieveCustomersResponse.class), + responseBody.string(), BulkRetrieveCustomersResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -522,17 +532,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BulkUpdateCustomersResponse.class), + responseBody.string(), BulkUpdateCustomersResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -611,16 +623,19 @@ public CompletableFuture> sear @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, SearchCustomersResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), SearchCustomersResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -667,16 +682,18 @@ public CompletableFuture> get( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetCustomerResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetCustomerResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -735,16 +752,19 @@ public CompletableFuture> updat @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateCustomerResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), UpdateCustomerResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -796,16 +816,19 @@ public CompletableFuture> delet @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, DeleteCustomerResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), DeleteCustomerResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/AsyncRawDevicesClient.java b/src/main/java/com/squareup/square/AsyncRawDevicesClient.java index fbf38cb8..6d201134 100644 --- a/src/main/java/com/squareup/square/AsyncRawDevicesClient.java +++ b/src/main/java/com/squareup/square/AsyncRawDevicesClient.java @@ -95,10 +95,9 @@ public CompletableFuture>> l @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListDevicesResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListDevicesResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListDevicesResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListDevicesRequest nextRequest = ListDevicesRequest.builder() .from(request) @@ -106,22 +105,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO .build(); List result = parsedResponse.getDevices().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return list(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return list(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -168,16 +169,18 @@ public CompletableFuture> get( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetDeviceResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetDeviceResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/AsyncRawDisputesClient.java b/src/main/java/com/squareup/square/AsyncRawDisputesClient.java index c6a8e53d..e38fe116 100644 --- a/src/main/java/com/squareup/square/AsyncRawDisputesClient.java +++ b/src/main/java/com/squareup/square/AsyncRawDisputesClient.java @@ -102,10 +102,9 @@ public CompletableFuture>> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListDisputesResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListDisputesResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListDisputesResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListDisputesRequest nextRequest = ListDisputesRequest.builder() .from(request) @@ -113,22 +112,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO .build(); List result = parsedResponse.getDisputes().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return list(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return list(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -175,16 +176,18 @@ public CompletableFuture> get( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetDisputeResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetDisputeResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -238,16 +241,18 @@ public CompletableFuture> accept @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, AcceptDisputeResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AcceptDisputeResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -283,10 +288,10 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateDisputeEvidenceFileResponse.class), + responseBody.string(), CreateDisputeEvidenceFileResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -388,17 +395,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateDisputeEvidenceTextResponse.class), + responseBody.string(), CreateDisputeEvidenceTextResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -457,16 +466,19 @@ public CompletableFuture> submi @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, SubmitEvidenceResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), SubmitEvidenceResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/AsyncRawEmployeesClient.java b/src/main/java/com/squareup/square/AsyncRawEmployeesClient.java index 43f269f1..8f1ea66a 100644 --- a/src/main/java/com/squareup/square/AsyncRawEmployeesClient.java +++ b/src/main/java/com/squareup/square/AsyncRawEmployeesClient.java @@ -84,10 +84,9 @@ public CompletableFuture>> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListEmployeesResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListEmployeesResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListEmployeesResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListEmployeesRequest nextRequest = ListEmployeesRequest.builder() .from(request) @@ -95,22 +94,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO .build(); List result = parsedResponse.getEmployees().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return list(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return list(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -151,16 +152,18 @@ public CompletableFuture> get( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetEmployeeResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetEmployeeResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/AsyncRawEventsClient.java b/src/main/java/com/squareup/square/AsyncRawEventsClient.java index dd4c3eb6..c6b880b8 100644 --- a/src/main/java/com/squareup/square/AsyncRawEventsClient.java +++ b/src/main/java/com/squareup/square/AsyncRawEventsClient.java @@ -84,16 +84,18 @@ public CompletableFuture> searchE @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, SearchEventsResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SearchEventsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -143,16 +145,18 @@ public CompletableFuture> disabl @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, DisableEventsResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), DisableEventsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -198,16 +202,18 @@ public CompletableFuture> enableE @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, EnableEventsResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), EnableEventsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -264,16 +270,19 @@ public CompletableFuture> listE @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListEventTypesResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), ListEventTypesResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/AsyncRawGiftCardsClient.java b/src/main/java/com/squareup/square/AsyncRawGiftCardsClient.java index 00ae0015..bf91dda6 100644 --- a/src/main/java/com/squareup/square/AsyncRawGiftCardsClient.java +++ b/src/main/java/com/squareup/square/AsyncRawGiftCardsClient.java @@ -113,10 +113,9 @@ public CompletableFuture>> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListGiftCardsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListGiftCardsResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListGiftCardsResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListGiftCardsRequest nextRequest = ListGiftCardsRequest.builder() .from(request) @@ -124,22 +123,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO .build(); List result = parsedResponse.getGiftCards().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return list(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return list(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -201,16 +202,19 @@ public CompletableFuture> creat @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateGiftCardResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), CreateGiftCardResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -265,17 +269,19 @@ public CompletableFuture> g @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, GetGiftCardFromGanResponse.class), + responseBody.string(), GetGiftCardFromGanResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -330,17 +336,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, GetGiftCardFromNonceResponse.class), + responseBody.string(), GetGiftCardFromNonceResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -397,17 +405,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, LinkCustomerToGiftCardResponse.class), + responseBody.string(), LinkCustomerToGiftCardResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -465,17 +475,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UnlinkCustomerFromGiftCardResponse.class), + responseBody.string(), UnlinkCustomerFromGiftCardResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -522,16 +534,18 @@ public CompletableFuture> get( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetGiftCardResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetGiftCardResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/AsyncRawInventoryClient.java b/src/main/java/com/squareup/square/AsyncRawInventoryClient.java index 6de8d935..44379820 100644 --- a/src/main/java/com/squareup/square/AsyncRawInventoryClient.java +++ b/src/main/java/com/squareup/square/AsyncRawInventoryClient.java @@ -92,17 +92,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, GetInventoryAdjustmentResponse.class), + responseBody.string(), GetInventoryAdjustmentResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -152,17 +154,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, GetInventoryAdjustmentResponse.class), + responseBody.string(), GetInventoryAdjustmentResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -219,17 +223,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BatchChangeInventoryResponse.class), + responseBody.string(), BatchChangeInventoryResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -296,17 +302,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BatchGetInventoryChangesResponse.class), + responseBody.string(), BatchGetInventoryChangesResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -371,17 +379,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BatchGetInventoryCountsResponse.class), + responseBody.string(), BatchGetInventoryCountsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -442,17 +452,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BatchChangeInventoryResponse.class), + responseBody.string(), BatchChangeInventoryResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -530,10 +542,9 @@ public CompletableFuture startingAfter = parsedResponse.getCursor(); BatchRetrieveInventoryChangesRequest nextRequest = BatchRetrieveInventoryChangesRequest.builder() @@ -543,22 +554,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO List result = parsedResponse.getChanges().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return batchGetChanges(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return batchGetChanges(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -645,10 +658,9 @@ public CompletableFuture startingAfter = parsedResponse.getCursor(); BatchGetInventoryCountsRequest nextRequest = BatchGetInventoryCountsRequest.builder() .from(request) @@ -656,22 +668,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO .build(); List result = parsedResponse.getCounts().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return batchGetCounts(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return batchGetCounts(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -722,17 +736,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, GetInventoryPhysicalCountResponse.class), + responseBody.string(), GetInventoryPhysicalCountResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -783,17 +799,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, GetInventoryPhysicalCountResponse.class), + responseBody.string(), GetInventoryPhysicalCountResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -843,17 +861,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, GetInventoryTransferResponse.class), + responseBody.string(), GetInventoryTransferResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -915,10 +935,9 @@ public CompletableFuture startingAfter = parsedResponse.getCursor(); GetInventoryRequest nextRequest = GetInventoryRequest.builder() .from(request) @@ -926,22 +945,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO .build(); List result = parsedResponse.getCounts().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return get(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return get(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -1016,10 +1037,9 @@ public CompletableFuture startingAfter = parsedResponse.getCursor(); ChangesInventoryRequest nextRequest = ChangesInventoryRequest.builder() .from(request) @@ -1028,22 +1048,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO List result = parsedResponse.getChanges().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return changes(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return changes(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/AsyncRawInvoicesClient.java b/src/main/java/com/squareup/square/AsyncRawInvoicesClient.java index ef2153a8..68b3c5ad 100644 --- a/src/main/java/com/squareup/square/AsyncRawInvoicesClient.java +++ b/src/main/java/com/squareup/square/AsyncRawInvoicesClient.java @@ -104,10 +104,9 @@ public CompletableFuture>> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListInvoicesResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListInvoicesResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListInvoicesResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListInvoicesRequest nextRequest = ListInvoicesRequest.builder() .from(request) @@ -115,22 +114,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO .build(); List result = parsedResponse.getInvoices().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return list(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return list(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -190,16 +191,18 @@ public CompletableFuture> create @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateInvoiceResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateInvoiceResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -263,16 +266,19 @@ public CompletableFuture> searc @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, SearchInvoicesResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), SearchInvoicesResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -319,16 +325,18 @@ public CompletableFuture> get( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetInvoiceResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetInvoiceResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -389,16 +397,18 @@ public CompletableFuture> update @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateInvoiceResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UpdateInvoiceResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -452,16 +462,18 @@ public CompletableFuture> delete @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, DeleteInvoiceResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), DeleteInvoiceResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -505,10 +517,10 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateInvoiceAttachmentResponse.class), + responseBody.string(), CreateInvoiceAttachmentResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -603,17 +617,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DeleteInvoiceAttachmentResponse.class), + responseBody.string(), DeleteInvoiceAttachmentResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -673,16 +689,18 @@ public CompletableFuture> cancel @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CancelInvoiceResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CancelInvoiceResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -758,16 +776,19 @@ public CompletableFuture> publi @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, PublishInvoiceResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), PublishInvoiceResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/AsyncRawLaborClient.java b/src/main/java/com/squareup/square/AsyncRawLaborClient.java index 83fe68d1..8e7656bb 100644 --- a/src/main/java/com/squareup/square/AsyncRawLaborClient.java +++ b/src/main/java/com/squareup/square/AsyncRawLaborClient.java @@ -109,17 +109,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateScheduledShiftResponse.class), + responseBody.string(), CreateScheduledShiftResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -183,17 +185,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BulkPublishScheduledShiftsResponse.class), + responseBody.string(), BulkPublishScheduledShiftsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -258,17 +262,19 @@ public CompletableFuture @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, SearchScheduledShiftsResponse.class), + responseBody.string(), SearchScheduledShiftsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -316,17 +322,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, RetrieveScheduledShiftResponse.class), + responseBody.string(), RetrieveScheduledShiftResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -402,17 +410,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpdateScheduledShiftResponse.class), + responseBody.string(), UpdateScheduledShiftResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -471,17 +481,19 @@ public CompletableFuture @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, PublishScheduledShiftResponse.class), + responseBody.string(), PublishScheduledShiftResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -572,16 +584,19 @@ public CompletableFuture> creat @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateTimecardResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), CreateTimecardResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -691,16 +706,19 @@ public CompletableFuture> sear @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, SearchTimecardsResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), SearchTimecardsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -748,16 +766,19 @@ public CompletableFuture> ret @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, RetrieveTimecardResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), RetrieveTimecardResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -821,16 +842,19 @@ public CompletableFuture> updat @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateTimecardResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), UpdateTimecardResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -878,16 +902,19 @@ public CompletableFuture> delet @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, DeleteTimecardResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), DeleteTimecardResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/AsyncRawLocationsClient.java b/src/main/java/com/squareup/square/AsyncRawLocationsClient.java index 553bd8b3..879beddd 100644 --- a/src/main/java/com/squareup/square/AsyncRawLocationsClient.java +++ b/src/main/java/com/squareup/square/AsyncRawLocationsClient.java @@ -72,16 +72,18 @@ public CompletableFuture> list(R @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListLocationsResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListLocationsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -160,16 +162,19 @@ public CompletableFuture> creat @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateLocationResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), CreateLocationResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -218,16 +223,18 @@ public CompletableFuture> get( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetLocationResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetLocationResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -282,16 +289,19 @@ public CompletableFuture> updat @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateLocationResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), UpdateLocationResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -356,16 +366,19 @@ public CompletableFuture> check @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateCheckoutResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), CreateCheckoutResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/AsyncRawLoyaltyClient.java b/src/main/java/com/squareup/square/AsyncRawLoyaltyClient.java index aa31a3d1..2540f6f8 100644 --- a/src/main/java/com/squareup/square/AsyncRawLoyaltyClient.java +++ b/src/main/java/com/squareup/square/AsyncRawLoyaltyClient.java @@ -95,17 +95,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, SearchLoyaltyEventsResponse.class), + responseBody.string(), SearchLoyaltyEventsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/AsyncRawMerchantsClient.java b/src/main/java/com/squareup/square/AsyncRawMerchantsClient.java index 7683af5d..aede5fe7 100644 --- a/src/main/java/com/squareup/square/AsyncRawMerchantsClient.java +++ b/src/main/java/com/squareup/square/AsyncRawMerchantsClient.java @@ -102,10 +102,9 @@ public CompletableFuture>> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListMerchantsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListMerchantsResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListMerchantsResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListMerchantsRequest nextRequest = ListMerchantsRequest.builder() .from(request) @@ -113,22 +112,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO .build(); List result = parsedResponse.getMerchant().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return list(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return list(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -175,16 +176,18 @@ public CompletableFuture> get( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetMerchantResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetMerchantResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/AsyncRawMobileClient.java b/src/main/java/com/squareup/square/AsyncRawMobileClient.java index c6a5831b..aa10140d 100644 --- a/src/main/java/com/squareup/square/AsyncRawMobileClient.java +++ b/src/main/java/com/squareup/square/AsyncRawMobileClient.java @@ -105,17 +105,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateMobileAuthorizationCodeResponse.class), + responseBody.string(), CreateMobileAuthorizationCodeResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/AsyncRawOAuthClient.java b/src/main/java/com/squareup/square/AsyncRawOAuthClient.java index f05fe7e6..9d545ecd 100644 --- a/src/main/java/com/squareup/square/AsyncRawOAuthClient.java +++ b/src/main/java/com/squareup/square/AsyncRawOAuthClient.java @@ -106,16 +106,18 @@ public CompletableFuture> revokeTo @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, RevokeTokenResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), RevokeTokenResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -209,16 +211,18 @@ public CompletableFuture> obtainTo @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ObtainTokenResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ObtainTokenResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -278,17 +282,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, RetrieveTokenStatusResponse.class), + responseBody.string(), RetrieveTokenStatusResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -331,9 +337,11 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO return; } String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/AsyncRawOrdersClient.java b/src/main/java/com/squareup/square/AsyncRawOrdersClient.java index 990b8541..e0c695c7 100644 --- a/src/main/java/com/squareup/square/AsyncRawOrdersClient.java +++ b/src/main/java/com/squareup/square/AsyncRawOrdersClient.java @@ -105,16 +105,18 @@ public CompletableFuture> create( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateOrderResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateOrderResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -170,16 +172,19 @@ public CompletableFuture> batch @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, BatchGetOrdersResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), BatchGetOrdersResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -234,16 +239,19 @@ public CompletableFuture> calcu @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CalculateOrderResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), CalculateOrderResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -299,16 +307,18 @@ public CompletableFuture> clone( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CloneOrderResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CloneOrderResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -408,16 +418,18 @@ public CompletableFuture> search( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, SearchOrdersResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SearchOrdersResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -464,16 +476,18 @@ public CompletableFuture> get( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetOrderResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetOrderResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -554,16 +568,18 @@ public CompletableFuture> update( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateOrderResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UpdateOrderResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -643,16 +659,18 @@ public CompletableFuture> pay( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, PayOrderResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), PayOrderResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/AsyncRawPaymentsClient.java b/src/main/java/com/squareup/square/AsyncRawPaymentsClient.java index 7b191908..020f5c14 100644 --- a/src/main/java/com/squareup/square/AsyncRawPaymentsClient.java +++ b/src/main/java/com/squareup/square/AsyncRawPaymentsClient.java @@ -164,10 +164,9 @@ public CompletableFuture>> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListPaymentsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListPaymentsResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListPaymentsResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListPaymentsRequest nextRequest = ListPaymentsRequest.builder() .from(request) @@ -175,22 +174,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO .build(); List result = parsedResponse.getPayments().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return list(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return list(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -256,16 +257,18 @@ public CompletableFuture> create @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreatePaymentResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreatePaymentResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -337,17 +340,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CancelPaymentByIdempotencyKeyResponse.class), + responseBody.string(), CancelPaymentByIdempotencyKeyResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -394,16 +399,18 @@ public CompletableFuture> get( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetPaymentResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetPaymentResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -460,16 +467,18 @@ public CompletableFuture> update @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdatePaymentResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UpdatePaymentResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -519,16 +528,18 @@ public CompletableFuture> cancel @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CancelPaymentResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CancelPaymentResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -589,16 +600,19 @@ public CompletableFuture> comp @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CompletePaymentResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), CompletePaymentResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/AsyncRawPayoutsClient.java b/src/main/java/com/squareup/square/AsyncRawPayoutsClient.java index ff14e1d8..e0606eba 100644 --- a/src/main/java/com/squareup/square/AsyncRawPayoutsClient.java +++ b/src/main/java/com/squareup/square/AsyncRawPayoutsClient.java @@ -113,10 +113,9 @@ public CompletableFuture>> l @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListPayoutsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListPayoutsResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListPayoutsResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListPayoutsRequest nextRequest = ListPayoutsRequest.builder() .from(request) @@ -124,22 +123,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO .build(); List result = parsedResponse.getPayouts().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return list(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return list(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -188,16 +189,18 @@ public CompletableFuture> get( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetPayoutResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetPayoutResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -259,10 +262,9 @@ public CompletableFuture startingAfter = parsedResponse.getCursor(); ListEntriesPayoutsRequest nextRequest = ListEntriesPayoutsRequest.builder() .from(request) @@ -271,22 +273,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO List result = parsedResponse.getPayoutEntries().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return listEntries(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return listEntries(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/AsyncRawRefundsClient.java b/src/main/java/com/squareup/square/AsyncRawRefundsClient.java index af462e63..0080920b 100644 --- a/src/main/java/com/squareup/square/AsyncRawRefundsClient.java +++ b/src/main/java/com/squareup/square/AsyncRawRefundsClient.java @@ -142,10 +142,9 @@ public CompletableFuture startingAfter = parsedResponse.getCursor(); ListRefundsRequest nextRequest = ListRefundsRequest.builder() .from(request) @@ -153,22 +152,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO .build(); List result = parsedResponse.getRefunds().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return list(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return list(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -229,16 +230,18 @@ public CompletableFuture> refund @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, RefundPaymentResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), RefundPaymentResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -285,16 +288,19 @@ public CompletableFuture> get @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetPaymentRefundResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), GetPaymentRefundResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/AsyncRawSitesClient.java b/src/main/java/com/squareup/square/AsyncRawSitesClient.java index c0b0f0d3..815049af 100644 --- a/src/main/java/com/squareup/square/AsyncRawSitesClient.java +++ b/src/main/java/com/squareup/square/AsyncRawSitesClient.java @@ -61,16 +61,18 @@ public CompletableFuture> list(Reque @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListSitesResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListSitesResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/AsyncRawSnippetsClient.java b/src/main/java/com/squareup/square/AsyncRawSnippetsClient.java index 72ecbdcd..f9a112f3 100644 --- a/src/main/java/com/squareup/square/AsyncRawSnippetsClient.java +++ b/src/main/java/com/squareup/square/AsyncRawSnippetsClient.java @@ -74,16 +74,18 @@ public CompletableFuture> get( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetSnippetResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetSnippetResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -145,16 +147,18 @@ public CompletableFuture> upsert @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpsertSnippetResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UpsertSnippetResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -206,16 +210,18 @@ public CompletableFuture> delete @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, DeleteSnippetResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), DeleteSnippetResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/AsyncRawSubscriptionsClient.java b/src/main/java/com/squareup/square/AsyncRawSubscriptionsClient.java index d43b19c2..c2367a94 100644 --- a/src/main/java/com/squareup/square/AsyncRawSubscriptionsClient.java +++ b/src/main/java/com/squareup/square/AsyncRawSubscriptionsClient.java @@ -112,17 +112,19 @@ public CompletableFuture> c @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateSubscriptionResponse.class), + responseBody.string(), CreateSubscriptionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -178,16 +180,18 @@ public CompletableFuture> bulkSwa @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, BulkSwapPlanResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), BulkSwapPlanResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -282,17 +286,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, SearchSubscriptionsResponse.class), + responseBody.string(), SearchSubscriptionsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -342,16 +348,19 @@ public CompletableFuture> get( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetSubscriptionResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), GetSubscriptionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -409,17 +418,19 @@ public CompletableFuture> u @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpdateSubscriptionResponse.class), + responseBody.string(), UpdateSubscriptionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -470,17 +481,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DeleteSubscriptionActionResponse.class), + responseBody.string(), DeleteSubscriptionActionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -539,17 +552,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, ChangeBillingAnchorDateResponse.class), + responseBody.string(), ChangeBillingAnchorDateResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -602,17 +617,19 @@ public CompletableFuture> c @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CancelSubscriptionResponse.class), + responseBody.string(), CancelSubscriptionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -669,10 +686,9 @@ public CompletableFuture startingAfter = parsedResponse.getCursor(); ListEventsSubscriptionsRequest nextRequest = ListEventsSubscriptionsRequest.builder() .from(request) @@ -681,22 +697,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO List result = parsedResponse.getSubscriptionEvents().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return listEvents(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return listEvents(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -753,17 +771,19 @@ public CompletableFuture> pa @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, PauseSubscriptionResponse.class), + responseBody.string(), PauseSubscriptionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -820,17 +840,19 @@ public CompletableFuture> r @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, ResumeSubscriptionResponse.class), + responseBody.string(), ResumeSubscriptionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -888,16 +910,18 @@ public CompletableFuture> swapPlan( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, SwapPlanResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SwapPlanResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/AsyncRawTeamClient.java b/src/main/java/com/squareup/square/AsyncRawTeamClient.java index ac794200..31796e04 100644 --- a/src/main/java/com/squareup/square/AsyncRawTeamClient.java +++ b/src/main/java/com/squareup/square/AsyncRawTeamClient.java @@ -81,16 +81,18 @@ public CompletableFuture> listJobs( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListJobsResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListJobsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -146,16 +148,18 @@ public CompletableFuture> createJob( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateJobResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateJobResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -202,16 +206,18 @@ public CompletableFuture> retrieve @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, RetrieveJobResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), RetrieveJobResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -270,16 +276,18 @@ public CompletableFuture> updateJob( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateJobResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UpdateJobResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/AsyncRawTeamMembersClient.java b/src/main/java/com/squareup/square/AsyncRawTeamMembersClient.java index ee010008..0f8ae545 100644 --- a/src/main/java/com/squareup/square/AsyncRawTeamMembersClient.java +++ b/src/main/java/com/squareup/square/AsyncRawTeamMembersClient.java @@ -108,16 +108,19 @@ public CompletableFuture> cre @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateTeamMemberResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), CreateTeamMemberResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -180,17 +183,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BatchCreateTeamMembersResponse.class), + responseBody.string(), BatchCreateTeamMembersResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -253,17 +258,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BatchUpdateTeamMembersResponse.class), + responseBody.string(), BatchUpdateTeamMembersResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -331,17 +338,19 @@ public CompletableFuture> se @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, SearchTeamMembersResponse.class), + responseBody.string(), SearchTeamMembersResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -390,16 +399,18 @@ public CompletableFuture> get( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetTeamMemberResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetTeamMemberResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -457,16 +468,19 @@ public CompletableFuture> upd @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateTeamMemberResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), UpdateTeamMemberResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/AsyncRawTerminalClient.java b/src/main/java/com/squareup/square/AsyncRawTerminalClient.java index 79919945..db65a6c7 100644 --- a/src/main/java/com/squareup/square/AsyncRawTerminalClient.java +++ b/src/main/java/com/squareup/square/AsyncRawTerminalClient.java @@ -71,17 +71,19 @@ public CompletableFuture @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DismissTerminalActionResponse.class), + responseBody.string(), DismissTerminalActionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -130,17 +132,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DismissTerminalCheckoutResponse.class), + responseBody.string(), DismissTerminalCheckoutResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -189,17 +193,19 @@ public CompletableFuture @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DismissTerminalRefundResponse.class), + responseBody.string(), DismissTerminalRefundResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/AsyncRawTransferOrdersClient.java b/src/main/java/com/squareup/square/AsyncRawTransferOrdersClient.java deleted file mode 100644 index 467fc380..00000000 --- a/src/main/java/com/squareup/square/AsyncRawTransferOrdersClient.java +++ /dev/null @@ -1,734 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.squareup.square.core.ClientOptions; -import com.squareup.square.core.MediaTypes; -import com.squareup.square.core.ObjectMappers; -import com.squareup.square.core.QueryStringMapper; -import com.squareup.square.core.RequestOptions; -import com.squareup.square.core.SquareApiException; -import com.squareup.square.core.SquareClientHttpResponse; -import com.squareup.square.core.SquareException; -import com.squareup.square.core.SyncPagingIterable; -import com.squareup.square.types.CancelTransferOrderRequest; -import com.squareup.square.types.CancelTransferOrderResponse; -import com.squareup.square.types.CreateTransferOrderRequest; -import com.squareup.square.types.CreateTransferOrderResponse; -import com.squareup.square.types.DeleteTransferOrderResponse; -import com.squareup.square.types.DeleteTransferOrdersRequest; -import com.squareup.square.types.GetTransferOrdersRequest; -import com.squareup.square.types.ReceiveTransferOrderRequest; -import com.squareup.square.types.ReceiveTransferOrderResponse; -import com.squareup.square.types.RetrieveTransferOrderResponse; -import com.squareup.square.types.SearchTransferOrdersRequest; -import com.squareup.square.types.SearchTransferOrdersResponse; -import com.squareup.square.types.StartTransferOrderRequest; -import com.squareup.square.types.StartTransferOrderResponse; -import com.squareup.square.types.TransferOrder; -import com.squareup.square.types.UpdateTransferOrderRequest; -import com.squareup.square.types.UpdateTransferOrderResponse; -import java.io.IOException; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; -import okhttp3.Call; -import okhttp3.Callback; -import okhttp3.Headers; -import okhttp3.HttpUrl; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.RequestBody; -import okhttp3.Response; -import okhttp3.ResponseBody; -import org.jetbrains.annotations.NotNull; - -public class AsyncRawTransferOrdersClient { - protected final ClientOptions clientOptions; - - public AsyncRawTransferOrdersClient(ClientOptions clientOptions) { - this.clientOptions = clientOptions; - } - - /** - * Creates a new transfer order in DRAFT status. A transfer order represents the intent - * to move CatalogItemVariations from one Location to another. - * The source and destination locations must be different and must belong to your Square account. - *

In DRAFT status, you can:

- *
    - *
  • Add or remove items
  • - *
  • Modify quantities
  • - *
  • Update shipping information
  • - *
  • Delete the entire order via DeleteTransferOrder
  • - *
- *

The request requires source_location_id and destination_location_id. - * Inventory levels are not affected until the order is started via - * StartTransferOrder.

- *

Common integration points:

- *
    - *
  • Sync with warehouse management systems
  • - *
  • Automate regular stock transfers
  • - *
  • Initialize transfers from inventory optimization systems
  • - *
- *

Creates a transfer_order.created webhook event.

- */ - public CompletableFuture> create( - CreateTransferOrderRequest request) { - return create(request, null); - } - - /** - * Creates a new transfer order in DRAFT status. A transfer order represents the intent - * to move CatalogItemVariations from one Location to another. - * The source and destination locations must be different and must belong to your Square account. - *

In DRAFT status, you can:

- *
    - *
  • Add or remove items
  • - *
  • Modify quantities
  • - *
  • Update shipping information
  • - *
  • Delete the entire order via DeleteTransferOrder
  • - *
- *

The request requires source_location_id and destination_location_id. - * Inventory levels are not affected until the order is started via - * StartTransferOrder.

- *

Common integration points:

- *
    - *
  • Sync with warehouse management systems
  • - *
  • Automate regular stock transfers
  • - *
  • Initialize transfers from inventory optimization systems
  • - *
- *

Creates a transfer_order.created webhook event.

- */ - public CompletableFuture> create( - CreateTransferOrderRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("v2/transfer-orders") - .build(); - RequestBody body; - try { - body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); - } catch (JsonProcessingException e) { - throw new SquareException("Failed to serialize request", e); - } - Request okhttpRequest = new Request.Builder() - .url(httpUrl) - .method("POST", body) - .headers(Headers.of(clientOptions.headers(requestOptions))) - .addHeader("Content-Type", "application/json") - .addHeader("Accept", "application/json") - .build(); - OkHttpClient client = clientOptions.httpClient(); - if (requestOptions != null && requestOptions.getTimeout().isPresent()) { - client = clientOptions.httpClientWithTimeout(requestOptions); - } - CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { - @Override - public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { - try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateTransferOrderResponse.class), - response)); - return; - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); - return; - } catch (IOException e) { - future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); - } - } - - @Override - public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); - } - }); - return future; - } - - /** - * Searches for transfer orders using filters. Returns a paginated list of matching - * TransferOrders sorted by creation date. - *

Common search scenarios:

- * - */ - public CompletableFuture>> search() { - return search(SearchTransferOrdersRequest.builder().build()); - } - - /** - * Searches for transfer orders using filters. Returns a paginated list of matching - * TransferOrders sorted by creation date. - *

Common search scenarios:

- * - */ - public CompletableFuture>> search( - SearchTransferOrdersRequest request) { - return search(request, null); - } - - /** - * Searches for transfer orders using filters. Returns a paginated list of matching - * TransferOrders sorted by creation date. - *

Common search scenarios:

- * - */ - public CompletableFuture>> search( - SearchTransferOrdersRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("v2/transfer-orders/search") - .build(); - RequestBody body; - try { - body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); - } catch (JsonProcessingException e) { - throw new SquareException("Failed to serialize request", e); - } - Request okhttpRequest = new Request.Builder() - .url(httpUrl) - .method("POST", body) - .headers(Headers.of(clientOptions.headers(requestOptions))) - .addHeader("Content-Type", "application/json") - .addHeader("Accept", "application/json") - .build(); - OkHttpClient client = clientOptions.httpClient(); - if (requestOptions != null && requestOptions.getTimeout().isPresent()) { - client = clientOptions.httpClientWithTimeout(requestOptions); - } - CompletableFuture>> future = - new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { - @Override - public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { - try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - SearchTransferOrdersResponse parsedResponse = ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, SearchTransferOrdersResponse.class); - Optional startingAfter = parsedResponse.getCursor(); - SearchTransferOrdersRequest nextRequest = SearchTransferOrdersRequest.builder() - .from(request) - .cursor(startingAfter) - .build(); - List result = - parsedResponse.getTransferOrders().orElse(Collections.emptyList()); - future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return search(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), - response)); - return; - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); - return; - } catch (IOException e) { - future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); - } - } - - @Override - public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); - } - }); - return future; - } - - /** - * Retrieves a specific TransferOrder by ID. Returns the complete - * order details including: - *
    - *
  • Basic information (status, dates, notes)
  • - *
  • Line items with ordered and received quantities
  • - *
  • Source and destination Locations
  • - *
  • Tracking information (if available)
  • - *
- */ - public CompletableFuture> get( - GetTransferOrdersRequest request) { - return get(request, null); - } - - /** - * Retrieves a specific TransferOrder by ID. Returns the complete - * order details including: - *
    - *
  • Basic information (status, dates, notes)
  • - *
  • Line items with ordered and received quantities
  • - *
  • Source and destination Locations
  • - *
  • Tracking information (if available)
  • - *
- */ - public CompletableFuture> get( - GetTransferOrdersRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("v2/transfer-orders") - .addPathSegment(request.getTransferOrderId()) - .build(); - Request.Builder _requestBuilder = new Request.Builder() - .url(httpUrl) - .method("GET", null) - .headers(Headers.of(clientOptions.headers(requestOptions))) - .addHeader("Accept", "application/json"); - Request okhttpRequest = _requestBuilder.build(); - OkHttpClient client = clientOptions.httpClient(); - if (requestOptions != null && requestOptions.getTimeout().isPresent()) { - client = clientOptions.httpClientWithTimeout(requestOptions); - } - CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { - @Override - public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { - try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, RetrieveTransferOrderResponse.class), - response)); - return; - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); - return; - } catch (IOException e) { - future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); - } - } - - @Override - public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); - } - }); - return future; - } - - /** - * Updates an existing transfer order. This endpoint supports sparse updates, - * allowing you to modify specific fields without affecting others. - *

Creates a transfer_order.updated webhook event.

- */ - public CompletableFuture> update( - UpdateTransferOrderRequest request) { - return update(request, null); - } - - /** - * Updates an existing transfer order. This endpoint supports sparse updates, - * allowing you to modify specific fields without affecting others. - *

Creates a transfer_order.updated webhook event.

- */ - public CompletableFuture> update( - UpdateTransferOrderRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("v2/transfer-orders") - .addPathSegment(request.getTransferOrderId()) - .build(); - RequestBody body; - try { - body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); - } catch (JsonProcessingException e) { - throw new SquareException("Failed to serialize request", e); - } - Request okhttpRequest = new Request.Builder() - .url(httpUrl) - .method("PUT", body) - .headers(Headers.of(clientOptions.headers(requestOptions))) - .addHeader("Content-Type", "application/json") - .addHeader("Accept", "application/json") - .build(); - OkHttpClient client = clientOptions.httpClient(); - if (requestOptions != null && requestOptions.getTimeout().isPresent()) { - client = clientOptions.httpClientWithTimeout(requestOptions); - } - CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { - @Override - public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { - try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpdateTransferOrderResponse.class), - response)); - return; - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); - return; - } catch (IOException e) { - future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); - } - } - - @Override - public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); - } - }); - return future; - } - - /** - * Deletes a transfer order in DRAFT status. - * Only draft orders can be deleted. Once an order is started via - * StartTransferOrder, it can no longer be deleted. - *

Creates a transfer_order.deleted webhook event.

- */ - public CompletableFuture> delete( - DeleteTransferOrdersRequest request) { - return delete(request, null); - } - - /** - * Deletes a transfer order in DRAFT status. - * Only draft orders can be deleted. Once an order is started via - * StartTransferOrder, it can no longer be deleted. - *

Creates a transfer_order.deleted webhook event.

- */ - public CompletableFuture> delete( - DeleteTransferOrdersRequest request, RequestOptions requestOptions) { - HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("v2/transfer-orders") - .addPathSegment(request.getTransferOrderId()); - if (request.getVersion().isPresent()) { - QueryStringMapper.addQueryParameter( - httpUrl, "version", request.getVersion().get(), false); - } - Request.Builder _requestBuilder = new Request.Builder() - .url(httpUrl.build()) - .method("DELETE", null) - .headers(Headers.of(clientOptions.headers(requestOptions))) - .addHeader("Accept", "application/json"); - Request okhttpRequest = _requestBuilder.build(); - OkHttpClient client = clientOptions.httpClient(); - if (requestOptions != null && requestOptions.getTimeout().isPresent()) { - client = clientOptions.httpClientWithTimeout(requestOptions); - } - CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { - @Override - public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { - try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DeleteTransferOrderResponse.class), - response)); - return; - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); - return; - } catch (IOException e) { - future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); - } - } - - @Override - public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); - } - }); - return future; - } - - /** - * Cancels a transfer order in STARTED or - * PARTIALLY_RECEIVED status. Any unreceived quantities will no - * longer be receivable and will be immediately returned to the source Location's inventory. - *

Common reasons for cancellation:

- *
    - *
  • Items no longer needed at destination
  • - *
  • Source location needs the inventory
  • - *
  • Order created in error
  • - *
- *

Creates a transfer_order.updated webhook event.

- */ - public CompletableFuture> cancel( - CancelTransferOrderRequest request) { - return cancel(request, null); - } - - /** - * Cancels a transfer order in STARTED or - * PARTIALLY_RECEIVED status. Any unreceived quantities will no - * longer be receivable and will be immediately returned to the source Location's inventory. - *

Common reasons for cancellation:

- *
    - *
  • Items no longer needed at destination
  • - *
  • Source location needs the inventory
  • - *
  • Order created in error
  • - *
- *

Creates a transfer_order.updated webhook event.

- */ - public CompletableFuture> cancel( - CancelTransferOrderRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("v2/transfer-orders") - .addPathSegment(request.getTransferOrderId()) - .addPathSegments("cancel") - .build(); - RequestBody body; - try { - body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); - } catch (JsonProcessingException e) { - throw new SquareException("Failed to serialize request", e); - } - Request okhttpRequest = new Request.Builder() - .url(httpUrl) - .method("POST", body) - .headers(Headers.of(clientOptions.headers(requestOptions))) - .addHeader("Content-Type", "application/json") - .addHeader("Accept", "application/json") - .build(); - OkHttpClient client = clientOptions.httpClient(); - if (requestOptions != null && requestOptions.getTimeout().isPresent()) { - client = clientOptions.httpClientWithTimeout(requestOptions); - } - CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { - @Override - public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { - try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CancelTransferOrderResponse.class), - response)); - return; - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); - return; - } catch (IOException e) { - future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); - } - } - - @Override - public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); - } - }); - return future; - } - - /** - * Records receipt of CatalogItemVariations for a transfer order. - * This endpoint supports partial receiving - you can receive items in multiple batches. - *

For each line item, you can specify:

- *
    - *
  • Quantity received in good condition (added to destination inventory with InventoryState of IN_STOCK)
  • - *
  • Quantity damaged during transit/handling (added to destination inventory with InventoryState of WASTE)
  • - *
  • Quantity canceled (returned to source location's inventory)
  • - *
- *

The order must be in STARTED or PARTIALLY_RECEIVED status. - * Received quantities are added to the destination Location's inventory according to their condition. - * Canceled quantities are immediately returned to the source Location's inventory.

- *

When all items are either received, damaged, or canceled, the order moves to - * COMPLETED status.

- *

Creates a transfer_order.updated webhook event.

- */ - public CompletableFuture> receive( - ReceiveTransferOrderRequest request) { - return receive(request, null); - } - - /** - * Records receipt of CatalogItemVariations for a transfer order. - * This endpoint supports partial receiving - you can receive items in multiple batches. - *

For each line item, you can specify:

- *
    - *
  • Quantity received in good condition (added to destination inventory with InventoryState of IN_STOCK)
  • - *
  • Quantity damaged during transit/handling (added to destination inventory with InventoryState of WASTE)
  • - *
  • Quantity canceled (returned to source location's inventory)
  • - *
- *

The order must be in STARTED or PARTIALLY_RECEIVED status. - * Received quantities are added to the destination Location's inventory according to their condition. - * Canceled quantities are immediately returned to the source Location's inventory.

- *

When all items are either received, damaged, or canceled, the order moves to - * COMPLETED status.

- *

Creates a transfer_order.updated webhook event.

- */ - public CompletableFuture> receive( - ReceiveTransferOrderRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("v2/transfer-orders") - .addPathSegment(request.getTransferOrderId()) - .addPathSegments("receive") - .build(); - RequestBody body; - try { - body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); - } catch (JsonProcessingException e) { - throw new SquareException("Failed to serialize request", e); - } - Request okhttpRequest = new Request.Builder() - .url(httpUrl) - .method("POST", body) - .headers(Headers.of(clientOptions.headers(requestOptions))) - .addHeader("Content-Type", "application/json") - .addHeader("Accept", "application/json") - .build(); - OkHttpClient client = clientOptions.httpClient(); - if (requestOptions != null && requestOptions.getTimeout().isPresent()) { - client = clientOptions.httpClientWithTimeout(requestOptions); - } - CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { - @Override - public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { - try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, ReceiveTransferOrderResponse.class), - response)); - return; - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); - return; - } catch (IOException e) { - future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); - } - } - - @Override - public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); - } - }); - return future; - } - - /** - * Changes a DRAFT transfer order to STARTED status. - * This decrements inventory at the source Location and marks it as in-transit. - *

The order must be in DRAFT status and have all required fields populated. - * Once started, the order can no longer be deleted, but it can be canceled via - * CancelTransferOrder.

- *

Creates a transfer_order.updated webhook event.

- */ - public CompletableFuture> start( - StartTransferOrderRequest request) { - return start(request, null); - } - - /** - * Changes a DRAFT transfer order to STARTED status. - * This decrements inventory at the source Location and marks it as in-transit. - *

The order must be in DRAFT status and have all required fields populated. - * Once started, the order can no longer be deleted, but it can be canceled via - * CancelTransferOrder.

- *

Creates a transfer_order.updated webhook event.

- */ - public CompletableFuture> start( - StartTransferOrderRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("v2/transfer-orders") - .addPathSegment(request.getTransferOrderId()) - .addPathSegments("start") - .build(); - RequestBody body; - try { - body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); - } catch (JsonProcessingException e) { - throw new SquareException("Failed to serialize request", e); - } - Request okhttpRequest = new Request.Builder() - .url(httpUrl) - .method("POST", body) - .headers(Headers.of(clientOptions.headers(requestOptions))) - .addHeader("Content-Type", "application/json") - .addHeader("Accept", "application/json") - .build(); - OkHttpClient client = clientOptions.httpClient(); - if (requestOptions != null && requestOptions.getTimeout().isPresent()) { - client = clientOptions.httpClientWithTimeout(requestOptions); - } - CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { - @Override - public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { - try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, StartTransferOrderResponse.class), - response)); - return; - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); - return; - } catch (IOException e) { - future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); - } - } - - @Override - public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); - } - }); - return future; - } -} diff --git a/src/main/java/com/squareup/square/AsyncRawV1TransactionsClient.java b/src/main/java/com/squareup/square/AsyncRawV1TransactionsClient.java index e70ae07e..87313777 100644 --- a/src/main/java/com/squareup/square/AsyncRawV1TransactionsClient.java +++ b/src/main/java/com/squareup/square/AsyncRawV1TransactionsClient.java @@ -82,17 +82,19 @@ public CompletableFuture>> v1ListOrders( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, new TypeReference>() {}), + responseBody.string(), new TypeReference>() {}), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -141,15 +143,17 @@ public CompletableFuture> v1RetrieveOrder( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, V1Order.class), response)); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), V1Order.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -206,15 +210,17 @@ public CompletableFuture> v1UpdateOrder( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, V1Order.class), response)); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), V1Order.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/AsyncRawVendorsClient.java b/src/main/java/com/squareup/square/AsyncRawVendorsClient.java index 349d95d6..fd6cf515 100644 --- a/src/main/java/com/squareup/square/AsyncRawVendorsClient.java +++ b/src/main/java/com/squareup/square/AsyncRawVendorsClient.java @@ -85,17 +85,19 @@ public CompletableFuture> b @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BatchCreateVendorsResponse.class), + responseBody.string(), BatchCreateVendorsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -157,16 +159,19 @@ public CompletableFuture> batc @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, BatchGetVendorsResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), BatchGetVendorsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -221,17 +226,19 @@ public CompletableFuture> b @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BatchUpdateVendorsResponse.class), + responseBody.string(), BatchUpdateVendorsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -285,16 +292,18 @@ public CompletableFuture> create( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateVendorResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateVendorResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -355,16 +364,18 @@ public CompletableFuture> search @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, SearchVendorsResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SearchVendorsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -411,16 +422,18 @@ public CompletableFuture> get( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetVendorResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetVendorResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -475,16 +488,18 @@ public CompletableFuture> update( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateVendorResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UpdateVendorResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/AsyncSquareClient.java b/src/main/java/com/squareup/square/AsyncSquareClient.java index c78a23b4..c307ebea 100644 --- a/src/main/java/com/squareup/square/AsyncSquareClient.java +++ b/src/main/java/com/squareup/square/AsyncSquareClient.java @@ -28,8 +28,6 @@ public class AsyncSquareClient { protected final Supplier catalogClient; - protected final Supplier channelsClient; - protected final Supplier customersClient; protected final Supplier devicesClient; @@ -76,8 +74,6 @@ public class AsyncSquareClient { protected final Supplier terminalClient; - protected final Supplier transferOrdersClient; - protected final Supplier vendorsClient; protected final Supplier cashDrawersClient; @@ -94,7 +90,6 @@ public AsyncSquareClient(ClientOptions clientOptions) { this.bookingsClient = Suppliers.memoize(() -> new AsyncBookingsClient(clientOptions)); this.cardsClient = Suppliers.memoize(() -> new AsyncCardsClient(clientOptions)); this.catalogClient = Suppliers.memoize(() -> new AsyncCatalogClient(clientOptions)); - this.channelsClient = Suppliers.memoize(() -> new AsyncChannelsClient(clientOptions)); this.customersClient = Suppliers.memoize(() -> new AsyncCustomersClient(clientOptions)); this.devicesClient = Suppliers.memoize(() -> new AsyncDevicesClient(clientOptions)); this.disputesClient = Suppliers.memoize(() -> new AsyncDisputesClient(clientOptions)); @@ -118,7 +113,6 @@ public AsyncSquareClient(ClientOptions clientOptions) { this.teamMembersClient = Suppliers.memoize(() -> new AsyncTeamMembersClient(clientOptions)); this.teamClient = Suppliers.memoize(() -> new AsyncTeamClient(clientOptions)); this.terminalClient = Suppliers.memoize(() -> new AsyncTerminalClient(clientOptions)); - this.transferOrdersClient = Suppliers.memoize(() -> new AsyncTransferOrdersClient(clientOptions)); this.vendorsClient = Suppliers.memoize(() -> new AsyncVendorsClient(clientOptions)); this.cashDrawersClient = Suppliers.memoize(() -> new AsyncCashDrawersClient(clientOptions)); this.webhooksClient = Suppliers.memoize(() -> new AsyncWebhooksClient(clientOptions)); @@ -156,10 +150,6 @@ public AsyncCatalogClient catalog() { return this.catalogClient.get(); } - public AsyncChannelsClient channels() { - return this.channelsClient.get(); - } - public AsyncCustomersClient customers() { return this.customersClient.get(); } @@ -252,10 +242,6 @@ public AsyncTerminalClient terminal() { return this.terminalClient.get(); } - public AsyncTransferOrdersClient transferOrders() { - return this.transferOrdersClient.get(); - } - public AsyncVendorsClient vendors() { return this.vendorsClient.get(); } diff --git a/src/main/java/com/squareup/square/AsyncSquareClientBuilder.java b/src/main/java/com/squareup/square/AsyncSquareClientBuilder.java index 2c0155a9..80385816 100644 --- a/src/main/java/com/squareup/square/AsyncSquareClientBuilder.java +++ b/src/main/java/com/squareup/square/AsyncSquareClientBuilder.java @@ -5,26 +5,17 @@ import com.squareup.square.core.ClientOptions; import com.squareup.square.core.Environment; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; import okhttp3.OkHttpClient; -public class AsyncSquareClientBuilder { - private Optional timeout = Optional.empty(); - - private Optional maxRetries = Optional.empty(); - - private final Map customHeaders = new HashMap<>(); +public final class AsyncSquareClientBuilder { + private ClientOptions.Builder clientOptionsBuilder = ClientOptions.builder(); private String token = System.getenv("SQUARE_TOKEN"); - private String version = "2025-10-16"; + private String version = "2025-07-16"; private Environment environment = Environment.PRODUCTION; - private OkHttpClient httpClient; - /** * Sets token. * Defaults to the SQUARE_TOKEN environment variable. @@ -56,7 +47,7 @@ public AsyncSquareClientBuilder url(String url) { * Sets the timeout (in seconds) for the client. Defaults to 60 seconds. */ public AsyncSquareClientBuilder timeout(int timeout) { - this.timeout = Optional.of(timeout); + this.clientOptionsBuilder.timeout(timeout); return this; } @@ -64,7 +55,7 @@ public AsyncSquareClientBuilder timeout(int timeout) { * Sets the maximum number of retries for the client. Defaults to 2 retries. */ public AsyncSquareClientBuilder maxRetries(int maxRetries) { - this.maxRetries = Optional.of(maxRetries); + this.clientOptionsBuilder.maxRetries(maxRetries); return this; } @@ -72,162 +63,14 @@ public AsyncSquareClientBuilder maxRetries(int maxRetries) { * Sets the underlying OkHttp client */ public AsyncSquareClientBuilder httpClient(OkHttpClient httpClient) { - this.httpClient = httpClient; - return this; - } - - /** - * Add a custom header to be sent with all requests. - * For headers that need to be computed dynamically or conditionally, use the setAdditional() method override instead. - * - * @param name The header name - * @param value The header value - * @return This builder for method chaining - */ - public AsyncSquareClientBuilder addHeader(String name, String value) { - this.customHeaders.put(name, value); + this.clientOptionsBuilder.httpClient(httpClient); return this; } - protected ClientOptions buildClientOptions() { - ClientOptions.Builder builder = ClientOptions.builder(); - setEnvironment(builder); - setAuthentication(builder); - setCustomHeaders(builder); - setHttpClient(builder); - setTimeouts(builder); - setRetries(builder); - for (Map.Entry header : this.customHeaders.entrySet()) { - builder.addHeader(header.getKey(), header.getValue()); - } - setAdditional(builder); - return builder.build(); - } - - /** - * Sets the environment configuration for the client. - * Override this method to modify URLs or add environment-specific logic. - * - * @param builder The ClientOptions.Builder to configure - */ - protected void setEnvironment(ClientOptions.Builder builder) { - builder.environment(this.environment); - } - - /** - * Override this method to customize authentication. - * This method is called during client options construction to set up authentication headers. - * - * @param builder The ClientOptions.Builder to configure - * - * Example: - *
{@code
-     * @Override
-     * protected void setAuthentication(ClientOptions.Builder builder) {
-     *     super.setAuthentication(builder); // Keep existing auth
-     *     builder.addHeader("X-API-Key", this.apiKey);
-     * }
-     * }
- */ - protected void setAuthentication(ClientOptions.Builder builder) { - if (this.token != null) { - builder.addHeader("Authorization", "Bearer " + this.token); - } - } - - /** - * Override this method to add or modify custom headers. - * This method is called during client options construction to set up custom headers defined in the API. - * - * @param builder The ClientOptions.Builder to configure - * - * Example: - *
{@code
-     * @Override
-     * protected void setCustomHeaders(ClientOptions.Builder builder) {
-     *     super.setCustomHeaders(builder); // Keep existing headers
-     *     builder.addHeader("X-Trace-ID", generateTraceId());
-     * }
-     * }
- */ - protected void setCustomHeaders(ClientOptions.Builder builder) { - builder.addHeader("Square-Version", this.version); - } - - /** - * Sets the request timeout configuration. - * Override this method to customize timeout behavior. - * - * @param builder The ClientOptions.Builder to configure - */ - protected void setTimeouts(ClientOptions.Builder builder) { - if (this.timeout.isPresent()) { - builder.timeout(this.timeout.get()); - } - } - - /** - * Sets the retry configuration for failed requests. - * Override this method to implement custom retry strategies. - * - * @param builder The ClientOptions.Builder to configure - */ - protected void setRetries(ClientOptions.Builder builder) { - if (this.maxRetries.isPresent()) { - builder.maxRetries(this.maxRetries.get()); - } - } - - /** - * Sets the OkHttp client configuration. - * Override this method to customize HTTP client behavior (interceptors, connection pools, etc). - * - * @param builder The ClientOptions.Builder to configure - */ - protected void setHttpClient(ClientOptions.Builder builder) { - if (this.httpClient != null) { - builder.httpClient(this.httpClient); - } - } - - /** - * Override this method to add any additional configuration to the client. - * This method is called at the end of the configuration chain, allowing you to add - * custom headers, modify settings, or perform any other client customization. - * - * @param builder The ClientOptions.Builder to configure - * - * Example: - *
{@code
-     * @Override
-     * protected void setAdditional(ClientOptions.Builder builder) {
-     *     builder.addHeader("X-Request-ID", () -> UUID.randomUUID().toString());
-     *     builder.addHeader("X-Client-Version", "1.0.0");
-     * }
-     * }
- */ - protected void setAdditional(ClientOptions.Builder builder) {} - - /** - * Override this method to add custom validation logic before the client is built. - * This method is called at the beginning of the build() method to ensure the configuration is valid. - * Throw an exception to prevent client creation if validation fails. - * - * Example: - *
{@code
-     * @Override
-     * protected void validateConfiguration() {
-     *     super.validateConfiguration(); // Run parent validations
-     *     if (tenantId == null || tenantId.isEmpty()) {
-     *         throw new IllegalStateException("tenantId is required");
-     *     }
-     * }
-     * }
- */ - protected void validateConfiguration() {} - public AsyncSquareClient build() { - validateConfiguration(); - return new AsyncSquareClient(buildClientOptions()); + this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + this.token); + this.clientOptionsBuilder.addHeader("Square-Version", this.version); + clientOptionsBuilder.environment(this.environment); + return new AsyncSquareClient(clientOptionsBuilder.build()); } } diff --git a/src/main/java/com/squareup/square/AsyncTransferOrdersClient.java b/src/main/java/com/squareup/square/AsyncTransferOrdersClient.java deleted file mode 100644 index 356796b9..00000000 --- a/src/main/java/com/squareup/square/AsyncTransferOrdersClient.java +++ /dev/null @@ -1,307 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square; - -import com.squareup.square.core.ClientOptions; -import com.squareup.square.core.RequestOptions; -import com.squareup.square.core.SyncPagingIterable; -import com.squareup.square.types.CancelTransferOrderRequest; -import com.squareup.square.types.CancelTransferOrderResponse; -import com.squareup.square.types.CreateTransferOrderRequest; -import com.squareup.square.types.CreateTransferOrderResponse; -import com.squareup.square.types.DeleteTransferOrderResponse; -import com.squareup.square.types.DeleteTransferOrdersRequest; -import com.squareup.square.types.GetTransferOrdersRequest; -import com.squareup.square.types.ReceiveTransferOrderRequest; -import com.squareup.square.types.ReceiveTransferOrderResponse; -import com.squareup.square.types.RetrieveTransferOrderResponse; -import com.squareup.square.types.SearchTransferOrdersRequest; -import com.squareup.square.types.StartTransferOrderRequest; -import com.squareup.square.types.StartTransferOrderResponse; -import com.squareup.square.types.TransferOrder; -import com.squareup.square.types.UpdateTransferOrderRequest; -import com.squareup.square.types.UpdateTransferOrderResponse; -import java.util.concurrent.CompletableFuture; - -public class AsyncTransferOrdersClient { - protected final ClientOptions clientOptions; - - private final AsyncRawTransferOrdersClient rawClient; - - public AsyncTransferOrdersClient(ClientOptions clientOptions) { - this.clientOptions = clientOptions; - this.rawClient = new AsyncRawTransferOrdersClient(clientOptions); - } - - /** - * Get responses with HTTP metadata like headers - */ - public AsyncRawTransferOrdersClient withRawResponse() { - return this.rawClient; - } - - /** - * Creates a new transfer order in DRAFT status. A transfer order represents the intent - * to move CatalogItemVariations from one Location to another. - * The source and destination locations must be different and must belong to your Square account. - *

In DRAFT status, you can:

- *
    - *
  • Add or remove items
  • - *
  • Modify quantities
  • - *
  • Update shipping information
  • - *
  • Delete the entire order via DeleteTransferOrder
  • - *
- *

The request requires source_location_id and destination_location_id. - * Inventory levels are not affected until the order is started via - * StartTransferOrder.

- *

Common integration points:

- *
    - *
  • Sync with warehouse management systems
  • - *
  • Automate regular stock transfers
  • - *
  • Initialize transfers from inventory optimization systems
  • - *
- *

Creates a transfer_order.created webhook event.

- */ - public CompletableFuture create(CreateTransferOrderRequest request) { - return this.rawClient.create(request).thenApply(response -> response.body()); - } - - /** - * Creates a new transfer order in DRAFT status. A transfer order represents the intent - * to move CatalogItemVariations from one Location to another. - * The source and destination locations must be different and must belong to your Square account. - *

In DRAFT status, you can:

- *
    - *
  • Add or remove items
  • - *
  • Modify quantities
  • - *
  • Update shipping information
  • - *
  • Delete the entire order via DeleteTransferOrder
  • - *
- *

The request requires source_location_id and destination_location_id. - * Inventory levels are not affected until the order is started via - * StartTransferOrder.

- *

Common integration points:

- *
    - *
  • Sync with warehouse management systems
  • - *
  • Automate regular stock transfers
  • - *
  • Initialize transfers from inventory optimization systems
  • - *
- *

Creates a transfer_order.created webhook event.

- */ - public CompletableFuture create( - CreateTransferOrderRequest request, RequestOptions requestOptions) { - return this.rawClient.create(request, requestOptions).thenApply(response -> response.body()); - } - - /** - * Searches for transfer orders using filters. Returns a paginated list of matching - * TransferOrders sorted by creation date. - *

Common search scenarios:

- * - */ - public CompletableFuture> search() { - return this.rawClient.search().thenApply(response -> response.body()); - } - - /** - * Searches for transfer orders using filters. Returns a paginated list of matching - * TransferOrders sorted by creation date. - *

Common search scenarios:

- * - */ - public CompletableFuture> search(SearchTransferOrdersRequest request) { - return this.rawClient.search(request).thenApply(response -> response.body()); - } - - /** - * Searches for transfer orders using filters. Returns a paginated list of matching - * TransferOrders sorted by creation date. - *

Common search scenarios:

- * - */ - public CompletableFuture> search( - SearchTransferOrdersRequest request, RequestOptions requestOptions) { - return this.rawClient.search(request, requestOptions).thenApply(response -> response.body()); - } - - /** - * Retrieves a specific TransferOrder by ID. Returns the complete - * order details including: - *
    - *
  • Basic information (status, dates, notes)
  • - *
  • Line items with ordered and received quantities
  • - *
  • Source and destination Locations
  • - *
  • Tracking information (if available)
  • - *
- */ - public CompletableFuture get(GetTransferOrdersRequest request) { - return this.rawClient.get(request).thenApply(response -> response.body()); - } - - /** - * Retrieves a specific TransferOrder by ID. Returns the complete - * order details including: - *
    - *
  • Basic information (status, dates, notes)
  • - *
  • Line items with ordered and received quantities
  • - *
  • Source and destination Locations
  • - *
  • Tracking information (if available)
  • - *
- */ - public CompletableFuture get( - GetTransferOrdersRequest request, RequestOptions requestOptions) { - return this.rawClient.get(request, requestOptions).thenApply(response -> response.body()); - } - - /** - * Updates an existing transfer order. This endpoint supports sparse updates, - * allowing you to modify specific fields without affecting others. - *

Creates a transfer_order.updated webhook event.

- */ - public CompletableFuture update(UpdateTransferOrderRequest request) { - return this.rawClient.update(request).thenApply(response -> response.body()); - } - - /** - * Updates an existing transfer order. This endpoint supports sparse updates, - * allowing you to modify specific fields without affecting others. - *

Creates a transfer_order.updated webhook event.

- */ - public CompletableFuture update( - UpdateTransferOrderRequest request, RequestOptions requestOptions) { - return this.rawClient.update(request, requestOptions).thenApply(response -> response.body()); - } - - /** - * Deletes a transfer order in DRAFT status. - * Only draft orders can be deleted. Once an order is started via - * StartTransferOrder, it can no longer be deleted. - *

Creates a transfer_order.deleted webhook event.

- */ - public CompletableFuture delete(DeleteTransferOrdersRequest request) { - return this.rawClient.delete(request).thenApply(response -> response.body()); - } - - /** - * Deletes a transfer order in DRAFT status. - * Only draft orders can be deleted. Once an order is started via - * StartTransferOrder, it can no longer be deleted. - *

Creates a transfer_order.deleted webhook event.

- */ - public CompletableFuture delete( - DeleteTransferOrdersRequest request, RequestOptions requestOptions) { - return this.rawClient.delete(request, requestOptions).thenApply(response -> response.body()); - } - - /** - * Cancels a transfer order in STARTED or - * PARTIALLY_RECEIVED status. Any unreceived quantities will no - * longer be receivable and will be immediately returned to the source Location's inventory. - *

Common reasons for cancellation:

- *
    - *
  • Items no longer needed at destination
  • - *
  • Source location needs the inventory
  • - *
  • Order created in error
  • - *
- *

Creates a transfer_order.updated webhook event.

- */ - public CompletableFuture cancel(CancelTransferOrderRequest request) { - return this.rawClient.cancel(request).thenApply(response -> response.body()); - } - - /** - * Cancels a transfer order in STARTED or - * PARTIALLY_RECEIVED status. Any unreceived quantities will no - * longer be receivable and will be immediately returned to the source Location's inventory. - *

Common reasons for cancellation:

- *
    - *
  • Items no longer needed at destination
  • - *
  • Source location needs the inventory
  • - *
  • Order created in error
  • - *
- *

Creates a transfer_order.updated webhook event.

- */ - public CompletableFuture cancel( - CancelTransferOrderRequest request, RequestOptions requestOptions) { - return this.rawClient.cancel(request, requestOptions).thenApply(response -> response.body()); - } - - /** - * Records receipt of CatalogItemVariations for a transfer order. - * This endpoint supports partial receiving - you can receive items in multiple batches. - *

For each line item, you can specify:

- *
    - *
  • Quantity received in good condition (added to destination inventory with InventoryState of IN_STOCK)
  • - *
  • Quantity damaged during transit/handling (added to destination inventory with InventoryState of WASTE)
  • - *
  • Quantity canceled (returned to source location's inventory)
  • - *
- *

The order must be in STARTED or PARTIALLY_RECEIVED status. - * Received quantities are added to the destination Location's inventory according to their condition. - * Canceled quantities are immediately returned to the source Location's inventory.

- *

When all items are either received, damaged, or canceled, the order moves to - * COMPLETED status.

- *

Creates a transfer_order.updated webhook event.

- */ - public CompletableFuture receive(ReceiveTransferOrderRequest request) { - return this.rawClient.receive(request).thenApply(response -> response.body()); - } - - /** - * Records receipt of CatalogItemVariations for a transfer order. - * This endpoint supports partial receiving - you can receive items in multiple batches. - *

For each line item, you can specify:

- *
    - *
  • Quantity received in good condition (added to destination inventory with InventoryState of IN_STOCK)
  • - *
  • Quantity damaged during transit/handling (added to destination inventory with InventoryState of WASTE)
  • - *
  • Quantity canceled (returned to source location's inventory)
  • - *
- *

The order must be in STARTED or PARTIALLY_RECEIVED status. - * Received quantities are added to the destination Location's inventory according to their condition. - * Canceled quantities are immediately returned to the source Location's inventory.

- *

When all items are either received, damaged, or canceled, the order moves to - * COMPLETED status.

- *

Creates a transfer_order.updated webhook event.

- */ - public CompletableFuture receive( - ReceiveTransferOrderRequest request, RequestOptions requestOptions) { - return this.rawClient.receive(request, requestOptions).thenApply(response -> response.body()); - } - - /** - * Changes a DRAFT transfer order to STARTED status. - * This decrements inventory at the source Location and marks it as in-transit. - *

The order must be in DRAFT status and have all required fields populated. - * Once started, the order can no longer be deleted, but it can be canceled via - * CancelTransferOrder.

- *

Creates a transfer_order.updated webhook event.

- */ - public CompletableFuture start(StartTransferOrderRequest request) { - return this.rawClient.start(request).thenApply(response -> response.body()); - } - - /** - * Changes a DRAFT transfer order to STARTED status. - * This decrements inventory at the source Location and marks it as in-transit. - *

The order must be in DRAFT status and have all required fields populated. - * Once started, the order can no longer be deleted, but it can be canceled via - * CancelTransferOrder.

- *

Creates a transfer_order.updated webhook event.

- */ - public CompletableFuture start( - StartTransferOrderRequest request, RequestOptions requestOptions) { - return this.rawClient.start(request, requestOptions).thenApply(response -> response.body()); - } -} diff --git a/src/main/java/com/squareup/square/ChannelsClient.java b/src/main/java/com/squareup/square/ChannelsClient.java deleted file mode 100644 index 0d74ed7c..00000000 --- a/src/main/java/com/squareup/square/ChannelsClient.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square; - -import com.squareup.square.core.ClientOptions; -import com.squareup.square.core.RequestOptions; -import com.squareup.square.core.SyncPagingIterable; -import com.squareup.square.types.BulkRetrieveChannelsRequest; -import com.squareup.square.types.BulkRetrieveChannelsResponse; -import com.squareup.square.types.Channel; -import com.squareup.square.types.GetChannelsRequest; -import com.squareup.square.types.ListChannelsRequest; -import com.squareup.square.types.RetrieveChannelResponse; - -public class ChannelsClient { - protected final ClientOptions clientOptions; - - private final RawChannelsClient rawClient; - - public ChannelsClient(ClientOptions clientOptions) { - this.clientOptions = clientOptions; - this.rawClient = new RawChannelsClient(clientOptions); - } - - /** - * Get responses with HTTP metadata like headers - */ - public RawChannelsClient withRawResponse() { - return this.rawClient; - } - - public SyncPagingIterable list() { - return this.rawClient.list().body(); - } - - public SyncPagingIterable list(ListChannelsRequest request) { - return this.rawClient.list(request).body(); - } - - public SyncPagingIterable list(ListChannelsRequest request, RequestOptions requestOptions) { - return this.rawClient.list(request, requestOptions).body(); - } - - public BulkRetrieveChannelsResponse bulkRetrieve(BulkRetrieveChannelsRequest request) { - return this.rawClient.bulkRetrieve(request).body(); - } - - public BulkRetrieveChannelsResponse bulkRetrieve( - BulkRetrieveChannelsRequest request, RequestOptions requestOptions) { - return this.rawClient.bulkRetrieve(request, requestOptions).body(); - } - - public RetrieveChannelResponse get(GetChannelsRequest request) { - return this.rawClient.get(request).body(); - } - - public RetrieveChannelResponse get(GetChannelsRequest request, RequestOptions requestOptions) { - return this.rawClient.get(request, requestOptions).body(); - } -} diff --git a/src/main/java/com/squareup/square/RawApplePayClient.java b/src/main/java/com/squareup/square/RawApplePayClient.java index 79cef207..863ef5d1 100644 --- a/src/main/java/com/squareup/square/RawApplePayClient.java +++ b/src/main/java/com/squareup/square/RawApplePayClient.java @@ -85,15 +85,17 @@ public SquareClientHttpResponse registerDomain( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, RegisterDomainResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), RegisterDomainResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/RawBankAccountsClient.java b/src/main/java/com/squareup/square/RawBankAccountsClient.java index 8e79642c..bf164777 100644 --- a/src/main/java/com/squareup/square/RawBankAccountsClient.java +++ b/src/main/java/com/squareup/square/RawBankAccountsClient.java @@ -82,10 +82,9 @@ public SquareClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListBankAccountsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListBankAccountsResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListBankAccountsResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListBankAccountsRequest nextRequest = ListBankAccountsRequest.builder() .from(request) @@ -94,14 +93,16 @@ public SquareClientHttpResponse> list( List result = parsedResponse.getBankAccounts().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -136,15 +137,17 @@ public SquareClientHttpResponse getByV1Id( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetBankAccountByV1IdResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetBankAccountByV1IdResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -181,15 +184,17 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetBankAccountResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetBankAccountResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/RawBookingsClient.java b/src/main/java/com/squareup/square/RawBookingsClient.java index c02a19d7..eff90ec7 100644 --- a/src/main/java/com/squareup/square/RawBookingsClient.java +++ b/src/main/java/com/squareup/square/RawBookingsClient.java @@ -120,10 +120,9 @@ public SquareClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListBookingsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListBookingsResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListBookingsResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListBookingsRequest nextRequest = ListBookingsRequest.builder() .from(request) @@ -131,14 +130,17 @@ public SquareClientHttpResponse> list( .build(); List result = parsedResponse.getBookings().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( - new SyncPagingIterable(startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) - .body()), + new SyncPagingIterable( + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) + .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -204,14 +206,17 @@ public SquareClientHttpResponse create( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateBookingResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateBookingResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -257,15 +262,17 @@ public SquareClientHttpResponse searchAvailability( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, SearchAvailabilityResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SearchAvailabilityResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -312,15 +319,17 @@ public SquareClientHttpResponse bulkRetrieveBookin } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, BulkRetrieveBookingsResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), BulkRetrieveBookingsResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -354,16 +363,18 @@ public SquareClientHttpResponse getBusinessPr } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, GetBusinessBookingProfileResponse.class), + responseBody.string(), GetBusinessBookingProfileResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -399,16 +410,18 @@ public SquareClientHttpResponse retrieve } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, RetrieveLocationBookingProfileResponse.class), + responseBody.string(), RetrieveLocationBookingProfileResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -452,16 +465,18 @@ public SquareClientHttpResponse retrieve } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BulkRetrieveTeamMemberBookingProfilesResponse.class), + responseBody.string(), BulkRetrieveTeamMemberBookingProfilesResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -499,14 +514,16 @@ public SquareClientHttpResponse get(GetBookingsRequest reque } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetBookingResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetBookingResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -557,14 +574,17 @@ public SquareClientHttpResponse update( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateBookingResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UpdateBookingResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -616,14 +636,17 @@ public SquareClientHttpResponse cancel( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CancelBookingResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CancelBookingResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/RawCardsClient.java b/src/main/java/com/squareup/square/RawCardsClient.java index d5c28c01..90cc30d1 100644 --- a/src/main/java/com/squareup/square/RawCardsClient.java +++ b/src/main/java/com/squareup/square/RawCardsClient.java @@ -98,10 +98,9 @@ public SquareClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListCardsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListCardsResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListCardsResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListCardsRequest nextRequest = ListCardsRequest.builder() .from(request) @@ -109,14 +108,17 @@ public SquareClientHttpResponse> list( .build(); List result = parsedResponse.getCards().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( - new SyncPagingIterable(startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) - .body()), + new SyncPagingIterable( + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) + .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -158,14 +160,16 @@ public SquareClientHttpResponse create( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateCardResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateCardResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -199,14 +203,16 @@ public SquareClientHttpResponse get(GetCardsRequest request, Re } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetCardResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetCardResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -244,14 +250,17 @@ public SquareClientHttpResponse disable( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, DisableCardResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), DisableCardResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/RawCatalogClient.java b/src/main/java/com/squareup/square/RawCatalogClient.java index 9fdd259f..ba0faa9e 100644 --- a/src/main/java/com/squareup/square/RawCatalogClient.java +++ b/src/main/java/com/squareup/square/RawCatalogClient.java @@ -109,16 +109,18 @@ public SquareClientHttpResponse batchDelete( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BatchDeleteCatalogObjectsResponse.class), + responseBody.string(), BatchDeleteCatalogObjectsResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -170,15 +172,18 @@ public SquareClientHttpResponse batchGet( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, BatchGetCatalogObjectsResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), BatchGetCatalogObjectsResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -243,16 +248,18 @@ public SquareClientHttpResponse batchUpsert( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BatchUpsertCatalogObjectsResponse.class), + responseBody.string(), BatchUpsertCatalogObjectsResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -287,14 +294,17 @@ public SquareClientHttpResponse info(RequestOptions request } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CatalogInfoResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CatalogInfoResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -361,10 +371,9 @@ public SquareClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListCatalogResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListCatalogResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListCatalogResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListCatalogRequest nextRequest = ListCatalogRequest.builder() .from(request) @@ -373,14 +382,16 @@ public SquareClientHttpResponse> list( List result = parsedResponse.getObjects().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -456,15 +467,17 @@ public SquareClientHttpResponse search( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, SearchCatalogObjectsResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SearchCatalogObjectsResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -540,15 +553,17 @@ public SquareClientHttpResponse searchItems( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, SearchCatalogItemsResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SearchCatalogItemsResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -595,15 +610,18 @@ public SquareClientHttpResponse updateItemModif } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateItemModifierListsResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), UpdateItemModifierListsResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -649,15 +667,17 @@ public SquareClientHttpResponse updateItemTaxes( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateItemTaxesResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UpdateItemTaxesResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/RawChannelsClient.java b/src/main/java/com/squareup/square/RawChannelsClient.java deleted file mode 100644 index f30fe1a7..00000000 --- a/src/main/java/com/squareup/square/RawChannelsClient.java +++ /dev/null @@ -1,191 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.squareup.square.core.ClientOptions; -import com.squareup.square.core.MediaTypes; -import com.squareup.square.core.ObjectMappers; -import com.squareup.square.core.QueryStringMapper; -import com.squareup.square.core.RequestOptions; -import com.squareup.square.core.SquareApiException; -import com.squareup.square.core.SquareClientHttpResponse; -import com.squareup.square.core.SquareException; -import com.squareup.square.core.SyncPagingIterable; -import com.squareup.square.types.BulkRetrieveChannelsRequest; -import com.squareup.square.types.BulkRetrieveChannelsResponse; -import com.squareup.square.types.Channel; -import com.squareup.square.types.GetChannelsRequest; -import com.squareup.square.types.ListChannelsRequest; -import com.squareup.square.types.ListChannelsResponse; -import com.squareup.square.types.RetrieveChannelResponse; -import java.io.IOException; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import okhttp3.Headers; -import okhttp3.HttpUrl; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.RequestBody; -import okhttp3.Response; -import okhttp3.ResponseBody; - -public class RawChannelsClient { - protected final ClientOptions clientOptions; - - public RawChannelsClient(ClientOptions clientOptions) { - this.clientOptions = clientOptions; - } - - public SquareClientHttpResponse> list() { - return list(ListChannelsRequest.builder().build()); - } - - public SquareClientHttpResponse> list(ListChannelsRequest request) { - return list(request, null); - } - - public SquareClientHttpResponse> list( - ListChannelsRequest request, RequestOptions requestOptions) { - HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("v2/channels"); - if (request.getReferenceType().isPresent()) { - QueryStringMapper.addQueryParameter( - httpUrl, "reference_type", request.getReferenceType().get(), false); - } - if (request.getReferenceId().isPresent()) { - QueryStringMapper.addQueryParameter( - httpUrl, "reference_id", request.getReferenceId().get(), false); - } - if (request.getStatus().isPresent()) { - QueryStringMapper.addQueryParameter( - httpUrl, "status", request.getStatus().get(), false); - } - if (request.getCursor().isPresent()) { - QueryStringMapper.addQueryParameter( - httpUrl, "cursor", request.getCursor().get(), false); - } - if (request.getLimit().isPresent()) { - QueryStringMapper.addQueryParameter( - httpUrl, "limit", request.getLimit().get(), false); - } - Request.Builder _requestBuilder = new Request.Builder() - .url(httpUrl.build()) - .method("GET", null) - .headers(Headers.of(clientOptions.headers(requestOptions))) - .addHeader("Accept", "application/json"); - Request okhttpRequest = _requestBuilder.build(); - OkHttpClient client = clientOptions.httpClient(); - if (requestOptions != null && requestOptions.getTimeout().isPresent()) { - client = clientOptions.httpClientWithTimeout(requestOptions); - } - try (Response response = client.newCall(okhttpRequest).execute()) { - ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - ListChannelsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListChannelsResponse.class); - Optional startingAfter = parsedResponse.getCursor(); - ListChannelsRequest nextRequest = ListChannelsRequest.builder() - .from(request) - .cursor(startingAfter) - .build(); - List result = parsedResponse.getChannels().orElse(Collections.emptyList()); - return new SquareClientHttpResponse<>( - new SyncPagingIterable(startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) - .body()), - response); - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); - } catch (IOException e) { - throw new SquareException("Network error executing HTTP request", e); - } - } - - public SquareClientHttpResponse bulkRetrieve(BulkRetrieveChannelsRequest request) { - return bulkRetrieve(request, null); - } - - public SquareClientHttpResponse bulkRetrieve( - BulkRetrieveChannelsRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("v2/channels/bulk-retrieve") - .build(); - RequestBody body; - try { - body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); - } catch (JsonProcessingException e) { - throw new SquareException("Failed to serialize request", e); - } - Request okhttpRequest = new Request.Builder() - .url(httpUrl) - .method("POST", body) - .headers(Headers.of(clientOptions.headers(requestOptions))) - .addHeader("Content-Type", "application/json") - .addHeader("Accept", "application/json") - .build(); - OkHttpClient client = clientOptions.httpClient(); - if (requestOptions != null && requestOptions.getTimeout().isPresent()) { - client = clientOptions.httpClientWithTimeout(requestOptions); - } - try (Response response = client.newCall(okhttpRequest).execute()) { - ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, BulkRetrieveChannelsResponse.class), - response); - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); - } catch (IOException e) { - throw new SquareException("Network error executing HTTP request", e); - } - } - - public SquareClientHttpResponse get(GetChannelsRequest request) { - return get(request, null); - } - - public SquareClientHttpResponse get( - GetChannelsRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("v2/channels") - .addPathSegment(request.getChannelId()) - .build(); - Request.Builder _requestBuilder = new Request.Builder() - .url(httpUrl) - .method("GET", null) - .headers(Headers.of(clientOptions.headers(requestOptions))) - .addHeader("Accept", "application/json"); - Request okhttpRequest = _requestBuilder.build(); - OkHttpClient client = clientOptions.httpClient(); - if (requestOptions != null && requestOptions.getTimeout().isPresent()) { - client = clientOptions.httpClientWithTimeout(requestOptions); - } - try (Response response = client.newCall(okhttpRequest).execute()) { - ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, RetrieveChannelResponse.class), - response); - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); - } catch (IOException e) { - throw new SquareException("Network error executing HTTP request", e); - } - } -} diff --git a/src/main/java/com/squareup/square/RawCheckoutClient.java b/src/main/java/com/squareup/square/RawCheckoutClient.java index 5c7b0468..72f4dab6 100644 --- a/src/main/java/com/squareup/square/RawCheckoutClient.java +++ b/src/main/java/com/squareup/square/RawCheckoutClient.java @@ -64,15 +64,18 @@ public SquareClientHttpResponse retrieveLocati } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, RetrieveLocationSettingsResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), RetrieveLocationSettingsResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -116,15 +119,18 @@ public SquareClientHttpResponse updateLocationSe } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateLocationSettingsResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), UpdateLocationSettingsResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -158,15 +164,18 @@ public SquareClientHttpResponse retrieveMercha } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, RetrieveMerchantSettingsResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), RetrieveMerchantSettingsResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -209,15 +218,18 @@ public SquareClientHttpResponse updateMerchantSe } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateMerchantSettingsResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), UpdateMerchantSettingsResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/RawCustomersClient.java b/src/main/java/com/squareup/square/RawCustomersClient.java index 39ab3d55..7ea67c8a 100644 --- a/src/main/java/com/squareup/square/RawCustomersClient.java +++ b/src/main/java/com/squareup/square/RawCustomersClient.java @@ -116,10 +116,9 @@ public SquareClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListCustomersResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListCustomersResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListCustomersResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListCustomersRequest nextRequest = ListCustomersRequest.builder() .from(request) @@ -127,14 +126,17 @@ public SquareClientHttpResponse> list( .build(); List result = parsedResponse.getCustomers().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( - new SyncPagingIterable(startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) - .body()), + new SyncPagingIterable( + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) + .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -210,15 +212,17 @@ public SquareClientHttpResponse create( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateCustomerResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateCustomerResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -278,15 +282,17 @@ public SquareClientHttpResponse batchCreate( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, BulkCreateCustomersResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), BulkCreateCustomersResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -331,15 +337,17 @@ public SquareClientHttpResponse bulkDeleteCustomers } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, BulkDeleteCustomersResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), BulkDeleteCustomersResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -384,15 +392,17 @@ public SquareClientHttpResponse bulkRetrieveCusto } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, BulkRetrieveCustomersResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), BulkRetrieveCustomersResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -437,15 +447,17 @@ public SquareClientHttpResponse bulkUpdateCustomers } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, BulkUpdateCustomersResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), BulkUpdateCustomersResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -512,15 +524,17 @@ public SquareClientHttpResponse search( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, SearchCustomersResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SearchCustomersResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -555,14 +569,17 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetCustomerResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetCustomerResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -609,15 +626,17 @@ public SquareClientHttpResponse update( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateCustomerResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UpdateCustomerResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -657,15 +676,17 @@ public SquareClientHttpResponse delete( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, DeleteCustomerResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), DeleteCustomerResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/RawDevicesClient.java b/src/main/java/com/squareup/square/RawDevicesClient.java index cf23c6c8..7b0abb7a 100644 --- a/src/main/java/com/squareup/square/RawDevicesClient.java +++ b/src/main/java/com/squareup/square/RawDevicesClient.java @@ -87,10 +87,9 @@ public SquareClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListDevicesResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListDevicesResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListDevicesResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListDevicesRequest nextRequest = ListDevicesRequest.builder() .from(request) @@ -98,14 +97,17 @@ public SquareClientHttpResponse> list( .build(); List result = parsedResponse.getDevices().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( - new SyncPagingIterable(startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) - .body()), + new SyncPagingIterable( + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) + .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -139,14 +141,16 @@ public SquareClientHttpResponse get(GetDevicesRequest request } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetDeviceResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetDeviceResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/RawDisputesClient.java b/src/main/java/com/squareup/square/RawDisputesClient.java index 88665e80..049d2f5b 100644 --- a/src/main/java/com/squareup/square/RawDisputesClient.java +++ b/src/main/java/com/squareup/square/RawDisputesClient.java @@ -94,10 +94,9 @@ public SquareClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListDisputesResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListDisputesResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListDisputesResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListDisputesRequest nextRequest = ListDisputesRequest.builder() .from(request) @@ -105,14 +104,17 @@ public SquareClientHttpResponse> list( .build(); List result = parsedResponse.getDisputes().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( - new SyncPagingIterable(startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) - .body()), + new SyncPagingIterable( + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) + .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -146,14 +148,16 @@ public SquareClientHttpResponse get(GetDisputesRequest reque } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetDisputeResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetDisputeResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -195,14 +199,17 @@ public SquareClientHttpResponse accept( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, AcceptDisputeResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AcceptDisputeResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -229,10 +236,10 @@ public SquareClientHttpResponse createEvidenc .addPathSegment(request.getDisputeId()) .addPathSegments("evidence-files") .build(); - MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM); + MultipartBody.Builder body = new MultipartBody.Builder().setType(MultipartBody.FORM); try { if (request.getRequest().isPresent()) { - multipartBodyBuilder.addFormDataPart( + body.addFormDataPart( "request", ObjectMappers.JSON_MAPPER.writeValueAsString( request.getRequest().get())); @@ -242,7 +249,7 @@ public SquareClientHttpResponse createEvidenc Files.probeContentType(request.getImageFile().get().toPath()); MediaType imageFileMimeTypeMediaType = imageFileMimeType != null ? MediaType.parse(imageFileMimeType) : null; - multipartBodyBuilder.addFormDataPart( + body.addFormDataPart( "image_file", request.getImageFile().get().getName(), RequestBody.create(request.getImageFile().get(), imageFileMimeTypeMediaType)); @@ -252,7 +259,7 @@ public SquareClientHttpResponse createEvidenc } Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl) - .method("POST", multipartBodyBuilder.build()) + .method("POST", body.build()) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); Request okhttpRequest = _requestBuilder.build(); @@ -262,16 +269,18 @@ public SquareClientHttpResponse createEvidenc } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateDisputeEvidenceFileResponse.class), + responseBody.string(), CreateDisputeEvidenceFileResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -316,16 +325,18 @@ public SquareClientHttpResponse createEvidenc } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateDisputeEvidenceTextResponse.class), + responseBody.string(), CreateDisputeEvidenceTextResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -371,15 +382,17 @@ public SquareClientHttpResponse submitEvidence( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, SubmitEvidenceResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SubmitEvidenceResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/RawEmployeesClient.java b/src/main/java/com/squareup/square/RawEmployeesClient.java index ad7e5e60..27eeab18 100644 --- a/src/main/java/com/squareup/square/RawEmployeesClient.java +++ b/src/main/java/com/squareup/square/RawEmployeesClient.java @@ -75,10 +75,9 @@ public SquareClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListEmployeesResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListEmployeesResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListEmployeesResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListEmployeesRequest nextRequest = ListEmployeesRequest.builder() .from(request) @@ -86,14 +85,17 @@ public SquareClientHttpResponse> list( .build(); List result = parsedResponse.getEmployees().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( - new SyncPagingIterable(startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) - .body()), + new SyncPagingIterable( + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) + .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -122,14 +124,17 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetEmployeeResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetEmployeeResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/RawEventsClient.java b/src/main/java/com/squareup/square/RawEventsClient.java index ffa362a3..a5be6e11 100644 --- a/src/main/java/com/squareup/square/RawEventsClient.java +++ b/src/main/java/com/squareup/square/RawEventsClient.java @@ -77,14 +77,17 @@ public SquareClientHttpResponse searchEvents( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, SearchEventsResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SearchEventsResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -121,14 +124,17 @@ public SquareClientHttpResponse disableEvents(RequestOpti } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, DisableEventsResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), DisableEventsResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -161,14 +167,17 @@ public SquareClientHttpResponse enableEvents(RequestOption } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, EnableEventsResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), EnableEventsResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -212,15 +221,17 @@ public SquareClientHttpResponse listEventTypes( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListEventTypesResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListEventTypesResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/RawGiftCardsClient.java b/src/main/java/com/squareup/square/RawGiftCardsClient.java index e95c4a7f..9dfb29ac 100644 --- a/src/main/java/com/squareup/square/RawGiftCardsClient.java +++ b/src/main/java/com/squareup/square/RawGiftCardsClient.java @@ -104,10 +104,9 @@ public SquareClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListGiftCardsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListGiftCardsResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListGiftCardsResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListGiftCardsRequest nextRequest = ListGiftCardsRequest.builder() .from(request) @@ -115,14 +114,17 @@ public SquareClientHttpResponse> list( .build(); List result = parsedResponse.getGiftCards().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( - new SyncPagingIterable(startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) - .body()), + new SyncPagingIterable( + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) + .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -172,15 +174,17 @@ public SquareClientHttpResponse create( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateGiftCardResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateGiftCardResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -222,15 +226,17 @@ public SquareClientHttpResponse getFromGan( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetGiftCardFromGanResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetGiftCardFromGanResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -272,15 +278,17 @@ public SquareClientHttpResponse getFromNonce( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetGiftCardFromNonceResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetGiftCardFromNonceResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -325,15 +333,18 @@ public SquareClientHttpResponse linkCustomer( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, LinkCustomerToGiftCardResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), LinkCustomerToGiftCardResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -378,16 +389,18 @@ public SquareClientHttpResponse unlinkCustom } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UnlinkCustomerFromGiftCardResponse.class), + responseBody.string(), UnlinkCustomerFromGiftCardResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -422,14 +435,17 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetGiftCardResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetGiftCardResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/RawInventoryClient.java b/src/main/java/com/squareup/square/RawInventoryClient.java index d2983e99..0e63c408 100644 --- a/src/main/java/com/squareup/square/RawInventoryClient.java +++ b/src/main/java/com/squareup/square/RawInventoryClient.java @@ -84,15 +84,18 @@ public SquareClientHttpResponse deprecatedGetAdj } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetInventoryAdjustmentResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), GetInventoryAdjustmentResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -130,15 +133,18 @@ public SquareClientHttpResponse getAdjustment( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetInventoryAdjustmentResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), GetInventoryAdjustmentResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -183,15 +189,17 @@ public SquareClientHttpResponse deprecatedBatchCha } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, BatchChangeInventoryResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), BatchChangeInventoryResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -245,15 +253,18 @@ public SquareClientHttpResponse deprecatedBatc } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, BatchGetInventoryChangesResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), BatchGetInventoryChangesResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -306,15 +317,18 @@ public SquareClientHttpResponse deprecatedBatch } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, BatchGetInventoryCountsResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), BatchGetInventoryCountsResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -363,15 +377,17 @@ public SquareClientHttpResponse batchCreateChanges } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, BatchChangeInventoryResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), BatchChangeInventoryResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -436,10 +452,9 @@ public SquareClientHttpResponse> batchGetCha } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { - BatchGetInventoryChangesResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, BatchGetInventoryChangesResponse.class); + BatchGetInventoryChangesResponse parsedResponse = ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), BatchGetInventoryChangesResponse.class); Optional startingAfter = parsedResponse.getCursor(); BatchRetrieveInventoryChangesRequest nextRequest = BatchRetrieveInventoryChangesRequest.builder() .from(request) @@ -448,14 +463,16 @@ public SquareClientHttpResponse> batchGetCha List result = parsedResponse.getChanges().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> batchGetChanges( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> batchGetChanges(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -529,10 +546,9 @@ public SquareClientHttpResponse> batchGetCoun } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { - BatchGetInventoryCountsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, BatchGetInventoryCountsResponse.class); + BatchGetInventoryCountsResponse parsedResponse = ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), BatchGetInventoryCountsResponse.class); Optional startingAfter = parsedResponse.getCursor(); BatchGetInventoryCountsRequest nextRequest = BatchGetInventoryCountsRequest.builder() .from(request) @@ -541,14 +557,16 @@ public SquareClientHttpResponse> batchGetCoun List result = parsedResponse.getCounts().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> batchGetCounts( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> batchGetCounts(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -586,16 +604,18 @@ public SquareClientHttpResponse deprecatedGet } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, GetInventoryPhysicalCountResponse.class), + responseBody.string(), GetInventoryPhysicalCountResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -633,16 +653,18 @@ public SquareClientHttpResponse getPhysicalCo } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, GetInventoryPhysicalCountResponse.class), + responseBody.string(), GetInventoryPhysicalCountResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -679,15 +701,17 @@ public SquareClientHttpResponse getTransfer( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetInventoryTransferResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetInventoryTransferResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -735,10 +759,9 @@ public SquareClientHttpResponse> get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { GetInventoryCountResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetInventoryCountResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetInventoryCountResponse.class); Optional startingAfter = parsedResponse.getCursor(); GetInventoryRequest nextRequest = GetInventoryRequest.builder() .from(request) @@ -747,14 +770,16 @@ public SquareClientHttpResponse> get( List result = parsedResponse.getCounts().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> get( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> get(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -815,10 +840,9 @@ public SquareClientHttpResponse> changes( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { GetInventoryChangesResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetInventoryChangesResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetInventoryChangesResponse.class); Optional startingAfter = parsedResponse.getCursor(); ChangesInventoryRequest nextRequest = ChangesInventoryRequest.builder() .from(request) @@ -827,14 +851,16 @@ public SquareClientHttpResponse> changes( List result = parsedResponse.getChanges().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> changes( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> changes(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/RawInvoicesClient.java b/src/main/java/com/squareup/square/RawInvoicesClient.java index 39fe8579..a5a7509d 100644 --- a/src/main/java/com/squareup/square/RawInvoicesClient.java +++ b/src/main/java/com/squareup/square/RawInvoicesClient.java @@ -96,10 +96,9 @@ public SquareClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListInvoicesResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListInvoicesResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListInvoicesResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListInvoicesRequest nextRequest = ListInvoicesRequest.builder() .from(request) @@ -107,14 +106,17 @@ public SquareClientHttpResponse> list( .build(); List result = parsedResponse.getInvoices().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( - new SyncPagingIterable(startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) - .body()), + new SyncPagingIterable( + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) + .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -162,14 +164,17 @@ public SquareClientHttpResponse create( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateInvoiceResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateInvoiceResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -221,15 +226,17 @@ public SquareClientHttpResponse search( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, SearchInvoicesResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SearchInvoicesResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -263,14 +270,16 @@ public SquareClientHttpResponse get(GetInvoicesRequest reque } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetInvoiceResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetInvoiceResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -319,14 +328,17 @@ public SquareClientHttpResponse update( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateInvoiceResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UpdateInvoiceResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -368,14 +380,17 @@ public SquareClientHttpResponse delete( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, DeleteInvoiceResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), DeleteInvoiceResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -410,10 +425,10 @@ public SquareClientHttpResponse createInvoiceAt .addPathSegment(request.getInvoiceId()) .addPathSegments("attachments") .build(); - MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM); + MultipartBody.Builder body = new MultipartBody.Builder().setType(MultipartBody.FORM); try { if (request.getRequest().isPresent()) { - multipartBodyBuilder.addFormDataPart( + body.addFormDataPart( "request", ObjectMappers.JSON_MAPPER.writeValueAsString( request.getRequest().get())); @@ -423,7 +438,7 @@ public SquareClientHttpResponse createInvoiceAt Files.probeContentType(request.getImageFile().get().toPath()); MediaType imageFileMimeTypeMediaType = imageFileMimeType != null ? MediaType.parse(imageFileMimeType) : null; - multipartBodyBuilder.addFormDataPart( + body.addFormDataPart( "image_file", request.getImageFile().get().getName(), RequestBody.create(request.getImageFile().get(), imageFileMimeTypeMediaType)); @@ -433,7 +448,7 @@ public SquareClientHttpResponse createInvoiceAt } Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl) - .method("POST", multipartBodyBuilder.build()) + .method("POST", body.build()) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); Request okhttpRequest = _requestBuilder.build(); @@ -443,15 +458,18 @@ public SquareClientHttpResponse createInvoiceAt } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateInvoiceAttachmentResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), CreateInvoiceAttachmentResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -491,15 +509,18 @@ public SquareClientHttpResponse deleteInvoiceAt } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, DeleteInvoiceAttachmentResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), DeleteInvoiceAttachmentResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -547,14 +568,17 @@ public SquareClientHttpResponse cancel( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CancelInvoiceResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CancelInvoiceResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -618,15 +642,17 @@ public SquareClientHttpResponse publish( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, PublishInvoiceResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), PublishInvoiceResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/RawLaborClient.java b/src/main/java/com/squareup/square/RawLaborClient.java index e6d18d31..b1b117b2 100644 --- a/src/main/java/com/squareup/square/RawLaborClient.java +++ b/src/main/java/com/squareup/square/RawLaborClient.java @@ -102,15 +102,17 @@ public SquareClientHttpResponse createScheduledShi } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateScheduledShiftResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateScheduledShiftResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -161,16 +163,18 @@ public SquareClientHttpResponse bulkPublishS } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BulkPublishScheduledShiftsResponse.class), + responseBody.string(), BulkPublishScheduledShiftsResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -223,15 +227,17 @@ public SquareClientHttpResponse searchScheduledSh } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, SearchScheduledShiftsResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SearchScheduledShiftsResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -267,15 +273,18 @@ public SquareClientHttpResponse retrieveSchedule } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, RetrieveScheduledShiftResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), RetrieveScheduledShiftResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -339,15 +348,17 @@ public SquareClientHttpResponse updateScheduledShi } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateScheduledShiftResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UpdateScheduledShiftResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -394,15 +405,17 @@ public SquareClientHttpResponse publishScheduledS } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, PublishScheduledShiftResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), PublishScheduledShiftResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -480,15 +493,17 @@ public SquareClientHttpResponse createTimecard( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateTimecardResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateTimecardResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -585,15 +600,17 @@ public SquareClientHttpResponse searchTimecards( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, SearchTimecardsResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SearchTimecardsResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -628,15 +645,17 @@ public SquareClientHttpResponse retrieveTimecard( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, RetrieveTimecardResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), RetrieveTimecardResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -687,15 +706,17 @@ public SquareClientHttpResponse updateTimecard( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateTimecardResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UpdateTimecardResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -730,15 +751,17 @@ public SquareClientHttpResponse deleteTimecard( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, DeleteTimecardResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), DeleteTimecardResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/RawLocationsClient.java b/src/main/java/com/squareup/square/RawLocationsClient.java index 8d3f20ed..a3221722 100644 --- a/src/main/java/com/squareup/square/RawLocationsClient.java +++ b/src/main/java/com/squareup/square/RawLocationsClient.java @@ -65,14 +65,17 @@ public SquareClientHttpResponse list(RequestOptions reque } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListLocationsResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListLocationsResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -139,15 +142,17 @@ public SquareClientHttpResponse create( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateLocationResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateLocationResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -184,14 +189,17 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetLocationResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetLocationResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -234,15 +242,17 @@ public SquareClientHttpResponse update( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateLocationResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UpdateLocationResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -294,15 +304,17 @@ public SquareClientHttpResponse checkouts( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateCheckoutResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateCheckoutResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/RawLoyaltyClient.java b/src/main/java/com/squareup/square/RawLoyaltyClient.java index 3d467f15..f73e37c5 100644 --- a/src/main/java/com/squareup/square/RawLoyaltyClient.java +++ b/src/main/java/com/squareup/square/RawLoyaltyClient.java @@ -87,15 +87,17 @@ public SquareClientHttpResponse searchEvents( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, SearchLoyaltyEventsResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SearchLoyaltyEventsResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/RawMerchantsClient.java b/src/main/java/com/squareup/square/RawMerchantsClient.java index 50024a97..c6bfdc94 100644 --- a/src/main/java/com/squareup/square/RawMerchantsClient.java +++ b/src/main/java/com/squareup/square/RawMerchantsClient.java @@ -93,10 +93,9 @@ public SquareClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListMerchantsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListMerchantsResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListMerchantsResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListMerchantsRequest nextRequest = ListMerchantsRequest.builder() .from(request) @@ -104,14 +103,17 @@ public SquareClientHttpResponse> list( .build(); List result = parsedResponse.getMerchant().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( - new SyncPagingIterable(startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) - .body()), + new SyncPagingIterable( + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) + .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -146,14 +148,17 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetMerchantResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetMerchantResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/RawMobileClient.java b/src/main/java/com/squareup/square/RawMobileClient.java index f4692fbc..9f49c7e8 100644 --- a/src/main/java/com/squareup/square/RawMobileClient.java +++ b/src/main/java/com/squareup/square/RawMobileClient.java @@ -97,16 +97,18 @@ public SquareClientHttpResponse authoriza } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateMobileAuthorizationCodeResponse.class), + responseBody.string(), CreateMobileAuthorizationCodeResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/RawOAuthClient.java b/src/main/java/com/squareup/square/RawOAuthClient.java index c6db14a8..abefb5c8 100644 --- a/src/main/java/com/squareup/square/RawOAuthClient.java +++ b/src/main/java/com/squareup/square/RawOAuthClient.java @@ -99,14 +99,17 @@ public SquareClientHttpResponse revokeToken( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, RevokeTokenResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), RevokeTokenResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -188,14 +191,17 @@ public SquareClientHttpResponse obtainToken( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ObtainTokenResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ObtainTokenResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -242,15 +248,17 @@ public SquareClientHttpResponse retrieveTokenStatus } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, RetrieveTokenStatusResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), RetrieveTokenStatusResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -280,9 +288,11 @@ public SquareClientHttpResponse authorize(RequestOptions requestOptions) { return new SquareClientHttpResponse<>(null, response); } String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/RawOrdersClient.java b/src/main/java/com/squareup/square/RawOrdersClient.java index 4669f70c..4eaa353f 100644 --- a/src/main/java/com/squareup/square/RawOrdersClient.java +++ b/src/main/java/com/squareup/square/RawOrdersClient.java @@ -98,14 +98,17 @@ public SquareClientHttpResponse create( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateOrderResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateOrderResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -149,15 +152,17 @@ public SquareClientHttpResponse batchGet( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, BatchGetOrdersResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), BatchGetOrdersResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -199,15 +204,17 @@ public SquareClientHttpResponse calculate( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CalculateOrderResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CalculateOrderResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -251,14 +258,16 @@ public SquareClientHttpResponse clone( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CloneOrderResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CloneOrderResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -346,14 +355,17 @@ public SquareClientHttpResponse search( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, SearchOrdersResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SearchOrdersResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -387,14 +399,16 @@ public SquareClientHttpResponse get(GetOrdersRequest request, } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetOrderResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetOrderResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -463,14 +477,17 @@ public SquareClientHttpResponse update( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateOrderResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UpdateOrderResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -537,14 +554,16 @@ public SquareClientHttpResponse pay(PayOrderRequest request, R } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, PayOrderResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), PayOrderResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/RawPaymentsClient.java b/src/main/java/com/squareup/square/RawPaymentsClient.java index 8a8ef0b0..cc44b906 100644 --- a/src/main/java/com/squareup/square/RawPaymentsClient.java +++ b/src/main/java/com/squareup/square/RawPaymentsClient.java @@ -156,10 +156,9 @@ public SquareClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListPaymentsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListPaymentsResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListPaymentsResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListPaymentsRequest nextRequest = ListPaymentsRequest.builder() .from(request) @@ -167,14 +166,17 @@ public SquareClientHttpResponse> list( .build(); List result = parsedResponse.getPayments().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( - new SyncPagingIterable(startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) - .body()), + new SyncPagingIterable( + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) + .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -228,14 +230,17 @@ public SquareClientHttpResponse create( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreatePaymentResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreatePaymentResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -294,16 +299,18 @@ public SquareClientHttpResponse cancelByI } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CancelPaymentByIdempotencyKeyResponse.class), + responseBody.string(), CancelPaymentByIdempotencyKeyResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -337,14 +344,16 @@ public SquareClientHttpResponse get(GetPaymentsRequest reque } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetPaymentResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetPaymentResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -389,14 +398,17 @@ public SquareClientHttpResponse update( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdatePaymentResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UpdatePaymentResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -434,14 +446,17 @@ public SquareClientHttpResponse cancel( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CancelPaymentResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CancelPaymentResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -489,15 +504,17 @@ public SquareClientHttpResponse complete( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CompletePaymentResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CompletePaymentResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/RawPayoutsClient.java b/src/main/java/com/squareup/square/RawPayoutsClient.java index 19ac9900..8408d8ee 100644 --- a/src/main/java/com/squareup/square/RawPayoutsClient.java +++ b/src/main/java/com/squareup/square/RawPayoutsClient.java @@ -105,10 +105,9 @@ public SquareClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListPayoutsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListPayoutsResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListPayoutsResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListPayoutsRequest nextRequest = ListPayoutsRequest.builder() .from(request) @@ -116,14 +115,17 @@ public SquareClientHttpResponse> list( .build(); List result = parsedResponse.getPayouts().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( - new SyncPagingIterable(startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) - .body()), + new SyncPagingIterable( + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) + .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -159,14 +161,16 @@ public SquareClientHttpResponse get(GetPayoutsRequest request } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetPayoutResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetPayoutResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -215,10 +219,9 @@ public SquareClientHttpResponse> listEntries( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListPayoutEntriesResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListPayoutEntriesResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListPayoutEntriesResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListEntriesPayoutsRequest nextRequest = ListEntriesPayoutsRequest.builder() .from(request) @@ -227,14 +230,16 @@ public SquareClientHttpResponse> listEntries( List result = parsedResponse.getPayoutEntries().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> listEntries( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> listEntries(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/RawRefundsClient.java b/src/main/java/com/squareup/square/RawRefundsClient.java index 822d340d..288de687 100644 --- a/src/main/java/com/squareup/square/RawRefundsClient.java +++ b/src/main/java/com/squareup/square/RawRefundsClient.java @@ -132,10 +132,9 @@ public SquareClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListPaymentRefundsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListPaymentRefundsResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListPaymentRefundsResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListRefundsRequest nextRequest = ListRefundsRequest.builder() .from(request) @@ -144,14 +143,16 @@ public SquareClientHttpResponse> list( List result = parsedResponse.getRefunds().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -199,14 +200,17 @@ public SquareClientHttpResponse refundPayment( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, RefundPaymentResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), RefundPaymentResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -241,15 +245,17 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetPaymentRefundResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetPaymentRefundResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/RawSitesClient.java b/src/main/java/com/squareup/square/RawSitesClient.java index fb361c27..e649d7da 100644 --- a/src/main/java/com/squareup/square/RawSitesClient.java +++ b/src/main/java/com/squareup/square/RawSitesClient.java @@ -54,14 +54,16 @@ public SquareClientHttpResponse list(RequestOptions requestOp } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListSitesResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListSitesResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/RawSnippetsClient.java b/src/main/java/com/squareup/square/RawSnippetsClient.java index f4d3f8b4..e4beb7cd 100644 --- a/src/main/java/com/squareup/square/RawSnippetsClient.java +++ b/src/main/java/com/squareup/square/RawSnippetsClient.java @@ -66,14 +66,16 @@ public SquareClientHttpResponse get(GetSnippetsRequest reque } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetSnippetResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetSnippetResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -123,14 +125,17 @@ public SquareClientHttpResponse upsert( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpsertSnippetResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UpsertSnippetResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -170,14 +175,17 @@ public SquareClientHttpResponse delete( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, DeleteSnippetResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), DeleteSnippetResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/RawSubscriptionsClient.java b/src/main/java/com/squareup/square/RawSubscriptionsClient.java index 23846067..3c7da78d 100644 --- a/src/main/java/com/squareup/square/RawSubscriptionsClient.java +++ b/src/main/java/com/squareup/square/RawSubscriptionsClient.java @@ -103,15 +103,17 @@ public SquareClientHttpResponse create( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateSubscriptionResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateSubscriptionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -155,14 +157,17 @@ public SquareClientHttpResponse bulkSwapPlan( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, BulkSwapPlanResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), BulkSwapPlanResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -244,15 +249,17 @@ public SquareClientHttpResponse search( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, SearchSubscriptionsResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SearchSubscriptionsResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -290,15 +297,17 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetSubscriptionResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetSubscriptionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -343,15 +352,17 @@ public SquareClientHttpResponse update( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateSubscriptionResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UpdateSubscriptionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -389,15 +400,18 @@ public SquareClientHttpResponse deleteAction( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, DeleteSubscriptionActionResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), DeleteSubscriptionActionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -444,15 +458,18 @@ public SquareClientHttpResponse changeBillingAn } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ChangeBillingAnchorDateResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), ChangeBillingAnchorDateResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -492,15 +509,17 @@ public SquareClientHttpResponse cancel( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CancelSubscriptionResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CancelSubscriptionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -544,10 +563,9 @@ public SquareClientHttpResponse> listEvent } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { - ListSubscriptionEventsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListSubscriptionEventsResponse.class); + ListSubscriptionEventsResponse parsedResponse = ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), ListSubscriptionEventsResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListEventsSubscriptionsRequest nextRequest = ListEventsSubscriptionsRequest.builder() .from(request) @@ -557,14 +575,16 @@ public SquareClientHttpResponse> listEvent parsedResponse.getSubscriptionEvents().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> listEvents( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> listEvents(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -608,15 +628,17 @@ public SquareClientHttpResponse pause( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, PauseSubscriptionResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), PauseSubscriptionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -660,15 +682,17 @@ public SquareClientHttpResponse resume( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ResumeSubscriptionResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ResumeSubscriptionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -713,14 +737,16 @@ public SquareClientHttpResponse swapPlan(SwapPlanRequest reque } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, SwapPlanResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SwapPlanResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/RawTeamClient.java b/src/main/java/com/squareup/square/RawTeamClient.java index c8319aa4..cae7bb95 100644 --- a/src/main/java/com/squareup/square/RawTeamClient.java +++ b/src/main/java/com/squareup/square/RawTeamClient.java @@ -73,14 +73,16 @@ public SquareClientHttpResponse listJobs(ListJobsRequest reque } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListJobsResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListJobsResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -124,14 +126,16 @@ public SquareClientHttpResponse createJob( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateJobResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateJobResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -166,14 +170,17 @@ public SquareClientHttpResponse retrieveJob( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, RetrieveJobResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), RetrieveJobResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -220,14 +227,16 @@ public SquareClientHttpResponse updateJob( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateJobResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UpdateJobResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/RawTeamMembersClient.java b/src/main/java/com/squareup/square/RawTeamMembersClient.java index fda92c9d..5b79aaff 100644 --- a/src/main/java/com/squareup/square/RawTeamMembersClient.java +++ b/src/main/java/com/squareup/square/RawTeamMembersClient.java @@ -100,15 +100,17 @@ public SquareClientHttpResponse create( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateTeamMemberResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateTeamMemberResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -158,15 +160,18 @@ public SquareClientHttpResponse batchCreate( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, BatchCreateTeamMembersResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), BatchCreateTeamMembersResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -216,15 +221,18 @@ public SquareClientHttpResponse batchUpdate( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, BatchUpdateTeamMembersResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), BatchUpdateTeamMembersResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -279,15 +287,17 @@ public SquareClientHttpResponse search( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, SearchTeamMembersResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SearchTeamMembersResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -324,14 +334,17 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetTeamMemberResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetTeamMemberResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -376,15 +389,17 @@ public SquareClientHttpResponse update( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateTeamMemberResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UpdateTeamMemberResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/RawTerminalClient.java b/src/main/java/com/squareup/square/RawTerminalClient.java index 5c641f12..211663b9 100644 --- a/src/main/java/com/squareup/square/RawTerminalClient.java +++ b/src/main/java/com/squareup/square/RawTerminalClient.java @@ -64,15 +64,17 @@ public SquareClientHttpResponse dismissTerminalAc } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, DismissTerminalActionResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), DismissTerminalActionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -109,15 +111,18 @@ public SquareClientHttpResponse dismissTerminal } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, DismissTerminalCheckoutResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), DismissTerminalCheckoutResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -154,15 +159,17 @@ public SquareClientHttpResponse dismissTerminalRe } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, DismissTerminalRefundResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), DismissTerminalRefundResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/RawTransferOrdersClient.java b/src/main/java/com/squareup/square/RawTransferOrdersClient.java deleted file mode 100644 index ebb22fd7..00000000 --- a/src/main/java/com/squareup/square/RawTransferOrdersClient.java +++ /dev/null @@ -1,602 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.squareup.square.core.ClientOptions; -import com.squareup.square.core.MediaTypes; -import com.squareup.square.core.ObjectMappers; -import com.squareup.square.core.QueryStringMapper; -import com.squareup.square.core.RequestOptions; -import com.squareup.square.core.SquareApiException; -import com.squareup.square.core.SquareClientHttpResponse; -import com.squareup.square.core.SquareException; -import com.squareup.square.core.SyncPagingIterable; -import com.squareup.square.types.CancelTransferOrderRequest; -import com.squareup.square.types.CancelTransferOrderResponse; -import com.squareup.square.types.CreateTransferOrderRequest; -import com.squareup.square.types.CreateTransferOrderResponse; -import com.squareup.square.types.DeleteTransferOrderResponse; -import com.squareup.square.types.DeleteTransferOrdersRequest; -import com.squareup.square.types.GetTransferOrdersRequest; -import com.squareup.square.types.ReceiveTransferOrderRequest; -import com.squareup.square.types.ReceiveTransferOrderResponse; -import com.squareup.square.types.RetrieveTransferOrderResponse; -import com.squareup.square.types.SearchTransferOrdersRequest; -import com.squareup.square.types.SearchTransferOrdersResponse; -import com.squareup.square.types.StartTransferOrderRequest; -import com.squareup.square.types.StartTransferOrderResponse; -import com.squareup.square.types.TransferOrder; -import com.squareup.square.types.UpdateTransferOrderRequest; -import com.squareup.square.types.UpdateTransferOrderResponse; -import java.io.IOException; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import okhttp3.Headers; -import okhttp3.HttpUrl; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.RequestBody; -import okhttp3.Response; -import okhttp3.ResponseBody; - -public class RawTransferOrdersClient { - protected final ClientOptions clientOptions; - - public RawTransferOrdersClient(ClientOptions clientOptions) { - this.clientOptions = clientOptions; - } - - /** - * Creates a new transfer order in DRAFT status. A transfer order represents the intent - * to move CatalogItemVariations from one Location to another. - * The source and destination locations must be different and must belong to your Square account. - *

In DRAFT status, you can:

- *
    - *
  • Add or remove items
  • - *
  • Modify quantities
  • - *
  • Update shipping information
  • - *
  • Delete the entire order via DeleteTransferOrder
  • - *
- *

The request requires source_location_id and destination_location_id. - * Inventory levels are not affected until the order is started via - * StartTransferOrder.

- *

Common integration points:

- *
    - *
  • Sync with warehouse management systems
  • - *
  • Automate regular stock transfers
  • - *
  • Initialize transfers from inventory optimization systems
  • - *
- *

Creates a transfer_order.created webhook event.

- */ - public SquareClientHttpResponse create(CreateTransferOrderRequest request) { - return create(request, null); - } - - /** - * Creates a new transfer order in DRAFT status. A transfer order represents the intent - * to move CatalogItemVariations from one Location to another. - * The source and destination locations must be different and must belong to your Square account. - *

In DRAFT status, you can:

- *
    - *
  • Add or remove items
  • - *
  • Modify quantities
  • - *
  • Update shipping information
  • - *
  • Delete the entire order via DeleteTransferOrder
  • - *
- *

The request requires source_location_id and destination_location_id. - * Inventory levels are not affected until the order is started via - * StartTransferOrder.

- *

Common integration points:

- *
    - *
  • Sync with warehouse management systems
  • - *
  • Automate regular stock transfers
  • - *
  • Initialize transfers from inventory optimization systems
  • - *
- *

Creates a transfer_order.created webhook event.

- */ - public SquareClientHttpResponse create( - CreateTransferOrderRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("v2/transfer-orders") - .build(); - RequestBody body; - try { - body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); - } catch (JsonProcessingException e) { - throw new SquareException("Failed to serialize request", e); - } - Request okhttpRequest = new Request.Builder() - .url(httpUrl) - .method("POST", body) - .headers(Headers.of(clientOptions.headers(requestOptions))) - .addHeader("Content-Type", "application/json") - .addHeader("Accept", "application/json") - .build(); - OkHttpClient client = clientOptions.httpClient(); - if (requestOptions != null && requestOptions.getTimeout().isPresent()) { - client = clientOptions.httpClientWithTimeout(requestOptions); - } - try (Response response = client.newCall(okhttpRequest).execute()) { - ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateTransferOrderResponse.class), - response); - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); - } catch (IOException e) { - throw new SquareException("Network error executing HTTP request", e); - } - } - - /** - * Searches for transfer orders using filters. Returns a paginated list of matching - * TransferOrders sorted by creation date. - *

Common search scenarios:

- * - */ - public SquareClientHttpResponse> search() { - return search(SearchTransferOrdersRequest.builder().build()); - } - - /** - * Searches for transfer orders using filters. Returns a paginated list of matching - * TransferOrders sorted by creation date. - *

Common search scenarios:

- * - */ - public SquareClientHttpResponse> search(SearchTransferOrdersRequest request) { - return search(request, null); - } - - /** - * Searches for transfer orders using filters. Returns a paginated list of matching - * TransferOrders sorted by creation date. - *

Common search scenarios:

- * - */ - public SquareClientHttpResponse> search( - SearchTransferOrdersRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("v2/transfer-orders/search") - .build(); - RequestBody body; - try { - body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); - } catch (JsonProcessingException e) { - throw new SquareException("Failed to serialize request", e); - } - Request okhttpRequest = new Request.Builder() - .url(httpUrl) - .method("POST", body) - .headers(Headers.of(clientOptions.headers(requestOptions))) - .addHeader("Content-Type", "application/json") - .addHeader("Accept", "application/json") - .build(); - OkHttpClient client = clientOptions.httpClient(); - if (requestOptions != null && requestOptions.getTimeout().isPresent()) { - client = clientOptions.httpClientWithTimeout(requestOptions); - } - try (Response response = client.newCall(okhttpRequest).execute()) { - ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - SearchTransferOrdersResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, SearchTransferOrdersResponse.class); - Optional startingAfter = parsedResponse.getCursor(); - SearchTransferOrdersRequest nextRequest = SearchTransferOrdersRequest.builder() - .from(request) - .cursor(startingAfter) - .build(); - List result = parsedResponse.getTransferOrders().orElse(Collections.emptyList()); - return new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> search( - nextRequest, requestOptions) - .body()), - response); - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); - } catch (IOException e) { - throw new SquareException("Network error executing HTTP request", e); - } - } - - /** - * Retrieves a specific TransferOrder by ID. Returns the complete - * order details including: - *
    - *
  • Basic information (status, dates, notes)
  • - *
  • Line items with ordered and received quantities
  • - *
  • Source and destination Locations
  • - *
  • Tracking information (if available)
  • - *
- */ - public SquareClientHttpResponse get(GetTransferOrdersRequest request) { - return get(request, null); - } - - /** - * Retrieves a specific TransferOrder by ID. Returns the complete - * order details including: - *
    - *
  • Basic information (status, dates, notes)
  • - *
  • Line items with ordered and received quantities
  • - *
  • Source and destination Locations
  • - *
  • Tracking information (if available)
  • - *
- */ - public SquareClientHttpResponse get( - GetTransferOrdersRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("v2/transfer-orders") - .addPathSegment(request.getTransferOrderId()) - .build(); - Request.Builder _requestBuilder = new Request.Builder() - .url(httpUrl) - .method("GET", null) - .headers(Headers.of(clientOptions.headers(requestOptions))) - .addHeader("Accept", "application/json"); - Request okhttpRequest = _requestBuilder.build(); - OkHttpClient client = clientOptions.httpClient(); - if (requestOptions != null && requestOptions.getTimeout().isPresent()) { - client = clientOptions.httpClientWithTimeout(requestOptions); - } - try (Response response = client.newCall(okhttpRequest).execute()) { - ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, RetrieveTransferOrderResponse.class), - response); - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); - } catch (IOException e) { - throw new SquareException("Network error executing HTTP request", e); - } - } - - /** - * Updates an existing transfer order. This endpoint supports sparse updates, - * allowing you to modify specific fields without affecting others. - *

Creates a transfer_order.updated webhook event.

- */ - public SquareClientHttpResponse update(UpdateTransferOrderRequest request) { - return update(request, null); - } - - /** - * Updates an existing transfer order. This endpoint supports sparse updates, - * allowing you to modify specific fields without affecting others. - *

Creates a transfer_order.updated webhook event.

- */ - public SquareClientHttpResponse update( - UpdateTransferOrderRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("v2/transfer-orders") - .addPathSegment(request.getTransferOrderId()) - .build(); - RequestBody body; - try { - body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); - } catch (JsonProcessingException e) { - throw new SquareException("Failed to serialize request", e); - } - Request okhttpRequest = new Request.Builder() - .url(httpUrl) - .method("PUT", body) - .headers(Headers.of(clientOptions.headers(requestOptions))) - .addHeader("Content-Type", "application/json") - .addHeader("Accept", "application/json") - .build(); - OkHttpClient client = clientOptions.httpClient(); - if (requestOptions != null && requestOptions.getTimeout().isPresent()) { - client = clientOptions.httpClientWithTimeout(requestOptions); - } - try (Response response = client.newCall(okhttpRequest).execute()) { - ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateTransferOrderResponse.class), - response); - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); - } catch (IOException e) { - throw new SquareException("Network error executing HTTP request", e); - } - } - - /** - * Deletes a transfer order in DRAFT status. - * Only draft orders can be deleted. Once an order is started via - * StartTransferOrder, it can no longer be deleted. - *

Creates a transfer_order.deleted webhook event.

- */ - public SquareClientHttpResponse delete(DeleteTransferOrdersRequest request) { - return delete(request, null); - } - - /** - * Deletes a transfer order in DRAFT status. - * Only draft orders can be deleted. Once an order is started via - * StartTransferOrder, it can no longer be deleted. - *

Creates a transfer_order.deleted webhook event.

- */ - public SquareClientHttpResponse delete( - DeleteTransferOrdersRequest request, RequestOptions requestOptions) { - HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("v2/transfer-orders") - .addPathSegment(request.getTransferOrderId()); - if (request.getVersion().isPresent()) { - QueryStringMapper.addQueryParameter( - httpUrl, "version", request.getVersion().get(), false); - } - Request.Builder _requestBuilder = new Request.Builder() - .url(httpUrl.build()) - .method("DELETE", null) - .headers(Headers.of(clientOptions.headers(requestOptions))) - .addHeader("Accept", "application/json"); - Request okhttpRequest = _requestBuilder.build(); - OkHttpClient client = clientOptions.httpClient(); - if (requestOptions != null && requestOptions.getTimeout().isPresent()) { - client = clientOptions.httpClientWithTimeout(requestOptions); - } - try (Response response = client.newCall(okhttpRequest).execute()) { - ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, DeleteTransferOrderResponse.class), - response); - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); - } catch (IOException e) { - throw new SquareException("Network error executing HTTP request", e); - } - } - - /** - * Cancels a transfer order in STARTED or - * PARTIALLY_RECEIVED status. Any unreceived quantities will no - * longer be receivable and will be immediately returned to the source Location's inventory. - *

Common reasons for cancellation:

- *
    - *
  • Items no longer needed at destination
  • - *
  • Source location needs the inventory
  • - *
  • Order created in error
  • - *
- *

Creates a transfer_order.updated webhook event.

- */ - public SquareClientHttpResponse cancel(CancelTransferOrderRequest request) { - return cancel(request, null); - } - - /** - * Cancels a transfer order in STARTED or - * PARTIALLY_RECEIVED status. Any unreceived quantities will no - * longer be receivable and will be immediately returned to the source Location's inventory. - *

Common reasons for cancellation:

- *
    - *
  • Items no longer needed at destination
  • - *
  • Source location needs the inventory
  • - *
  • Order created in error
  • - *
- *

Creates a transfer_order.updated webhook event.

- */ - public SquareClientHttpResponse cancel( - CancelTransferOrderRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("v2/transfer-orders") - .addPathSegment(request.getTransferOrderId()) - .addPathSegments("cancel") - .build(); - RequestBody body; - try { - body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); - } catch (JsonProcessingException e) { - throw new SquareException("Failed to serialize request", e); - } - Request okhttpRequest = new Request.Builder() - .url(httpUrl) - .method("POST", body) - .headers(Headers.of(clientOptions.headers(requestOptions))) - .addHeader("Content-Type", "application/json") - .addHeader("Accept", "application/json") - .build(); - OkHttpClient client = clientOptions.httpClient(); - if (requestOptions != null && requestOptions.getTimeout().isPresent()) { - client = clientOptions.httpClientWithTimeout(requestOptions); - } - try (Response response = client.newCall(okhttpRequest).execute()) { - ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CancelTransferOrderResponse.class), - response); - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); - } catch (IOException e) { - throw new SquareException("Network error executing HTTP request", e); - } - } - - /** - * Records receipt of CatalogItemVariations for a transfer order. - * This endpoint supports partial receiving - you can receive items in multiple batches. - *

For each line item, you can specify:

- *
    - *
  • Quantity received in good condition (added to destination inventory with InventoryState of IN_STOCK)
  • - *
  • Quantity damaged during transit/handling (added to destination inventory with InventoryState of WASTE)
  • - *
  • Quantity canceled (returned to source location's inventory)
  • - *
- *

The order must be in STARTED or PARTIALLY_RECEIVED status. - * Received quantities are added to the destination Location's inventory according to their condition. - * Canceled quantities are immediately returned to the source Location's inventory.

- *

When all items are either received, damaged, or canceled, the order moves to - * COMPLETED status.

- *

Creates a transfer_order.updated webhook event.

- */ - public SquareClientHttpResponse receive(ReceiveTransferOrderRequest request) { - return receive(request, null); - } - - /** - * Records receipt of CatalogItemVariations for a transfer order. - * This endpoint supports partial receiving - you can receive items in multiple batches. - *

For each line item, you can specify:

- *
    - *
  • Quantity received in good condition (added to destination inventory with InventoryState of IN_STOCK)
  • - *
  • Quantity damaged during transit/handling (added to destination inventory with InventoryState of WASTE)
  • - *
  • Quantity canceled (returned to source location's inventory)
  • - *
- *

The order must be in STARTED or PARTIALLY_RECEIVED status. - * Received quantities are added to the destination Location's inventory according to their condition. - * Canceled quantities are immediately returned to the source Location's inventory.

- *

When all items are either received, damaged, or canceled, the order moves to - * COMPLETED status.

- *

Creates a transfer_order.updated webhook event.

- */ - public SquareClientHttpResponse receive( - ReceiveTransferOrderRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("v2/transfer-orders") - .addPathSegment(request.getTransferOrderId()) - .addPathSegments("receive") - .build(); - RequestBody body; - try { - body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); - } catch (JsonProcessingException e) { - throw new SquareException("Failed to serialize request", e); - } - Request okhttpRequest = new Request.Builder() - .url(httpUrl) - .method("POST", body) - .headers(Headers.of(clientOptions.headers(requestOptions))) - .addHeader("Content-Type", "application/json") - .addHeader("Accept", "application/json") - .build(); - OkHttpClient client = clientOptions.httpClient(); - if (requestOptions != null && requestOptions.getTimeout().isPresent()) { - client = clientOptions.httpClientWithTimeout(requestOptions); - } - try (Response response = client.newCall(okhttpRequest).execute()) { - ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ReceiveTransferOrderResponse.class), - response); - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); - } catch (IOException e) { - throw new SquareException("Network error executing HTTP request", e); - } - } - - /** - * Changes a DRAFT transfer order to STARTED status. - * This decrements inventory at the source Location and marks it as in-transit. - *

The order must be in DRAFT status and have all required fields populated. - * Once started, the order can no longer be deleted, but it can be canceled via - * CancelTransferOrder.

- *

Creates a transfer_order.updated webhook event.

- */ - public SquareClientHttpResponse start(StartTransferOrderRequest request) { - return start(request, null); - } - - /** - * Changes a DRAFT transfer order to STARTED status. - * This decrements inventory at the source Location and marks it as in-transit. - *

The order must be in DRAFT status and have all required fields populated. - * Once started, the order can no longer be deleted, but it can be canceled via - * CancelTransferOrder.

- *

Creates a transfer_order.updated webhook event.

- */ - public SquareClientHttpResponse start( - StartTransferOrderRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("v2/transfer-orders") - .addPathSegment(request.getTransferOrderId()) - .addPathSegments("start") - .build(); - RequestBody body; - try { - body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); - } catch (JsonProcessingException e) { - throw new SquareException("Failed to serialize request", e); - } - Request okhttpRequest = new Request.Builder() - .url(httpUrl) - .method("POST", body) - .headers(Headers.of(clientOptions.headers(requestOptions))) - .addHeader("Content-Type", "application/json") - .addHeader("Accept", "application/json") - .build(); - OkHttpClient client = clientOptions.httpClient(); - if (requestOptions != null && requestOptions.getTimeout().isPresent()) { - client = clientOptions.httpClientWithTimeout(requestOptions); - } - try (Response response = client.newCall(okhttpRequest).execute()) { - ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, StartTransferOrderResponse.class), - response); - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); - } catch (IOException e) { - throw new SquareException("Network error executing HTTP request", e); - } - } -} diff --git a/src/main/java/com/squareup/square/RawV1TransactionsClient.java b/src/main/java/com/squareup/square/RawV1TransactionsClient.java index 32c8efa7..bd478dd3 100644 --- a/src/main/java/com/squareup/square/RawV1TransactionsClient.java +++ b/src/main/java/com/squareup/square/RawV1TransactionsClient.java @@ -75,15 +75,18 @@ public SquareClientHttpResponse> v1ListOrders( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, new TypeReference>() {}), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), new TypeReference>() {}), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -120,14 +123,16 @@ public SquareClientHttpResponse v1RetrieveOrder( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, V1Order.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), V1Order.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -172,14 +177,16 @@ public SquareClientHttpResponse v1UpdateOrder( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, V1Order.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), V1Order.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/RawVendorsClient.java b/src/main/java/com/squareup/square/RawVendorsClient.java index fd640751..eee42cf9 100644 --- a/src/main/java/com/squareup/square/RawVendorsClient.java +++ b/src/main/java/com/squareup/square/RawVendorsClient.java @@ -77,15 +77,17 @@ public SquareClientHttpResponse batchCreate( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, BatchCreateVendorsResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), BatchCreateVendorsResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -134,15 +136,17 @@ public SquareClientHttpResponse batchGet( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, BatchGetVendorsResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), BatchGetVendorsResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -184,15 +188,17 @@ public SquareClientHttpResponse batchUpdate( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, BatchUpdateVendorsResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), BatchUpdateVendorsResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -234,14 +240,17 @@ public SquareClientHttpResponse create( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateVendorResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateVendorResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -290,14 +299,17 @@ public SquareClientHttpResponse search( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, SearchVendorsResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SearchVendorsResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -331,14 +343,16 @@ public SquareClientHttpResponse get(GetVendorsRequest request } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetVendorResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetVendorResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -381,14 +395,17 @@ public SquareClientHttpResponse update( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateVendorResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UpdateVendorResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/SquareClient.java b/src/main/java/com/squareup/square/SquareClient.java index 722d9a2e..1340e133 100644 --- a/src/main/java/com/squareup/square/SquareClient.java +++ b/src/main/java/com/squareup/square/SquareClient.java @@ -28,8 +28,6 @@ public class SquareClient { protected final Supplier catalogClient; - protected final Supplier channelsClient; - protected final Supplier customersClient; protected final Supplier devicesClient; @@ -76,8 +74,6 @@ public class SquareClient { protected final Supplier terminalClient; - protected final Supplier transferOrdersClient; - protected final Supplier vendorsClient; protected final Supplier cashDrawersClient; @@ -94,7 +90,6 @@ public SquareClient(ClientOptions clientOptions) { this.bookingsClient = Suppliers.memoize(() -> new BookingsClient(clientOptions)); this.cardsClient = Suppliers.memoize(() -> new CardsClient(clientOptions)); this.catalogClient = Suppliers.memoize(() -> new CatalogClient(clientOptions)); - this.channelsClient = Suppliers.memoize(() -> new ChannelsClient(clientOptions)); this.customersClient = Suppliers.memoize(() -> new CustomersClient(clientOptions)); this.devicesClient = Suppliers.memoize(() -> new DevicesClient(clientOptions)); this.disputesClient = Suppliers.memoize(() -> new DisputesClient(clientOptions)); @@ -118,7 +113,6 @@ public SquareClient(ClientOptions clientOptions) { this.teamMembersClient = Suppliers.memoize(() -> new TeamMembersClient(clientOptions)); this.teamClient = Suppliers.memoize(() -> new TeamClient(clientOptions)); this.terminalClient = Suppliers.memoize(() -> new TerminalClient(clientOptions)); - this.transferOrdersClient = Suppliers.memoize(() -> new TransferOrdersClient(clientOptions)); this.vendorsClient = Suppliers.memoize(() -> new VendorsClient(clientOptions)); this.cashDrawersClient = Suppliers.memoize(() -> new CashDrawersClient(clientOptions)); this.webhooksClient = Suppliers.memoize(() -> new WebhooksClient(clientOptions)); @@ -156,10 +150,6 @@ public CatalogClient catalog() { return this.catalogClient.get(); } - public ChannelsClient channels() { - return this.channelsClient.get(); - } - public CustomersClient customers() { return this.customersClient.get(); } @@ -252,10 +242,6 @@ public TerminalClient terminal() { return this.terminalClient.get(); } - public TransferOrdersClient transferOrders() { - return this.transferOrdersClient.get(); - } - public VendorsClient vendors() { return this.vendorsClient.get(); } diff --git a/src/main/java/com/squareup/square/SquareClientBuilder.java b/src/main/java/com/squareup/square/SquareClientBuilder.java index ae79625a..03cd96c7 100644 --- a/src/main/java/com/squareup/square/SquareClientBuilder.java +++ b/src/main/java/com/squareup/square/SquareClientBuilder.java @@ -5,26 +5,17 @@ import com.squareup.square.core.ClientOptions; import com.squareup.square.core.Environment; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; import okhttp3.OkHttpClient; -public class SquareClientBuilder { - private Optional timeout = Optional.empty(); - - private Optional maxRetries = Optional.empty(); - - private final Map customHeaders = new HashMap<>(); +public final class SquareClientBuilder { + private ClientOptions.Builder clientOptionsBuilder = ClientOptions.builder(); private String token = System.getenv("SQUARE_TOKEN"); - private String version = "2025-10-16"; + private String version = "2025-07-16"; private Environment environment = Environment.PRODUCTION; - private OkHttpClient httpClient; - /** * Sets token. * Defaults to the SQUARE_TOKEN environment variable. @@ -56,7 +47,7 @@ public SquareClientBuilder url(String url) { * Sets the timeout (in seconds) for the client. Defaults to 60 seconds. */ public SquareClientBuilder timeout(int timeout) { - this.timeout = Optional.of(timeout); + this.clientOptionsBuilder.timeout(timeout); return this; } @@ -64,7 +55,7 @@ public SquareClientBuilder timeout(int timeout) { * Sets the maximum number of retries for the client. Defaults to 2 retries. */ public SquareClientBuilder maxRetries(int maxRetries) { - this.maxRetries = Optional.of(maxRetries); + this.clientOptionsBuilder.maxRetries(maxRetries); return this; } @@ -72,162 +63,14 @@ public SquareClientBuilder maxRetries(int maxRetries) { * Sets the underlying OkHttp client */ public SquareClientBuilder httpClient(OkHttpClient httpClient) { - this.httpClient = httpClient; - return this; - } - - /** - * Add a custom header to be sent with all requests. - * For headers that need to be computed dynamically or conditionally, use the setAdditional() method override instead. - * - * @param name The header name - * @param value The header value - * @return This builder for method chaining - */ - public SquareClientBuilder addHeader(String name, String value) { - this.customHeaders.put(name, value); + this.clientOptionsBuilder.httpClient(httpClient); return this; } - protected ClientOptions buildClientOptions() { - ClientOptions.Builder builder = ClientOptions.builder(); - setEnvironment(builder); - setAuthentication(builder); - setCustomHeaders(builder); - setHttpClient(builder); - setTimeouts(builder); - setRetries(builder); - for (Map.Entry header : this.customHeaders.entrySet()) { - builder.addHeader(header.getKey(), header.getValue()); - } - setAdditional(builder); - return builder.build(); - } - - /** - * Sets the environment configuration for the client. - * Override this method to modify URLs or add environment-specific logic. - * - * @param builder The ClientOptions.Builder to configure - */ - protected void setEnvironment(ClientOptions.Builder builder) { - builder.environment(this.environment); - } - - /** - * Override this method to customize authentication. - * This method is called during client options construction to set up authentication headers. - * - * @param builder The ClientOptions.Builder to configure - * - * Example: - *
{@code
-     * @Override
-     * protected void setAuthentication(ClientOptions.Builder builder) {
-     *     super.setAuthentication(builder); // Keep existing auth
-     *     builder.addHeader("X-API-Key", this.apiKey);
-     * }
-     * }
- */ - protected void setAuthentication(ClientOptions.Builder builder) { - if (this.token != null) { - builder.addHeader("Authorization", "Bearer " + this.token); - } - } - - /** - * Override this method to add or modify custom headers. - * This method is called during client options construction to set up custom headers defined in the API. - * - * @param builder The ClientOptions.Builder to configure - * - * Example: - *
{@code
-     * @Override
-     * protected void setCustomHeaders(ClientOptions.Builder builder) {
-     *     super.setCustomHeaders(builder); // Keep existing headers
-     *     builder.addHeader("X-Trace-ID", generateTraceId());
-     * }
-     * }
- */ - protected void setCustomHeaders(ClientOptions.Builder builder) { - builder.addHeader("Square-Version", this.version); - } - - /** - * Sets the request timeout configuration. - * Override this method to customize timeout behavior. - * - * @param builder The ClientOptions.Builder to configure - */ - protected void setTimeouts(ClientOptions.Builder builder) { - if (this.timeout.isPresent()) { - builder.timeout(this.timeout.get()); - } - } - - /** - * Sets the retry configuration for failed requests. - * Override this method to implement custom retry strategies. - * - * @param builder The ClientOptions.Builder to configure - */ - protected void setRetries(ClientOptions.Builder builder) { - if (this.maxRetries.isPresent()) { - builder.maxRetries(this.maxRetries.get()); - } - } - - /** - * Sets the OkHttp client configuration. - * Override this method to customize HTTP client behavior (interceptors, connection pools, etc). - * - * @param builder The ClientOptions.Builder to configure - */ - protected void setHttpClient(ClientOptions.Builder builder) { - if (this.httpClient != null) { - builder.httpClient(this.httpClient); - } - } - - /** - * Override this method to add any additional configuration to the client. - * This method is called at the end of the configuration chain, allowing you to add - * custom headers, modify settings, or perform any other client customization. - * - * @param builder The ClientOptions.Builder to configure - * - * Example: - *
{@code
-     * @Override
-     * protected void setAdditional(ClientOptions.Builder builder) {
-     *     builder.addHeader("X-Request-ID", () -> UUID.randomUUID().toString());
-     *     builder.addHeader("X-Client-Version", "1.0.0");
-     * }
-     * }
- */ - protected void setAdditional(ClientOptions.Builder builder) {} - - /** - * Override this method to add custom validation logic before the client is built. - * This method is called at the beginning of the build() method to ensure the configuration is valid. - * Throw an exception to prevent client creation if validation fails. - * - * Example: - *
{@code
-     * @Override
-     * protected void validateConfiguration() {
-     *     super.validateConfiguration(); // Run parent validations
-     *     if (tenantId == null || tenantId.isEmpty()) {
-     *         throw new IllegalStateException("tenantId is required");
-     *     }
-     * }
-     * }
- */ - protected void validateConfiguration() {} - public SquareClient build() { - validateConfiguration(); - return new SquareClient(buildClientOptions()); + this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + this.token); + this.clientOptionsBuilder.addHeader("Square-Version", this.version); + clientOptionsBuilder.environment(this.environment); + return new SquareClient(clientOptionsBuilder.build()); } } diff --git a/src/main/java/com/squareup/square/TransferOrdersClient.java b/src/main/java/com/squareup/square/TransferOrdersClient.java deleted file mode 100644 index 72153370..00000000 --- a/src/main/java/com/squareup/square/TransferOrdersClient.java +++ /dev/null @@ -1,299 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square; - -import com.squareup.square.core.ClientOptions; -import com.squareup.square.core.RequestOptions; -import com.squareup.square.core.SyncPagingIterable; -import com.squareup.square.types.CancelTransferOrderRequest; -import com.squareup.square.types.CancelTransferOrderResponse; -import com.squareup.square.types.CreateTransferOrderRequest; -import com.squareup.square.types.CreateTransferOrderResponse; -import com.squareup.square.types.DeleteTransferOrderResponse; -import com.squareup.square.types.DeleteTransferOrdersRequest; -import com.squareup.square.types.GetTransferOrdersRequest; -import com.squareup.square.types.ReceiveTransferOrderRequest; -import com.squareup.square.types.ReceiveTransferOrderResponse; -import com.squareup.square.types.RetrieveTransferOrderResponse; -import com.squareup.square.types.SearchTransferOrdersRequest; -import com.squareup.square.types.StartTransferOrderRequest; -import com.squareup.square.types.StartTransferOrderResponse; -import com.squareup.square.types.TransferOrder; -import com.squareup.square.types.UpdateTransferOrderRequest; -import com.squareup.square.types.UpdateTransferOrderResponse; - -public class TransferOrdersClient { - protected final ClientOptions clientOptions; - - private final RawTransferOrdersClient rawClient; - - public TransferOrdersClient(ClientOptions clientOptions) { - this.clientOptions = clientOptions; - this.rawClient = new RawTransferOrdersClient(clientOptions); - } - - /** - * Get responses with HTTP metadata like headers - */ - public RawTransferOrdersClient withRawResponse() { - return this.rawClient; - } - - /** - * Creates a new transfer order in DRAFT status. A transfer order represents the intent - * to move CatalogItemVariations from one Location to another. - * The source and destination locations must be different and must belong to your Square account. - *

In DRAFT status, you can:

- *
    - *
  • Add or remove items
  • - *
  • Modify quantities
  • - *
  • Update shipping information
  • - *
  • Delete the entire order via DeleteTransferOrder
  • - *
- *

The request requires source_location_id and destination_location_id. - * Inventory levels are not affected until the order is started via - * StartTransferOrder.

- *

Common integration points:

- *
    - *
  • Sync with warehouse management systems
  • - *
  • Automate regular stock transfers
  • - *
  • Initialize transfers from inventory optimization systems
  • - *
- *

Creates a transfer_order.created webhook event.

- */ - public CreateTransferOrderResponse create(CreateTransferOrderRequest request) { - return this.rawClient.create(request).body(); - } - - /** - * Creates a new transfer order in DRAFT status. A transfer order represents the intent - * to move CatalogItemVariations from one Location to another. - * The source and destination locations must be different and must belong to your Square account. - *

In DRAFT status, you can:

- *
    - *
  • Add or remove items
  • - *
  • Modify quantities
  • - *
  • Update shipping information
  • - *
  • Delete the entire order via DeleteTransferOrder
  • - *
- *

The request requires source_location_id and destination_location_id. - * Inventory levels are not affected until the order is started via - * StartTransferOrder.

- *

Common integration points:

- *
    - *
  • Sync with warehouse management systems
  • - *
  • Automate regular stock transfers
  • - *
  • Initialize transfers from inventory optimization systems
  • - *
- *

Creates a transfer_order.created webhook event.

- */ - public CreateTransferOrderResponse create(CreateTransferOrderRequest request, RequestOptions requestOptions) { - return this.rawClient.create(request, requestOptions).body(); - } - - /** - * Searches for transfer orders using filters. Returns a paginated list of matching - * TransferOrders sorted by creation date. - *

Common search scenarios:

- * - */ - public SyncPagingIterable search() { - return this.rawClient.search().body(); - } - - /** - * Searches for transfer orders using filters. Returns a paginated list of matching - * TransferOrders sorted by creation date. - *

Common search scenarios:

- * - */ - public SyncPagingIterable search(SearchTransferOrdersRequest request) { - return this.rawClient.search(request).body(); - } - - /** - * Searches for transfer orders using filters. Returns a paginated list of matching - * TransferOrders sorted by creation date. - *

Common search scenarios:

- * - */ - public SyncPagingIterable search( - SearchTransferOrdersRequest request, RequestOptions requestOptions) { - return this.rawClient.search(request, requestOptions).body(); - } - - /** - * Retrieves a specific TransferOrder by ID. Returns the complete - * order details including: - *
    - *
  • Basic information (status, dates, notes)
  • - *
  • Line items with ordered and received quantities
  • - *
  • Source and destination Locations
  • - *
  • Tracking information (if available)
  • - *
- */ - public RetrieveTransferOrderResponse get(GetTransferOrdersRequest request) { - return this.rawClient.get(request).body(); - } - - /** - * Retrieves a specific TransferOrder by ID. Returns the complete - * order details including: - *
    - *
  • Basic information (status, dates, notes)
  • - *
  • Line items with ordered and received quantities
  • - *
  • Source and destination Locations
  • - *
  • Tracking information (if available)
  • - *
- */ - public RetrieveTransferOrderResponse get(GetTransferOrdersRequest request, RequestOptions requestOptions) { - return this.rawClient.get(request, requestOptions).body(); - } - - /** - * Updates an existing transfer order. This endpoint supports sparse updates, - * allowing you to modify specific fields without affecting others. - *

Creates a transfer_order.updated webhook event.

- */ - public UpdateTransferOrderResponse update(UpdateTransferOrderRequest request) { - return this.rawClient.update(request).body(); - } - - /** - * Updates an existing transfer order. This endpoint supports sparse updates, - * allowing you to modify specific fields without affecting others. - *

Creates a transfer_order.updated webhook event.

- */ - public UpdateTransferOrderResponse update(UpdateTransferOrderRequest request, RequestOptions requestOptions) { - return this.rawClient.update(request, requestOptions).body(); - } - - /** - * Deletes a transfer order in DRAFT status. - * Only draft orders can be deleted. Once an order is started via - * StartTransferOrder, it can no longer be deleted. - *

Creates a transfer_order.deleted webhook event.

- */ - public DeleteTransferOrderResponse delete(DeleteTransferOrdersRequest request) { - return this.rawClient.delete(request).body(); - } - - /** - * Deletes a transfer order in DRAFT status. - * Only draft orders can be deleted. Once an order is started via - * StartTransferOrder, it can no longer be deleted. - *

Creates a transfer_order.deleted webhook event.

- */ - public DeleteTransferOrderResponse delete(DeleteTransferOrdersRequest request, RequestOptions requestOptions) { - return this.rawClient.delete(request, requestOptions).body(); - } - - /** - * Cancels a transfer order in STARTED or - * PARTIALLY_RECEIVED status. Any unreceived quantities will no - * longer be receivable and will be immediately returned to the source Location's inventory. - *

Common reasons for cancellation:

- *
    - *
  • Items no longer needed at destination
  • - *
  • Source location needs the inventory
  • - *
  • Order created in error
  • - *
- *

Creates a transfer_order.updated webhook event.

- */ - public CancelTransferOrderResponse cancel(CancelTransferOrderRequest request) { - return this.rawClient.cancel(request).body(); - } - - /** - * Cancels a transfer order in STARTED or - * PARTIALLY_RECEIVED status. Any unreceived quantities will no - * longer be receivable and will be immediately returned to the source Location's inventory. - *

Common reasons for cancellation:

- *
    - *
  • Items no longer needed at destination
  • - *
  • Source location needs the inventory
  • - *
  • Order created in error
  • - *
- *

Creates a transfer_order.updated webhook event.

- */ - public CancelTransferOrderResponse cancel(CancelTransferOrderRequest request, RequestOptions requestOptions) { - return this.rawClient.cancel(request, requestOptions).body(); - } - - /** - * Records receipt of CatalogItemVariations for a transfer order. - * This endpoint supports partial receiving - you can receive items in multiple batches. - *

For each line item, you can specify:

- *
    - *
  • Quantity received in good condition (added to destination inventory with InventoryState of IN_STOCK)
  • - *
  • Quantity damaged during transit/handling (added to destination inventory with InventoryState of WASTE)
  • - *
  • Quantity canceled (returned to source location's inventory)
  • - *
- *

The order must be in STARTED or PARTIALLY_RECEIVED status. - * Received quantities are added to the destination Location's inventory according to their condition. - * Canceled quantities are immediately returned to the source Location's inventory.

- *

When all items are either received, damaged, or canceled, the order moves to - * COMPLETED status.

- *

Creates a transfer_order.updated webhook event.

- */ - public ReceiveTransferOrderResponse receive(ReceiveTransferOrderRequest request) { - return this.rawClient.receive(request).body(); - } - - /** - * Records receipt of CatalogItemVariations for a transfer order. - * This endpoint supports partial receiving - you can receive items in multiple batches. - *

For each line item, you can specify:

- *
    - *
  • Quantity received in good condition (added to destination inventory with InventoryState of IN_STOCK)
  • - *
  • Quantity damaged during transit/handling (added to destination inventory with InventoryState of WASTE)
  • - *
  • Quantity canceled (returned to source location's inventory)
  • - *
- *

The order must be in STARTED or PARTIALLY_RECEIVED status. - * Received quantities are added to the destination Location's inventory according to their condition. - * Canceled quantities are immediately returned to the source Location's inventory.

- *

When all items are either received, damaged, or canceled, the order moves to - * COMPLETED status.

- *

Creates a transfer_order.updated webhook event.

- */ - public ReceiveTransferOrderResponse receive(ReceiveTransferOrderRequest request, RequestOptions requestOptions) { - return this.rawClient.receive(request, requestOptions).body(); - } - - /** - * Changes a DRAFT transfer order to STARTED status. - * This decrements inventory at the source Location and marks it as in-transit. - *

The order must be in DRAFT status and have all required fields populated. - * Once started, the order can no longer be deleted, but it can be canceled via - * CancelTransferOrder.

- *

Creates a transfer_order.updated webhook event.

- */ - public StartTransferOrderResponse start(StartTransferOrderRequest request) { - return this.rawClient.start(request).body(); - } - - /** - * Changes a DRAFT transfer order to STARTED status. - * This decrements inventory at the source Location and marks it as in-transit. - *

The order must be in DRAFT status and have all required fields populated. - * Once started, the order can no longer be deleted, but it can be canceled via - * CancelTransferOrder.

- *

Creates a transfer_order.updated webhook event.

- */ - public StartTransferOrderResponse start(StartTransferOrderRequest request, RequestOptions requestOptions) { - return this.rawClient.start(request, requestOptions).body(); - } -} diff --git a/src/main/java/com/squareup/square/bookings/AsyncRawCustomAttributeDefinitionsClient.java b/src/main/java/com/squareup/square/bookings/AsyncRawCustomAttributeDefinitionsClient.java index fad95255..3e11e97c 100644 --- a/src/main/java/com/squareup/square/bookings/AsyncRawCustomAttributeDefinitionsClient.java +++ b/src/main/java/com/squareup/square/bookings/AsyncRawCustomAttributeDefinitionsClient.java @@ -101,11 +101,10 @@ public CompletableFuture startingAfter = parsedResponse.getCursor(); ListCustomAttributeDefinitionsRequest nextRequest = ListCustomAttributeDefinitionsRequest.builder() @@ -116,7 +115,7 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO parsedResponse.getCustomAttributeDefinitions().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { + startingAfter.isPresent(), result, () -> { try { return list(nextRequest, requestOptions) .get() @@ -128,9 +127,12 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -194,17 +196,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateBookingCustomAttributeDefinitionResponse.class), + responseBody.string(), CreateBookingCustomAttributeDefinitionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -260,17 +264,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, RetrieveBookingCustomAttributeDefinitionResponse.class), + responseBody.string(), RetrieveBookingCustomAttributeDefinitionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -335,17 +341,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpdateBookingCustomAttributeDefinitionResponse.class), + responseBody.string(), UpdateBookingCustomAttributeDefinitionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -402,17 +410,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DeleteBookingCustomAttributeDefinitionResponse.class), + responseBody.string(), DeleteBookingCustomAttributeDefinitionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/bookings/AsyncRawCustomAttributesClient.java b/src/main/java/com/squareup/square/bookings/AsyncRawCustomAttributesClient.java index eec7a770..4c932ae9 100644 --- a/src/main/java/com/squareup/square/bookings/AsyncRawCustomAttributesClient.java +++ b/src/main/java/com/squareup/square/bookings/AsyncRawCustomAttributesClient.java @@ -99,17 +99,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BulkDeleteBookingCustomAttributesResponse.class), + responseBody.string(), BulkDeleteBookingCustomAttributesResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -173,17 +175,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BulkUpsertBookingCustomAttributesResponse.class), + responseBody.string(), BulkUpsertBookingCustomAttributesResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -248,10 +252,9 @@ public CompletableFuture startingAfter = parsedResponse.getCursor(); ListCustomAttributesRequest nextRequest = ListCustomAttributesRequest.builder() .from(request) @@ -260,22 +263,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO List result = parsedResponse.getCustomAttributes().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return list(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return list(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -337,17 +342,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, RetrieveBookingCustomAttributeResponse.class), + responseBody.string(), RetrieveBookingCustomAttributeResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -414,17 +421,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpsertBookingCustomAttributeResponse.class), + responseBody.string(), UpsertBookingCustomAttributeResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -483,17 +492,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DeleteBookingCustomAttributeResponse.class), + responseBody.string(), DeleteBookingCustomAttributeResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/bookings/AsyncRawLocationProfilesClient.java b/src/main/java/com/squareup/square/bookings/AsyncRawLocationProfilesClient.java index 94c126be..01d288c4 100644 --- a/src/main/java/com/squareup/square/bookings/AsyncRawLocationProfilesClient.java +++ b/src/main/java/com/squareup/square/bookings/AsyncRawLocationProfilesClient.java @@ -84,10 +84,9 @@ public CompletableFuture startingAfter = parsedResponse.getCursor(); ListLocationProfilesRequest nextRequest = ListLocationProfilesRequest.builder() .from(request) @@ -97,7 +96,7 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO parsedResponse.getLocationBookingProfiles().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { + startingAfter.isPresent(), result, () -> { try { return list(nextRequest, requestOptions) .get() @@ -109,9 +108,12 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/bookings/AsyncRawTeamMemberProfilesClient.java b/src/main/java/com/squareup/square/bookings/AsyncRawTeamMemberProfilesClient.java index a8805904..e9b6a0aa 100644 --- a/src/main/java/com/squareup/square/bookings/AsyncRawTeamMemberProfilesClient.java +++ b/src/main/java/com/squareup/square/bookings/AsyncRawTeamMemberProfilesClient.java @@ -94,10 +94,9 @@ public CompletableFuture startingAfter = parsedResponse.getCursor(); ListTeamMemberProfilesRequest nextRequest = ListTeamMemberProfilesRequest.builder() .from(request) @@ -107,7 +106,7 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO parsedResponse.getTeamMemberBookingProfiles().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { + startingAfter.isPresent(), result, () -> { try { return list(nextRequest, requestOptions) .get() @@ -119,9 +118,12 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -170,17 +172,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, GetTeamMemberBookingProfileResponse.class), + responseBody.string(), GetTeamMemberBookingProfileResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/bookings/RawCustomAttributeDefinitionsClient.java b/src/main/java/com/squareup/square/bookings/RawCustomAttributeDefinitionsClient.java index 1d294a28..a7087547 100644 --- a/src/main/java/com/squareup/square/bookings/RawCustomAttributeDefinitionsClient.java +++ b/src/main/java/com/squareup/square/bookings/RawCustomAttributeDefinitionsClient.java @@ -92,10 +92,9 @@ public SquareClientHttpResponse> l } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListBookingCustomAttributeDefinitionsResponse parsedResponse = ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, ListBookingCustomAttributeDefinitionsResponse.class); + responseBody.string(), ListBookingCustomAttributeDefinitionsResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListCustomAttributeDefinitionsRequest nextRequest = ListCustomAttributeDefinitionsRequest.builder() .from(request) @@ -105,14 +104,16 @@ public SquareClientHttpResponse> l parsedResponse.getCustomAttributeDefinitions().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -163,16 +164,18 @@ public SquareClientHttpResponse } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateBookingCustomAttributeDefinitionResponse.class), + responseBody.string(), CreateBookingCustomAttributeDefinitionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -215,16 +218,18 @@ public SquareClientHttpResponse( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, RetrieveBookingCustomAttributeDefinitionResponse.class), + responseBody.string(), RetrieveBookingCustomAttributeDefinitionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -276,16 +281,18 @@ public SquareClientHttpResponse } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpdateBookingCustomAttributeDefinitionResponse.class), + responseBody.string(), UpdateBookingCustomAttributeDefinitionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -329,16 +336,18 @@ public SquareClientHttpResponse } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DeleteBookingCustomAttributeDefinitionResponse.class), + responseBody.string(), DeleteBookingCustomAttributeDefinitionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/bookings/RawCustomAttributesClient.java b/src/main/java/com/squareup/square/bookings/RawCustomAttributesClient.java index 047723d7..a9741eed 100644 --- a/src/main/java/com/squareup/square/bookings/RawCustomAttributesClient.java +++ b/src/main/java/com/squareup/square/bookings/RawCustomAttributesClient.java @@ -90,16 +90,18 @@ public SquareClientHttpResponse batch } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BulkDeleteBookingCustomAttributesResponse.class), + responseBody.string(), BulkDeleteBookingCustomAttributesResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -150,16 +152,18 @@ public SquareClientHttpResponse batch } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BulkUpsertBookingCustomAttributesResponse.class), + responseBody.string(), BulkUpsertBookingCustomAttributesResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -210,10 +214,9 @@ public SquareClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListBookingCustomAttributesResponse parsedResponse = ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, ListBookingCustomAttributesResponse.class); + responseBody.string(), ListBookingCustomAttributesResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListCustomAttributesRequest nextRequest = ListCustomAttributesRequest.builder() .from(request) @@ -223,14 +226,16 @@ public SquareClientHttpResponse> list( parsedResponse.getCustomAttributes().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -278,16 +283,18 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, RetrieveBookingCustomAttributeResponse.class), + responseBody.string(), RetrieveBookingCustomAttributeResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -341,16 +348,18 @@ public SquareClientHttpResponse upsert( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpsertBookingCustomAttributeResponse.class), + responseBody.string(), UpsertBookingCustomAttributeResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -396,16 +405,18 @@ public SquareClientHttpResponse delete( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DeleteBookingCustomAttributeResponse.class), + responseBody.string(), DeleteBookingCustomAttributeResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/bookings/RawLocationProfilesClient.java b/src/main/java/com/squareup/square/bookings/RawLocationProfilesClient.java index a886c2cc..3ef54e6c 100644 --- a/src/main/java/com/squareup/square/bookings/RawLocationProfilesClient.java +++ b/src/main/java/com/squareup/square/bookings/RawLocationProfilesClient.java @@ -75,10 +75,9 @@ public SquareClientHttpResponse> list } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListLocationBookingProfilesResponse parsedResponse = ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, ListLocationBookingProfilesResponse.class); + responseBody.string(), ListLocationBookingProfilesResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListLocationProfilesRequest nextRequest = ListLocationProfilesRequest.builder() .from(request) @@ -88,14 +87,16 @@ public SquareClientHttpResponse> list parsedResponse.getLocationBookingProfiles().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/bookings/RawTeamMemberProfilesClient.java b/src/main/java/com/squareup/square/bookings/RawTeamMemberProfilesClient.java index e5549cff..0d2d0c54 100644 --- a/src/main/java/com/squareup/square/bookings/RawTeamMemberProfilesClient.java +++ b/src/main/java/com/squareup/square/bookings/RawTeamMemberProfilesClient.java @@ -85,10 +85,9 @@ public SquareClientHttpResponse> li } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListTeamMemberBookingProfilesResponse parsedResponse = ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, ListTeamMemberBookingProfilesResponse.class); + responseBody.string(), ListTeamMemberBookingProfilesResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListTeamMemberProfilesRequest nextRequest = ListTeamMemberProfilesRequest.builder() .from(request) @@ -98,14 +97,16 @@ public SquareClientHttpResponse> li parsedResponse.getTeamMemberBookingProfiles().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -140,16 +141,18 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, GetTeamMemberBookingProfileResponse.class), + responseBody.string(), GetTeamMemberBookingProfileResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/bookings/types/BulkDeleteBookingCustomAttributesRequest.java b/src/main/java/com/squareup/square/bookings/types/BulkDeleteBookingCustomAttributesRequest.java index d55726c9..469e435d 100644 --- a/src/main/java/com/squareup/square/bookings/types/BulkDeleteBookingCustomAttributesRequest.java +++ b/src/main/java/com/squareup/square/bookings/types/BulkDeleteBookingCustomAttributesRequest.java @@ -93,16 +93,12 @@ public Builder from(BulkDeleteBookingCustomAttributesRequest other) { @JsonSetter(value = "values", nulls = Nulls.SKIP) public Builder values(Map values) { this.values.clear(); - if (values != null) { - this.values.putAll(values); - } + this.values.putAll(values); return this; } public Builder putAllValues(Map values) { - if (values != null) { - this.values.putAll(values); - } + this.values.putAll(values); return this; } diff --git a/src/main/java/com/squareup/square/bookings/types/BulkUpsertBookingCustomAttributesRequest.java b/src/main/java/com/squareup/square/bookings/types/BulkUpsertBookingCustomAttributesRequest.java index 9cae6c18..bdcb1921 100644 --- a/src/main/java/com/squareup/square/bookings/types/BulkUpsertBookingCustomAttributesRequest.java +++ b/src/main/java/com/squareup/square/bookings/types/BulkUpsertBookingCustomAttributesRequest.java @@ -93,16 +93,12 @@ public Builder from(BulkUpsertBookingCustomAttributesRequest other) { @JsonSetter(value = "values", nulls = Nulls.SKIP) public Builder values(Map values) { this.values.clear(); - if (values != null) { - this.values.putAll(values); - } + this.values.putAll(values); return this; } public Builder putAllValues(Map values) { - if (values != null) { - this.values.putAll(values); - } + this.values.putAll(values); return this; } diff --git a/src/main/java/com/squareup/square/cashdrawers/AsyncRawShiftsClient.java b/src/main/java/com/squareup/square/cashdrawers/AsyncRawShiftsClient.java index 182c9b14..de8a0961 100644 --- a/src/main/java/com/squareup/square/cashdrawers/AsyncRawShiftsClient.java +++ b/src/main/java/com/squareup/square/cashdrawers/AsyncRawShiftsClient.java @@ -97,10 +97,9 @@ public CompletableFuture startingAfter = parsedResponse.getCursor(); ListShiftsRequest nextRequest = ListShiftsRequest.builder() .from(request) @@ -110,7 +109,7 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO parsedResponse.getCashDrawerShifts().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { + startingAfter.isPresent(), result, () -> { try { return list(nextRequest, requestOptions) .get() @@ -122,9 +121,12 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -173,17 +175,19 @@ public CompletableFuture> g @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, GetCashDrawerShiftResponse.class), + responseBody.string(), GetCashDrawerShiftResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -241,10 +245,9 @@ public CompletableFuture startingAfter = parsedResponse.getCursor(); ListEventsShiftsRequest nextRequest = ListEventsShiftsRequest.builder() .from(request) @@ -253,22 +256,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO List result = parsedResponse.getCashDrawerShiftEvents().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return listEvents(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return listEvents(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/cashdrawers/RawShiftsClient.java b/src/main/java/com/squareup/square/cashdrawers/RawShiftsClient.java index 886a5671..6a823624 100644 --- a/src/main/java/com/squareup/square/cashdrawers/RawShiftsClient.java +++ b/src/main/java/com/squareup/square/cashdrawers/RawShiftsClient.java @@ -87,10 +87,9 @@ public SquareClientHttpResponse> list } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListCashDrawerShiftsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListCashDrawerShiftsResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListCashDrawerShiftsResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListShiftsRequest nextRequest = ListShiftsRequest.builder() .from(request) @@ -100,14 +99,16 @@ public SquareClientHttpResponse> list parsedResponse.getCashDrawerShifts().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -144,15 +145,17 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetCashDrawerShiftResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetCashDrawerShiftResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -197,10 +200,9 @@ public SquareClientHttpResponse> listEv } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListCashDrawerShiftEventsResponse parsedResponse = ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, ListCashDrawerShiftEventsResponse.class); + responseBody.string(), ListCashDrawerShiftEventsResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListEventsShiftsRequest nextRequest = ListEventsShiftsRequest.builder() .from(request) @@ -210,14 +212,16 @@ public SquareClientHttpResponse> listEv parsedResponse.getCashDrawerShiftEvents().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> listEvents( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> listEvents(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/catalog/AsyncImagesClient.java b/src/main/java/com/squareup/square/catalog/AsyncImagesClient.java index fda57e3b..4f9859c0 100644 --- a/src/main/java/com/squareup/square/catalog/AsyncImagesClient.java +++ b/src/main/java/com/squareup/square/catalog/AsyncImagesClient.java @@ -9,9 +9,7 @@ import com.squareup.square.core.RequestOptions; import com.squareup.square.types.CreateCatalogImageResponse; import com.squareup.square.types.UpdateCatalogImageResponse; -import java.io.InputStream; import java.util.concurrent.CompletableFuture; -import okhttp3.MediaType; public class AsyncImagesClient { protected final ClientOptions clientOptions; @@ -64,27 +62,6 @@ public CompletableFuture create( return this.rawClient.create(request, requestOptions).thenApply(response -> response.body()); } - public CompletableFuture create(InputStream stream, String filename) { - return this.rawClient.create(stream, filename).thenApply(response -> response.body()); - } - - public CompletableFuture create( - InputStream stream, String filename, MediaType mediaType) { - return this.rawClient.create(stream, filename, mediaType).thenApply(response -> response.body()); - } - - public CompletableFuture create( - InputStream stream, String filename, RequestOptions requestOptions) { - return this.rawClient.create(stream, filename, requestOptions).thenApply(response -> response.body()); - } - - public CompletableFuture create( - InputStream stream, String filename, MediaType mediaType, RequestOptions requestOptions) { - return this.rawClient - .create(stream, filename, mediaType, requestOptions) - .thenApply(response -> response.body()); - } - /** * Uploads a new image file to replace the existing one in the specified CatalogImage object. *

This UpdateCatalogImage endpoint accepts HTTP multipart/form-data requests with a JSON part and an image file part in diff --git a/src/main/java/com/squareup/square/catalog/AsyncRawImagesClient.java b/src/main/java/com/squareup/square/catalog/AsyncRawImagesClient.java index 0171f31a..93f34bfa 100644 --- a/src/main/java/com/squareup/square/catalog/AsyncRawImagesClient.java +++ b/src/main/java/com/squareup/square/catalog/AsyncRawImagesClient.java @@ -6,7 +6,6 @@ import com.squareup.square.catalog.types.CreateImagesRequest; import com.squareup.square.catalog.types.UpdateImagesRequest; import com.squareup.square.core.ClientOptions; -import com.squareup.square.core.FileStream; import com.squareup.square.core.ObjectMappers; import com.squareup.square.core.RequestOptions; import com.squareup.square.core.SquareApiException; @@ -15,7 +14,6 @@ import com.squareup.square.types.CreateCatalogImageResponse; import com.squareup.square.types.UpdateCatalogImageResponse; import java.io.IOException; -import java.io.InputStream; import java.nio.file.Files; import java.util.concurrent.CompletableFuture; import okhttp3.Call; @@ -73,10 +71,10 @@ public CompletableFuture> c .newBuilder() .addPathSegments("v2/catalog/images") .build(); - MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM); + MultipartBody.Builder body = new MultipartBody.Builder().setType(MultipartBody.FORM); try { if (request.getRequest().isPresent()) { - multipartBodyBuilder.addFormDataPart( + body.addFormDataPart( "request", ObjectMappers.JSON_MAPPER.writeValueAsString( request.getRequest().get())); @@ -86,7 +84,7 @@ public CompletableFuture> c Files.probeContentType(request.getImageFile().get().toPath()); MediaType imageFileMimeTypeMediaType = imageFileMimeType != null ? MediaType.parse(imageFileMimeType) : null; - multipartBodyBuilder.addFormDataPart( + body.addFormDataPart( "image_file", request.getImageFile().get().getName(), RequestBody.create(request.getImageFile().get(), imageFileMimeTypeMediaType)); @@ -96,7 +94,7 @@ public CompletableFuture> c } Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl) - .method("POST", multipartBodyBuilder.build()) + .method("POST", body.build()) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); Request okhttpRequest = _requestBuilder.build(); @@ -109,207 +107,19 @@ public CompletableFuture> c @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateCatalogImageResponse.class), - response)); - return; - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); - return; - } catch (IOException e) { - future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); - } - } - - @Override - public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); - } - }); - return future; - } - - public CompletableFuture> create( - InputStream stream, String filename) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("v2/catalog/images") - .build(); - FileStream fs = new FileStream(stream, filename, null); - MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM); - multipartBodyBuilder.addFormDataPart("image_file", filename, fs.toRequestBody()); - RequestBody body = multipartBodyBuilder.build(); - Request.Builder _requestBuilder = new Request.Builder(); - _requestBuilder.url(httpUrl); - _requestBuilder.method("POST", body); - _requestBuilder.headers(Headers.of(this.clientOptions.headers(null))); - Request okhttpRequest = _requestBuilder.build(); - OkHttpClient client = clientOptions.httpClient(); - CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { - @Override - public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { - try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateCatalogImageResponse.class), - response)); - return; - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); - return; - } catch (IOException e) { - future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); - } - } - - @Override - public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); - } - }); - return future; - } - - public CompletableFuture> create( - InputStream stream, String filename, MediaType mediaType) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("v2/catalog/images") - .build(); - FileStream fs = new FileStream(stream, filename, mediaType); - MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM); - multipartBodyBuilder.addFormDataPart("image_file", filename, fs.toRequestBody()); - RequestBody body = multipartBodyBuilder.build(); - Request.Builder _requestBuilder = new Request.Builder(); - _requestBuilder.url(httpUrl); - _requestBuilder.method("POST", body); - _requestBuilder.headers(Headers.of(this.clientOptions.headers(null))); - Request okhttpRequest = _requestBuilder.build(); - OkHttpClient client = clientOptions.httpClient(); - CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { - @Override - public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { - try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateCatalogImageResponse.class), - response)); - return; - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); - return; - } catch (IOException e) { - future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); - } - } - - @Override - public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); - } - }); - return future; - } - - public CompletableFuture> create( - InputStream stream, String filename, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("v2/catalog/images") - .build(); - FileStream fs = new FileStream(stream, filename, null); - MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM); - multipartBodyBuilder.addFormDataPart("image_file", filename, fs.toRequestBody()); - RequestBody body = multipartBodyBuilder.build(); - Request.Builder _requestBuilder = new Request.Builder(); - _requestBuilder.url(httpUrl); - _requestBuilder.method("POST", body); - _requestBuilder.headers(Headers.of(this.clientOptions.headers(requestOptions))); - Request okhttpRequest = _requestBuilder.build(); - OkHttpClient client = clientOptions.httpClient(); - if (requestOptions != null && requestOptions.getTimeout().isPresent()) { - client = clientOptions.httpClientWithTimeout(requestOptions); - } - CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { - @Override - public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { - try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateCatalogImageResponse.class), + responseBody.string(), CreateCatalogImageResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); - return; - } catch (IOException e) { - future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); - } - } - - @Override - public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); - } - }); - return future; - } - - public CompletableFuture> create( - InputStream stream, String filename, MediaType mediaType, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("v2/catalog/images") - .build(); - FileStream fs = new FileStream(stream, filename, mediaType); - MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM); - multipartBodyBuilder.addFormDataPart("image_file", filename, fs.toRequestBody()); - RequestBody body = multipartBodyBuilder.build(); - Request.Builder _requestBuilder = new Request.Builder(); - _requestBuilder.url(httpUrl); - _requestBuilder.method("POST", body); - _requestBuilder.headers(Headers.of(this.clientOptions.headers(requestOptions))); - Request okhttpRequest = _requestBuilder.build(); - OkHttpClient client = clientOptions.httpClient(); - if (requestOptions != null && requestOptions.getTimeout().isPresent()) { - client = clientOptions.httpClientWithTimeout(requestOptions); - } - CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { - @Override - public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { - try (ResponseBody responseBody = response.body()) { String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateCatalogImageResponse.class), - response)); - return; - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -345,10 +155,10 @@ public CompletableFuture> u .addPathSegments("v2/catalog/images") .addPathSegment(request.getImageId()) .build(); - MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM); + MultipartBody.Builder body = new MultipartBody.Builder().setType(MultipartBody.FORM); try { if (request.getRequest().isPresent()) { - multipartBodyBuilder.addFormDataPart( + body.addFormDataPart( "request", ObjectMappers.JSON_MAPPER.writeValueAsString( request.getRequest().get())); @@ -358,7 +168,7 @@ public CompletableFuture> u Files.probeContentType(request.getImageFile().get().toPath()); MediaType imageFileMimeTypeMediaType = imageFileMimeType != null ? MediaType.parse(imageFileMimeType) : null; - multipartBodyBuilder.addFormDataPart( + body.addFormDataPart( "image_file", request.getImageFile().get().getName(), RequestBody.create(request.getImageFile().get(), imageFileMimeTypeMediaType)); @@ -368,7 +178,7 @@ public CompletableFuture> u } Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl) - .method("PUT", multipartBodyBuilder.build()) + .method("PUT", body.build()) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); Request okhttpRequest = _requestBuilder.build(); @@ -381,17 +191,19 @@ public CompletableFuture> u @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpdateCatalogImageResponse.class), + responseBody.string(), UpdateCatalogImageResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/catalog/AsyncRawObjectClient.java b/src/main/java/com/squareup/square/catalog/AsyncRawObjectClient.java index 24891fe2..7e998617 100644 --- a/src/main/java/com/squareup/square/catalog/AsyncRawObjectClient.java +++ b/src/main/java/com/squareup/square/catalog/AsyncRawObjectClient.java @@ -84,17 +84,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpsertCatalogObjectResponse.class), + responseBody.string(), UpsertCatalogObjectResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -170,16 +172,19 @@ public CompletableFuture> get @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetCatalogObjectResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), GetCatalogObjectResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -243,17 +248,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DeleteCatalogObjectResponse.class), + responseBody.string(), DeleteCatalogObjectResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/catalog/ImagesClient.java b/src/main/java/com/squareup/square/catalog/ImagesClient.java index 58ff02be..77878d0d 100644 --- a/src/main/java/com/squareup/square/catalog/ImagesClient.java +++ b/src/main/java/com/squareup/square/catalog/ImagesClient.java @@ -9,8 +9,6 @@ import com.squareup.square.core.RequestOptions; import com.squareup.square.types.CreateCatalogImageResponse; import com.squareup.square.types.UpdateCatalogImageResponse; -import java.io.InputStream; -import okhttp3.MediaType; public class ImagesClient { protected final ClientOptions clientOptions; @@ -62,25 +60,6 @@ public CreateCatalogImageResponse create(CreateImagesRequest request, RequestOpt return this.rawClient.create(request, requestOptions).body(); } - public CreateCatalogImageResponse create(InputStream stream, String filename) { - return this.rawClient.create(stream, filename).body(); - } - - public CreateCatalogImageResponse create(InputStream stream, String filename, MediaType mediaType) { - return this.rawClient.create(stream, filename, mediaType).body(); - } - - public CreateCatalogImageResponse create(InputStream stream, String filename, RequestOptions requestOptions) { - return this.rawClient.create(stream, filename, requestOptions).body(); - } - - public CreateCatalogImageResponse create( - InputStream stream, String filename, MediaType mediaType, RequestOptions requestOptions) { - return this.rawClient - .create(stream, filename, mediaType, requestOptions) - .body(); - } - /** * Uploads a new image file to replace the existing one in the specified CatalogImage object. *

This UpdateCatalogImage endpoint accepts HTTP multipart/form-data requests with a JSON part and an image file part in diff --git a/src/main/java/com/squareup/square/catalog/RawImagesClient.java b/src/main/java/com/squareup/square/catalog/RawImagesClient.java index ee8826ed..98d52191 100644 --- a/src/main/java/com/squareup/square/catalog/RawImagesClient.java +++ b/src/main/java/com/squareup/square/catalog/RawImagesClient.java @@ -6,7 +6,6 @@ import com.squareup.square.catalog.types.CreateImagesRequest; import com.squareup.square.catalog.types.UpdateImagesRequest; import com.squareup.square.core.ClientOptions; -import com.squareup.square.core.FileStream; import com.squareup.square.core.ObjectMappers; import com.squareup.square.core.RequestOptions; import com.squareup.square.core.SquareApiException; @@ -15,7 +14,6 @@ import com.squareup.square.types.CreateCatalogImageResponse; import com.squareup.square.types.UpdateCatalogImageResponse; import java.io.IOException; -import java.io.InputStream; import java.nio.file.Files; import okhttp3.Headers; import okhttp3.HttpUrl; @@ -69,10 +67,10 @@ public SquareClientHttpResponse create( .newBuilder() .addPathSegments("v2/catalog/images") .build(); - MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM); + MultipartBody.Builder body = new MultipartBody.Builder().setType(MultipartBody.FORM); try { if (request.getRequest().isPresent()) { - multipartBodyBuilder.addFormDataPart( + body.addFormDataPart( "request", ObjectMappers.JSON_MAPPER.writeValueAsString( request.getRequest().get())); @@ -82,7 +80,7 @@ public SquareClientHttpResponse create( Files.probeContentType(request.getImageFile().get().toPath()); MediaType imageFileMimeTypeMediaType = imageFileMimeType != null ? MediaType.parse(imageFileMimeType) : null; - multipartBodyBuilder.addFormDataPart( + body.addFormDataPart( "image_file", request.getImageFile().get().getName(), RequestBody.create(request.getImageFile().get(), imageFileMimeTypeMediaType)); @@ -92,7 +90,7 @@ public SquareClientHttpResponse create( } Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl) - .method("POST", multipartBodyBuilder.build()) + .method("POST", body.build()) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); Request okhttpRequest = _requestBuilder.build(); @@ -102,148 +100,17 @@ public SquareClientHttpResponse create( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateCatalogImageResponse.class), - response); - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); - } catch (IOException e) { - throw new SquareException("Network error executing HTTP request", e); - } - } - - public SquareClientHttpResponse create(InputStream stream, String filename) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("v2/catalog/images") - .build(); - FileStream fs = new FileStream(stream, filename, null); - MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM); - multipartBodyBuilder.addFormDataPart("image_file", filename, fs.toRequestBody()); - RequestBody body = multipartBodyBuilder.build(); - Request.Builder _requestBuilder = new Request.Builder(); - _requestBuilder.url(httpUrl); - _requestBuilder.method("POST", body); - _requestBuilder.headers(Headers.of(this.clientOptions.headers(null))); - Request okhttpRequest = _requestBuilder.build(); - OkHttpClient client = clientOptions.httpClient(); - try (Response response = client.newCall(okhttpRequest).execute()) { - ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateCatalogImageResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateCatalogImageResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); - } catch (IOException e) { - throw new SquareException("Network error executing HTTP request", e); - } - } - - public SquareClientHttpResponse create( - InputStream stream, String filename, MediaType mediaType) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("v2/catalog/images") - .build(); - FileStream fs = new FileStream(stream, filename, mediaType); - MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM); - multipartBodyBuilder.addFormDataPart("image_file", filename, fs.toRequestBody()); - RequestBody body = multipartBodyBuilder.build(); - Request.Builder _requestBuilder = new Request.Builder(); - _requestBuilder.url(httpUrl); - _requestBuilder.method("POST", body); - _requestBuilder.headers(Headers.of(this.clientOptions.headers(null))); - Request okhttpRequest = _requestBuilder.build(); - OkHttpClient client = clientOptions.httpClient(); - try (Response response = client.newCall(okhttpRequest).execute()) { - ResponseBody responseBody = response.body(); String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateCatalogImageResponse.class), - response); - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); - } catch (IOException e) { - throw new SquareException("Network error executing HTTP request", e); - } - } - - public SquareClientHttpResponse create( - InputStream stream, String filename, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("v2/catalog/images") - .build(); - FileStream fs = new FileStream(stream, filename, null); - MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM); - multipartBodyBuilder.addFormDataPart("image_file", filename, fs.toRequestBody()); - RequestBody body = multipartBodyBuilder.build(); - Request.Builder _requestBuilder = new Request.Builder(); - _requestBuilder.url(httpUrl); - _requestBuilder.method("POST", body); - _requestBuilder.headers(Headers.of(this.clientOptions.headers(requestOptions))); - Request okhttpRequest = _requestBuilder.build(); - OkHttpClient client = clientOptions.httpClient(); - if (requestOptions != null && requestOptions.getTimeout().isPresent()) { - client = clientOptions.httpClientWithTimeout(requestOptions); - } - try (Response response = client.newCall(okhttpRequest).execute()) { - ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateCatalogImageResponse.class), - response); - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); - } catch (IOException e) { - throw new SquareException("Network error executing HTTP request", e); - } - } - - public SquareClientHttpResponse create( - InputStream stream, String filename, MediaType mediaType, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) - .newBuilder() - .addPathSegments("v2/catalog/images") - .build(); - FileStream fs = new FileStream(stream, filename, mediaType); - MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM); - multipartBodyBuilder.addFormDataPart("image_file", filename, fs.toRequestBody()); - RequestBody body = multipartBodyBuilder.build(); - Request.Builder _requestBuilder = new Request.Builder(); - _requestBuilder.url(httpUrl); - _requestBuilder.method("POST", body); - _requestBuilder.headers(Headers.of(this.clientOptions.headers(requestOptions))); - Request okhttpRequest = _requestBuilder.build(); - OkHttpClient client = clientOptions.httpClient(); - if (requestOptions != null && requestOptions.getTimeout().isPresent()) { - client = clientOptions.httpClientWithTimeout(requestOptions); - } - try (Response response = client.newCall(okhttpRequest).execute()) { - ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; - if (response.isSuccessful()) { - return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateCatalogImageResponse.class), - response); - } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); - throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -270,10 +137,10 @@ public SquareClientHttpResponse update( .addPathSegments("v2/catalog/images") .addPathSegment(request.getImageId()) .build(); - MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM); + MultipartBody.Builder body = new MultipartBody.Builder().setType(MultipartBody.FORM); try { if (request.getRequest().isPresent()) { - multipartBodyBuilder.addFormDataPart( + body.addFormDataPart( "request", ObjectMappers.JSON_MAPPER.writeValueAsString( request.getRequest().get())); @@ -283,7 +150,7 @@ public SquareClientHttpResponse update( Files.probeContentType(request.getImageFile().get().toPath()); MediaType imageFileMimeTypeMediaType = imageFileMimeType != null ? MediaType.parse(imageFileMimeType) : null; - multipartBodyBuilder.addFormDataPart( + body.addFormDataPart( "image_file", request.getImageFile().get().getName(), RequestBody.create(request.getImageFile().get(), imageFileMimeTypeMediaType)); @@ -293,7 +160,7 @@ public SquareClientHttpResponse update( } Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl) - .method("PUT", multipartBodyBuilder.build()) + .method("PUT", body.build()) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); Request okhttpRequest = _requestBuilder.build(); @@ -303,15 +170,17 @@ public SquareClientHttpResponse update( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateCatalogImageResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UpdateCatalogImageResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/catalog/RawObjectClient.java b/src/main/java/com/squareup/square/catalog/RawObjectClient.java index fe3cfe08..519fef4e 100644 --- a/src/main/java/com/squareup/square/catalog/RawObjectClient.java +++ b/src/main/java/com/squareup/square/catalog/RawObjectClient.java @@ -76,15 +76,17 @@ public SquareClientHttpResponse upsert( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpsertCatalogObjectResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UpsertCatalogObjectResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -148,15 +150,17 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetCatalogObjectResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetCatalogObjectResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -207,15 +211,17 @@ public SquareClientHttpResponse delete( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, DeleteCatalogObjectResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), DeleteCatalogObjectResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/checkout/AsyncRawPaymentLinksClient.java b/src/main/java/com/squareup/square/checkout/AsyncRawPaymentLinksClient.java index 7af04e93..9cc8dfaa 100644 --- a/src/main/java/com/squareup/square/checkout/AsyncRawPaymentLinksClient.java +++ b/src/main/java/com/squareup/square/checkout/AsyncRawPaymentLinksClient.java @@ -94,10 +94,9 @@ public CompletableFuture startingAfter = parsedResponse.getCursor(); ListPaymentLinksRequest nextRequest = ListPaymentLinksRequest.builder() .from(request) @@ -106,22 +105,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO List result = parsedResponse.getPaymentLinks().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return list(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return list(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -183,17 +184,19 @@ public CompletableFuture> cr @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreatePaymentLinkResponse.class), + responseBody.string(), CreatePaymentLinkResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -240,16 +243,19 @@ public CompletableFuture> get( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetPaymentLinkResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), GetPaymentLinkResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -309,17 +315,19 @@ public CompletableFuture> up @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpdatePaymentLinkResponse.class), + responseBody.string(), UpdatePaymentLinkResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -367,17 +375,19 @@ public CompletableFuture> de @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DeletePaymentLinkResponse.class), + responseBody.string(), DeletePaymentLinkResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/checkout/RawPaymentLinksClient.java b/src/main/java/com/squareup/square/checkout/RawPaymentLinksClient.java index 15df312a..65cf5b5c 100644 --- a/src/main/java/com/squareup/square/checkout/RawPaymentLinksClient.java +++ b/src/main/java/com/squareup/square/checkout/RawPaymentLinksClient.java @@ -85,10 +85,9 @@ public SquareClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListPaymentLinksResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListPaymentLinksResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListPaymentLinksResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListPaymentLinksRequest nextRequest = ListPaymentLinksRequest.builder() .from(request) @@ -97,14 +96,16 @@ public SquareClientHttpResponse> list( List result = parsedResponse.getPaymentLinks().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -153,15 +154,17 @@ public SquareClientHttpResponse create( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreatePaymentLinkResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreatePaymentLinkResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -196,15 +199,17 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetPaymentLinkResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetPaymentLinkResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -251,15 +256,17 @@ public SquareClientHttpResponse update( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdatePaymentLinkResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UpdatePaymentLinkResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -294,15 +301,17 @@ public SquareClientHttpResponse delete( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, DeletePaymentLinkResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), DeletePaymentLinkResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/core/AsyncCustomPager.java b/src/main/java/com/squareup/square/core/AsyncCustomPager.java deleted file mode 100644 index 74085142..00000000 --- a/src/main/java/com/squareup/square/core/AsyncCustomPager.java +++ /dev/null @@ -1,164 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.core; - -import java.io.IOException; -import java.util.List; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CompletionStage; - -/** - * Skeleton implementation for custom asynchronous bidirectional pagination. - * - * THIS CLASS MUST BE IMPLEMENTED BY THE USER. - * - * This file is added to .fernignore and will not be regenerated. - * Replace this skeleton implementation with your custom async pagination logic - * that handles your API's specific pagination structure (e.g., HATEOAS links). - * - * Example implementation for HATEOAS-style async pagination: - *

{@code
- * public class AsyncCustomPager implements BiDirectionalPage {
- *     private final List items;
- *     private final String nextUrl;
- *     private final String previousUrl;
- *     private final AsyncHttpClient client;
- *
- *     public AsyncCustomPager(Response response, AsyncHttpClient client, ...) {
- *         this.items = response.getData();
- *         this.nextUrl = response.getLinks().getNext();
- *         this.previousUrl = response.getLinks().getPrevious();
- *         // ... store other needed context
- *     }
- *
- *     @Override
- *     public boolean hasNext() {
- *         return nextUrl != null;
- *     }
- *
- *     @Override
- *     public CompletableFuture> nextPageAsync() {
- *         if (!hasNext()) {
- *             CompletableFuture> future = new CompletableFuture<>();
- *             future.completeExceptionally(new NoSuchElementException("No next page available"));
- *             return future;
- *         }
- *         // Make async HTTP request to nextUrl
- *         return client.getAsync(nextUrl)
- *             .thenApply(response -> new AsyncCustomPager<>(response, client, ...));
- *     }
- *
- *     // ... implement other methods
- * }
- * }
- * - * @param The type of items in the page - */ -public class AsyncCustomPager implements BiDirectionalPage { - - /** - * Create an AsyncCustomPager from an initial response. - * - * @param initialResponse The first page response from the API - * @param client The async HTTP client to use for subsequent requests - * @param requestOptions Request options for authentication, headers, etc. - * @return A CompletableFuture containing the new AsyncCustomPager instance - */ - public static CompletableFuture> createAsync( - Object initialResponse, okhttp3.OkHttpClient client, Object requestOptions) { - throw new UnsupportedOperationException("AsyncCustomPager must be implemented. " - + "Please implement this class in core/AsyncCustomPager.java to define your async pagination logic. " - + "This file has been added to .fernignore and will not be overwritten. " - + "See the class documentation for implementation examples."); - } - - @Override - public boolean hasNext() { - throw new UnsupportedOperationException("AsyncCustomPager.hasNext() must be implemented. " - + "This method should return true if a next page is available."); - } - - @Override - public boolean hasPrevious() { - throw new UnsupportedOperationException("AsyncCustomPager.hasPrevious() must be implemented. " - + "This method should return true if a previous page is available."); - } - - /** - * Asynchronously fetch the next page. - * - * @return A CompletableFuture that completes with the next page - * @throws java.util.NoSuchElementException if no next page exists (wrapped in CompletableFuture) - */ - public CompletableFuture> nextPageAsync() { - CompletableFuture> future = new CompletableFuture<>(); - future.completeExceptionally( - new UnsupportedOperationException("AsyncCustomPager.nextPageAsync() must be implemented. " - + "This method should asynchronously fetch and return the next page of results.")); - return future; - } - - /** - * Asynchronously fetch the previous page. - * - * @return A CompletableFuture that completes with the previous page - * @throws java.util.NoSuchElementException if no previous page exists (wrapped in CompletableFuture) - */ - public CompletableFuture> previousPageAsync() { - CompletableFuture> future = new CompletableFuture<>(); - future.completeExceptionally( - new UnsupportedOperationException("AsyncCustomPager.previousPageAsync() must be implemented. " - + "This method should asynchronously fetch and return the previous page of results.")); - return future; - } - - @Override - public BiDirectionalPage nextPage() throws IOException { - throw new UnsupportedOperationException("AsyncCustomPager.nextPage() must be implemented. " - + "Consider using nextPageAsync() for async operations, or implement synchronous blocking version."); - } - - @Override - public BiDirectionalPage previousPage() throws IOException { - throw new UnsupportedOperationException( - "AsyncCustomPager.previousPage() must be implemented. " - + "Consider using previousPageAsync() for async operations, or implement synchronous blocking version."); - } - - @Override - public List getItems() { - throw new UnsupportedOperationException("AsyncCustomPager.getItems() must be implemented. " - + "This method should return the items in the current page."); - } - - @Override - public Optional getResponse() { - throw new UnsupportedOperationException("AsyncCustomPager.getResponse() must be implemented. " - + "This method should return the full response object for accessing pagination metadata."); - } - - /** - * Asynchronously iterate through all pages starting from current. - * Returns a CompletableFuture that completes with all items from all pages. - * - * @return CompletableFuture containing all items across all pages - */ - public CompletableFuture> getAllItemsAsync() { - throw new UnsupportedOperationException("AsyncCustomPager.getAllItemsAsync() must be implemented. " - + "This method should asynchronously fetch all pages and return all items."); - } - - /** - * Process each page asynchronously as it arrives. - * - * @param pageProcessor Function to process each page - * @return CompletableFuture that completes when all pages are processed - */ - public CompletableFuture forEachPageAsync( - java.util.function.Function, CompletionStage> pageProcessor) { - throw new UnsupportedOperationException("AsyncCustomPager.forEachPageAsync() must be implemented. " - + "This method should asynchronously process each page with the given function."); - } -} diff --git a/src/main/java/com/squareup/square/core/BasePage.java b/src/main/java/com/squareup/square/core/BasePage.java index 4fb16b04..1ed43f1c 100644 --- a/src/main/java/com/squareup/square/core/BasePage.java +++ b/src/main/java/com/squareup/square/core/BasePage.java @@ -4,17 +4,14 @@ package com.squareup.square.core; import java.util.List; -import java.util.Optional; public abstract class BasePage { private final boolean hasNext; private final List items; - private final Object response; - public BasePage(boolean hasNext, List items, Object response) { + public BasePage(boolean hasNext, List items) { this.hasNext = hasNext; this.items = items; - this.response = response; } public boolean hasNext() { @@ -24,15 +21,4 @@ public boolean hasNext() { public List getItems() { return items; } - - /** - * Returns the full response object for accessing pagination metadata like cursor tokens. - * - * @return Optional containing the response, or empty if unavailable - */ - public Optional getResponse() { - @SuppressWarnings("unchecked") - R typedResponse = (R) response; - return Optional.ofNullable(typedResponse); - } } diff --git a/src/main/java/com/squareup/square/core/BiDirectionalPage.java b/src/main/java/com/squareup/square/core/BiDirectionalPage.java deleted file mode 100644 index bf982cfd..00000000 --- a/src/main/java/com/squareup/square/core/BiDirectionalPage.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.core; - -import java.util.List; - -/** - * Interface for pages that support bidirectional pagination (both forward and backward navigation). - * This is used for custom pagination scenarios where the API provides both next and previous page links. - * - * @param The type of items in the page - */ -public interface BiDirectionalPage { - /** - * Returns whether there is a next page available. - * - * @return true if next page exists and can be fetched - */ - boolean hasNext(); - - /** - * Returns whether there is a previous page available. - * - * @return true if previous page exists and can be fetched - */ - boolean hasPrevious(); - - /** - * Fetches and returns the next page. - * - * @return the next page - * @throws java.util.NoSuchElementException if no next page exists - * @throws java.io.IOException if the HTTP request fails - */ - BiDirectionalPage nextPage() throws java.io.IOException; - - /** - * Fetches and returns the previous page. - * - * @return the previous page - * @throws java.util.NoSuchElementException if no previous page exists - * @throws java.io.IOException if the HTTP request fails - */ - BiDirectionalPage previousPage() throws java.io.IOException; - - /** - * Returns the items in the current page. - * - * @return list of items in this page - */ - List getItems(); - - /** - * Returns the full response object for accessing pagination metadata. - * - * @return Optional containing the response, or empty if unavailable - */ - java.util.Optional getResponse(); -} diff --git a/src/main/java/com/squareup/square/core/ClientOptions.java b/src/main/java/com/squareup/square/core/ClientOptions.java index 36eac4e9..dda2746c 100644 --- a/src/main/java/com/squareup/square/core/ClientOptions.java +++ b/src/main/java/com/squareup/square/core/ClientOptions.java @@ -21,30 +21,26 @@ public final class ClientOptions { private final int timeout; - private final int maxRetries; - private ClientOptions( Environment environment, Map headers, Map> headerSuppliers, OkHttpClient httpClient, - int timeout, - int maxRetries) { + int timeout) { this.environment = environment; this.headers = new HashMap<>(); this.headers.putAll(headers); this.headers.putAll(new HashMap() { { - put("User-Agent", "com.squareup:square/45.2.0.20251016"); + put("User-Agent", "com.squareup:square/45.2.1"); put("X-Fern-Language", "JAVA"); put("X-Fern-SDK-Name", "com.square.fern:api-sdk"); - put("X-Fern-SDK-Version", "45.2.0.20251016"); + put("X-Fern-SDK-Version", "45.2.1"); } }); this.headerSuppliers = headerSuppliers; this.httpClient = httpClient; this.timeout = timeout; - this.maxRetries = maxRetries; } public Environment environment() { @@ -86,15 +82,11 @@ public OkHttpClient httpClientWithTimeout(RequestOptions requestOptions) { .build(); } - public int maxRetries() { - return this.maxRetries; - } - public static Builder builder() { return new Builder(); } - public static class Builder { + public static final class Builder { private Environment environment; private final Map headers = new HashMap<>(); @@ -173,19 +165,7 @@ public ClientOptions build() { this.httpClient = httpClientBuilder.build(); this.timeout = Optional.of(httpClient.callTimeoutMillis() / 1000); - return new ClientOptions( - environment, headers, headerSuppliers, httpClient, this.timeout.get(), this.maxRetries); - } - - /** - * Create a new Builder initialized with values from an existing ClientOptions - */ - public static Builder from(ClientOptions clientOptions) { - Builder builder = new Builder(); - builder.environment = clientOptions.environment(); - builder.timeout = Optional.of(clientOptions.timeout(null)); - builder.httpClient = clientOptions.httpClient(); - return builder; + return new ClientOptions(environment, headers, headerSuppliers, httpClient, this.timeout.get()); } } } diff --git a/src/main/java/com/squareup/square/core/CustomPager.java b/src/main/java/com/squareup/square/core/CustomPager.java deleted file mode 100644 index 892f86a1..00000000 --- a/src/main/java/com/squareup/square/core/CustomPager.java +++ /dev/null @@ -1,117 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.core; - -import java.io.IOException; -import java.util.Iterator; -import java.util.List; -import java.util.Optional; - -/** - * Skeleton implementation for custom bidirectional pagination. - * - * THIS CLASS MUST BE IMPLEMENTED BY THE USER. - * - * This file is added to .fernignore and will not be regenerated. - * Replace this skeleton implementation with your custom pagination logic - * that handles your API's specific pagination structure (e.g., HATEOAS links). - * - * Example implementation for HATEOAS-style pagination: - *
{@code
- * public class CustomPager implements BiDirectionalPage, Iterable {
- *     private final List items;
- *     private final String nextUrl;
- *     private final String previousUrl;
- *     private final OkHttpClient client;
- *     private final TypeReference> responseType;
- *
- *     public CustomPager(Response response, OkHttpClient client, ...) {
- *         this.items = response.getData();
- *         this.nextUrl = response.getLinks().getNext();
- *         this.previousUrl = response.getLinks().getPrevious();
- *         // ... store other needed context
- *     }
- *
- *     @Override
- *     public boolean hasNext() {
- *         return nextUrl != null;
- *     }
- *
- *     @Override
- *     public CustomPager nextPage() throws IOException {
- *         if (!hasNext()) {
- *             throw new NoSuchElementException("No next page available");
- *         }
- *         // Make HTTP request to nextUrl
- *         // Parse response
- *         // Return new CustomPager instance
- *     }
- *
- *     // ... implement other methods
- * }
- * }
- * - * @param The type of items in the page - */ -public class CustomPager implements BiDirectionalPage, Iterable { - - /** - * Create a CustomPager from an initial response. - * - * @param initialResponse The first page response from the API - * @param client The HTTP client to use for subsequent requests - * @param requestOptions Request options for authentication, headers, etc. - * @return A new CustomPager instance - * @throws IOException if the request fails - */ - public static CustomPager create(Object initialResponse, okhttp3.OkHttpClient client, Object requestOptions) - throws IOException { - throw new UnsupportedOperationException("CustomPager must be implemented. " - + "Please implement this class in core/CustomPager.java to define your pagination logic. " - + "This file has been added to .fernignore and will not be overwritten. " - + "See the class documentation for implementation examples."); - } - - @Override - public boolean hasNext() { - throw new UnsupportedOperationException("CustomPager.hasNext() must be implemented. " - + "This method should return true if a next page is available."); - } - - @Override - public boolean hasPrevious() { - throw new UnsupportedOperationException("CustomPager.hasPrevious() must be implemented. " - + "This method should return true if a previous page is available."); - } - - @Override - public BiDirectionalPage nextPage() throws IOException { - throw new UnsupportedOperationException("CustomPager.nextPage() must be implemented. " - + "This method should fetch and return the next page of results."); - } - - @Override - public BiDirectionalPage previousPage() throws IOException { - throw new UnsupportedOperationException("CustomPager.previousPage() must be implemented. " - + "This method should fetch and return the previous page of results."); - } - - @Override - public List getItems() { - throw new UnsupportedOperationException("CustomPager.getItems() must be implemented. " - + "This method should return the items in the current page."); - } - - @Override - public Optional getResponse() { - throw new UnsupportedOperationException("CustomPager.getResponse() must be implemented. " - + "This method should return the full response object for accessing pagination metadata."); - } - - @Override - public Iterator iterator() { - throw new UnsupportedOperationException("CustomPager.iterator() must be implemented. " - + "This method should return an iterator that traverses all items across all pages."); - } -} diff --git a/src/main/java/com/squareup/square/core/NullableNonemptyFilter.java b/src/main/java/com/squareup/square/core/NullableNonemptyFilter.java index f55bba89..4f8493b6 100644 --- a/src/main/java/com/squareup/square/core/NullableNonemptyFilter.java +++ b/src/main/java/com/squareup/square/core/NullableNonemptyFilter.java @@ -14,9 +14,6 @@ public boolean equals(Object o) { } private boolean isOptionalEmpty(Object o) { - if (o instanceof Optional) { - return !((Optional) o).isPresent(); - } - return false; + return o instanceof Optional && !((Optional) o).isPresent(); } } diff --git a/src/main/java/com/squareup/square/core/ObjectMappers.java b/src/main/java/com/squareup/square/core/ObjectMappers.java index 6cb27074..f0fc54b1 100644 --- a/src/main/java/com/squareup/square/core/ObjectMappers.java +++ b/src/main/java/com/squareup/square/core/ObjectMappers.java @@ -4,7 +4,6 @@ package com.squareup.square.core; import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; @@ -34,12 +33,4 @@ public static String stringify(Object o) { return o.getClass().getName() + "@" + Integer.toHexString(o.hashCode()); } } - - public static Object parseErrorBody(String responseBodyString) { - try { - return JSON_MAPPER.readValue(responseBodyString, Object.class); - } catch (JsonProcessingException ignored) { - return responseBodyString; - } - } } diff --git a/src/main/java/com/squareup/square/core/RequestOptions.java b/src/main/java/com/squareup/square/core/RequestOptions.java index 7f56bad6..9a910f21 100644 --- a/src/main/java/com/squareup/square/core/RequestOptions.java +++ b/src/main/java/com/squareup/square/core/RequestOptions.java @@ -64,7 +64,7 @@ public static Builder builder() { return new Builder(); } - public static class Builder { + public static final class Builder { private String token = null; private String version = null; diff --git a/src/main/java/com/squareup/square/core/RetryInterceptor.java b/src/main/java/com/squareup/square/core/RetryInterceptor.java index 30d4daa8..728c0bcc 100644 --- a/src/main/java/com/squareup/square/core/RetryInterceptor.java +++ b/src/main/java/com/squareup/square/core/RetryInterceptor.java @@ -5,9 +5,6 @@ import java.io.IOException; import java.time.Duration; -import java.time.ZonedDateTime; -import java.time.format.DateTimeFormatter; -import java.time.format.DateTimeParseException; import java.util.Optional; import java.util.Random; import okhttp3.Interceptor; @@ -15,10 +12,7 @@ public class RetryInterceptor implements Interceptor { - private static final Duration INITIAL_RETRY_DELAY = Duration.ofMillis(1000); - private static final Duration MAX_RETRY_DELAY = Duration.ofMillis(60000); - private static final double JITTER_FACTOR = 0.2; - + private static final Duration ONE_SECOND = Duration.ofSeconds(1); private final ExponentialBackoff backoff; private final Random random = new Random(); @@ -38,7 +32,7 @@ public Response intercept(Chain chain) throws IOException { } private Response retryChain(Response response, Chain chain) throws IOException { - Optional nextBackoff = this.backoff.nextBackoff(response); + Optional nextBackoff = this.backoff.nextBackoff(); while (nextBackoff.isPresent()) { try { Thread.sleep(nextBackoff.get().toMillis()); @@ -48,7 +42,7 @@ private Response retryChain(Response response, Chain chain) throws IOException { response.close(); response = chain.proceed(chain.request()); if (shouldRetry(response.code())) { - nextBackoff = this.backoff.nextBackoff(response); + nextBackoff = this.backoff.nextBackoff(); } else { return response; } @@ -57,102 +51,6 @@ private Response retryChain(Response response, Chain chain) throws IOException { return response; } - /** - * Calculates the retry delay from response headers, with fallback to exponential backoff. - * Priority: Retry-After > X-RateLimit-Reset > Exponential Backoff - */ - private Duration getRetryDelayFromHeaders(Response response, int retryAttempt) { - // Check for Retry-After header first (RFC 7231), with no jitter - String retryAfter = response.header("Retry-After"); - if (retryAfter != null) { - // Parse as number of seconds... - Optional secondsDelay = tryParseLong(retryAfter) - .map(seconds -> seconds * 1000) - .filter(delayMs -> delayMs > 0) - .map(delayMs -> Math.min(delayMs, MAX_RETRY_DELAY.toMillis())) - .map(Duration::ofMillis); - if (secondsDelay.isPresent()) { - return secondsDelay.get(); - } - - // ...or as an HTTP date; both are valid - Optional dateDelay = tryParseHttpDate(retryAfter) - .map(resetTime -> resetTime.toInstant().toEpochMilli() - System.currentTimeMillis()) - .filter(delayMs -> delayMs > 0) - .map(delayMs -> Math.min(delayMs, MAX_RETRY_DELAY.toMillis())) - .map(Duration::ofMillis); - if (dateDelay.isPresent()) { - return dateDelay.get(); - } - } - - // Then check for industry-standard X-RateLimit-Reset header, with positive jitter - String rateLimitReset = response.header("X-RateLimit-Reset"); - if (rateLimitReset != null) { - // Assume Unix timestamp in epoch seconds - Optional rateLimitDelay = tryParseLong(rateLimitReset) - .map(resetTimeSeconds -> (resetTimeSeconds * 1000) - System.currentTimeMillis()) - .filter(delayMs -> delayMs > 0) - .map(delayMs -> Math.min(delayMs, MAX_RETRY_DELAY.toMillis())) - .map(this::addPositiveJitter) - .map(Duration::ofMillis); - if (rateLimitDelay.isPresent()) { - return rateLimitDelay.get(); - } - } - - // Fall back to exponential backoff, with symmetric jitter - long baseDelay = INITIAL_RETRY_DELAY.toMillis() * (1L << retryAttempt); // 2^retryAttempt - long cappedDelay = Math.min(baseDelay, MAX_RETRY_DELAY.toMillis()); - return Duration.ofMillis(addSymmetricJitter(cappedDelay)); - } - - /** - * Attempts to parse a string as a long, returning empty Optional on failure. - */ - private Optional tryParseLong(String value) { - if (value == null) { - return Optional.empty(); - } - try { - return Optional.of(Long.parseLong(value)); - } catch (NumberFormatException e) { - return Optional.empty(); - } - } - - /** - * Attempts to parse a string as an HTTP date (RFC 1123), returning empty Optional on failure. - */ - private Optional tryParseHttpDate(String value) { - if (value == null) { - return Optional.empty(); - } - try { - return Optional.of(ZonedDateTime.parse(value, DateTimeFormatter.RFC_1123_DATE_TIME)); - } catch (DateTimeParseException e) { - return Optional.empty(); - } - } - - /** - * Adds positive jitter (100-120% of original value) to prevent thundering herd. - * Used for X-RateLimit-Reset header delays. - */ - private long addPositiveJitter(long delayMs) { - double jitterMultiplier = 1.0 + (random.nextDouble() * JITTER_FACTOR); - return (long) (delayMs * jitterMultiplier); - } - - /** - * Adds symmetric jitter (90-110% of original value) to prevent thundering herd. - * Used for exponential backoff delays. - */ - private long addSymmetricJitter(long delayMs) { - double jitterMultiplier = 1.0 + ((random.nextDouble() - 0.5) * JITTER_FACTOR); - return (long) (delayMs * jitterMultiplier); - } - private static boolean shouldRetry(int statusCode) { return statusCode == 408 || statusCode == 429 || statusCode >= 500; } @@ -167,14 +65,14 @@ private final class ExponentialBackoff { this.maxNumRetries = maxNumRetries; } - public Optional nextBackoff(Response response) { - if (retryNumber >= maxNumRetries) { + public Optional nextBackoff() { + retryNumber += 1; + if (retryNumber > maxNumRetries) { return Optional.empty(); } - Duration delay = getRetryDelayFromHeaders(response, retryNumber); - retryNumber += 1; - return Optional.of(delay); + int upperBound = (int) Math.pow(2, retryNumber); + return Optional.of(ONE_SECOND.multipliedBy(random.nextInt(upperBound))); } } } diff --git a/src/main/java/com/squareup/square/core/Stream.java b/src/main/java/com/squareup/square/core/Stream.java index 39ae566e..7ea39a0c 100644 --- a/src/main/java/com/squareup/square/core/Stream.java +++ b/src/main/java/com/squareup/square/core/Stream.java @@ -174,8 +174,8 @@ private final class SSEIterator implements Iterator { private T nextItem; private boolean hasNextItem = false; private boolean endOfStream = false; - private StringBuilder eventDataBuffer = new StringBuilder(); - private String currentEventType = null; + private StringBuilder buffer = new StringBuilder(); + private boolean prefixSeen = false; private SSEIterator() { if (sseReader != null && !isStreamClosed()) { @@ -223,69 +223,39 @@ private boolean readNextMessage() { try { while (sseScanner.hasNextLine()) { - String line = sseScanner.nextLine(); - - if (line.trim().isEmpty()) { - if (eventDataBuffer.length() > 0) { - try { - nextItem = ObjectMappers.JSON_MAPPER.readValue(eventDataBuffer.toString(), valueType); - hasNextItem = true; - eventDataBuffer.setLength(0); - currentEventType = null; - return true; - } catch (Exception parseEx) { - System.err.println("Failed to parse SSE event: " + parseEx.getMessage()); - eventDataBuffer.setLength(0); - currentEventType = null; - continue; - } + String chunk = sseScanner.nextLine(); + buffer.append(chunk).append(NEWLINE); + + int terminatorIndex; + while ((terminatorIndex = buffer.indexOf(messageTerminator)) >= 0) { + String line = buffer.substring(0, terminatorIndex + messageTerminator.length()); + buffer.delete(0, terminatorIndex + messageTerminator.length()); + + line = line.trim(); + if (line.isEmpty()) { + continue; } - continue; - } - if (line.startsWith(DATA_PREFIX)) { - String dataContent = line.substring(DATA_PREFIX.length()); - if (dataContent.startsWith(" ")) { - dataContent = dataContent.substring(1); + if (!prefixSeen && line.startsWith(DATA_PREFIX)) { + prefixSeen = true; + line = line.substring(DATA_PREFIX.length()).trim(); + } else if (!prefixSeen) { + continue; } - if (eventDataBuffer.length() == 0 - && streamTerminator != null - && dataContent.trim().equals(streamTerminator)) { + if (streamTerminator != null && line.contains(streamTerminator)) { endOfStream = true; return false; } - if (eventDataBuffer.length() > 0) { - eventDataBuffer.append('\n'); - } - eventDataBuffer.append(dataContent); - } else if (line.startsWith("event:")) { - String eventValue = line.length() > 6 ? line.substring(6) : ""; - if (eventValue.startsWith(" ")) { - eventValue = eventValue.substring(1); + try { + nextItem = ObjectMappers.JSON_MAPPER.readValue(line, valueType); + hasNextItem = true; + prefixSeen = false; + return true; + } catch (Exception parseEx) { + continue; } - currentEventType = eventValue; - } else if (line.startsWith("id:")) { - // Event ID field (ignored) - } else if (line.startsWith("retry:")) { - // Retry field (ignored) - } else if (line.startsWith(":")) { - // Comment line (ignored) - } - } - - if (eventDataBuffer.length() > 0) { - try { - nextItem = ObjectMappers.JSON_MAPPER.readValue(eventDataBuffer.toString(), valueType); - hasNextItem = true; - eventDataBuffer.setLength(0); - currentEventType = null; - return true; - } catch (Exception parseEx) { - System.err.println("Failed to parse final SSE event: " + parseEx.getMessage()); - eventDataBuffer.setLength(0); - currentEventType = null; } } diff --git a/src/main/java/com/squareup/square/core/SyncPage.java b/src/main/java/com/squareup/square/core/SyncPage.java index 5689efe8..c652b585 100644 --- a/src/main/java/com/squareup/square/core/SyncPage.java +++ b/src/main/java/com/squareup/square/core/SyncPage.java @@ -10,8 +10,8 @@ public class SyncPage extends BasePage { protected final Supplier> nextSupplier; - public SyncPage(boolean hasNext, List items, Object response, Supplier> nextSupplier) { - super(hasNext, items, response); + public SyncPage(boolean hasNext, List items, Supplier> nextSupplier) { + super(hasNext, items); this.nextSupplier = nextSupplier; } diff --git a/src/main/java/com/squareup/square/core/SyncPagingIterable.java b/src/main/java/com/squareup/square/core/SyncPagingIterable.java index c870d8a1..105667a5 100644 --- a/src/main/java/com/squareup/square/core/SyncPagingIterable.java +++ b/src/main/java/com/squareup/square/core/SyncPagingIterable.java @@ -14,14 +14,12 @@ public class SyncPagingIterable extends SyncPage implements Iterable { - public SyncPagingIterable( - boolean hasNext, List items, Object response, Supplier> getNext) { - super(hasNext, items, response, getNext); + public SyncPagingIterable(boolean hasNext, List items, Supplier> getNext) { + super(hasNext, items, getNext); } - public SyncPagingIterable( - boolean hasNext, Optional> items, Object response, Supplier> getNext) { - super(hasNext, items.orElse(new ArrayList<>()), response, getNext); + public SyncPagingIterable(boolean hasNext, Optional> items, Supplier> getNext) { + super(hasNext, items.orElse(new ArrayList<>()), getNext); } public Stream streamItems() { diff --git a/src/main/java/com/squareup/square/customers/AsyncRawCardsClient.java b/src/main/java/com/squareup/square/customers/AsyncRawCardsClient.java index 24cf6ccf..fdf5824f 100644 --- a/src/main/java/com/squareup/square/customers/AsyncRawCardsClient.java +++ b/src/main/java/com/squareup/square/customers/AsyncRawCardsClient.java @@ -83,17 +83,19 @@ public CompletableFuture> c @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateCustomerCardResponse.class), + responseBody.string(), CreateCustomerCardResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -142,17 +144,19 @@ public CompletableFuture> d @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DeleteCustomerCardResponse.class), + responseBody.string(), DeleteCustomerCardResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/customers/AsyncRawCustomAttributeDefinitionsClient.java b/src/main/java/com/squareup/square/customers/AsyncRawCustomAttributeDefinitionsClient.java index 96e6620c..2db99d7a 100644 --- a/src/main/java/com/squareup/square/customers/AsyncRawCustomAttributeDefinitionsClient.java +++ b/src/main/java/com/squareup/square/customers/AsyncRawCustomAttributeDefinitionsClient.java @@ -109,11 +109,10 @@ public CompletableFuture startingAfter = parsedResponse.getCursor(); ListCustomAttributeDefinitionsRequest nextRequest = ListCustomAttributeDefinitionsRequest.builder() @@ -124,7 +123,7 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO parsedResponse.getCustomAttributeDefinitions().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { + startingAfter.isPresent(), result, () -> { try { return list(nextRequest, requestOptions) .get() @@ -136,9 +135,12 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -210,17 +212,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateCustomerCustomAttributeDefinitionResponse.class), + responseBody.string(), CreateCustomerCustomAttributeDefinitionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -278,17 +282,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, GetCustomerCustomAttributeDefinitionResponse.class), + responseBody.string(), GetCustomerCustomAttributeDefinitionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -353,17 +359,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpdateCustomerCustomAttributeDefinitionResponse.class), + responseBody.string(), UpdateCustomerCustomAttributeDefinitionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -418,17 +426,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DeleteCustomerCustomAttributeDefinitionResponse.class), + responseBody.string(), DeleteCustomerCustomAttributeDefinitionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -504,17 +514,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BatchUpsertCustomerCustomAttributesResponse.class), + responseBody.string(), BatchUpsertCustomerCustomAttributesResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/customers/AsyncRawCustomAttributesClient.java b/src/main/java/com/squareup/square/customers/AsyncRawCustomAttributesClient.java index a0d965fa..ffedc450 100644 --- a/src/main/java/com/squareup/square/customers/AsyncRawCustomAttributesClient.java +++ b/src/main/java/com/squareup/square/customers/AsyncRawCustomAttributesClient.java @@ -102,10 +102,9 @@ public CompletableFuture startingAfter = parsedResponse.getCursor(); ListCustomAttributesRequest nextRequest = ListCustomAttributesRequest.builder() .from(request) @@ -114,22 +113,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO List result = parsedResponse.getCustomAttributes().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return list(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return list(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -197,17 +198,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, GetCustomerCustomAttributeResponse.class), + responseBody.string(), GetCustomerCustomAttributeResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -278,17 +281,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpsertCustomerCustomAttributeResponse.class), + responseBody.string(), UpsertCustomerCustomAttributeResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -345,17 +350,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DeleteCustomerCustomAttributeResponse.class), + responseBody.string(), DeleteCustomerCustomAttributeResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/customers/AsyncRawGroupsClient.java b/src/main/java/com/squareup/square/customers/AsyncRawGroupsClient.java index 78d823b6..48cd7c17 100644 --- a/src/main/java/com/squareup/square/customers/AsyncRawGroupsClient.java +++ b/src/main/java/com/squareup/square/customers/AsyncRawGroupsClient.java @@ -99,10 +99,9 @@ public CompletableFuture startingAfter = parsedResponse.getCursor(); ListGroupsRequest nextRequest = ListGroupsRequest.builder() .from(request) @@ -110,22 +109,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO .build(); List result = parsedResponse.getGroups().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return list(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return list(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -182,17 +183,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateCustomerGroupResponse.class), + responseBody.string(), CreateCustomerGroupResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -239,16 +242,19 @@ public CompletableFuture> get @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetCustomerGroupResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), GetCustomerGroupResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -304,17 +310,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpdateCustomerGroupResponse.class), + responseBody.string(), UpdateCustomerGroupResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -362,17 +370,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DeleteCustomerGroupResponse.class), + responseBody.string(), DeleteCustomerGroupResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -425,17 +435,19 @@ public CompletableFuture> a @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, AddGroupToCustomerResponse.class), + responseBody.string(), AddGroupToCustomerResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -489,17 +501,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, RemoveGroupFromCustomerResponse.class), + responseBody.string(), RemoveGroupFromCustomerResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/customers/AsyncRawSegmentsClient.java b/src/main/java/com/squareup/square/customers/AsyncRawSegmentsClient.java index 29705d68..38364954 100644 --- a/src/main/java/com/squareup/square/customers/AsyncRawSegmentsClient.java +++ b/src/main/java/com/squareup/square/customers/AsyncRawSegmentsClient.java @@ -86,10 +86,9 @@ public CompletableFuture startingAfter = parsedResponse.getCursor(); ListSegmentsRequest nextRequest = ListSegmentsRequest.builder() .from(request) @@ -98,22 +97,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO List result = parsedResponse.getSegments().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return list(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return list(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -160,17 +161,19 @@ public CompletableFuture> g @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, GetCustomerSegmentResponse.class), + responseBody.string(), GetCustomerSegmentResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/customers/RawCardsClient.java b/src/main/java/com/squareup/square/customers/RawCardsClient.java index 00c8ff52..d61c9b82 100644 --- a/src/main/java/com/squareup/square/customers/RawCardsClient.java +++ b/src/main/java/com/squareup/square/customers/RawCardsClient.java @@ -75,15 +75,17 @@ public SquareClientHttpResponse create( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateCustomerCardResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateCustomerCardResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -120,15 +122,17 @@ public SquareClientHttpResponse delete( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, DeleteCustomerCardResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), DeleteCustomerCardResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/customers/RawCustomAttributeDefinitionsClient.java b/src/main/java/com/squareup/square/customers/RawCustomAttributeDefinitionsClient.java index 5e862fa1..75aecdd7 100644 --- a/src/main/java/com/squareup/square/customers/RawCustomAttributeDefinitionsClient.java +++ b/src/main/java/com/squareup/square/customers/RawCustomAttributeDefinitionsClient.java @@ -100,10 +100,9 @@ public SquareClientHttpResponse> l } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListCustomerCustomAttributeDefinitionsResponse parsedResponse = ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, ListCustomerCustomAttributeDefinitionsResponse.class); + responseBody.string(), ListCustomerCustomAttributeDefinitionsResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListCustomAttributeDefinitionsRequest nextRequest = ListCustomAttributeDefinitionsRequest.builder() .from(request) @@ -113,14 +112,16 @@ public SquareClientHttpResponse> l parsedResponse.getCustomAttributeDefinitions().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -179,16 +180,18 @@ public SquareClientHttpResponse } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateCustomerCustomAttributeDefinitionResponse.class), + responseBody.string(), CreateCustomerCustomAttributeDefinitionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -233,16 +236,18 @@ public SquareClientHttpResponse ge } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, GetCustomerCustomAttributeDefinitionResponse.class), + responseBody.string(), GetCustomerCustomAttributeDefinitionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -294,16 +299,18 @@ public SquareClientHttpResponse } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpdateCustomerCustomAttributeDefinitionResponse.class), + responseBody.string(), UpdateCustomerCustomAttributeDefinitionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -345,16 +352,18 @@ public SquareClientHttpResponse } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DeleteCustomerCustomAttributeDefinitionResponse.class), + responseBody.string(), DeleteCustomerCustomAttributeDefinitionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -417,16 +426,18 @@ public SquareClientHttpResponse bat } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BatchUpsertCustomerCustomAttributesResponse.class), + responseBody.string(), BatchUpsertCustomerCustomAttributesResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/customers/RawCustomAttributesClient.java b/src/main/java/com/squareup/square/customers/RawCustomAttributesClient.java index 4a288a47..6154be8c 100644 --- a/src/main/java/com/squareup/square/customers/RawCustomAttributesClient.java +++ b/src/main/java/com/squareup/square/customers/RawCustomAttributesClient.java @@ -92,10 +92,9 @@ public SquareClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListCustomerCustomAttributesResponse parsedResponse = ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, ListCustomerCustomAttributesResponse.class); + responseBody.string(), ListCustomerCustomAttributesResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListCustomAttributesRequest nextRequest = ListCustomAttributesRequest.builder() .from(request) @@ -105,14 +104,16 @@ public SquareClientHttpResponse> list( parsedResponse.getCustomAttributes().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -166,16 +167,18 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, GetCustomerCustomAttributeResponse.class), + responseBody.string(), GetCustomerCustomAttributeResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -233,16 +236,18 @@ public SquareClientHttpResponse upsert( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpsertCustomerCustomAttributeResponse.class), + responseBody.string(), UpsertCustomerCustomAttributeResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -286,16 +291,18 @@ public SquareClientHttpResponse delete( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DeleteCustomerCustomAttributeResponse.class), + responseBody.string(), DeleteCustomerCustomAttributeResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/customers/RawGroupsClient.java b/src/main/java/com/squareup/square/customers/RawGroupsClient.java index f04ff5a3..151a1c5f 100644 --- a/src/main/java/com/squareup/square/customers/RawGroupsClient.java +++ b/src/main/java/com/squareup/square/customers/RawGroupsClient.java @@ -89,10 +89,9 @@ public SquareClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListCustomerGroupsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListCustomerGroupsResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListCustomerGroupsResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListGroupsRequest nextRequest = ListGroupsRequest.builder() .from(request) @@ -101,14 +100,16 @@ public SquareClientHttpResponse> list( List result = parsedResponse.getGroups().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -152,15 +153,17 @@ public SquareClientHttpResponse create( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateCustomerGroupResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateCustomerGroupResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -195,15 +198,17 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetCustomerGroupResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetCustomerGroupResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -246,15 +251,17 @@ public SquareClientHttpResponse update( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateCustomerGroupResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UpdateCustomerGroupResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -289,15 +296,17 @@ public SquareClientHttpResponse delete( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, DeleteCustomerGroupResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), DeleteCustomerGroupResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -338,15 +347,17 @@ public SquareClientHttpResponse add( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, AddGroupToCustomerResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AddGroupToCustomerResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -387,15 +398,18 @@ public SquareClientHttpResponse remove( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, RemoveGroupFromCustomerResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), RemoveGroupFromCustomerResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/customers/RawSegmentsClient.java b/src/main/java/com/squareup/square/customers/RawSegmentsClient.java index 2475d474..443ff20a 100644 --- a/src/main/java/com/squareup/square/customers/RawSegmentsClient.java +++ b/src/main/java/com/squareup/square/customers/RawSegmentsClient.java @@ -76,10 +76,9 @@ public SquareClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListCustomerSegmentsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListCustomerSegmentsResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListCustomerSegmentsResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListSegmentsRequest nextRequest = ListSegmentsRequest.builder() .from(request) @@ -88,14 +87,16 @@ public SquareClientHttpResponse> list( List result = parsedResponse.getSegments().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -130,15 +131,17 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetCustomerSegmentResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetCustomerSegmentResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/customers/types/BatchUpsertCustomerCustomAttributesRequest.java b/src/main/java/com/squareup/square/customers/types/BatchUpsertCustomerCustomAttributesRequest.java index 76d956f3..5320cca8 100644 --- a/src/main/java/com/squareup/square/customers/types/BatchUpsertCustomerCustomAttributesRequest.java +++ b/src/main/java/com/squareup/square/customers/types/BatchUpsertCustomerCustomAttributesRequest.java @@ -96,17 +96,13 @@ public Builder from(BatchUpsertCustomerCustomAttributesRequest other) { public Builder values( Map values) { this.values.clear(); - if (values != null) { - this.values.putAll(values); - } + this.values.putAll(values); return this; } public Builder putAllValues( Map values) { - if (values != null) { - this.values.putAll(values); - } + this.values.putAll(values); return this; } diff --git a/src/main/java/com/squareup/square/devices/AsyncRawCodesClient.java b/src/main/java/com/squareup/square/devices/AsyncRawCodesClient.java index d0f18a14..789026e7 100644 --- a/src/main/java/com/squareup/square/devices/AsyncRawCodesClient.java +++ b/src/main/java/com/squareup/square/devices/AsyncRawCodesClient.java @@ -97,10 +97,9 @@ public CompletableFuture @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { - ListDeviceCodesResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListDeviceCodesResponse.class); + ListDeviceCodesResponse parsedResponse = ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), ListDeviceCodesResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListCodesRequest nextRequest = ListCodesRequest.builder() .from(request) @@ -109,22 +108,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO List result = parsedResponse.getDeviceCodes().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return list(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return list(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -181,16 +182,19 @@ public CompletableFuture> cre @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateDeviceCodeResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), CreateDeviceCodeResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -237,16 +241,18 @@ public CompletableFuture> get( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetDeviceCodeResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetDeviceCodeResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/devices/RawCodesClient.java b/src/main/java/com/squareup/square/devices/RawCodesClient.java index b29096d8..7703d3b4 100644 --- a/src/main/java/com/squareup/square/devices/RawCodesClient.java +++ b/src/main/java/com/squareup/square/devices/RawCodesClient.java @@ -89,10 +89,9 @@ public SquareClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListDeviceCodesResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListDeviceCodesResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListDeviceCodesResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListCodesRequest nextRequest = ListCodesRequest.builder() .from(request) @@ -101,14 +100,16 @@ public SquareClientHttpResponse> list( List result = parsedResponse.getDeviceCodes().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -152,15 +153,17 @@ public SquareClientHttpResponse create( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateDeviceCodeResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateDeviceCodeResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -194,14 +197,17 @@ public SquareClientHttpResponse get(GetCodesRequest reque } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetDeviceCodeResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetDeviceCodeResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/disputes/AsyncRawEvidenceClient.java b/src/main/java/com/squareup/square/disputes/AsyncRawEvidenceClient.java index 5c100178..1b025396 100644 --- a/src/main/java/com/squareup/square/disputes/AsyncRawEvidenceClient.java +++ b/src/main/java/com/squareup/square/disputes/AsyncRawEvidenceClient.java @@ -79,10 +79,9 @@ public CompletableFuture startingAfter = parsedResponse.getCursor(); ListEvidenceRequest nextRequest = ListEvidenceRequest.builder() .from(request) @@ -91,22 +90,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO List result = parsedResponse.getEvidence().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return list(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return list(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -157,17 +158,19 @@ public CompletableFuture> g @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, GetDisputeEvidenceResponse.class), + responseBody.string(), GetDisputeEvidenceResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -219,17 +222,19 @@ public CompletableFuture @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DeleteDisputeEvidenceResponse.class), + responseBody.string(), DeleteDisputeEvidenceResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/disputes/RawEvidenceClient.java b/src/main/java/com/squareup/square/disputes/RawEvidenceClient.java index 7b1aebda..3ad65ee9 100644 --- a/src/main/java/com/squareup/square/disputes/RawEvidenceClient.java +++ b/src/main/java/com/squareup/square/disputes/RawEvidenceClient.java @@ -69,10 +69,9 @@ public SquareClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListDisputeEvidenceResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListDisputeEvidenceResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListDisputeEvidenceResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListEvidenceRequest nextRequest = ListEvidenceRequest.builder() .from(request) @@ -81,14 +80,16 @@ public SquareClientHttpResponse> list( List result = parsedResponse.getEvidence().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -127,15 +128,17 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetDisputeEvidenceResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetDisputeEvidenceResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -174,15 +177,17 @@ public SquareClientHttpResponse delete( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, DeleteDisputeEvidenceResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), DeleteDisputeEvidenceResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/giftcards/AsyncRawActivitiesClient.java b/src/main/java/com/squareup/square/giftcards/AsyncRawActivitiesClient.java index a8e21fb2..2ee0cb90 100644 --- a/src/main/java/com/squareup/square/giftcards/AsyncRawActivitiesClient.java +++ b/src/main/java/com/squareup/square/giftcards/AsyncRawActivitiesClient.java @@ -122,10 +122,9 @@ public CompletableFuture startingAfter = parsedResponse.getCursor(); ListActivitiesRequest nextRequest = ListActivitiesRequest.builder() .from(request) @@ -134,22 +133,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO List result = parsedResponse.getGiftCardActivities().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return list(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return list(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -206,17 +207,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateGiftCardActivityResponse.class), + responseBody.string(), CreateGiftCardActivityResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/giftcards/RawActivitiesClient.java b/src/main/java/com/squareup/square/giftcards/RawActivitiesClient.java index 82709420..0402d6c6 100644 --- a/src/main/java/com/squareup/square/giftcards/RawActivitiesClient.java +++ b/src/main/java/com/squareup/square/giftcards/RawActivitiesClient.java @@ -112,10 +112,9 @@ public SquareClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { - ListGiftCardActivitiesResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListGiftCardActivitiesResponse.class); + ListGiftCardActivitiesResponse parsedResponse = ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), ListGiftCardActivitiesResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListActivitiesRequest nextRequest = ListActivitiesRequest.builder() .from(request) @@ -125,14 +124,16 @@ public SquareClientHttpResponse> list( parsedResponse.getGiftCardActivities().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -176,15 +177,18 @@ public SquareClientHttpResponse create( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateGiftCardActivityResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), CreateGiftCardActivityResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/labor/AsyncRawBreakTypesClient.java b/src/main/java/com/squareup/square/labor/AsyncRawBreakTypesClient.java index fcdcb2b6..d5f5e80d 100644 --- a/src/main/java/com/squareup/square/labor/AsyncRawBreakTypesClient.java +++ b/src/main/java/com/squareup/square/labor/AsyncRawBreakTypesClient.java @@ -98,10 +98,9 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { - ListBreakTypesResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListBreakTypesResponse.class); + ListBreakTypesResponse parsedResponse = ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), ListBreakTypesResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListBreakTypesRequest nextRequest = ListBreakTypesRequest.builder() .from(request) @@ -109,22 +108,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO .build(); List result = parsedResponse.getBreakTypes().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return list(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return list(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -202,16 +203,19 @@ public CompletableFuture> crea @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateBreakTypeResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), CreateBreakTypeResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -258,16 +262,18 @@ public CompletableFuture> get( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetBreakTypeResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetBreakTypeResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -322,16 +328,19 @@ public CompletableFuture> upda @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateBreakTypeResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), UpdateBreakTypeResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -381,16 +390,19 @@ public CompletableFuture> dele @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, DeleteBreakTypeResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), DeleteBreakTypeResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/labor/AsyncRawEmployeeWagesClient.java b/src/main/java/com/squareup/square/labor/AsyncRawEmployeeWagesClient.java index a922889a..610d8227 100644 --- a/src/main/java/com/squareup/square/labor/AsyncRawEmployeeWagesClient.java +++ b/src/main/java/com/squareup/square/labor/AsyncRawEmployeeWagesClient.java @@ -90,10 +90,9 @@ public CompletableFuture startingAfter = parsedResponse.getCursor(); ListEmployeeWagesRequest nextRequest = ListEmployeeWagesRequest.builder() .from(request) @@ -102,22 +101,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO List result = parsedResponse.getEmployeeWages().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return list(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return list(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -164,16 +165,19 @@ public CompletableFuture> get( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetEmployeeWageResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), GetEmployeeWageResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/labor/AsyncRawShiftsClient.java b/src/main/java/com/squareup/square/labor/AsyncRawShiftsClient.java index 95e51805..a617eaa5 100644 --- a/src/main/java/com/squareup/square/labor/AsyncRawShiftsClient.java +++ b/src/main/java/com/squareup/square/labor/AsyncRawShiftsClient.java @@ -116,16 +116,18 @@ public CompletableFuture> create( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateShiftResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateShiftResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -234,16 +236,18 @@ public CompletableFuture> search( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, SearchShiftsResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SearchShiftsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -290,16 +294,18 @@ public CompletableFuture> get( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetShiftResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetShiftResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -362,16 +368,18 @@ public CompletableFuture> update( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateShiftResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UpdateShiftResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -418,16 +426,18 @@ public CompletableFuture> delete( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, DeleteShiftResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), DeleteShiftResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/labor/AsyncRawTeamMemberWagesClient.java b/src/main/java/com/squareup/square/labor/AsyncRawTeamMemberWagesClient.java index 03359b33..6e1930ae 100644 --- a/src/main/java/com/squareup/square/labor/AsyncRawTeamMemberWagesClient.java +++ b/src/main/java/com/squareup/square/labor/AsyncRawTeamMemberWagesClient.java @@ -90,10 +90,9 @@ public CompletableFuture startingAfter = parsedResponse.getCursor(); ListTeamMemberWagesRequest nextRequest = ListTeamMemberWagesRequest.builder() .from(request) @@ -102,22 +101,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO List result = parsedResponse.getTeamMemberWages().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return list(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return list(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -165,17 +166,19 @@ public CompletableFuture> ge @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, GetTeamMemberWageResponse.class), + responseBody.string(), GetTeamMemberWageResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/labor/AsyncRawWorkweekConfigsClient.java b/src/main/java/com/squareup/square/labor/AsyncRawWorkweekConfigsClient.java index 3c9a16b7..7af5ef52 100644 --- a/src/main/java/com/squareup/square/labor/AsyncRawWorkweekConfigsClient.java +++ b/src/main/java/com/squareup/square/labor/AsyncRawWorkweekConfigsClient.java @@ -89,10 +89,9 @@ public CompletableFuture startingAfter = parsedResponse.getCursor(); ListWorkweekConfigsRequest nextRequest = ListWorkweekConfigsRequest.builder() .from(request) @@ -101,22 +100,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO List result = parsedResponse.getWorkweekConfigs().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return list(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return list(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -172,17 +173,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpdateWorkweekConfigResponse.class), + responseBody.string(), UpdateWorkweekConfigResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/labor/RawBreakTypesClient.java b/src/main/java/com/squareup/square/labor/RawBreakTypesClient.java index e93e2a74..ad569e48 100644 --- a/src/main/java/com/squareup/square/labor/RawBreakTypesClient.java +++ b/src/main/java/com/squareup/square/labor/RawBreakTypesClient.java @@ -89,10 +89,9 @@ public SquareClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListBreakTypesResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListBreakTypesResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListBreakTypesResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListBreakTypesRequest nextRequest = ListBreakTypesRequest.builder() .from(request) @@ -100,14 +99,17 @@ public SquareClientHttpResponse> list( .build(); List result = parsedResponse.getBreakTypes().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( - new SyncPagingIterable(startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) - .body()), + new SyncPagingIterable( + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) + .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -173,15 +175,17 @@ public SquareClientHttpResponse create( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateBreakTypeResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateBreakTypeResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -216,14 +220,17 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetBreakTypeResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetBreakTypeResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -266,15 +273,17 @@ public SquareClientHttpResponse update( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateBreakTypeResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UpdateBreakTypeResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -311,15 +320,17 @@ public SquareClientHttpResponse delete( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, DeleteBreakTypeResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), DeleteBreakTypeResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/labor/RawEmployeeWagesClient.java b/src/main/java/com/squareup/square/labor/RawEmployeeWagesClient.java index 8188ca44..d4f3347a 100644 --- a/src/main/java/com/squareup/square/labor/RawEmployeeWagesClient.java +++ b/src/main/java/com/squareup/square/labor/RawEmployeeWagesClient.java @@ -80,10 +80,9 @@ public SquareClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListEmployeeWagesResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListEmployeeWagesResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListEmployeeWagesResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListEmployeeWagesRequest nextRequest = ListEmployeeWagesRequest.builder() .from(request) @@ -92,14 +91,16 @@ public SquareClientHttpResponse> list( List result = parsedResponse.getEmployeeWages().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -134,15 +135,17 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetEmployeeWageResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetEmployeeWageResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/labor/RawShiftsClient.java b/src/main/java/com/squareup/square/labor/RawShiftsClient.java index 383270e8..cb7387e1 100644 --- a/src/main/java/com/squareup/square/labor/RawShiftsClient.java +++ b/src/main/java/com/squareup/square/labor/RawShiftsClient.java @@ -109,14 +109,17 @@ public SquareClientHttpResponse create( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateShiftResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateShiftResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -213,14 +216,17 @@ public SquareClientHttpResponse search( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, SearchShiftsResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SearchShiftsResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -254,14 +260,16 @@ public SquareClientHttpResponse get(GetShiftsRequest request, } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetShiftResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetShiftResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -312,14 +320,17 @@ public SquareClientHttpResponse update( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateShiftResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UpdateShiftResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -354,14 +365,17 @@ public SquareClientHttpResponse delete( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, DeleteShiftResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), DeleteShiftResponse.class), + response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/labor/RawTeamMemberWagesClient.java b/src/main/java/com/squareup/square/labor/RawTeamMemberWagesClient.java index 648b3ed4..1945ca7d 100644 --- a/src/main/java/com/squareup/square/labor/RawTeamMemberWagesClient.java +++ b/src/main/java/com/squareup/square/labor/RawTeamMemberWagesClient.java @@ -80,10 +80,9 @@ public SquareClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListTeamMemberWagesResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListTeamMemberWagesResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListTeamMemberWagesResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListTeamMemberWagesRequest nextRequest = ListTeamMemberWagesRequest.builder() .from(request) @@ -93,14 +92,16 @@ public SquareClientHttpResponse> list( parsedResponse.getTeamMemberWages().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -135,15 +136,17 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetTeamMemberWageResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetTeamMemberWageResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/labor/RawWorkweekConfigsClient.java b/src/main/java/com/squareup/square/labor/RawWorkweekConfigsClient.java index 04847c13..0cf4a7b0 100644 --- a/src/main/java/com/squareup/square/labor/RawWorkweekConfigsClient.java +++ b/src/main/java/com/squareup/square/labor/RawWorkweekConfigsClient.java @@ -79,10 +79,9 @@ public SquareClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListWorkweekConfigsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListWorkweekConfigsResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListWorkweekConfigsResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListWorkweekConfigsRequest nextRequest = ListWorkweekConfigsRequest.builder() .from(request) @@ -92,14 +91,16 @@ public SquareClientHttpResponse> list( parsedResponse.getWorkweekConfigs().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -142,15 +143,17 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateWorkweekConfigResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UpdateWorkweekConfigResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/locations/AsyncRawCustomAttributeDefinitionsClient.java b/src/main/java/com/squareup/square/locations/AsyncRawCustomAttributeDefinitionsClient.java index bc39b243..502dc30c 100644 --- a/src/main/java/com/squareup/square/locations/AsyncRawCustomAttributeDefinitionsClient.java +++ b/src/main/java/com/squareup/square/locations/AsyncRawCustomAttributeDefinitionsClient.java @@ -108,11 +108,10 @@ public CompletableFuture startingAfter = parsedResponse.getCursor(); ListCustomAttributeDefinitionsRequest nextRequest = ListCustomAttributeDefinitionsRequest.builder() @@ -123,7 +122,7 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO parsedResponse.getCustomAttributeDefinitions().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { + startingAfter.isPresent(), result, () -> { try { return list(nextRequest, requestOptions) .get() @@ -135,9 +134,12 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -205,17 +207,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateLocationCustomAttributeDefinitionResponse.class), + responseBody.string(), CreateLocationCustomAttributeDefinitionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -271,17 +275,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, RetrieveLocationCustomAttributeDefinitionResponse.class), + responseBody.string(), RetrieveLocationCustomAttributeDefinitionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -344,17 +350,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpdateLocationCustomAttributeDefinitionResponse.class), + responseBody.string(), UpdateLocationCustomAttributeDefinitionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -409,17 +417,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DeleteLocationCustomAttributeDefinitionResponse.class), + responseBody.string(), DeleteLocationCustomAttributeDefinitionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/locations/AsyncRawCustomAttributesClient.java b/src/main/java/com/squareup/square/locations/AsyncRawCustomAttributesClient.java index 5631cef8..e7faf18b 100644 --- a/src/main/java/com/squareup/square/locations/AsyncRawCustomAttributesClient.java +++ b/src/main/java/com/squareup/square/locations/AsyncRawCustomAttributesClient.java @@ -95,17 +95,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BulkDeleteLocationCustomAttributesResponse.class), + responseBody.string(), BulkDeleteLocationCustomAttributesResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -179,17 +181,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BulkUpsertLocationCustomAttributesResponse.class), + responseBody.string(), BulkUpsertLocationCustomAttributesResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -264,10 +268,9 @@ public CompletableFuture startingAfter = parsedResponse.getCursor(); ListCustomAttributesRequest nextRequest = ListCustomAttributesRequest.builder() .from(request) @@ -276,22 +279,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO List result = parsedResponse.getCustomAttributes().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return list(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return list(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -357,17 +362,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, RetrieveLocationCustomAttributeResponse.class), + responseBody.string(), RetrieveLocationCustomAttributeResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -436,17 +443,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpsertLocationCustomAttributeResponse.class), + responseBody.string(), UpsertLocationCustomAttributeResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -501,17 +510,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DeleteLocationCustomAttributeResponse.class), + responseBody.string(), DeleteLocationCustomAttributeResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/locations/AsyncRawTransactionsClient.java b/src/main/java/com/squareup/square/locations/AsyncRawTransactionsClient.java index da07e208..3f2d63ce 100644 --- a/src/main/java/com/squareup/square/locations/AsyncRawTransactionsClient.java +++ b/src/main/java/com/squareup/square/locations/AsyncRawTransactionsClient.java @@ -92,16 +92,19 @@ public CompletableFuture> lis @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListTransactionsResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), ListTransactionsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -150,16 +153,19 @@ public CompletableFuture> get( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetTransactionResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), GetTransactionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -216,17 +222,19 @@ public CompletableFuture> c @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CaptureTransactionResponse.class), + responseBody.string(), CaptureTransactionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -282,16 +290,19 @@ public CompletableFuture> void @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, VoidTransactionResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), VoidTransactionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/locations/RawCustomAttributeDefinitionsClient.java b/src/main/java/com/squareup/square/locations/RawCustomAttributeDefinitionsClient.java index 1d0c4170..c4b37159 100644 --- a/src/main/java/com/squareup/square/locations/RawCustomAttributeDefinitionsClient.java +++ b/src/main/java/com/squareup/square/locations/RawCustomAttributeDefinitionsClient.java @@ -99,10 +99,9 @@ public SquareClientHttpResponse> l } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListLocationCustomAttributeDefinitionsResponse parsedResponse = ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, ListLocationCustomAttributeDefinitionsResponse.class); + responseBody.string(), ListLocationCustomAttributeDefinitionsResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListCustomAttributeDefinitionsRequest nextRequest = ListCustomAttributeDefinitionsRequest.builder() .from(request) @@ -112,14 +111,16 @@ public SquareClientHttpResponse> l parsedResponse.getCustomAttributeDefinitions().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -174,16 +175,18 @@ public SquareClientHttpResponse } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateLocationCustomAttributeDefinitionResponse.class), + responseBody.string(), CreateLocationCustomAttributeDefinitionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -226,16 +229,18 @@ public SquareClientHttpResponse( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, RetrieveLocationCustomAttributeDefinitionResponse.class), + responseBody.string(), RetrieveLocationCustomAttributeDefinitionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -285,16 +290,18 @@ public SquareClientHttpResponse } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpdateLocationCustomAttributeDefinitionResponse.class), + responseBody.string(), UpdateLocationCustomAttributeDefinitionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -336,16 +343,18 @@ public SquareClientHttpResponse } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DeleteLocationCustomAttributeDefinitionResponse.class), + responseBody.string(), DeleteLocationCustomAttributeDefinitionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/locations/RawCustomAttributesClient.java b/src/main/java/com/squareup/square/locations/RawCustomAttributesClient.java index f6053b8d..8ed3a68d 100644 --- a/src/main/java/com/squareup/square/locations/RawCustomAttributesClient.java +++ b/src/main/java/com/squareup/square/locations/RawCustomAttributesClient.java @@ -86,16 +86,18 @@ public SquareClientHttpResponse batc } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BulkDeleteLocationCustomAttributesResponse.class), + responseBody.string(), BulkDeleteLocationCustomAttributesResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -156,16 +158,18 @@ public SquareClientHttpResponse batc } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BulkUpsertLocationCustomAttributesResponse.class), + responseBody.string(), BulkUpsertLocationCustomAttributesResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -226,10 +230,9 @@ public SquareClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListLocationCustomAttributesResponse parsedResponse = ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, ListLocationCustomAttributesResponse.class); + responseBody.string(), ListLocationCustomAttributesResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListCustomAttributesRequest nextRequest = ListCustomAttributesRequest.builder() .from(request) @@ -239,14 +242,16 @@ public SquareClientHttpResponse> list( parsedResponse.getCustomAttributes().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -298,16 +303,18 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, RetrieveLocationCustomAttributeResponse.class), + responseBody.string(), RetrieveLocationCustomAttributeResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -363,16 +370,18 @@ public SquareClientHttpResponse upsert( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpsertLocationCustomAttributeResponse.class), + responseBody.string(), UpsertLocationCustomAttributeResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -414,16 +423,18 @@ public SquareClientHttpResponse delete( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DeleteLocationCustomAttributeResponse.class), + responseBody.string(), DeleteLocationCustomAttributeResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/locations/RawTransactionsClient.java b/src/main/java/com/squareup/square/locations/RawTransactionsClient.java index bcd6ee37..5f7893c8 100644 --- a/src/main/java/com/squareup/square/locations/RawTransactionsClient.java +++ b/src/main/java/com/squareup/square/locations/RawTransactionsClient.java @@ -85,15 +85,17 @@ public SquareClientHttpResponse list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListTransactionsResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListTransactionsResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -130,15 +132,17 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetTransactionResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetTransactionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -182,15 +186,17 @@ public SquareClientHttpResponse capture( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CaptureTransactionResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CaptureTransactionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -234,15 +240,17 @@ public SquareClientHttpResponse void_( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, VoidTransactionResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), VoidTransactionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/locations/types/BulkDeleteLocationCustomAttributesRequest.java b/src/main/java/com/squareup/square/locations/types/BulkDeleteLocationCustomAttributesRequest.java index e71da171..265293bb 100644 --- a/src/main/java/com/squareup/square/locations/types/BulkDeleteLocationCustomAttributesRequest.java +++ b/src/main/java/com/squareup/square/locations/types/BulkDeleteLocationCustomAttributesRequest.java @@ -94,17 +94,13 @@ public Builder from(BulkDeleteLocationCustomAttributesRequest other) { public Builder values( Map values) { this.values.clear(); - if (values != null) { - this.values.putAll(values); - } + this.values.putAll(values); return this; } public Builder putAllValues( Map values) { - if (values != null) { - this.values.putAll(values); - } + this.values.putAll(values); return this; } diff --git a/src/main/java/com/squareup/square/locations/types/BulkUpsertLocationCustomAttributesRequest.java b/src/main/java/com/squareup/square/locations/types/BulkUpsertLocationCustomAttributesRequest.java index c4b508ce..9b315fbb 100644 --- a/src/main/java/com/squareup/square/locations/types/BulkUpsertLocationCustomAttributesRequest.java +++ b/src/main/java/com/squareup/square/locations/types/BulkUpsertLocationCustomAttributesRequest.java @@ -96,17 +96,13 @@ public Builder from(BulkUpsertLocationCustomAttributesRequest other) { public Builder values( Map values) { this.values.clear(); - if (values != null) { - this.values.putAll(values); - } + this.values.putAll(values); return this; } public Builder putAllValues( Map values) { - if (values != null) { - this.values.putAll(values); - } + this.values.putAll(values); return this; } diff --git a/src/main/java/com/squareup/square/loyalty/AsyncRawAccountsClient.java b/src/main/java/com/squareup/square/loyalty/AsyncRawAccountsClient.java index 65c791ef..d59c6aaa 100644 --- a/src/main/java/com/squareup/square/loyalty/AsyncRawAccountsClient.java +++ b/src/main/java/com/squareup/square/loyalty/AsyncRawAccountsClient.java @@ -81,17 +81,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateLoyaltyAccountResponse.class), + responseBody.string(), CreateLoyaltyAccountResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -159,17 +161,19 @@ public CompletableFuture @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, SearchLoyaltyAccountsResponse.class), + responseBody.string(), SearchLoyaltyAccountsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -216,17 +220,19 @@ public CompletableFuture> ge @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, GetLoyaltyAccountResponse.class), + responseBody.string(), GetLoyaltyAccountResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -317,17 +323,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, AccumulateLoyaltyPointsResponse.class), + responseBody.string(), AccumulateLoyaltyPointsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -390,17 +398,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, AdjustLoyaltyPointsResponse.class), + responseBody.string(), AdjustLoyaltyPointsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/loyalty/AsyncRawProgramsClient.java b/src/main/java/com/squareup/square/loyalty/AsyncRawProgramsClient.java index d2ba8fa3..7c9ab89b 100644 --- a/src/main/java/com/squareup/square/loyalty/AsyncRawProgramsClient.java +++ b/src/main/java/com/squareup/square/loyalty/AsyncRawProgramsClient.java @@ -71,17 +71,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, ListLoyaltyProgramsResponse.class), + responseBody.string(), ListLoyaltyProgramsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -130,17 +132,19 @@ public CompletableFuture> ge @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, GetLoyaltyProgramResponse.class), + responseBody.string(), GetLoyaltyProgramResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -233,17 +237,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CalculateLoyaltyPointsResponse.class), + responseBody.string(), CalculateLoyaltyPointsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/loyalty/AsyncRawRewardsClient.java b/src/main/java/com/squareup/square/loyalty/AsyncRawRewardsClient.java index 40311854..6cfc17da 100644 --- a/src/main/java/com/squareup/square/loyalty/AsyncRawRewardsClient.java +++ b/src/main/java/com/squareup/square/loyalty/AsyncRawRewardsClient.java @@ -95,17 +95,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateLoyaltyRewardResponse.class), + responseBody.string(), CreateLoyaltyRewardResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -179,17 +181,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, SearchLoyaltyRewardsResponse.class), + responseBody.string(), SearchLoyaltyRewardsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -236,16 +240,19 @@ public CompletableFuture> get @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetLoyaltyRewardResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), GetLoyaltyRewardResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -309,17 +316,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DeleteLoyaltyRewardResponse.class), + responseBody.string(), DeleteLoyaltyRewardResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -390,17 +399,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, RedeemLoyaltyRewardResponse.class), + responseBody.string(), RedeemLoyaltyRewardResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/loyalty/RawAccountsClient.java b/src/main/java/com/squareup/square/loyalty/RawAccountsClient.java index a96aa327..739c3cbc 100644 --- a/src/main/java/com/squareup/square/loyalty/RawAccountsClient.java +++ b/src/main/java/com/squareup/square/loyalty/RawAccountsClient.java @@ -73,15 +73,17 @@ public SquareClientHttpResponse create( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateLoyaltyAccountResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateLoyaltyAccountResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -136,15 +138,17 @@ public SquareClientHttpResponse search( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, SearchLoyaltyAccountsResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SearchLoyaltyAccountsResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -179,15 +183,17 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetLoyaltyAccountResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetLoyaltyAccountResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -266,15 +272,18 @@ public SquareClientHttpResponse accumulatePoint } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, AccumulateLoyaltyPointsResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), AccumulateLoyaltyPointsResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -324,15 +333,17 @@ public SquareClientHttpResponse adjust( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, AdjustLoyaltyPointsResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AdjustLoyaltyPointsResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/loyalty/RawProgramsClient.java b/src/main/java/com/squareup/square/loyalty/RawProgramsClient.java index 7917c7c0..2169f723 100644 --- a/src/main/java/com/squareup/square/loyalty/RawProgramsClient.java +++ b/src/main/java/com/squareup/square/loyalty/RawProgramsClient.java @@ -63,15 +63,17 @@ public SquareClientHttpResponse list(RequestOptions } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListLoyaltyProgramsResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListLoyaltyProgramsResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -108,15 +110,17 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetLoyaltyProgramResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetLoyaltyProgramResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -196,15 +200,18 @@ public SquareClientHttpResponse calculate( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CalculateLoyaltyPointsResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), CalculateLoyaltyPointsResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/loyalty/RawRewardsClient.java b/src/main/java/com/squareup/square/loyalty/RawRewardsClient.java index ab724f8f..6e023c40 100644 --- a/src/main/java/com/squareup/square/loyalty/RawRewardsClient.java +++ b/src/main/java/com/squareup/square/loyalty/RawRewardsClient.java @@ -87,15 +87,17 @@ public SquareClientHttpResponse create( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateLoyaltyRewardResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateLoyaltyRewardResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -156,15 +158,17 @@ public SquareClientHttpResponse search( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, SearchLoyaltyRewardsResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SearchLoyaltyRewardsResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -199,15 +203,17 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetLoyaltyRewardResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetLoyaltyRewardResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -258,15 +264,17 @@ public SquareClientHttpResponse delete( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, DeleteLoyaltyRewardResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), DeleteLoyaltyRewardResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -324,15 +332,17 @@ public SquareClientHttpResponse redeem( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, RedeemLoyaltyRewardResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), RedeemLoyaltyRewardResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/loyalty/programs/AsyncRawPromotionsClient.java b/src/main/java/com/squareup/square/loyalty/programs/AsyncRawPromotionsClient.java index 2f386f83..5980e12e 100644 --- a/src/main/java/com/squareup/square/loyalty/programs/AsyncRawPromotionsClient.java +++ b/src/main/java/com/squareup/square/loyalty/programs/AsyncRawPromotionsClient.java @@ -94,10 +94,9 @@ public CompletableFuture startingAfter = parsedResponse.getCursor(); ListPromotionsRequest nextRequest = ListPromotionsRequest.builder() .from(request) @@ -106,22 +105,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO List result = parsedResponse.getLoyaltyPromotions().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return list(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return list(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -186,17 +187,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateLoyaltyPromotionResponse.class), + responseBody.string(), CreateLoyaltyPromotionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -245,17 +248,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, GetLoyaltyPromotionResponse.class), + responseBody.string(), GetLoyaltyPromotionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -314,17 +319,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CancelLoyaltyPromotionResponse.class), + responseBody.string(), CancelLoyaltyPromotionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/loyalty/programs/RawPromotionsClient.java b/src/main/java/com/squareup/square/loyalty/programs/RawPromotionsClient.java index bf2b637e..d7ebf070 100644 --- a/src/main/java/com/squareup/square/loyalty/programs/RawPromotionsClient.java +++ b/src/main/java/com/squareup/square/loyalty/programs/RawPromotionsClient.java @@ -84,10 +84,9 @@ public SquareClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListLoyaltyPromotionsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListLoyaltyPromotionsResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListLoyaltyPromotionsResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListPromotionsRequest nextRequest = ListPromotionsRequest.builder() .from(request) @@ -97,14 +96,16 @@ public SquareClientHttpResponse> list( parsedResponse.getLoyaltyPromotions().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -156,15 +157,18 @@ public SquareClientHttpResponse create( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateLoyaltyPromotionResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), CreateLoyaltyPromotionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -201,15 +205,17 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetLoyaltyPromotionResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetLoyaltyPromotionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -255,15 +261,18 @@ public SquareClientHttpResponse cancel( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CancelLoyaltyPromotionResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), CancelLoyaltyPromotionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/merchants/AsyncRawCustomAttributeDefinitionsClient.java b/src/main/java/com/squareup/square/merchants/AsyncRawCustomAttributeDefinitionsClient.java index f7ce62e1..70cc729b 100644 --- a/src/main/java/com/squareup/square/merchants/AsyncRawCustomAttributeDefinitionsClient.java +++ b/src/main/java/com/squareup/square/merchants/AsyncRawCustomAttributeDefinitionsClient.java @@ -108,11 +108,10 @@ public CompletableFuture startingAfter = parsedResponse.getCursor(); ListCustomAttributeDefinitionsRequest nextRequest = ListCustomAttributeDefinitionsRequest.builder() @@ -123,7 +122,7 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO parsedResponse.getCustomAttributeDefinitions().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { + startingAfter.isPresent(), result, () -> { try { return list(nextRequest, requestOptions) .get() @@ -135,9 +134,12 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -205,17 +207,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateMerchantCustomAttributeDefinitionResponse.class), + responseBody.string(), CreateMerchantCustomAttributeDefinitionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -271,17 +275,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, RetrieveMerchantCustomAttributeDefinitionResponse.class), + responseBody.string(), RetrieveMerchantCustomAttributeDefinitionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -344,17 +350,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpdateMerchantCustomAttributeDefinitionResponse.class), + responseBody.string(), UpdateMerchantCustomAttributeDefinitionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -409,17 +417,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DeleteMerchantCustomAttributeDefinitionResponse.class), + responseBody.string(), DeleteMerchantCustomAttributeDefinitionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/merchants/AsyncRawCustomAttributesClient.java b/src/main/java/com/squareup/square/merchants/AsyncRawCustomAttributesClient.java index 2288581c..ac3693e2 100644 --- a/src/main/java/com/squareup/square/merchants/AsyncRawCustomAttributesClient.java +++ b/src/main/java/com/squareup/square/merchants/AsyncRawCustomAttributesClient.java @@ -95,17 +95,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BulkDeleteMerchantCustomAttributesResponse.class), + responseBody.string(), BulkDeleteMerchantCustomAttributesResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -179,17 +181,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BulkUpsertMerchantCustomAttributesResponse.class), + responseBody.string(), BulkUpsertMerchantCustomAttributesResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -264,10 +268,9 @@ public CompletableFuture startingAfter = parsedResponse.getCursor(); ListCustomAttributesRequest nextRequest = ListCustomAttributesRequest.builder() .from(request) @@ -276,22 +279,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO List result = parsedResponse.getCustomAttributes().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return list(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return list(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -357,17 +362,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, RetrieveMerchantCustomAttributeResponse.class), + responseBody.string(), RetrieveMerchantCustomAttributeResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -436,17 +443,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpsertMerchantCustomAttributeResponse.class), + responseBody.string(), UpsertMerchantCustomAttributeResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -501,17 +510,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DeleteMerchantCustomAttributeResponse.class), + responseBody.string(), DeleteMerchantCustomAttributeResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/merchants/RawCustomAttributeDefinitionsClient.java b/src/main/java/com/squareup/square/merchants/RawCustomAttributeDefinitionsClient.java index 74e2cfb5..e267ca5a 100644 --- a/src/main/java/com/squareup/square/merchants/RawCustomAttributeDefinitionsClient.java +++ b/src/main/java/com/squareup/square/merchants/RawCustomAttributeDefinitionsClient.java @@ -99,10 +99,9 @@ public SquareClientHttpResponse> l } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListMerchantCustomAttributeDefinitionsResponse parsedResponse = ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, ListMerchantCustomAttributeDefinitionsResponse.class); + responseBody.string(), ListMerchantCustomAttributeDefinitionsResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListCustomAttributeDefinitionsRequest nextRequest = ListCustomAttributeDefinitionsRequest.builder() .from(request) @@ -112,14 +111,16 @@ public SquareClientHttpResponse> l parsedResponse.getCustomAttributeDefinitions().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -174,16 +175,18 @@ public SquareClientHttpResponse } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateMerchantCustomAttributeDefinitionResponse.class), + responseBody.string(), CreateMerchantCustomAttributeDefinitionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -226,16 +229,18 @@ public SquareClientHttpResponse( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, RetrieveMerchantCustomAttributeDefinitionResponse.class), + responseBody.string(), RetrieveMerchantCustomAttributeDefinitionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -285,16 +290,18 @@ public SquareClientHttpResponse } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpdateMerchantCustomAttributeDefinitionResponse.class), + responseBody.string(), UpdateMerchantCustomAttributeDefinitionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -336,16 +343,18 @@ public SquareClientHttpResponse } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DeleteMerchantCustomAttributeDefinitionResponse.class), + responseBody.string(), DeleteMerchantCustomAttributeDefinitionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/merchants/RawCustomAttributesClient.java b/src/main/java/com/squareup/square/merchants/RawCustomAttributesClient.java index 31f56220..ecbfefe2 100644 --- a/src/main/java/com/squareup/square/merchants/RawCustomAttributesClient.java +++ b/src/main/java/com/squareup/square/merchants/RawCustomAttributesClient.java @@ -86,16 +86,18 @@ public SquareClientHttpResponse batc } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BulkDeleteMerchantCustomAttributesResponse.class), + responseBody.string(), BulkDeleteMerchantCustomAttributesResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -156,16 +158,18 @@ public SquareClientHttpResponse batc } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BulkUpsertMerchantCustomAttributesResponse.class), + responseBody.string(), BulkUpsertMerchantCustomAttributesResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -226,10 +230,9 @@ public SquareClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListMerchantCustomAttributesResponse parsedResponse = ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, ListMerchantCustomAttributesResponse.class); + responseBody.string(), ListMerchantCustomAttributesResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListCustomAttributesRequest nextRequest = ListCustomAttributesRequest.builder() .from(request) @@ -239,14 +242,16 @@ public SquareClientHttpResponse> list( parsedResponse.getCustomAttributes().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -298,16 +303,18 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, RetrieveMerchantCustomAttributeResponse.class), + responseBody.string(), RetrieveMerchantCustomAttributeResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -363,16 +370,18 @@ public SquareClientHttpResponse upsert( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpsertMerchantCustomAttributeResponse.class), + responseBody.string(), UpsertMerchantCustomAttributeResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -414,16 +423,18 @@ public SquareClientHttpResponse delete( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DeleteMerchantCustomAttributeResponse.class), + responseBody.string(), DeleteMerchantCustomAttributeResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/merchants/types/BulkDeleteMerchantCustomAttributesRequest.java b/src/main/java/com/squareup/square/merchants/types/BulkDeleteMerchantCustomAttributesRequest.java index 54170ddf..89470080 100644 --- a/src/main/java/com/squareup/square/merchants/types/BulkDeleteMerchantCustomAttributesRequest.java +++ b/src/main/java/com/squareup/square/merchants/types/BulkDeleteMerchantCustomAttributesRequest.java @@ -94,17 +94,13 @@ public Builder from(BulkDeleteMerchantCustomAttributesRequest other) { public Builder values( Map values) { this.values.clear(); - if (values != null) { - this.values.putAll(values); - } + this.values.putAll(values); return this; } public Builder putAllValues( Map values) { - if (values != null) { - this.values.putAll(values); - } + this.values.putAll(values); return this; } diff --git a/src/main/java/com/squareup/square/merchants/types/BulkUpsertMerchantCustomAttributesRequest.java b/src/main/java/com/squareup/square/merchants/types/BulkUpsertMerchantCustomAttributesRequest.java index 938c708a..a60507ec 100644 --- a/src/main/java/com/squareup/square/merchants/types/BulkUpsertMerchantCustomAttributesRequest.java +++ b/src/main/java/com/squareup/square/merchants/types/BulkUpsertMerchantCustomAttributesRequest.java @@ -96,17 +96,13 @@ public Builder from(BulkUpsertMerchantCustomAttributesRequest other) { public Builder values( Map values) { this.values.clear(); - if (values != null) { - this.values.putAll(values); - } + this.values.putAll(values); return this; } public Builder putAllValues( Map values) { - if (values != null) { - this.values.putAll(values); - } + this.values.putAll(values); return this; } diff --git a/src/main/java/com/squareup/square/orders/AsyncRawCustomAttributeDefinitionsClient.java b/src/main/java/com/squareup/square/orders/AsyncRawCustomAttributeDefinitionsClient.java index eeea4042..eceac8ab 100644 --- a/src/main/java/com/squareup/square/orders/AsyncRawCustomAttributeDefinitionsClient.java +++ b/src/main/java/com/squareup/square/orders/AsyncRawCustomAttributeDefinitionsClient.java @@ -110,11 +110,10 @@ public CompletableFuture startingAfter = parsedResponse.getCursor(); ListCustomAttributeDefinitionsRequest nextRequest = ListCustomAttributeDefinitionsRequest.builder() @@ -124,7 +123,7 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO List result = parsedResponse.getCustomAttributeDefinitions(); future.complete(new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { + startingAfter.isPresent(), result, () -> { try { return list(nextRequest, requestOptions) .get() @@ -136,9 +135,12 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -200,17 +202,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateOrderCustomAttributeDefinitionResponse.class), + responseBody.string(), CreateOrderCustomAttributeDefinitionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -268,17 +272,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, RetrieveOrderCustomAttributeDefinitionResponse.class), + responseBody.string(), RetrieveOrderCustomAttributeDefinitionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -337,17 +343,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpdateOrderCustomAttributeDefinitionResponse.class), + responseBody.string(), UpdateOrderCustomAttributeDefinitionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -398,17 +406,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DeleteOrderCustomAttributeDefinitionResponse.class), + responseBody.string(), DeleteOrderCustomAttributeDefinitionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/orders/AsyncRawCustomAttributesClient.java b/src/main/java/com/squareup/square/orders/AsyncRawCustomAttributesClient.java index b2bc51ab..853a9f40 100644 --- a/src/main/java/com/squareup/square/orders/AsyncRawCustomAttributesClient.java +++ b/src/main/java/com/squareup/square/orders/AsyncRawCustomAttributesClient.java @@ -111,17 +111,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BulkDeleteOrderCustomAttributesResponse.class), + responseBody.string(), BulkDeleteOrderCustomAttributesResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -197,17 +199,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BulkUpsertOrderCustomAttributesResponse.class), + responseBody.string(), BulkUpsertOrderCustomAttributesResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -282,10 +286,9 @@ public CompletableFuture startingAfter = parsedResponse.getCursor(); ListCustomAttributesRequest nextRequest = ListCustomAttributesRequest.builder() .from(request) @@ -294,22 +297,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO List result = parsedResponse.getCustomAttributes().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return list(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return list(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -377,17 +382,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, RetrieveOrderCustomAttributeResponse.class), + responseBody.string(), RetrieveOrderCustomAttributeResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -458,17 +465,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpsertOrderCustomAttributeResponse.class), + responseBody.string(), UpsertOrderCustomAttributeResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -525,17 +534,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DeleteOrderCustomAttributeResponse.class), + responseBody.string(), DeleteOrderCustomAttributeResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/orders/RawCustomAttributeDefinitionsClient.java b/src/main/java/com/squareup/square/orders/RawCustomAttributeDefinitionsClient.java index 83eb4339..1c1e2189 100644 --- a/src/main/java/com/squareup/square/orders/RawCustomAttributeDefinitionsClient.java +++ b/src/main/java/com/squareup/square/orders/RawCustomAttributeDefinitionsClient.java @@ -101,10 +101,9 @@ public SquareClientHttpResponse> l } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListOrderCustomAttributeDefinitionsResponse parsedResponse = ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, ListOrderCustomAttributeDefinitionsResponse.class); + responseBody.string(), ListOrderCustomAttributeDefinitionsResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListCustomAttributeDefinitionsRequest nextRequest = ListCustomAttributeDefinitionsRequest.builder() .from(request) @@ -113,14 +112,16 @@ public SquareClientHttpResponse> l List result = parsedResponse.getCustomAttributeDefinitions(); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -169,16 +170,18 @@ public SquareClientHttpResponse cr } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateOrderCustomAttributeDefinitionResponse.class), + responseBody.string(), CreateOrderCustomAttributeDefinitionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -223,16 +226,18 @@ public SquareClientHttpResponse } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, RetrieveOrderCustomAttributeDefinitionResponse.class), + responseBody.string(), RetrieveOrderCustomAttributeDefinitionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -278,16 +283,18 @@ public SquareClientHttpResponse up } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpdateOrderCustomAttributeDefinitionResponse.class), + responseBody.string(), UpdateOrderCustomAttributeDefinitionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -325,16 +332,18 @@ public SquareClientHttpResponse de } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DeleteOrderCustomAttributeDefinitionResponse.class), + responseBody.string(), DeleteOrderCustomAttributeDefinitionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/orders/RawCustomAttributesClient.java b/src/main/java/com/squareup/square/orders/RawCustomAttributesClient.java index d5f62c0c..be51835d 100644 --- a/src/main/java/com/squareup/square/orders/RawCustomAttributesClient.java +++ b/src/main/java/com/squareup/square/orders/RawCustomAttributesClient.java @@ -102,16 +102,18 @@ public SquareClientHttpResponse batchDe } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BulkDeleteOrderCustomAttributesResponse.class), + responseBody.string(), BulkDeleteOrderCustomAttributesResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -174,16 +176,18 @@ public SquareClientHttpResponse batchUp } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, BulkUpsertOrderCustomAttributesResponse.class), + responseBody.string(), BulkUpsertOrderCustomAttributesResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -244,10 +248,9 @@ public SquareClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListOrderCustomAttributesResponse parsedResponse = ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, ListOrderCustomAttributesResponse.class); + responseBody.string(), ListOrderCustomAttributesResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListCustomAttributesRequest nextRequest = ListCustomAttributesRequest.builder() .from(request) @@ -257,14 +260,16 @@ public SquareClientHttpResponse> list( parsedResponse.getCustomAttributes().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -318,16 +323,18 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, RetrieveOrderCustomAttributeResponse.class), + responseBody.string(), RetrieveOrderCustomAttributeResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -385,16 +392,18 @@ public SquareClientHttpResponse upsert( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpsertOrderCustomAttributeResponse.class), + responseBody.string(), UpsertOrderCustomAttributeResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -437,16 +446,18 @@ public SquareClientHttpResponse delete( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DeleteOrderCustomAttributeResponse.class), + responseBody.string(), DeleteOrderCustomAttributeResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/orders/types/BulkDeleteOrderCustomAttributesRequest.java b/src/main/java/com/squareup/square/orders/types/BulkDeleteOrderCustomAttributesRequest.java index 2d1e890c..2c673d4b 100644 --- a/src/main/java/com/squareup/square/orders/types/BulkDeleteOrderCustomAttributesRequest.java +++ b/src/main/java/com/squareup/square/orders/types/BulkDeleteOrderCustomAttributesRequest.java @@ -90,16 +90,12 @@ public Builder from(BulkDeleteOrderCustomAttributesRequest other) { @JsonSetter(value = "values", nulls = Nulls.SKIP) public Builder values(Map values) { this.values.clear(); - if (values != null) { - this.values.putAll(values); - } + this.values.putAll(values); return this; } public Builder putAllValues(Map values) { - if (values != null) { - this.values.putAll(values); - } + this.values.putAll(values); return this; } diff --git a/src/main/java/com/squareup/square/orders/types/BulkUpsertOrderCustomAttributesRequest.java b/src/main/java/com/squareup/square/orders/types/BulkUpsertOrderCustomAttributesRequest.java index 38f2c257..a704e1c6 100644 --- a/src/main/java/com/squareup/square/orders/types/BulkUpsertOrderCustomAttributesRequest.java +++ b/src/main/java/com/squareup/square/orders/types/BulkUpsertOrderCustomAttributesRequest.java @@ -90,16 +90,12 @@ public Builder from(BulkUpsertOrderCustomAttributesRequest other) { @JsonSetter(value = "values", nulls = Nulls.SKIP) public Builder values(Map values) { this.values.clear(); - if (values != null) { - this.values.putAll(values); - } + this.values.putAll(values); return this; } public Builder putAllValues(Map values) { - if (values != null) { - this.values.putAll(values); - } + this.values.putAll(values); return this; } diff --git a/src/main/java/com/squareup/square/teammembers/AsyncRawWageSettingClient.java b/src/main/java/com/squareup/square/teammembers/AsyncRawWageSettingClient.java index ecaa1bfb..ab9534bc 100644 --- a/src/main/java/com/squareup/square/teammembers/AsyncRawWageSettingClient.java +++ b/src/main/java/com/squareup/square/teammembers/AsyncRawWageSettingClient.java @@ -76,16 +76,19 @@ public CompletableFuture> get( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetWageSettingResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), GetWageSettingResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -154,17 +157,19 @@ public CompletableFuture> up @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpdateWageSettingResponse.class), + responseBody.string(), UpdateWageSettingResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/teammembers/RawWageSettingClient.java b/src/main/java/com/squareup/square/teammembers/RawWageSettingClient.java index f8de4da6..e36e7b55 100644 --- a/src/main/java/com/squareup/square/teammembers/RawWageSettingClient.java +++ b/src/main/java/com/squareup/square/teammembers/RawWageSettingClient.java @@ -69,15 +69,17 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetWageSettingResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetWageSettingResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -133,15 +135,17 @@ public SquareClientHttpResponse update( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, UpdateWageSettingResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UpdateWageSettingResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/terminal/AsyncRawActionsClient.java b/src/main/java/com/squareup/square/terminal/AsyncRawActionsClient.java index d48a5855..3a4921e5 100644 --- a/src/main/java/com/squareup/square/terminal/AsyncRawActionsClient.java +++ b/src/main/java/com/squareup/square/terminal/AsyncRawActionsClient.java @@ -79,17 +79,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateTerminalActionResponse.class), + responseBody.string(), CreateTerminalActionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -151,17 +153,19 @@ public CompletableFuture @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, SearchTerminalActionsResponse.class), + responseBody.string(), SearchTerminalActionsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -208,17 +212,19 @@ public CompletableFuture> ge @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, GetTerminalActionResponse.class), + responseBody.string(), GetTerminalActionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -267,17 +273,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CancelTerminalActionResponse.class), + responseBody.string(), CancelTerminalActionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/terminal/AsyncRawCheckoutsClient.java b/src/main/java/com/squareup/square/terminal/AsyncRawCheckoutsClient.java index acc75dfd..cc5d98a8 100644 --- a/src/main/java/com/squareup/square/terminal/AsyncRawCheckoutsClient.java +++ b/src/main/java/com/squareup/square/terminal/AsyncRawCheckoutsClient.java @@ -81,17 +81,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateTerminalCheckoutResponse.class), + responseBody.string(), CreateTerminalCheckoutResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -153,17 +155,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, SearchTerminalCheckoutsResponse.class), + responseBody.string(), SearchTerminalCheckoutsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -210,17 +214,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, GetTerminalCheckoutResponse.class), + responseBody.string(), GetTerminalCheckoutResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -269,17 +275,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CancelTerminalCheckoutResponse.class), + responseBody.string(), CancelTerminalCheckoutResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/terminal/AsyncRawRefundsClient.java b/src/main/java/com/squareup/square/terminal/AsyncRawRefundsClient.java index 3d031fa0..af289d51 100644 --- a/src/main/java/com/squareup/square/terminal/AsyncRawRefundsClient.java +++ b/src/main/java/com/squareup/square/terminal/AsyncRawRefundsClient.java @@ -79,17 +79,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateTerminalRefundResponse.class), + responseBody.string(), CreateTerminalRefundResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -151,17 +153,19 @@ public CompletableFuture @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, SearchTerminalRefundsResponse.class), + responseBody.string(), SearchTerminalRefundsResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -208,17 +212,19 @@ public CompletableFuture> ge @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, GetTerminalRefundResponse.class), + responseBody.string(), GetTerminalRefundResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -267,17 +273,19 @@ public CompletableFuture> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CancelTerminalRefundResponse.class), + responseBody.string(), CancelTerminalRefundResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/terminal/RawActionsClient.java b/src/main/java/com/squareup/square/terminal/RawActionsClient.java index 5268ac08..928149b2 100644 --- a/src/main/java/com/squareup/square/terminal/RawActionsClient.java +++ b/src/main/java/com/squareup/square/terminal/RawActionsClient.java @@ -71,15 +71,17 @@ public SquareClientHttpResponse create( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateTerminalActionResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateTerminalActionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -128,15 +130,17 @@ public SquareClientHttpResponse search( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, SearchTerminalActionsResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SearchTerminalActionsResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -171,15 +175,17 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetTerminalActionResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetTerminalActionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -215,15 +221,17 @@ public SquareClientHttpResponse cancel( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CancelTerminalActionResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CancelTerminalActionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/terminal/RawCheckoutsClient.java b/src/main/java/com/squareup/square/terminal/RawCheckoutsClient.java index 132c05c6..6e30ccd4 100644 --- a/src/main/java/com/squareup/square/terminal/RawCheckoutsClient.java +++ b/src/main/java/com/squareup/square/terminal/RawCheckoutsClient.java @@ -73,15 +73,18 @@ public SquareClientHttpResponse create( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateTerminalCheckoutResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), CreateTerminalCheckoutResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -130,15 +133,18 @@ public SquareClientHttpResponse search( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, SearchTerminalCheckoutsResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), SearchTerminalCheckoutsResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -173,15 +179,17 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetTerminalCheckoutResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetTerminalCheckoutResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -217,15 +225,18 @@ public SquareClientHttpResponse cancel( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CancelTerminalCheckoutResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), CancelTerminalCheckoutResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/terminal/RawRefundsClient.java b/src/main/java/com/squareup/square/terminal/RawRefundsClient.java index 0ccafc2c..0962cf47 100644 --- a/src/main/java/com/squareup/square/terminal/RawRefundsClient.java +++ b/src/main/java/com/squareup/square/terminal/RawRefundsClient.java @@ -71,15 +71,17 @@ public SquareClientHttpResponse create( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateTerminalRefundResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateTerminalRefundResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -128,15 +130,17 @@ public SquareClientHttpResponse search( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, SearchTerminalRefundsResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SearchTerminalRefundsResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -171,15 +175,17 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetTerminalRefundResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetTerminalRefundResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -215,15 +221,17 @@ public SquareClientHttpResponse cancel( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CancelTerminalRefundResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CancelTerminalRefundResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/types/BatchCreateTeamMembersRequest.java b/src/main/java/com/squareup/square/types/BatchCreateTeamMembersRequest.java index da498ff0..6c0e0f44 100644 --- a/src/main/java/com/squareup/square/types/BatchCreateTeamMembersRequest.java +++ b/src/main/java/com/squareup/square/types/BatchCreateTeamMembersRequest.java @@ -93,16 +93,12 @@ public Builder from(BatchCreateTeamMembersRequest other) { @JsonSetter(value = "team_members", nulls = Nulls.SKIP) public Builder teamMembers(Map teamMembers) { this.teamMembers.clear(); - if (teamMembers != null) { - this.teamMembers.putAll(teamMembers); - } + this.teamMembers.putAll(teamMembers); return this; } public Builder putAllTeamMembers(Map teamMembers) { - if (teamMembers != null) { - this.teamMembers.putAll(teamMembers); - } + this.teamMembers.putAll(teamMembers); return this; } diff --git a/src/main/java/com/squareup/square/types/BatchCreateVendorsRequest.java b/src/main/java/com/squareup/square/types/BatchCreateVendorsRequest.java index c1ddbc7e..0e3acee0 100644 --- a/src/main/java/com/squareup/square/types/BatchCreateVendorsRequest.java +++ b/src/main/java/com/squareup/square/types/BatchCreateVendorsRequest.java @@ -86,16 +86,12 @@ public Builder from(BatchCreateVendorsRequest other) { @JsonSetter(value = "vendors", nulls = Nulls.SKIP) public Builder vendors(Map vendors) { this.vendors.clear(); - if (vendors != null) { - this.vendors.putAll(vendors); - } + this.vendors.putAll(vendors); return this; } public Builder putAllVendors(Map vendors) { - if (vendors != null) { - this.vendors.putAll(vendors); - } + this.vendors.putAll(vendors); return this; } diff --git a/src/main/java/com/squareup/square/types/BatchDeleteCatalogObjectsRequest.java b/src/main/java/com/squareup/square/types/BatchDeleteCatalogObjectsRequest.java index 55025c3f..a5d64dab 100644 --- a/src/main/java/com/squareup/square/types/BatchDeleteCatalogObjectsRequest.java +++ b/src/main/java/com/squareup/square/types/BatchDeleteCatalogObjectsRequest.java @@ -91,9 +91,7 @@ public Builder from(BatchDeleteCatalogObjectsRequest other) { @JsonSetter(value = "object_ids", nulls = Nulls.SKIP) public Builder objectIds(List objectIds) { this.objectIds.clear(); - if (objectIds != null) { - this.objectIds.addAll(objectIds); - } + this.objectIds.addAll(objectIds); return this; } @@ -103,9 +101,7 @@ public Builder addObjectIds(String objectIds) { } public Builder addAllObjectIds(List objectIds) { - if (objectIds != null) { - this.objectIds.addAll(objectIds); - } + this.objectIds.addAll(objectIds); return this; } diff --git a/src/main/java/com/squareup/square/types/BatchGetCatalogObjectsRequest.java b/src/main/java/com/squareup/square/types/BatchGetCatalogObjectsRequest.java index 0e11ebf7..a1c45e1d 100644 --- a/src/main/java/com/squareup/square/types/BatchGetCatalogObjectsRequest.java +++ b/src/main/java/com/squareup/square/types/BatchGetCatalogObjectsRequest.java @@ -215,9 +215,7 @@ public Builder from(BatchGetCatalogObjectsRequest other) { @JsonSetter(value = "object_ids", nulls = Nulls.SKIP) public Builder objectIds(List objectIds) { this.objectIds.clear(); - if (objectIds != null) { - this.objectIds.addAll(objectIds); - } + this.objectIds.addAll(objectIds); return this; } @@ -227,9 +225,7 @@ public Builder addObjectIds(String objectIds) { } public Builder addAllObjectIds(List objectIds) { - if (objectIds != null) { - this.objectIds.addAll(objectIds); - } + this.objectIds.addAll(objectIds); return this; } diff --git a/src/main/java/com/squareup/square/types/BatchGetOrdersRequest.java b/src/main/java/com/squareup/square/types/BatchGetOrdersRequest.java index f0f05773..e6e8d3e6 100644 --- a/src/main/java/com/squareup/square/types/BatchGetOrdersRequest.java +++ b/src/main/java/com/squareup/square/types/BatchGetOrdersRequest.java @@ -142,9 +142,7 @@ public Builder locationId(Nullable locationId) { @JsonSetter(value = "order_ids", nulls = Nulls.SKIP) public Builder orderIds(List orderIds) { this.orderIds.clear(); - if (orderIds != null) { - this.orderIds.addAll(orderIds); - } + this.orderIds.addAll(orderIds); return this; } @@ -154,9 +152,7 @@ public Builder addOrderIds(String orderIds) { } public Builder addAllOrderIds(List orderIds) { - if (orderIds != null) { - this.orderIds.addAll(orderIds); - } + this.orderIds.addAll(orderIds); return this; } diff --git a/src/main/java/com/squareup/square/types/BatchUpdateTeamMembersRequest.java b/src/main/java/com/squareup/square/types/BatchUpdateTeamMembersRequest.java index 0aabc1de..1dd0ffed 100644 --- a/src/main/java/com/squareup/square/types/BatchUpdateTeamMembersRequest.java +++ b/src/main/java/com/squareup/square/types/BatchUpdateTeamMembersRequest.java @@ -95,16 +95,12 @@ public Builder from(BatchUpdateTeamMembersRequest other) { @JsonSetter(value = "team_members", nulls = Nulls.SKIP) public Builder teamMembers(Map teamMembers) { this.teamMembers.clear(); - if (teamMembers != null) { - this.teamMembers.putAll(teamMembers); - } + this.teamMembers.putAll(teamMembers); return this; } public Builder putAllTeamMembers(Map teamMembers) { - if (teamMembers != null) { - this.teamMembers.putAll(teamMembers); - } + this.teamMembers.putAll(teamMembers); return this; } diff --git a/src/main/java/com/squareup/square/types/BatchUpdateVendorsRequest.java b/src/main/java/com/squareup/square/types/BatchUpdateVendorsRequest.java index a13343bf..f4f9f4d8 100644 --- a/src/main/java/com/squareup/square/types/BatchUpdateVendorsRequest.java +++ b/src/main/java/com/squareup/square/types/BatchUpdateVendorsRequest.java @@ -89,16 +89,12 @@ public Builder from(BatchUpdateVendorsRequest other) { @JsonSetter(value = "vendors", nulls = Nulls.SKIP) public Builder vendors(Map vendors) { this.vendors.clear(); - if (vendors != null) { - this.vendors.putAll(vendors); - } + this.vendors.putAll(vendors); return this; } public Builder putAllVendors(Map vendors) { - if (vendors != null) { - this.vendors.putAll(vendors); - } + this.vendors.putAll(vendors); return this; } diff --git a/src/main/java/com/squareup/square/types/BatchUpsertCatalogObjectsRequest.java b/src/main/java/com/squareup/square/types/BatchUpsertCatalogObjectsRequest.java index 821c0b01..f416fc14 100644 --- a/src/main/java/com/squareup/square/types/BatchUpsertCatalogObjectsRequest.java +++ b/src/main/java/com/squareup/square/types/BatchUpsertCatalogObjectsRequest.java @@ -211,9 +211,7 @@ public _FinalStage idempotencyKey(@NotNull String idempotencyKey) { */ @java.lang.Override public _FinalStage addAllBatches(List batches) { - if (batches != null) { - this.batches.addAll(batches); - } + this.batches.addAll(batches); return this; } @@ -264,9 +262,7 @@ public _FinalStage addBatches(CatalogObjectBatch batches) { @JsonSetter(value = "batches", nulls = Nulls.SKIP) public _FinalStage batches(List batches) { this.batches.clear(); - if (batches != null) { - this.batches.addAll(batches); - } + this.batches.addAll(batches); return this; } diff --git a/src/main/java/com/squareup/square/types/BulkCreateCustomersRequest.java b/src/main/java/com/squareup/square/types/BulkCreateCustomersRequest.java index 3662ef66..0231c2e0 100644 --- a/src/main/java/com/squareup/square/types/BulkCreateCustomersRequest.java +++ b/src/main/java/com/squareup/square/types/BulkCreateCustomersRequest.java @@ -95,16 +95,12 @@ public Builder from(BulkCreateCustomersRequest other) { @JsonSetter(value = "customers", nulls = Nulls.SKIP) public Builder customers(Map customers) { this.customers.clear(); - if (customers != null) { - this.customers.putAll(customers); - } + this.customers.putAll(customers); return this; } public Builder putAllCustomers(Map customers) { - if (customers != null) { - this.customers.putAll(customers); - } + this.customers.putAll(customers); return this; } diff --git a/src/main/java/com/squareup/square/types/BulkDeleteCustomersRequest.java b/src/main/java/com/squareup/square/types/BulkDeleteCustomersRequest.java index 94a6db7a..34a57320 100644 --- a/src/main/java/com/squareup/square/types/BulkDeleteCustomersRequest.java +++ b/src/main/java/com/squareup/square/types/BulkDeleteCustomersRequest.java @@ -87,9 +87,7 @@ public Builder from(BulkDeleteCustomersRequest other) { @JsonSetter(value = "customer_ids", nulls = Nulls.SKIP) public Builder customerIds(List customerIds) { this.customerIds.clear(); - if (customerIds != null) { - this.customerIds.addAll(customerIds); - } + this.customerIds.addAll(customerIds); return this; } @@ -99,9 +97,7 @@ public Builder addCustomerIds(String customerIds) { } public Builder addAllCustomerIds(List customerIds) { - if (customerIds != null) { - this.customerIds.addAll(customerIds); - } + this.customerIds.addAll(customerIds); return this; } diff --git a/src/main/java/com/squareup/square/types/BulkDeleteLocationCustomAttributesResponse.java b/src/main/java/com/squareup/square/types/BulkDeleteLocationCustomAttributesResponse.java index c5dc0297..a6d8165f 100644 --- a/src/main/java/com/squareup/square/types/BulkDeleteLocationCustomAttributesResponse.java +++ b/src/main/java/com/squareup/square/types/BulkDeleteLocationCustomAttributesResponse.java @@ -110,17 +110,13 @@ public Builder from(BulkDeleteLocationCustomAttributesResponse other) { public Builder values( Map values) { this.values.clear(); - if (values != null) { - this.values.putAll(values); - } + this.values.putAll(values); return this; } public Builder putAllValues( Map values) { - if (values != null) { - this.values.putAll(values); - } + this.values.putAll(values); return this; } diff --git a/src/main/java/com/squareup/square/types/BulkDeleteMerchantCustomAttributesResponse.java b/src/main/java/com/squareup/square/types/BulkDeleteMerchantCustomAttributesResponse.java index 0bf80b50..a8d166d8 100644 --- a/src/main/java/com/squareup/square/types/BulkDeleteMerchantCustomAttributesResponse.java +++ b/src/main/java/com/squareup/square/types/BulkDeleteMerchantCustomAttributesResponse.java @@ -110,17 +110,13 @@ public Builder from(BulkDeleteMerchantCustomAttributesResponse other) { public Builder values( Map values) { this.values.clear(); - if (values != null) { - this.values.putAll(values); - } + this.values.putAll(values); return this; } public Builder putAllValues( Map values) { - if (values != null) { - this.values.putAll(values); - } + this.values.putAll(values); return this; } diff --git a/src/main/java/com/squareup/square/types/BulkDeleteOrderCustomAttributesResponse.java b/src/main/java/com/squareup/square/types/BulkDeleteOrderCustomAttributesResponse.java index 216aa37a..cf8bd3c1 100644 --- a/src/main/java/com/squareup/square/types/BulkDeleteOrderCustomAttributesResponse.java +++ b/src/main/java/com/squareup/square/types/BulkDeleteOrderCustomAttributesResponse.java @@ -122,16 +122,12 @@ public Builder errors(List errors) { @JsonSetter(value = "values", nulls = Nulls.SKIP) public Builder values(Map values) { this.values.clear(); - if (values != null) { - this.values.putAll(values); - } + this.values.putAll(values); return this; } public Builder putAllValues(Map values) { - if (values != null) { - this.values.putAll(values); - } + this.values.putAll(values); return this; } diff --git a/src/main/java/com/squareup/square/types/BulkPublishScheduledShiftsRequest.java b/src/main/java/com/squareup/square/types/BulkPublishScheduledShiftsRequest.java index 4e6f26da..4bd973bb 100644 --- a/src/main/java/com/squareup/square/types/BulkPublishScheduledShiftsRequest.java +++ b/src/main/java/com/squareup/square/types/BulkPublishScheduledShiftsRequest.java @@ -118,16 +118,12 @@ public Builder from(BulkPublishScheduledShiftsRequest other) { @JsonSetter(value = "scheduled_shifts", nulls = Nulls.SKIP) public Builder scheduledShifts(Map scheduledShifts) { this.scheduledShifts.clear(); - if (scheduledShifts != null) { - this.scheduledShifts.putAll(scheduledShifts); - } + this.scheduledShifts.putAll(scheduledShifts); return this; } public Builder putAllScheduledShifts(Map scheduledShifts) { - if (scheduledShifts != null) { - this.scheduledShifts.putAll(scheduledShifts); - } + this.scheduledShifts.putAll(scheduledShifts); return this; } diff --git a/src/main/java/com/squareup/square/types/BulkRetrieveBookingsRequest.java b/src/main/java/com/squareup/square/types/BulkRetrieveBookingsRequest.java index 36a52782..628be0d2 100644 --- a/src/main/java/com/squareup/square/types/BulkRetrieveBookingsRequest.java +++ b/src/main/java/com/squareup/square/types/BulkRetrieveBookingsRequest.java @@ -87,9 +87,7 @@ public Builder from(BulkRetrieveBookingsRequest other) { @JsonSetter(value = "booking_ids", nulls = Nulls.SKIP) public Builder bookingIds(List bookingIds) { this.bookingIds.clear(); - if (bookingIds != null) { - this.bookingIds.addAll(bookingIds); - } + this.bookingIds.addAll(bookingIds); return this; } @@ -99,9 +97,7 @@ public Builder addBookingIds(String bookingIds) { } public Builder addAllBookingIds(List bookingIds) { - if (bookingIds != null) { - this.bookingIds.addAll(bookingIds); - } + this.bookingIds.addAll(bookingIds); return this; } diff --git a/src/main/java/com/squareup/square/types/BulkRetrieveChannelsRequest.java b/src/main/java/com/squareup/square/types/BulkRetrieveChannelsRequest.java deleted file mode 100644 index c2fe07e4..00000000 --- a/src/main/java/com/squareup/square/types/BulkRetrieveChannelsRequest.java +++ /dev/null @@ -1,106 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.ObjectMappers; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = BulkRetrieveChannelsRequest.Builder.class) -public final class BulkRetrieveChannelsRequest { - private final List channelIds; - - private final Map additionalProperties; - - private BulkRetrieveChannelsRequest(List channelIds, Map additionalProperties) { - this.channelIds = channelIds; - this.additionalProperties = additionalProperties; - } - - @JsonProperty("channel_ids") - public List getChannelIds() { - return channelIds; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof BulkRetrieveChannelsRequest && equalTo((BulkRetrieveChannelsRequest) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(BulkRetrieveChannelsRequest other) { - return channelIds.equals(other.channelIds); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.channelIds); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private List channelIds = new ArrayList<>(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(BulkRetrieveChannelsRequest other) { - channelIds(other.getChannelIds()); - return this; - } - - @JsonSetter(value = "channel_ids", nulls = Nulls.SKIP) - public Builder channelIds(List channelIds) { - this.channelIds.clear(); - if (channelIds != null) { - this.channelIds.addAll(channelIds); - } - return this; - } - - public Builder addChannelIds(String channelIds) { - this.channelIds.add(channelIds); - return this; - } - - public Builder addAllChannelIds(List channelIds) { - if (channelIds != null) { - this.channelIds.addAll(channelIds); - } - return this; - } - - public BulkRetrieveChannelsRequest build() { - return new BulkRetrieveChannelsRequest(channelIds, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/BulkRetrieveChannelsResponse.java b/src/main/java/com/squareup/square/types/BulkRetrieveChannelsResponse.java deleted file mode 100644 index ccad1b53..00000000 --- a/src/main/java/com/squareup/square/types/BulkRetrieveChannelsResponse.java +++ /dev/null @@ -1,139 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = BulkRetrieveChannelsResponse.Builder.class) -public final class BulkRetrieveChannelsResponse { - private final Optional> errors; - - private final Optional> responses; - - private final Map additionalProperties; - - private BulkRetrieveChannelsResponse( - Optional> errors, - Optional> responses, - Map additionalProperties) { - this.errors = errors; - this.responses = responses; - this.additionalProperties = additionalProperties; - } - - /** - * @return Information about errors encountered during the request. - */ - @JsonProperty("errors") - public Optional> getErrors() { - return errors; - } - - /** - * @return A map of channel IDs to channel responses which tell whether - * retrieval for a specific channel is success or not. - * Channel response of a success retrieval would contain channel info - * whereas channel response of a failed retrieval would have error info. - */ - @JsonProperty("responses") - public Optional> getResponses() { - return responses; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof BulkRetrieveChannelsResponse && equalTo((BulkRetrieveChannelsResponse) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(BulkRetrieveChannelsResponse other) { - return errors.equals(other.errors) && responses.equals(other.responses); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.errors, this.responses); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional> errors = Optional.empty(); - - private Optional> responses = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(BulkRetrieveChannelsResponse other) { - errors(other.getErrors()); - responses(other.getResponses()); - return this; - } - - /** - *

Information about errors encountered during the request.

- */ - @JsonSetter(value = "errors", nulls = Nulls.SKIP) - public Builder errors(Optional> errors) { - this.errors = errors; - return this; - } - - public Builder errors(List errors) { - this.errors = Optional.ofNullable(errors); - return this; - } - - /** - *

A map of channel IDs to channel responses which tell whether - * retrieval for a specific channel is success or not. - * Channel response of a success retrieval would contain channel info - * whereas channel response of a failed retrieval would have error info.

- */ - @JsonSetter(value = "responses", nulls = Nulls.SKIP) - public Builder responses(Optional> responses) { - this.responses = responses; - return this; - } - - public Builder responses(Map responses) { - this.responses = Optional.ofNullable(responses); - return this; - } - - public BulkRetrieveChannelsResponse build() { - return new BulkRetrieveChannelsResponse(errors, responses, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/BulkRetrieveCustomersRequest.java b/src/main/java/com/squareup/square/types/BulkRetrieveCustomersRequest.java index d09d15dd..3e4209d3 100644 --- a/src/main/java/com/squareup/square/types/BulkRetrieveCustomersRequest.java +++ b/src/main/java/com/squareup/square/types/BulkRetrieveCustomersRequest.java @@ -87,9 +87,7 @@ public Builder from(BulkRetrieveCustomersRequest other) { @JsonSetter(value = "customer_ids", nulls = Nulls.SKIP) public Builder customerIds(List customerIds) { this.customerIds.clear(); - if (customerIds != null) { - this.customerIds.addAll(customerIds); - } + this.customerIds.addAll(customerIds); return this; } @@ -99,9 +97,7 @@ public Builder addCustomerIds(String customerIds) { } public Builder addAllCustomerIds(List customerIds) { - if (customerIds != null) { - this.customerIds.addAll(customerIds); - } + this.customerIds.addAll(customerIds); return this; } diff --git a/src/main/java/com/squareup/square/types/BulkRetrieveTeamMemberBookingProfilesRequest.java b/src/main/java/com/squareup/square/types/BulkRetrieveTeamMemberBookingProfilesRequest.java index 599ebeb7..f2bc6854 100644 --- a/src/main/java/com/squareup/square/types/BulkRetrieveTeamMemberBookingProfilesRequest.java +++ b/src/main/java/com/squareup/square/types/BulkRetrieveTeamMemberBookingProfilesRequest.java @@ -89,9 +89,7 @@ public Builder from(BulkRetrieveTeamMemberBookingProfilesRequest other) { @JsonSetter(value = "team_member_ids", nulls = Nulls.SKIP) public Builder teamMemberIds(List teamMemberIds) { this.teamMemberIds.clear(); - if (teamMemberIds != null) { - this.teamMemberIds.addAll(teamMemberIds); - } + this.teamMemberIds.addAll(teamMemberIds); return this; } @@ -101,9 +99,7 @@ public Builder addTeamMemberIds(String teamMemberIds) { } public Builder addAllTeamMemberIds(List teamMemberIds) { - if (teamMemberIds != null) { - this.teamMemberIds.addAll(teamMemberIds); - } + this.teamMemberIds.addAll(teamMemberIds); return this; } diff --git a/src/main/java/com/squareup/square/types/BulkUpdateCustomersRequest.java b/src/main/java/com/squareup/square/types/BulkUpdateCustomersRequest.java index 1d20a960..70479605 100644 --- a/src/main/java/com/squareup/square/types/BulkUpdateCustomersRequest.java +++ b/src/main/java/com/squareup/square/types/BulkUpdateCustomersRequest.java @@ -97,16 +97,12 @@ public Builder from(BulkUpdateCustomersRequest other) { @JsonSetter(value = "customers", nulls = Nulls.SKIP) public Builder customers(Map customers) { this.customers.clear(); - if (customers != null) { - this.customers.putAll(customers); - } + this.customers.putAll(customers); return this; } public Builder putAllCustomers(Map customers) { - if (customers != null) { - this.customers.putAll(customers); - } + this.customers.putAll(customers); return this; } diff --git a/src/main/java/com/squareup/square/types/BulkUpsertOrderCustomAttributesResponse.java b/src/main/java/com/squareup/square/types/BulkUpsertOrderCustomAttributesResponse.java index 117b3b68..43778608 100644 --- a/src/main/java/com/squareup/square/types/BulkUpsertOrderCustomAttributesResponse.java +++ b/src/main/java/com/squareup/square/types/BulkUpsertOrderCustomAttributesResponse.java @@ -120,16 +120,12 @@ public Builder errors(List errors) { @JsonSetter(value = "values", nulls = Nulls.SKIP) public Builder values(Map values) { this.values.clear(); - if (values != null) { - this.values.putAll(values); - } + this.values.putAll(values); return this; } public Builder putAllValues(Map values) { - if (values != null) { - this.values.putAll(values); - } + this.values.putAll(values); return this; } diff --git a/src/main/java/com/squareup/square/types/CancelTransferOrderRequest.java b/src/main/java/com/squareup/square/types/CancelTransferOrderRequest.java deleted file mode 100644 index e1e74bc8..00000000 --- a/src/main/java/com/squareup/square/types/CancelTransferOrderRequest.java +++ /dev/null @@ -1,199 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import org.jetbrains.annotations.NotNull; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = CancelTransferOrderRequest.Builder.class) -public final class CancelTransferOrderRequest { - private final String transferOrderId; - - private final String idempotencyKey; - - private final Optional version; - - private final Map additionalProperties; - - private CancelTransferOrderRequest( - String transferOrderId, - String idempotencyKey, - Optional version, - Map additionalProperties) { - this.transferOrderId = transferOrderId; - this.idempotencyKey = idempotencyKey; - this.version = version; - this.additionalProperties = additionalProperties; - } - - /** - * @return The ID of the transfer order to cancel. Must be in STARTED or PARTIALLY_RECEIVED status. - */ - @JsonProperty("transfer_order_id") - public String getTransferOrderId() { - return transferOrderId; - } - - /** - * @return A unique string that identifies this UpdateTransferOrder request. Keys can be - * any valid string but must be unique for every UpdateTransferOrder request. - */ - @JsonProperty("idempotency_key") - public String getIdempotencyKey() { - return idempotencyKey; - } - - /** - * @return Version for optimistic concurrency - */ - @JsonProperty("version") - public Optional getVersion() { - return version; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof CancelTransferOrderRequest && equalTo((CancelTransferOrderRequest) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(CancelTransferOrderRequest other) { - return transferOrderId.equals(other.transferOrderId) - && idempotencyKey.equals(other.idempotencyKey) - && version.equals(other.version); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.transferOrderId, this.idempotencyKey, this.version); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static TransferOrderIdStage builder() { - return new Builder(); - } - - public interface TransferOrderIdStage { - /** - *

The ID of the transfer order to cancel. Must be in STARTED or PARTIALLY_RECEIVED status.

- */ - IdempotencyKeyStage transferOrderId(@NotNull String transferOrderId); - - Builder from(CancelTransferOrderRequest other); - } - - public interface IdempotencyKeyStage { - /** - *

A unique string that identifies this UpdateTransferOrder request. Keys can be - * any valid string but must be unique for every UpdateTransferOrder request.

- */ - _FinalStage idempotencyKey(@NotNull String idempotencyKey); - } - - public interface _FinalStage { - CancelTransferOrderRequest build(); - - /** - *

Version for optimistic concurrency

- */ - _FinalStage version(Optional version); - - _FinalStage version(Long version); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder implements TransferOrderIdStage, IdempotencyKeyStage, _FinalStage { - private String transferOrderId; - - private String idempotencyKey; - - private Optional version = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - @java.lang.Override - public Builder from(CancelTransferOrderRequest other) { - transferOrderId(other.getTransferOrderId()); - idempotencyKey(other.getIdempotencyKey()); - version(other.getVersion()); - return this; - } - - /** - *

The ID of the transfer order to cancel. Must be in STARTED or PARTIALLY_RECEIVED status.

- *

The ID of the transfer order to cancel. Must be in STARTED or PARTIALLY_RECEIVED status.

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - @JsonSetter("transfer_order_id") - public IdempotencyKeyStage transferOrderId(@NotNull String transferOrderId) { - this.transferOrderId = Objects.requireNonNull(transferOrderId, "transferOrderId must not be null"); - return this; - } - - /** - *

A unique string that identifies this UpdateTransferOrder request. Keys can be - * any valid string but must be unique for every UpdateTransferOrder request.

- *

A unique string that identifies this UpdateTransferOrder request. Keys can be - * any valid string but must be unique for every UpdateTransferOrder request.

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - @JsonSetter("idempotency_key") - public _FinalStage idempotencyKey(@NotNull String idempotencyKey) { - this.idempotencyKey = Objects.requireNonNull(idempotencyKey, "idempotencyKey must not be null"); - return this; - } - - /** - *

Version for optimistic concurrency

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - public _FinalStage version(Long version) { - this.version = Optional.ofNullable(version); - return this; - } - - /** - *

Version for optimistic concurrency

- */ - @java.lang.Override - @JsonSetter(value = "version", nulls = Nulls.SKIP) - public _FinalStage version(Optional version) { - this.version = version; - return this; - } - - @java.lang.Override - public CancelTransferOrderRequest build() { - return new CancelTransferOrderRequest(transferOrderId, idempotencyKey, version, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/CancelTransferOrderResponse.java b/src/main/java/com/squareup/square/types/CancelTransferOrderResponse.java deleted file mode 100644 index cc89e572..00000000 --- a/src/main/java/com/squareup/square/types/CancelTransferOrderResponse.java +++ /dev/null @@ -1,133 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = CancelTransferOrderResponse.Builder.class) -public final class CancelTransferOrderResponse { - private final Optional transferOrder; - - private final Optional> errors; - - private final Map additionalProperties; - - private CancelTransferOrderResponse( - Optional transferOrder, - Optional> errors, - Map additionalProperties) { - this.transferOrder = transferOrder; - this.errors = errors; - this.additionalProperties = additionalProperties; - } - - /** - * @return The updated transfer order with status changed to CANCELED - */ - @JsonProperty("transfer_order") - public Optional getTransferOrder() { - return transferOrder; - } - - /** - * @return Any errors that occurred during the request - */ - @JsonProperty("errors") - public Optional> getErrors() { - return errors; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof CancelTransferOrderResponse && equalTo((CancelTransferOrderResponse) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(CancelTransferOrderResponse other) { - return transferOrder.equals(other.transferOrder) && errors.equals(other.errors); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.transferOrder, this.errors); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional transferOrder = Optional.empty(); - - private Optional> errors = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(CancelTransferOrderResponse other) { - transferOrder(other.getTransferOrder()); - errors(other.getErrors()); - return this; - } - - /** - *

The updated transfer order with status changed to CANCELED

- */ - @JsonSetter(value = "transfer_order", nulls = Nulls.SKIP) - public Builder transferOrder(Optional transferOrder) { - this.transferOrder = transferOrder; - return this; - } - - public Builder transferOrder(TransferOrder transferOrder) { - this.transferOrder = Optional.ofNullable(transferOrder); - return this; - } - - /** - *

Any errors that occurred during the request

- */ - @JsonSetter(value = "errors", nulls = Nulls.SKIP) - public Builder errors(Optional> errors) { - this.errors = errors; - return this; - } - - public Builder errors(List errors) { - this.errors = Optional.ofNullable(errors); - return this; - } - - public CancelTransferOrderResponse build() { - return new CancelTransferOrderResponse(transferOrder, errors, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/CardPaymentDetails.java b/src/main/java/com/squareup/square/types/CardPaymentDetails.java index 83862888..86a58efd 100644 --- a/src/main/java/com/squareup/square/types/CardPaymentDetails.java +++ b/src/main/java/com/squareup/square/types/CardPaymentDetails.java @@ -5,12 +5,15 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonSetter; import com.fasterxml.jackson.annotation.Nulls; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.squareup.square.core.Nullable; +import com.squareup.square.core.NullableNonemptyFilter; import com.squareup.square.core.ObjectMappers; import java.util.HashMap; import java.util.List; @@ -96,8 +99,11 @@ private CardPaymentDetails( * @return The card payment's current state. The state can be AUTHORIZED, CAPTURED, VOIDED, or * FAILED. */ - @JsonProperty("status") + @JsonIgnore public Optional getStatus() { + if (status == null) { + return Optional.empty(); + } return status; } @@ -113,8 +119,11 @@ public Optional getCard() { * @return The method used to enter the card's details for the payment. The method can be * KEYED, SWIPED, EMV, ON_FILE, or CONTACTLESS. */ - @JsonProperty("entry_method") + @JsonIgnore public Optional getEntryMethod() { + if (entryMethod == null) { + return Optional.empty(); + } return entryMethod; } @@ -122,8 +131,11 @@ public Optional getEntryMethod() { * @return The status code returned from the Card Verification Value (CVV) check. The code can be * CVV_ACCEPTED, CVV_REJECTED, or CVV_NOT_CHECKED. */ - @JsonProperty("cvv_status") + @JsonIgnore public Optional getCvvStatus() { + if (cvvStatus == null) { + return Optional.empty(); + } return cvvStatus; } @@ -131,8 +143,11 @@ public Optional getCvvStatus() { * @return The status code returned from the Address Verification System (AVS) check. The code can be * AVS_ACCEPTED, AVS_REJECTED, or AVS_NOT_CHECKED. */ - @JsonProperty("avs_status") + @JsonIgnore public Optional getAvsStatus() { + if (avsStatus == null) { + return Optional.empty(); + } return avsStatus; } @@ -140,32 +155,44 @@ public Optional getAvsStatus() { * @return The status code returned by the card issuer that describes the payment's * authorization status. */ - @JsonProperty("auth_result_code") + @JsonIgnore public Optional getAuthResultCode() { + if (authResultCode == null) { + return Optional.empty(); + } return authResultCode; } /** * @return For EMV payments, the application ID identifies the EMV application used for the payment. */ - @JsonProperty("application_identifier") + @JsonIgnore public Optional getApplicationIdentifier() { + if (applicationIdentifier == null) { + return Optional.empty(); + } return applicationIdentifier; } /** * @return For EMV payments, the human-readable name of the EMV application used for the payment. */ - @JsonProperty("application_name") + @JsonIgnore public Optional getApplicationName() { + if (applicationName == null) { + return Optional.empty(); + } return applicationName; } /** * @return For EMV payments, the cryptogram generated for the payment. */ - @JsonProperty("application_cryptogram") + @JsonIgnore public Optional getApplicationCryptogram() { + if (applicationCryptogram == null) { + return Optional.empty(); + } return applicationCryptogram; } @@ -173,8 +200,11 @@ public Optional getApplicationCryptogram() { * @return For EMV payments, the method used to verify the cardholder's identity. The method can be * PIN, SIGNATURE, PIN_AND_SIGNATURE, ON_DEVICE, or NONE. */ - @JsonProperty("verification_method") + @JsonIgnore public Optional getVerificationMethod() { + if (verificationMethod == null) { + return Optional.empty(); + } return verificationMethod; } @@ -182,8 +212,11 @@ public Optional getVerificationMethod() { * @return For EMV payments, the results of the cardholder verification. The result can be * SUCCESS, FAILURE, or UNKNOWN. */ - @JsonProperty("verification_results") + @JsonIgnore public Optional getVerificationResults() { + if (verificationResults == null) { + return Optional.empty(); + } return verificationResults; } @@ -192,8 +225,11 @@ public Optional getVerificationResults() { *

Note: The actual statement description varies and is likely to be truncated and appended with * additional information on a per issuer basis.

*/ - @JsonProperty("statement_description") + @JsonIgnore public Optional getStatementDescription() { + if (statementDescription == null) { + return Optional.empty(); + } return statementDescription; } @@ -218,16 +254,100 @@ public Optional getCardPaymentTimeline() { * @return Whether the card must be physically present for the payment to * be refunded. If set to true, the card must be present. */ - @JsonProperty("refund_requires_card_presence") + @JsonIgnore public Optional getRefundRequiresCardPresence() { + if (refundRequiresCardPresence == null) { + return Optional.empty(); + } return refundRequiresCardPresence; } /** * @return Information about errors encountered during the request. */ - @JsonProperty("errors") + @JsonIgnore public Optional> getErrors() { + if (errors == null) { + return Optional.empty(); + } + return errors; + } + + @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) + @JsonProperty("status") + private Optional _getStatus() { + return status; + } + + @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) + @JsonProperty("entry_method") + private Optional _getEntryMethod() { + return entryMethod; + } + + @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) + @JsonProperty("cvv_status") + private Optional _getCvvStatus() { + return cvvStatus; + } + + @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) + @JsonProperty("avs_status") + private Optional _getAvsStatus() { + return avsStatus; + } + + @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) + @JsonProperty("auth_result_code") + private Optional _getAuthResultCode() { + return authResultCode; + } + + @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) + @JsonProperty("application_identifier") + private Optional _getApplicationIdentifier() { + return applicationIdentifier; + } + + @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) + @JsonProperty("application_name") + private Optional _getApplicationName() { + return applicationName; + } + + @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) + @JsonProperty("application_cryptogram") + private Optional _getApplicationCryptogram() { + return applicationCryptogram; + } + + @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) + @JsonProperty("verification_method") + private Optional _getVerificationMethod() { + return verificationMethod; + } + + @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) + @JsonProperty("verification_results") + private Optional _getVerificationResults() { + return verificationResults; + } + + @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) + @JsonProperty("statement_description") + private Optional _getStatementDescription() { + return statementDescription; + } + + @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) + @JsonProperty("refund_requires_card_presence") + private Optional _getRefundRequiresCardPresence() { + return refundRequiresCardPresence; + } + + @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) + @JsonProperty("errors") + private Optional> _getErrors() { return errors; } @@ -365,6 +485,17 @@ public Builder status(String status) { return this; } + public Builder status(Nullable status) { + if (status.isNull()) { + this.status = null; + } else if (status.isEmpty()) { + this.status = Optional.empty(); + } else { + this.status = Optional.of(status.get()); + } + return this; + } + /** *

The credit card's non-confidential details.

*/ @@ -394,6 +525,17 @@ public Builder entryMethod(String entryMethod) { return this; } + public Builder entryMethod(Nullable entryMethod) { + if (entryMethod.isNull()) { + this.entryMethod = null; + } else if (entryMethod.isEmpty()) { + this.entryMethod = Optional.empty(); + } else { + this.entryMethod = Optional.of(entryMethod.get()); + } + return this; + } + /** *

The status code returned from the Card Verification Value (CVV) check. The code can be * CVV_ACCEPTED, CVV_REJECTED, or CVV_NOT_CHECKED.

@@ -409,6 +551,17 @@ public Builder cvvStatus(String cvvStatus) { return this; } + public Builder cvvStatus(Nullable cvvStatus) { + if (cvvStatus.isNull()) { + this.cvvStatus = null; + } else if (cvvStatus.isEmpty()) { + this.cvvStatus = Optional.empty(); + } else { + this.cvvStatus = Optional.of(cvvStatus.get()); + } + return this; + } + /** *

The status code returned from the Address Verification System (AVS) check. The code can be * AVS_ACCEPTED, AVS_REJECTED, or AVS_NOT_CHECKED.

@@ -424,6 +577,17 @@ public Builder avsStatus(String avsStatus) { return this; } + public Builder avsStatus(Nullable avsStatus) { + if (avsStatus.isNull()) { + this.avsStatus = null; + } else if (avsStatus.isEmpty()) { + this.avsStatus = Optional.empty(); + } else { + this.avsStatus = Optional.of(avsStatus.get()); + } + return this; + } + /** *

The status code returned by the card issuer that describes the payment's * authorization status.

@@ -439,6 +603,17 @@ public Builder authResultCode(String authResultCode) { return this; } + public Builder authResultCode(Nullable authResultCode) { + if (authResultCode.isNull()) { + this.authResultCode = null; + } else if (authResultCode.isEmpty()) { + this.authResultCode = Optional.empty(); + } else { + this.authResultCode = Optional.of(authResultCode.get()); + } + return this; + } + /** *

For EMV payments, the application ID identifies the EMV application used for the payment.

*/ @@ -453,6 +628,17 @@ public Builder applicationIdentifier(String applicationIdentifier) { return this; } + public Builder applicationIdentifier(Nullable applicationIdentifier) { + if (applicationIdentifier.isNull()) { + this.applicationIdentifier = null; + } else if (applicationIdentifier.isEmpty()) { + this.applicationIdentifier = Optional.empty(); + } else { + this.applicationIdentifier = Optional.of(applicationIdentifier.get()); + } + return this; + } + /** *

For EMV payments, the human-readable name of the EMV application used for the payment.

*/ @@ -467,6 +653,17 @@ public Builder applicationName(String applicationName) { return this; } + public Builder applicationName(Nullable applicationName) { + if (applicationName.isNull()) { + this.applicationName = null; + } else if (applicationName.isEmpty()) { + this.applicationName = Optional.empty(); + } else { + this.applicationName = Optional.of(applicationName.get()); + } + return this; + } + /** *

For EMV payments, the cryptogram generated for the payment.

*/ @@ -481,6 +678,17 @@ public Builder applicationCryptogram(String applicationCryptogram) { return this; } + public Builder applicationCryptogram(Nullable applicationCryptogram) { + if (applicationCryptogram.isNull()) { + this.applicationCryptogram = null; + } else if (applicationCryptogram.isEmpty()) { + this.applicationCryptogram = Optional.empty(); + } else { + this.applicationCryptogram = Optional.of(applicationCryptogram.get()); + } + return this; + } + /** *

For EMV payments, the method used to verify the cardholder's identity. The method can be * PIN, SIGNATURE, PIN_AND_SIGNATURE, ON_DEVICE, or NONE.

@@ -496,6 +704,17 @@ public Builder verificationMethod(String verificationMethod) { return this; } + public Builder verificationMethod(Nullable verificationMethod) { + if (verificationMethod.isNull()) { + this.verificationMethod = null; + } else if (verificationMethod.isEmpty()) { + this.verificationMethod = Optional.empty(); + } else { + this.verificationMethod = Optional.of(verificationMethod.get()); + } + return this; + } + /** *

For EMV payments, the results of the cardholder verification. The result can be * SUCCESS, FAILURE, or UNKNOWN.

@@ -511,6 +730,17 @@ public Builder verificationResults(String verificationResults) { return this; } + public Builder verificationResults(Nullable verificationResults) { + if (verificationResults.isNull()) { + this.verificationResults = null; + } else if (verificationResults.isEmpty()) { + this.verificationResults = Optional.empty(); + } else { + this.verificationResults = Optional.of(verificationResults.get()); + } + return this; + } + /** *

The statement description sent to the card networks.

*

Note: The actual statement description varies and is likely to be truncated and appended with @@ -527,6 +757,17 @@ public Builder statementDescription(String statementDescription) { return this; } + public Builder statementDescription(Nullable statementDescription) { + if (statementDescription.isNull()) { + this.statementDescription = null; + } else if (statementDescription.isEmpty()) { + this.statementDescription = Optional.empty(); + } else { + this.statementDescription = Optional.of(statementDescription.get()); + } + return this; + } + /** *

Deprecated: Use Payment.device_details instead.

*

Details about the device that took the payment.

@@ -571,6 +812,17 @@ public Builder refundRequiresCardPresence(Boolean refundRequiresCardPresence) { return this; } + public Builder refundRequiresCardPresence(Nullable refundRequiresCardPresence) { + if (refundRequiresCardPresence.isNull()) { + this.refundRequiresCardPresence = null; + } else if (refundRequiresCardPresence.isEmpty()) { + this.refundRequiresCardPresence = Optional.empty(); + } else { + this.refundRequiresCardPresence = Optional.of(refundRequiresCardPresence.get()); + } + return this; + } + /** *

Information about errors encountered during the request.

*/ @@ -585,6 +837,17 @@ public Builder errors(List errors) { return this; } + public Builder errors(Nullable> errors) { + if (errors.isNull()) { + this.errors = null; + } else if (errors.isEmpty()) { + this.errors = Optional.empty(); + } else { + this.errors = Optional.of(errors.get()); + } + return this; + } + public CardPaymentDetails build() { return new CardPaymentDetails( status, diff --git a/src/main/java/com/squareup/square/types/CatalogCustomAttributeDefinition.java b/src/main/java/com/squareup/square/types/CatalogCustomAttributeDefinition.java index a6f1f2b1..1cf414a4 100644 --- a/src/main/java/com/squareup/square/types/CatalogCustomAttributeDefinition.java +++ b/src/main/java/com/squareup/square/types/CatalogCustomAttributeDefinition.java @@ -647,9 +647,7 @@ public _FinalStage sellerVisibility( */ @java.lang.Override public _FinalStage addAllAllowedObjectTypes(List allowedObjectTypes) { - if (allowedObjectTypes != null) { - this.allowedObjectTypes.addAll(allowedObjectTypes); - } + this.allowedObjectTypes.addAll(allowedObjectTypes); return this; } @@ -674,9 +672,7 @@ public _FinalStage addAllowedObjectTypes(CatalogObjectType allowedObjectTypes) { @JsonSetter(value = "allowed_object_types", nulls = Nulls.SKIP) public _FinalStage allowedObjectTypes(List allowedObjectTypes) { this.allowedObjectTypes.clear(); - if (allowedObjectTypes != null) { - this.allowedObjectTypes.addAll(allowedObjectTypes); - } + this.allowedObjectTypes.addAll(allowedObjectTypes); return this; } diff --git a/src/main/java/com/squareup/square/types/CatalogObjectBatch.java b/src/main/java/com/squareup/square/types/CatalogObjectBatch.java index 932980fa..dfdb2901 100644 --- a/src/main/java/com/squareup/square/types/CatalogObjectBatch.java +++ b/src/main/java/com/squareup/square/types/CatalogObjectBatch.java @@ -87,9 +87,7 @@ public Builder from(CatalogObjectBatch other) { @JsonSetter(value = "objects", nulls = Nulls.SKIP) public Builder objects(List objects) { this.objects.clear(); - if (objects != null) { - this.objects.addAll(objects); - } + this.objects.addAll(objects); return this; } @@ -99,9 +97,7 @@ public Builder addObjects(CatalogObject objects) { } public Builder addAllObjects(List objects) { - if (objects != null) { - this.objects.addAll(objects); - } + this.objects.addAll(objects); return this; } diff --git a/src/main/java/com/squareup/square/types/CatalogQueryItemsForModifierList.java b/src/main/java/com/squareup/square/types/CatalogQueryItemsForModifierList.java index 725f492f..b8e23249 100644 --- a/src/main/java/com/squareup/square/types/CatalogQueryItemsForModifierList.java +++ b/src/main/java/com/squareup/square/types/CatalogQueryItemsForModifierList.java @@ -87,9 +87,7 @@ public Builder from(CatalogQueryItemsForModifierList other) { @JsonSetter(value = "modifier_list_ids", nulls = Nulls.SKIP) public Builder modifierListIds(List modifierListIds) { this.modifierListIds.clear(); - if (modifierListIds != null) { - this.modifierListIds.addAll(modifierListIds); - } + this.modifierListIds.addAll(modifierListIds); return this; } @@ -99,9 +97,7 @@ public Builder addModifierListIds(String modifierListIds) { } public Builder addAllModifierListIds(List modifierListIds) { - if (modifierListIds != null) { - this.modifierListIds.addAll(modifierListIds); - } + this.modifierListIds.addAll(modifierListIds); return this; } diff --git a/src/main/java/com/squareup/square/types/CatalogQueryItemsForTax.java b/src/main/java/com/squareup/square/types/CatalogQueryItemsForTax.java index 0023fa4e..38f70b3a 100644 --- a/src/main/java/com/squareup/square/types/CatalogQueryItemsForTax.java +++ b/src/main/java/com/squareup/square/types/CatalogQueryItemsForTax.java @@ -87,9 +87,7 @@ public Builder from(CatalogQueryItemsForTax other) { @JsonSetter(value = "tax_ids", nulls = Nulls.SKIP) public Builder taxIds(List taxIds) { this.taxIds.clear(); - if (taxIds != null) { - this.taxIds.addAll(taxIds); - } + this.taxIds.addAll(taxIds); return this; } @@ -99,9 +97,7 @@ public Builder addTaxIds(String taxIds) { } public Builder addAllTaxIds(List taxIds) { - if (taxIds != null) { - this.taxIds.addAll(taxIds); - } + this.taxIds.addAll(taxIds); return this; } diff --git a/src/main/java/com/squareup/square/types/CatalogQuerySet.java b/src/main/java/com/squareup/square/types/CatalogQuerySet.java index ebf9d589..1234cab6 100644 --- a/src/main/java/com/squareup/square/types/CatalogQuerySet.java +++ b/src/main/java/com/squareup/square/types/CatalogQuerySet.java @@ -141,9 +141,7 @@ public _FinalStage attributeName(@NotNull String attributeName) { */ @java.lang.Override public _FinalStage addAllAttributeValues(List attributeValues) { - if (attributeValues != null) { - this.attributeValues.addAll(attributeValues); - } + this.attributeValues.addAll(attributeValues); return this; } @@ -166,9 +164,7 @@ public _FinalStage addAttributeValues(String attributeValues) { @JsonSetter(value = "attribute_values", nulls = Nulls.SKIP) public _FinalStage attributeValues(List attributeValues) { this.attributeValues.clear(); - if (attributeValues != null) { - this.attributeValues.addAll(attributeValues); - } + this.attributeValues.addAll(attributeValues); return this; } diff --git a/src/main/java/com/squareup/square/types/CatalogQueryText.java b/src/main/java/com/squareup/square/types/CatalogQueryText.java index 37cb61a8..4146fb5e 100644 --- a/src/main/java/com/squareup/square/types/CatalogQueryText.java +++ b/src/main/java/com/squareup/square/types/CatalogQueryText.java @@ -87,9 +87,7 @@ public Builder from(CatalogQueryText other) { @JsonSetter(value = "keywords", nulls = Nulls.SKIP) public Builder keywords(List keywords) { this.keywords.clear(); - if (keywords != null) { - this.keywords.addAll(keywords); - } + this.keywords.addAll(keywords); return this; } @@ -99,9 +97,7 @@ public Builder addKeywords(String keywords) { } public Builder addAllKeywords(List keywords) { - if (keywords != null) { - this.keywords.addAll(keywords); - } + this.keywords.addAll(keywords); return this; } diff --git a/src/main/java/com/squareup/square/types/CatalogSubscriptionPlanVariation.java b/src/main/java/com/squareup/square/types/CatalogSubscriptionPlanVariation.java index a1706694..d468aa0d 100644 --- a/src/main/java/com/squareup/square/types/CatalogSubscriptionPlanVariation.java +++ b/src/main/java/com/squareup/square/types/CatalogSubscriptionPlanVariation.java @@ -441,9 +441,7 @@ public _FinalStage subscriptionPlanId(Optional subscriptionPlanId) { */ @java.lang.Override public _FinalStage addAllPhases(List phases) { - if (phases != null) { - this.phases.addAll(phases); - } + this.phases.addAll(phases); return this; } @@ -464,9 +462,7 @@ public _FinalStage addPhases(SubscriptionPhase phases) { @JsonSetter(value = "phases", nulls = Nulls.SKIP) public _FinalStage phases(List phases) { this.phases.clear(); - if (phases != null) { - this.phases.addAll(phases); - } + this.phases.addAll(phases); return this; } diff --git a/src/main/java/com/squareup/square/types/Channel.java b/src/main/java/com/squareup/square/types/Channel.java deleted file mode 100644 index 2ab67bdf..00000000 --- a/src/main/java/com/squareup/square/types/Channel.java +++ /dev/null @@ -1,351 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.Nullable; -import com.squareup.square.core.NullableNonemptyFilter; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = Channel.Builder.class) -public final class Channel { - private final Optional id; - - private final Optional merchantId; - - private final Optional name; - - private final Optional version; - - private final Optional reference; - - private final Optional status; - - private final Optional createdAt; - - private final Optional updatedAt; - - private final Map additionalProperties; - - private Channel( - Optional id, - Optional merchantId, - Optional name, - Optional version, - Optional reference, - Optional status, - Optional createdAt, - Optional updatedAt, - Map additionalProperties) { - this.id = id; - this.merchantId = merchantId; - this.name = name; - this.version = version; - this.reference = reference; - this.status = status; - this.createdAt = createdAt; - this.updatedAt = updatedAt; - this.additionalProperties = additionalProperties; - } - - /** - * @return The channel's unique ID. - */ - @JsonProperty("id") - public Optional getId() { - return id; - } - - /** - * @return The unique ID of the merchant this channel belongs to. - */ - @JsonProperty("merchant_id") - public Optional getMerchantId() { - return merchantId; - } - - /** - * @return The name of the channel. - */ - @JsonIgnore - public Optional getName() { - if (name == null) { - return Optional.empty(); - } - return name; - } - - /** - * @return The version number which is incremented each time an update is made to the channel. - */ - @JsonProperty("version") - public Optional getVersion() { - return version; - } - - /** - * @return Represents an entity the channel is associated with. - */ - @JsonProperty("reference") - public Optional getReference() { - return reference; - } - - /** - * @return Status of the channel. - * See Status for possible values - */ - @JsonProperty("status") - public Optional getStatus() { - return status; - } - - /** - * @return The timestamp for when the channel was created, in RFC 3339 format (for example, "2016-09-04T23:59:33.123Z"). - * For more information, see Working with Dates. - */ - @JsonProperty("created_at") - public Optional getCreatedAt() { - return createdAt; - } - - /** - * @return The timestamp for when the channel was last updated, in RFC 3339 format (for example, "2016-09-04T23:59:33.123Z"). - * For more information, see Working with Dates. - */ - @JsonProperty("updated_at") - public Optional getUpdatedAt() { - return updatedAt; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("name") - private Optional _getName() { - return name; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof Channel && equalTo((Channel) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(Channel other) { - return id.equals(other.id) - && merchantId.equals(other.merchantId) - && name.equals(other.name) - && version.equals(other.version) - && reference.equals(other.reference) - && status.equals(other.status) - && createdAt.equals(other.createdAt) - && updatedAt.equals(other.updatedAt); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash( - this.id, - this.merchantId, - this.name, - this.version, - this.reference, - this.status, - this.createdAt, - this.updatedAt); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional id = Optional.empty(); - - private Optional merchantId = Optional.empty(); - - private Optional name = Optional.empty(); - - private Optional version = Optional.empty(); - - private Optional reference = Optional.empty(); - - private Optional status = Optional.empty(); - - private Optional createdAt = Optional.empty(); - - private Optional updatedAt = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(Channel other) { - id(other.getId()); - merchantId(other.getMerchantId()); - name(other.getName()); - version(other.getVersion()); - reference(other.getReference()); - status(other.getStatus()); - createdAt(other.getCreatedAt()); - updatedAt(other.getUpdatedAt()); - return this; - } - - /** - *

The channel's unique ID.

- */ - @JsonSetter(value = "id", nulls = Nulls.SKIP) - public Builder id(Optional id) { - this.id = id; - return this; - } - - public Builder id(String id) { - this.id = Optional.ofNullable(id); - return this; - } - - /** - *

The unique ID of the merchant this channel belongs to.

- */ - @JsonSetter(value = "merchant_id", nulls = Nulls.SKIP) - public Builder merchantId(Optional merchantId) { - this.merchantId = merchantId; - return this; - } - - public Builder merchantId(String merchantId) { - this.merchantId = Optional.ofNullable(merchantId); - return this; - } - - /** - *

The name of the channel.

- */ - @JsonSetter(value = "name", nulls = Nulls.SKIP) - public Builder name(Optional name) { - this.name = name; - return this; - } - - public Builder name(String name) { - this.name = Optional.ofNullable(name); - return this; - } - - public Builder name(Nullable name) { - if (name.isNull()) { - this.name = null; - } else if (name.isEmpty()) { - this.name = Optional.empty(); - } else { - this.name = Optional.of(name.get()); - } - return this; - } - - /** - *

The version number which is incremented each time an update is made to the channel.

- */ - @JsonSetter(value = "version", nulls = Nulls.SKIP) - public Builder version(Optional version) { - this.version = version; - return this; - } - - public Builder version(Integer version) { - this.version = Optional.ofNullable(version); - return this; - } - - /** - *

Represents an entity the channel is associated with.

- */ - @JsonSetter(value = "reference", nulls = Nulls.SKIP) - public Builder reference(Optional reference) { - this.reference = reference; - return this; - } - - public Builder reference(Reference reference) { - this.reference = Optional.ofNullable(reference); - return this; - } - - /** - *

Status of the channel. - * See Status for possible values

- */ - @JsonSetter(value = "status", nulls = Nulls.SKIP) - public Builder status(Optional status) { - this.status = status; - return this; - } - - public Builder status(ChannelStatus status) { - this.status = Optional.ofNullable(status); - return this; - } - - /** - *

The timestamp for when the channel was created, in RFC 3339 format (for example, "2016-09-04T23:59:33.123Z"). - * For more information, see Working with Dates.

- */ - @JsonSetter(value = "created_at", nulls = Nulls.SKIP) - public Builder createdAt(Optional createdAt) { - this.createdAt = createdAt; - return this; - } - - public Builder createdAt(String createdAt) { - this.createdAt = Optional.ofNullable(createdAt); - return this; - } - - /** - *

The timestamp for when the channel was last updated, in RFC 3339 format (for example, "2016-09-04T23:59:33.123Z"). - * For more information, see Working with Dates.

- */ - @JsonSetter(value = "updated_at", nulls = Nulls.SKIP) - public Builder updatedAt(Optional updatedAt) { - this.updatedAt = updatedAt; - return this; - } - - public Builder updatedAt(String updatedAt) { - this.updatedAt = Optional.ofNullable(updatedAt); - return this; - } - - public Channel build() { - return new Channel( - id, merchantId, name, version, reference, status, createdAt, updatedAt, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/ChannelStatus.java b/src/main/java/com/squareup/square/types/ChannelStatus.java deleted file mode 100644 index 666cc610..00000000 --- a/src/main/java/com/squareup/square/types/ChannelStatus.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -public final class ChannelStatus { - public static final ChannelStatus ACTIVE = new ChannelStatus(Value.ACTIVE, "ACTIVE"); - - public static final ChannelStatus INACTIVE = new ChannelStatus(Value.INACTIVE, "INACTIVE"); - - private final Value value; - - private final String string; - - ChannelStatus(Value value, String string) { - this.value = value; - this.string = string; - } - - public Value getEnumValue() { - return value; - } - - @java.lang.Override - @JsonValue - public String toString() { - return this.string; - } - - @java.lang.Override - public boolean equals(Object other) { - return (this == other) - || (other instanceof ChannelStatus && this.string.equals(((ChannelStatus) other).string)); - } - - @java.lang.Override - public int hashCode() { - return this.string.hashCode(); - } - - public T visit(Visitor visitor) { - switch (value) { - case ACTIVE: - return visitor.visitActive(); - case INACTIVE: - return visitor.visitInactive(); - case UNKNOWN: - default: - return visitor.visitUnknown(string); - } - } - - @JsonCreator(mode = JsonCreator.Mode.DELEGATING) - public static ChannelStatus valueOf(String value) { - switch (value) { - case "ACTIVE": - return ACTIVE; - case "INACTIVE": - return INACTIVE; - default: - return new ChannelStatus(Value.UNKNOWN, value); - } - } - - public enum Value { - ACTIVE, - - INACTIVE, - - UNKNOWN - } - - public interface Visitor { - T visitActive(); - - T visitInactive(); - - T visitUnknown(String unknownType); - } -} diff --git a/src/main/java/com/squareup/square/types/CreateSubscriptionRequest.java b/src/main/java/com/squareup/square/types/CreateSubscriptionRequest.java index edadeb36..10e5e634 100644 --- a/src/main/java/com/squareup/square/types/CreateSubscriptionRequest.java +++ b/src/main/java/com/squareup/square/types/CreateSubscriptionRequest.java @@ -131,7 +131,7 @@ public Optional getStartDate() { * If the cancellation date is earlier than the end date of a subscription cycle, the subscription stops * at the canceled date and the subscriber is sent a prorated invoice at the beginning of the canceled cycle.

*

When the subscription plan of the newly created subscription has a fixed number of cycles and the canceled_date - * occurs before the subscription plan completes, the specified canceled_date sets the date when the subscription + * occurs before the subscription plan expires, the specified canceled_date sets the date when the subscription * stops through the end of the last cycle.

*/ @JsonProperty("canceled_date") @@ -308,7 +308,7 @@ public interface _FinalStage { * If the cancellation date is earlier than the end date of a subscription cycle, the subscription stops * at the canceled date and the subscriber is sent a prorated invoice at the beginning of the canceled cycle.

*

When the subscription plan of the newly created subscription has a fixed number of cycles and the canceled_date - * occurs before the subscription plan completes, the specified canceled_date sets the date when the subscription + * occurs before the subscription plan expires, the specified canceled_date sets the date when the subscription * stops through the end of the last cycle.

*/ _FinalStage canceledDate(Optional canceledDate); @@ -613,7 +613,7 @@ public _FinalStage taxPercentage(Optional taxPercentage) { * If the cancellation date is earlier than the end date of a subscription cycle, the subscription stops * at the canceled date and the subscriber is sent a prorated invoice at the beginning of the canceled cycle.

*

When the subscription plan of the newly created subscription has a fixed number of cycles and the canceled_date - * occurs before the subscription plan completes, the specified canceled_date sets the date when the subscription + * occurs before the subscription plan expires, the specified canceled_date sets the date when the subscription * stops through the end of the last cycle.

* @return Reference to {@code this} so that method calls can be chained together. */ @@ -629,7 +629,7 @@ public _FinalStage canceledDate(String canceledDate) { * If the cancellation date is earlier than the end date of a subscription cycle, the subscription stops * at the canceled date and the subscriber is sent a prorated invoice at the beginning of the canceled cycle.

*

When the subscription plan of the newly created subscription has a fixed number of cycles and the canceled_date - * occurs before the subscription plan completes, the specified canceled_date sets the date when the subscription + * occurs before the subscription plan expires, the specified canceled_date sets the date when the subscription * stops through the end of the last cycle.

*/ @java.lang.Override diff --git a/src/main/java/com/squareup/square/types/CreateTransferOrderData.java b/src/main/java/com/squareup/square/types/CreateTransferOrderData.java deleted file mode 100644 index 55cdeca1..00000000 --- a/src/main/java/com/squareup/square/types/CreateTransferOrderData.java +++ /dev/null @@ -1,535 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.Nullable; -import com.squareup.square.core.NullableNonemptyFilter; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import org.jetbrains.annotations.NotNull; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = CreateTransferOrderData.Builder.class) -public final class CreateTransferOrderData { - private final String sourceLocationId; - - private final String destinationLocationId; - - private final Optional expectedAt; - - private final Optional notes; - - private final Optional trackingNumber; - - private final Optional createdByTeamMemberId; - - private final Optional> lineItems; - - private final Map additionalProperties; - - private CreateTransferOrderData( - String sourceLocationId, - String destinationLocationId, - Optional expectedAt, - Optional notes, - Optional trackingNumber, - Optional createdByTeamMemberId, - Optional> lineItems, - Map additionalProperties) { - this.sourceLocationId = sourceLocationId; - this.destinationLocationId = destinationLocationId; - this.expectedAt = expectedAt; - this.notes = notes; - this.trackingNumber = trackingNumber; - this.createdByTeamMemberId = createdByTeamMemberId; - this.lineItems = lineItems; - this.additionalProperties = additionalProperties; - } - - /** - * @return The source Location that will send the items. Must be an active location - * in your Square account with sufficient inventory of the requested items. - */ - @JsonProperty("source_location_id") - public String getSourceLocationId() { - return sourceLocationId; - } - - /** - * @return The destination Location that will receive the items. Must be an active location - * in your Square account - */ - @JsonProperty("destination_location_id") - public String getDestinationLocationId() { - return destinationLocationId; - } - - /** - * @return Expected transfer date in RFC 3339 format (e.g. "2023-10-01T12:00:00Z"). - */ - @JsonIgnore - public Optional getExpectedAt() { - if (expectedAt == null) { - return Optional.empty(); - } - return expectedAt; - } - - /** - * @return Optional notes about the transfer - */ - @JsonIgnore - public Optional getNotes() { - if (notes == null) { - return Optional.empty(); - } - return notes; - } - - /** - * @return Optional shipment tracking number - */ - @JsonIgnore - public Optional getTrackingNumber() { - if (trackingNumber == null) { - return Optional.empty(); - } - return trackingNumber; - } - - /** - * @return ID of the TeamMember creating this transfer order. Used for tracking - * and auditing purposes. - */ - @JsonIgnore - public Optional getCreatedByTeamMemberId() { - if (createdByTeamMemberId == null) { - return Optional.empty(); - } - return createdByTeamMemberId; - } - - /** - * @return List of CatalogItemVariations to transfer, including quantities - */ - @JsonIgnore - public Optional> getLineItems() { - if (lineItems == null) { - return Optional.empty(); - } - return lineItems; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("expected_at") - private Optional _getExpectedAt() { - return expectedAt; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("notes") - private Optional _getNotes() { - return notes; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("tracking_number") - private Optional _getTrackingNumber() { - return trackingNumber; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("created_by_team_member_id") - private Optional _getCreatedByTeamMemberId() { - return createdByTeamMemberId; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("line_items") - private Optional> _getLineItems() { - return lineItems; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof CreateTransferOrderData && equalTo((CreateTransferOrderData) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(CreateTransferOrderData other) { - return sourceLocationId.equals(other.sourceLocationId) - && destinationLocationId.equals(other.destinationLocationId) - && expectedAt.equals(other.expectedAt) - && notes.equals(other.notes) - && trackingNumber.equals(other.trackingNumber) - && createdByTeamMemberId.equals(other.createdByTeamMemberId) - && lineItems.equals(other.lineItems); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash( - this.sourceLocationId, - this.destinationLocationId, - this.expectedAt, - this.notes, - this.trackingNumber, - this.createdByTeamMemberId, - this.lineItems); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static SourceLocationIdStage builder() { - return new Builder(); - } - - public interface SourceLocationIdStage { - /** - *

The source Location that will send the items. Must be an active location - * in your Square account with sufficient inventory of the requested items.

- */ - DestinationLocationIdStage sourceLocationId(@NotNull String sourceLocationId); - - Builder from(CreateTransferOrderData other); - } - - public interface DestinationLocationIdStage { - /** - *

The destination Location that will receive the items. Must be an active location - * in your Square account

- */ - _FinalStage destinationLocationId(@NotNull String destinationLocationId); - } - - public interface _FinalStage { - CreateTransferOrderData build(); - - /** - *

Expected transfer date in RFC 3339 format (e.g. "2023-10-01T12:00:00Z").

- */ - _FinalStage expectedAt(Optional expectedAt); - - _FinalStage expectedAt(String expectedAt); - - _FinalStage expectedAt(Nullable expectedAt); - - /** - *

Optional notes about the transfer

- */ - _FinalStage notes(Optional notes); - - _FinalStage notes(String notes); - - _FinalStage notes(Nullable notes); - - /** - *

Optional shipment tracking number

- */ - _FinalStage trackingNumber(Optional trackingNumber); - - _FinalStage trackingNumber(String trackingNumber); - - _FinalStage trackingNumber(Nullable trackingNumber); - - /** - *

ID of the TeamMember creating this transfer order. Used for tracking - * and auditing purposes.

- */ - _FinalStage createdByTeamMemberId(Optional createdByTeamMemberId); - - _FinalStage createdByTeamMemberId(String createdByTeamMemberId); - - _FinalStage createdByTeamMemberId(Nullable createdByTeamMemberId); - - /** - *

List of CatalogItemVariations to transfer, including quantities

- */ - _FinalStage lineItems(Optional> lineItems); - - _FinalStage lineItems(List lineItems); - - _FinalStage lineItems(Nullable> lineItems); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder implements SourceLocationIdStage, DestinationLocationIdStage, _FinalStage { - private String sourceLocationId; - - private String destinationLocationId; - - private Optional> lineItems = Optional.empty(); - - private Optional createdByTeamMemberId = Optional.empty(); - - private Optional trackingNumber = Optional.empty(); - - private Optional notes = Optional.empty(); - - private Optional expectedAt = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - @java.lang.Override - public Builder from(CreateTransferOrderData other) { - sourceLocationId(other.getSourceLocationId()); - destinationLocationId(other.getDestinationLocationId()); - expectedAt(other.getExpectedAt()); - notes(other.getNotes()); - trackingNumber(other.getTrackingNumber()); - createdByTeamMemberId(other.getCreatedByTeamMemberId()); - lineItems(other.getLineItems()); - return this; - } - - /** - *

The source Location that will send the items. Must be an active location - * in your Square account with sufficient inventory of the requested items.

- *

The source Location that will send the items. Must be an active location - * in your Square account with sufficient inventory of the requested items.

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - @JsonSetter("source_location_id") - public DestinationLocationIdStage sourceLocationId(@NotNull String sourceLocationId) { - this.sourceLocationId = Objects.requireNonNull(sourceLocationId, "sourceLocationId must not be null"); - return this; - } - - /** - *

The destination Location that will receive the items. Must be an active location - * in your Square account

- *

The destination Location that will receive the items. Must be an active location - * in your Square account

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - @JsonSetter("destination_location_id") - public _FinalStage destinationLocationId(@NotNull String destinationLocationId) { - this.destinationLocationId = - Objects.requireNonNull(destinationLocationId, "destinationLocationId must not be null"); - return this; - } - - /** - *

List of CatalogItemVariations to transfer, including quantities

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - public _FinalStage lineItems(Nullable> lineItems) { - if (lineItems.isNull()) { - this.lineItems = null; - } else if (lineItems.isEmpty()) { - this.lineItems = Optional.empty(); - } else { - this.lineItems = Optional.of(lineItems.get()); - } - return this; - } - - /** - *

List of CatalogItemVariations to transfer, including quantities

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - public _FinalStage lineItems(List lineItems) { - this.lineItems = Optional.ofNullable(lineItems); - return this; - } - - /** - *

List of CatalogItemVariations to transfer, including quantities

- */ - @java.lang.Override - @JsonSetter(value = "line_items", nulls = Nulls.SKIP) - public _FinalStage lineItems(Optional> lineItems) { - this.lineItems = lineItems; - return this; - } - - /** - *

ID of the TeamMember creating this transfer order. Used for tracking - * and auditing purposes.

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - public _FinalStage createdByTeamMemberId(Nullable createdByTeamMemberId) { - if (createdByTeamMemberId.isNull()) { - this.createdByTeamMemberId = null; - } else if (createdByTeamMemberId.isEmpty()) { - this.createdByTeamMemberId = Optional.empty(); - } else { - this.createdByTeamMemberId = Optional.of(createdByTeamMemberId.get()); - } - return this; - } - - /** - *

ID of the TeamMember creating this transfer order. Used for tracking - * and auditing purposes.

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - public _FinalStage createdByTeamMemberId(String createdByTeamMemberId) { - this.createdByTeamMemberId = Optional.ofNullable(createdByTeamMemberId); - return this; - } - - /** - *

ID of the TeamMember creating this transfer order. Used for tracking - * and auditing purposes.

- */ - @java.lang.Override - @JsonSetter(value = "created_by_team_member_id", nulls = Nulls.SKIP) - public _FinalStage createdByTeamMemberId(Optional createdByTeamMemberId) { - this.createdByTeamMemberId = createdByTeamMemberId; - return this; - } - - /** - *

Optional shipment tracking number

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - public _FinalStage trackingNumber(Nullable trackingNumber) { - if (trackingNumber.isNull()) { - this.trackingNumber = null; - } else if (trackingNumber.isEmpty()) { - this.trackingNumber = Optional.empty(); - } else { - this.trackingNumber = Optional.of(trackingNumber.get()); - } - return this; - } - - /** - *

Optional shipment tracking number

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - public _FinalStage trackingNumber(String trackingNumber) { - this.trackingNumber = Optional.ofNullable(trackingNumber); - return this; - } - - /** - *

Optional shipment tracking number

- */ - @java.lang.Override - @JsonSetter(value = "tracking_number", nulls = Nulls.SKIP) - public _FinalStage trackingNumber(Optional trackingNumber) { - this.trackingNumber = trackingNumber; - return this; - } - - /** - *

Optional notes about the transfer

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - public _FinalStage notes(Nullable notes) { - if (notes.isNull()) { - this.notes = null; - } else if (notes.isEmpty()) { - this.notes = Optional.empty(); - } else { - this.notes = Optional.of(notes.get()); - } - return this; - } - - /** - *

Optional notes about the transfer

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - public _FinalStage notes(String notes) { - this.notes = Optional.ofNullable(notes); - return this; - } - - /** - *

Optional notes about the transfer

- */ - @java.lang.Override - @JsonSetter(value = "notes", nulls = Nulls.SKIP) - public _FinalStage notes(Optional notes) { - this.notes = notes; - return this; - } - - /** - *

Expected transfer date in RFC 3339 format (e.g. "2023-10-01T12:00:00Z").

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - public _FinalStage expectedAt(Nullable expectedAt) { - if (expectedAt.isNull()) { - this.expectedAt = null; - } else if (expectedAt.isEmpty()) { - this.expectedAt = Optional.empty(); - } else { - this.expectedAt = Optional.of(expectedAt.get()); - } - return this; - } - - /** - *

Expected transfer date in RFC 3339 format (e.g. "2023-10-01T12:00:00Z").

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - public _FinalStage expectedAt(String expectedAt) { - this.expectedAt = Optional.ofNullable(expectedAt); - return this; - } - - /** - *

Expected transfer date in RFC 3339 format (e.g. "2023-10-01T12:00:00Z").

- */ - @java.lang.Override - @JsonSetter(value = "expected_at", nulls = Nulls.SKIP) - public _FinalStage expectedAt(Optional expectedAt) { - this.expectedAt = expectedAt; - return this; - } - - @java.lang.Override - public CreateTransferOrderData build() { - return new CreateTransferOrderData( - sourceLocationId, - destinationLocationId, - expectedAt, - notes, - trackingNumber, - createdByTeamMemberId, - lineItems, - additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/CreateTransferOrderLineData.java b/src/main/java/com/squareup/square/types/CreateTransferOrderLineData.java deleted file mode 100644 index ea827c0f..00000000 --- a/src/main/java/com/squareup/square/types/CreateTransferOrderLineData.java +++ /dev/null @@ -1,171 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import org.jetbrains.annotations.NotNull; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = CreateTransferOrderLineData.Builder.class) -public final class CreateTransferOrderLineData { - private final String itemVariationId; - - private final String quantityOrdered; - - private final Map additionalProperties; - - private CreateTransferOrderLineData( - String itemVariationId, String quantityOrdered, Map additionalProperties) { - this.itemVariationId = itemVariationId; - this.quantityOrdered = quantityOrdered; - this.additionalProperties = additionalProperties; - } - - /** - * @return ID of the CatalogItemVariation to transfer. Must reference a valid - * item variation in the Catalog. The item variation must be: - *
    - *
  • Active and available for sale
  • - *
  • Enabled for inventory tracking
  • - *
  • Available at the source location
  • - *
- */ - @JsonProperty("item_variation_id") - public String getItemVariationId() { - return itemVariationId; - } - - /** - * @return Total quantity ordered - */ - @JsonProperty("quantity_ordered") - public String getQuantityOrdered() { - return quantityOrdered; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof CreateTransferOrderLineData && equalTo((CreateTransferOrderLineData) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(CreateTransferOrderLineData other) { - return itemVariationId.equals(other.itemVariationId) && quantityOrdered.equals(other.quantityOrdered); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.itemVariationId, this.quantityOrdered); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static ItemVariationIdStage builder() { - return new Builder(); - } - - public interface ItemVariationIdStage { - /** - *

ID of the CatalogItemVariation to transfer. Must reference a valid - * item variation in the Catalog. The item variation must be:

- *
    - *
  • Active and available for sale
  • - *
  • Enabled for inventory tracking
  • - *
  • Available at the source location
  • - *
- */ - QuantityOrderedStage itemVariationId(@NotNull String itemVariationId); - - Builder from(CreateTransferOrderLineData other); - } - - public interface QuantityOrderedStage { - /** - *

Total quantity ordered

- */ - _FinalStage quantityOrdered(@NotNull String quantityOrdered); - } - - public interface _FinalStage { - CreateTransferOrderLineData build(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder implements ItemVariationIdStage, QuantityOrderedStage, _FinalStage { - private String itemVariationId; - - private String quantityOrdered; - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - @java.lang.Override - public Builder from(CreateTransferOrderLineData other) { - itemVariationId(other.getItemVariationId()); - quantityOrdered(other.getQuantityOrdered()); - return this; - } - - /** - *

ID of the CatalogItemVariation to transfer. Must reference a valid - * item variation in the Catalog. The item variation must be:

- *
    - *
  • Active and available for sale
  • - *
  • Enabled for inventory tracking
  • - *
  • Available at the source location
  • - *
- *

ID of the CatalogItemVariation to transfer. Must reference a valid - * item variation in the Catalog. The item variation must be:

- *
    - *
  • Active and available for sale
  • - *
  • Enabled for inventory tracking
  • - *
  • Available at the source location
  • - *
- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - @JsonSetter("item_variation_id") - public QuantityOrderedStage itemVariationId(@NotNull String itemVariationId) { - this.itemVariationId = Objects.requireNonNull(itemVariationId, "itemVariationId must not be null"); - return this; - } - - /** - *

Total quantity ordered

- *

Total quantity ordered

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - @JsonSetter("quantity_ordered") - public _FinalStage quantityOrdered(@NotNull String quantityOrdered) { - this.quantityOrdered = Objects.requireNonNull(quantityOrdered, "quantityOrdered must not be null"); - return this; - } - - @java.lang.Override - public CreateTransferOrderLineData build() { - return new CreateTransferOrderLineData(itemVariationId, quantityOrdered, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/CreateTransferOrderRequest.java b/src/main/java/com/squareup/square/types/CreateTransferOrderRequest.java deleted file mode 100644 index 0d480d52..00000000 --- a/src/main/java/com/squareup/square/types/CreateTransferOrderRequest.java +++ /dev/null @@ -1,151 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import org.jetbrains.annotations.NotNull; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = CreateTransferOrderRequest.Builder.class) -public final class CreateTransferOrderRequest { - private final String idempotencyKey; - - private final CreateTransferOrderData transferOrder; - - private final Map additionalProperties; - - private CreateTransferOrderRequest( - String idempotencyKey, CreateTransferOrderData transferOrder, Map additionalProperties) { - this.idempotencyKey = idempotencyKey; - this.transferOrder = transferOrder; - this.additionalProperties = additionalProperties; - } - - /** - * @return A unique string that identifies this CreateTransferOrder request. Keys can be - * any valid string but must be unique for every CreateTransferOrder request. - */ - @JsonProperty("idempotency_key") - public String getIdempotencyKey() { - return idempotencyKey; - } - - /** - * @return The transfer order to create - */ - @JsonProperty("transfer_order") - public CreateTransferOrderData getTransferOrder() { - return transferOrder; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof CreateTransferOrderRequest && equalTo((CreateTransferOrderRequest) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(CreateTransferOrderRequest other) { - return idempotencyKey.equals(other.idempotencyKey) && transferOrder.equals(other.transferOrder); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.idempotencyKey, this.transferOrder); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static IdempotencyKeyStage builder() { - return new Builder(); - } - - public interface IdempotencyKeyStage { - /** - *

A unique string that identifies this CreateTransferOrder request. Keys can be - * any valid string but must be unique for every CreateTransferOrder request.

- */ - TransferOrderStage idempotencyKey(@NotNull String idempotencyKey); - - Builder from(CreateTransferOrderRequest other); - } - - public interface TransferOrderStage { - /** - *

The transfer order to create

- */ - _FinalStage transferOrder(@NotNull CreateTransferOrderData transferOrder); - } - - public interface _FinalStage { - CreateTransferOrderRequest build(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder implements IdempotencyKeyStage, TransferOrderStage, _FinalStage { - private String idempotencyKey; - - private CreateTransferOrderData transferOrder; - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - @java.lang.Override - public Builder from(CreateTransferOrderRequest other) { - idempotencyKey(other.getIdempotencyKey()); - transferOrder(other.getTransferOrder()); - return this; - } - - /** - *

A unique string that identifies this CreateTransferOrder request. Keys can be - * any valid string but must be unique for every CreateTransferOrder request.

- *

A unique string that identifies this CreateTransferOrder request. Keys can be - * any valid string but must be unique for every CreateTransferOrder request.

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - @JsonSetter("idempotency_key") - public TransferOrderStage idempotencyKey(@NotNull String idempotencyKey) { - this.idempotencyKey = Objects.requireNonNull(idempotencyKey, "idempotencyKey must not be null"); - return this; - } - - /** - *

The transfer order to create

- *

The transfer order to create

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - @JsonSetter("transfer_order") - public _FinalStage transferOrder(@NotNull CreateTransferOrderData transferOrder) { - this.transferOrder = Objects.requireNonNull(transferOrder, "transferOrder must not be null"); - return this; - } - - @java.lang.Override - public CreateTransferOrderRequest build() { - return new CreateTransferOrderRequest(idempotencyKey, transferOrder, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/CreateTransferOrderResponse.java b/src/main/java/com/squareup/square/types/CreateTransferOrderResponse.java deleted file mode 100644 index 3702e395..00000000 --- a/src/main/java/com/squareup/square/types/CreateTransferOrderResponse.java +++ /dev/null @@ -1,133 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = CreateTransferOrderResponse.Builder.class) -public final class CreateTransferOrderResponse { - private final Optional transferOrder; - - private final Optional> errors; - - private final Map additionalProperties; - - private CreateTransferOrderResponse( - Optional transferOrder, - Optional> errors, - Map additionalProperties) { - this.transferOrder = transferOrder; - this.errors = errors; - this.additionalProperties = additionalProperties; - } - - /** - * @return The created transfer order - */ - @JsonProperty("transfer_order") - public Optional getTransferOrder() { - return transferOrder; - } - - /** - * @return Any errors that occurred during the request - */ - @JsonProperty("errors") - public Optional> getErrors() { - return errors; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof CreateTransferOrderResponse && equalTo((CreateTransferOrderResponse) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(CreateTransferOrderResponse other) { - return transferOrder.equals(other.transferOrder) && errors.equals(other.errors); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.transferOrder, this.errors); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional transferOrder = Optional.empty(); - - private Optional> errors = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(CreateTransferOrderResponse other) { - transferOrder(other.getTransferOrder()); - errors(other.getErrors()); - return this; - } - - /** - *

The created transfer order

- */ - @JsonSetter(value = "transfer_order", nulls = Nulls.SKIP) - public Builder transferOrder(Optional transferOrder) { - this.transferOrder = transferOrder; - return this; - } - - public Builder transferOrder(TransferOrder transferOrder) { - this.transferOrder = Optional.ofNullable(transferOrder); - return this; - } - - /** - *

Any errors that occurred during the request

- */ - @JsonSetter(value = "errors", nulls = Nulls.SKIP) - public Builder errors(Optional> errors) { - this.errors = errors; - return this; - } - - public Builder errors(List errors) { - this.errors = Optional.ofNullable(errors); - return this; - } - - public CreateTransferOrderResponse build() { - return new CreateTransferOrderResponse(transferOrder, errors, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/DeleteTransferOrderResponse.java b/src/main/java/com/squareup/square/types/DeleteTransferOrderResponse.java deleted file mode 100644 index 27d9b9a0..00000000 --- a/src/main/java/com/squareup/square/types/DeleteTransferOrderResponse.java +++ /dev/null @@ -1,102 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = DeleteTransferOrderResponse.Builder.class) -public final class DeleteTransferOrderResponse { - private final Optional> errors; - - private final Map additionalProperties; - - private DeleteTransferOrderResponse(Optional> errors, Map additionalProperties) { - this.errors = errors; - this.additionalProperties = additionalProperties; - } - - /** - * @return Any errors that occurred during the request - */ - @JsonProperty("errors") - public Optional> getErrors() { - return errors; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof DeleteTransferOrderResponse && equalTo((DeleteTransferOrderResponse) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(DeleteTransferOrderResponse other) { - return errors.equals(other.errors); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.errors); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional> errors = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(DeleteTransferOrderResponse other) { - errors(other.getErrors()); - return this; - } - - /** - *

Any errors that occurred during the request

- */ - @JsonSetter(value = "errors", nulls = Nulls.SKIP) - public Builder errors(Optional> errors) { - this.errors = errors; - return this; - } - - public Builder errors(List errors) { - this.errors = Optional.ofNullable(errors); - return this; - } - - public DeleteTransferOrderResponse build() { - return new DeleteTransferOrderResponse(errors, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/DeleteTransferOrdersRequest.java b/src/main/java/com/squareup/square/types/DeleteTransferOrdersRequest.java deleted file mode 100644 index 1379695b..00000000 --- a/src/main/java/com/squareup/square/types/DeleteTransferOrdersRequest.java +++ /dev/null @@ -1,187 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.Nullable; -import com.squareup.square.core.NullableNonemptyFilter; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import org.jetbrains.annotations.NotNull; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = DeleteTransferOrdersRequest.Builder.class) -public final class DeleteTransferOrdersRequest { - private final String transferOrderId; - - private final Optional version; - - private final Map additionalProperties; - - private DeleteTransferOrdersRequest( - String transferOrderId, Optional version, Map additionalProperties) { - this.transferOrderId = transferOrderId; - this.version = version; - this.additionalProperties = additionalProperties; - } - - /** - * @return The ID of the transfer order to delete - */ - @JsonProperty("transfer_order_id") - public String getTransferOrderId() { - return transferOrderId; - } - - /** - * @return Version for optimistic concurrency - */ - @JsonIgnore - public Optional getVersion() { - if (version == null) { - return Optional.empty(); - } - return version; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("version") - private Optional _getVersion() { - return version; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof DeleteTransferOrdersRequest && equalTo((DeleteTransferOrdersRequest) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(DeleteTransferOrdersRequest other) { - return transferOrderId.equals(other.transferOrderId) && version.equals(other.version); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.transferOrderId, this.version); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static TransferOrderIdStage builder() { - return new Builder(); - } - - public interface TransferOrderIdStage { - /** - *

The ID of the transfer order to delete

- */ - _FinalStage transferOrderId(@NotNull String transferOrderId); - - Builder from(DeleteTransferOrdersRequest other); - } - - public interface _FinalStage { - DeleteTransferOrdersRequest build(); - - /** - *

Version for optimistic concurrency

- */ - _FinalStage version(Optional version); - - _FinalStage version(Long version); - - _FinalStage version(Nullable version); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder implements TransferOrderIdStage, _FinalStage { - private String transferOrderId; - - private Optional version = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - @java.lang.Override - public Builder from(DeleteTransferOrdersRequest other) { - transferOrderId(other.getTransferOrderId()); - version(other.getVersion()); - return this; - } - - /** - *

The ID of the transfer order to delete

- *

The ID of the transfer order to delete

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - @JsonSetter("transfer_order_id") - public _FinalStage transferOrderId(@NotNull String transferOrderId) { - this.transferOrderId = Objects.requireNonNull(transferOrderId, "transferOrderId must not be null"); - return this; - } - - /** - *

Version for optimistic concurrency

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - public _FinalStage version(Nullable version) { - if (version.isNull()) { - this.version = null; - } else if (version.isEmpty()) { - this.version = Optional.empty(); - } else { - this.version = Optional.of(version.get()); - } - return this; - } - - /** - *

Version for optimistic concurrency

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - public _FinalStage version(Long version) { - this.version = Optional.ofNullable(version); - return this; - } - - /** - *

Version for optimistic concurrency

- */ - @java.lang.Override - @JsonSetter(value = "version", nulls = Nulls.SKIP) - public _FinalStage version(Optional version) { - this.version = version; - return this; - } - - @java.lang.Override - public DeleteTransferOrdersRequest build() { - return new DeleteTransferOrdersRequest(transferOrderId, version, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/DeviceAttributes.java b/src/main/java/com/squareup/square/types/DeviceAttributes.java index 5f4e116d..e50f836d 100644 --- a/src/main/java/com/squareup/square/types/DeviceAttributes.java +++ b/src/main/java/com/squareup/square/types/DeviceAttributes.java @@ -24,7 +24,7 @@ @JsonInclude(JsonInclude.Include.NON_ABSENT) @JsonDeserialize(builder = DeviceAttributes.Builder.class) public final class DeviceAttributes { - private final DeviceAttributesDeviceType type; + private final String type; private final String manufacturer; @@ -43,7 +43,7 @@ public final class DeviceAttributes { private final Map additionalProperties; private DeviceAttributes( - DeviceAttributesDeviceType type, + String type, String manufacturer, Optional model, Optional name, @@ -68,7 +68,7 @@ private DeviceAttributes( * See DeviceType for possible values */ @JsonProperty("type") - public DeviceAttributesDeviceType getType() { + public String getType() { return type; } @@ -215,7 +215,7 @@ public interface TypeStage { *

The device type. * See DeviceType for possible values

*/ - ManufacturerStage type(@NotNull DeviceAttributesDeviceType type); + ManufacturerStage type(@NotNull String type); Builder from(DeviceAttributes other); } @@ -285,7 +285,7 @@ public interface _FinalStage { @JsonIgnoreProperties(ignoreUnknown = true) public static final class Builder implements TypeStage, ManufacturerStage, _FinalStage { - private DeviceAttributesDeviceType type; + private String type; private String manufacturer; @@ -328,7 +328,7 @@ public Builder from(DeviceAttributes other) { */ @java.lang.Override @JsonSetter("type") - public ManufacturerStage type(@NotNull DeviceAttributesDeviceType type) { + public ManufacturerStage type(@NotNull String type) { this.type = Objects.requireNonNull(type, "type must not be null"); return this; } diff --git a/src/main/java/com/squareup/square/types/DeviceAttributesDeviceType.java b/src/main/java/com/squareup/square/types/DeviceAttributesDeviceType.java deleted file mode 100644 index 24ccfdba..00000000 --- a/src/main/java/com/squareup/square/types/DeviceAttributesDeviceType.java +++ /dev/null @@ -1,86 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -public final class DeviceAttributesDeviceType { - public static final DeviceAttributesDeviceType TERMINAL = - new DeviceAttributesDeviceType(Value.TERMINAL, "TERMINAL"); - - public static final DeviceAttributesDeviceType HANDHELD = - new DeviceAttributesDeviceType(Value.HANDHELD, "HANDHELD"); - - private final Value value; - - private final String string; - - DeviceAttributesDeviceType(Value value, String string) { - this.value = value; - this.string = string; - } - - public Value getEnumValue() { - return value; - } - - @java.lang.Override - @JsonValue - public String toString() { - return this.string; - } - - @java.lang.Override - public boolean equals(Object other) { - return (this == other) - || (other instanceof DeviceAttributesDeviceType - && this.string.equals(((DeviceAttributesDeviceType) other).string)); - } - - @java.lang.Override - public int hashCode() { - return this.string.hashCode(); - } - - public T visit(Visitor visitor) { - switch (value) { - case TERMINAL: - return visitor.visitTerminal(); - case HANDHELD: - return visitor.visitHandheld(); - case UNKNOWN: - default: - return visitor.visitUnknown(string); - } - } - - @JsonCreator(mode = JsonCreator.Mode.DELEGATING) - public static DeviceAttributesDeviceType valueOf(String value) { - switch (value) { - case "TERMINAL": - return TERMINAL; - case "HANDHELD": - return HANDHELD; - default: - return new DeviceAttributesDeviceType(Value.UNKNOWN, value); - } - } - - public enum Value { - TERMINAL, - - HANDHELD, - - UNKNOWN - } - - public interface Visitor { - T visitTerminal(); - - T visitHandheld(); - - T visitUnknown(String unknownType); - } -} diff --git a/src/main/java/com/squareup/square/types/DeviceComponentDetailsEthernetDetails.java b/src/main/java/com/squareup/square/types/DeviceComponentDetailsEthernetDetails.java index 2077f3b3..0739cc90 100644 --- a/src/main/java/com/squareup/square/types/DeviceComponentDetailsEthernetDetails.java +++ b/src/main/java/com/squareup/square/types/DeviceComponentDetailsEthernetDetails.java @@ -27,18 +27,12 @@ public final class DeviceComponentDetailsEthernetDetails { private final Optional ipAddressV4; - private final Optional macAddress; - private final Map additionalProperties; private DeviceComponentDetailsEthernetDetails( - Optional active, - Optional ipAddressV4, - Optional macAddress, - Map additionalProperties) { + Optional active, Optional ipAddressV4, Map additionalProperties) { this.active = active; this.ipAddressV4 = ipAddressV4; - this.macAddress = macAddress; this.additionalProperties = additionalProperties; } @@ -64,17 +58,6 @@ public Optional getIpAddressV4() { return ipAddressV4; } - /** - * @return The mac address of the device in this network. - */ - @JsonIgnore - public Optional getMacAddress() { - if (macAddress == null) { - return Optional.empty(); - } - return macAddress; - } - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) @JsonProperty("active") private Optional _getActive() { @@ -87,12 +70,6 @@ private Optional _getIpAddressV4() { return ipAddressV4; } - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("mac_address") - private Optional _getMacAddress() { - return macAddress; - } - @java.lang.Override public boolean equals(Object other) { if (this == other) return true; @@ -106,14 +83,12 @@ public Map getAdditionalProperties() { } private boolean equalTo(DeviceComponentDetailsEthernetDetails other) { - return active.equals(other.active) - && ipAddressV4.equals(other.ipAddressV4) - && macAddress.equals(other.macAddress); + return active.equals(other.active) && ipAddressV4.equals(other.ipAddressV4); } @java.lang.Override public int hashCode() { - return Objects.hash(this.active, this.ipAddressV4, this.macAddress); + return Objects.hash(this.active, this.ipAddressV4); } @java.lang.Override @@ -131,8 +106,6 @@ public static final class Builder { private Optional ipAddressV4 = Optional.empty(); - private Optional macAddress = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); @@ -141,7 +114,6 @@ private Builder() {} public Builder from(DeviceComponentDetailsEthernetDetails other) { active(other.getActive()); ipAddressV4(other.getIpAddressV4()); - macAddress(other.getMacAddress()); return this; } @@ -195,33 +167,8 @@ public Builder ipAddressV4(Nullable ipAddressV4) { return this; } - /** - *

The mac address of the device in this network.

- */ - @JsonSetter(value = "mac_address", nulls = Nulls.SKIP) - public Builder macAddress(Optional macAddress) { - this.macAddress = macAddress; - return this; - } - - public Builder macAddress(String macAddress) { - this.macAddress = Optional.ofNullable(macAddress); - return this; - } - - public Builder macAddress(Nullable macAddress) { - if (macAddress.isNull()) { - this.macAddress = null; - } else if (macAddress.isEmpty()) { - this.macAddress = Optional.empty(); - } else { - this.macAddress = Optional.of(macAddress.get()); - } - return this; - } - public DeviceComponentDetailsEthernetDetails build() { - return new DeviceComponentDetailsEthernetDetails(active, ipAddressV4, macAddress, additionalProperties); + return new DeviceComponentDetailsEthernetDetails(active, ipAddressV4, additionalProperties); } } } diff --git a/src/main/java/com/squareup/square/types/DeviceComponentDetailsMeasurement.java b/src/main/java/com/squareup/square/types/DeviceComponentDetailsMeasurement.java index fdc3595d..e924053d 100644 --- a/src/main/java/com/squareup/square/types/DeviceComponentDetailsMeasurement.java +++ b/src/main/java/com/squareup/square/types/DeviceComponentDetailsMeasurement.java @@ -32,9 +32,6 @@ private DeviceComponentDetailsMeasurement(Optional value, Map getValue() { if (value == null) { @@ -92,9 +89,6 @@ public Builder from(DeviceComponentDetailsMeasurement other) { return this; } - /** - *

Value of measure.

- */ @JsonSetter(value = "value", nulls = Nulls.SKIP) public Builder value(Optional value) { this.value = value; diff --git a/src/main/java/com/squareup/square/types/DeviceComponentDetailsWiFiDetails.java b/src/main/java/com/squareup/square/types/DeviceComponentDetailsWiFiDetails.java index f3a19aa0..536dc575 100644 --- a/src/main/java/com/squareup/square/types/DeviceComponentDetailsWiFiDetails.java +++ b/src/main/java/com/squareup/square/types/DeviceComponentDetailsWiFiDetails.java @@ -33,8 +33,6 @@ public final class DeviceComponentDetailsWiFiDetails { private final Optional signalStrength; - private final Optional macAddress; - private final Map additionalProperties; private DeviceComponentDetailsWiFiDetails( @@ -43,14 +41,12 @@ private DeviceComponentDetailsWiFiDetails( Optional ipAddressV4, Optional secureConnection, Optional signalStrength, - Optional macAddress, Map additionalProperties) { this.active = active; this.ssid = ssid; this.ipAddressV4 = ipAddressV4; this.secureConnection = secureConnection; this.signalStrength = signalStrength; - this.macAddress = macAddress; this.additionalProperties = additionalProperties; } @@ -107,17 +103,6 @@ public Optional getSignalStrength() { return signalStrength; } - /** - * @return The mac address of the device in this network. - */ - @JsonIgnore - public Optional getMacAddress() { - if (macAddress == null) { - return Optional.empty(); - } - return macAddress; - } - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) @JsonProperty("active") private Optional _getActive() { @@ -142,12 +127,6 @@ private Optional _getSecureConnection() { return secureConnection; } - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("mac_address") - private Optional _getMacAddress() { - return macAddress; - } - @java.lang.Override public boolean equals(Object other) { if (this == other) return true; @@ -164,14 +143,12 @@ private boolean equalTo(DeviceComponentDetailsWiFiDetails other) { && ssid.equals(other.ssid) && ipAddressV4.equals(other.ipAddressV4) && secureConnection.equals(other.secureConnection) - && signalStrength.equals(other.signalStrength) - && macAddress.equals(other.macAddress); + && signalStrength.equals(other.signalStrength); } @java.lang.Override public int hashCode() { - return Objects.hash( - this.active, this.ssid, this.ipAddressV4, this.secureConnection, this.signalStrength, this.macAddress); + return Objects.hash(this.active, this.ssid, this.ipAddressV4, this.secureConnection, this.signalStrength); } @java.lang.Override @@ -195,8 +172,6 @@ public static final class Builder { private Optional signalStrength = Optional.empty(); - private Optional macAddress = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); @@ -208,7 +183,6 @@ public Builder from(DeviceComponentDetailsWiFiDetails other) { ipAddressV4(other.getIpAddressV4()); secureConnection(other.getSecureConnection()); signalStrength(other.getSignalStrength()); - macAddress(other.getMacAddress()); return this; } @@ -327,34 +301,9 @@ public Builder signalStrength(DeviceComponentDetailsMeasurement signalStrength) return this; } - /** - *

The mac address of the device in this network.

- */ - @JsonSetter(value = "mac_address", nulls = Nulls.SKIP) - public Builder macAddress(Optional macAddress) { - this.macAddress = macAddress; - return this; - } - - public Builder macAddress(String macAddress) { - this.macAddress = Optional.ofNullable(macAddress); - return this; - } - - public Builder macAddress(Nullable macAddress) { - if (macAddress.isNull()) { - this.macAddress = null; - } else if (macAddress.isEmpty()) { - this.macAddress = Optional.empty(); - } else { - this.macAddress = Optional.of(macAddress.get()); - } - return this; - } - public DeviceComponentDetailsWiFiDetails build() { return new DeviceComponentDetailsWiFiDetails( - active, ssid, ipAddressV4, secureConnection, signalStrength, macAddress, additionalProperties); + active, ssid, ipAddressV4, secureConnection, signalStrength, additionalProperties); } } } diff --git a/src/main/java/com/squareup/square/types/DeviceStatus.java b/src/main/java/com/squareup/square/types/DeviceStatus.java index 8447ad2f..887daaed 100644 --- a/src/main/java/com/squareup/square/types/DeviceStatus.java +++ b/src/main/java/com/squareup/square/types/DeviceStatus.java @@ -30,8 +30,7 @@ private DeviceStatus(Optional category, MapCategory for possible values + * @return See Category for possible values */ @JsonProperty("category") public Optional getCategory() { @@ -82,8 +81,7 @@ public Builder from(DeviceStatus other) { } /** - *

Category of the device status. - * See Category for possible values

+ *

See Category for possible values

*/ @JsonSetter(value = "category", nulls = Nulls.SKIP) public Builder category(Optional category) { diff --git a/src/main/java/com/squareup/square/types/GetChannelsRequest.java b/src/main/java/com/squareup/square/types/GetChannelsRequest.java deleted file mode 100644 index a537800e..00000000 --- a/src/main/java/com/squareup/square/types/GetChannelsRequest.java +++ /dev/null @@ -1,113 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import org.jetbrains.annotations.NotNull; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = GetChannelsRequest.Builder.class) -public final class GetChannelsRequest { - private final String channelId; - - private final Map additionalProperties; - - private GetChannelsRequest(String channelId, Map additionalProperties) { - this.channelId = channelId; - this.additionalProperties = additionalProperties; - } - - /** - * @return A channel id - */ - @JsonProperty("channel_id") - public String getChannelId() { - return channelId; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof GetChannelsRequest && equalTo((GetChannelsRequest) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(GetChannelsRequest other) { - return channelId.equals(other.channelId); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.channelId); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static ChannelIdStage builder() { - return new Builder(); - } - - public interface ChannelIdStage { - /** - *

A channel id

- */ - _FinalStage channelId(@NotNull String channelId); - - Builder from(GetChannelsRequest other); - } - - public interface _FinalStage { - GetChannelsRequest build(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder implements ChannelIdStage, _FinalStage { - private String channelId; - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - @java.lang.Override - public Builder from(GetChannelsRequest other) { - channelId(other.getChannelId()); - return this; - } - - /** - *

A channel id

- *

A channel id

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - @JsonSetter("channel_id") - public _FinalStage channelId(@NotNull String channelId) { - this.channelId = Objects.requireNonNull(channelId, "channelId must not be null"); - return this; - } - - @java.lang.Override - public GetChannelsRequest build() { - return new GetChannelsRequest(channelId, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/GetTransferOrdersRequest.java b/src/main/java/com/squareup/square/types/GetTransferOrdersRequest.java deleted file mode 100644 index aff67216..00000000 --- a/src/main/java/com/squareup/square/types/GetTransferOrdersRequest.java +++ /dev/null @@ -1,113 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import org.jetbrains.annotations.NotNull; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = GetTransferOrdersRequest.Builder.class) -public final class GetTransferOrdersRequest { - private final String transferOrderId; - - private final Map additionalProperties; - - private GetTransferOrdersRequest(String transferOrderId, Map additionalProperties) { - this.transferOrderId = transferOrderId; - this.additionalProperties = additionalProperties; - } - - /** - * @return The ID of the transfer order to retrieve - */ - @JsonProperty("transfer_order_id") - public String getTransferOrderId() { - return transferOrderId; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof GetTransferOrdersRequest && equalTo((GetTransferOrdersRequest) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(GetTransferOrdersRequest other) { - return transferOrderId.equals(other.transferOrderId); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.transferOrderId); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static TransferOrderIdStage builder() { - return new Builder(); - } - - public interface TransferOrderIdStage { - /** - *

The ID of the transfer order to retrieve

- */ - _FinalStage transferOrderId(@NotNull String transferOrderId); - - Builder from(GetTransferOrdersRequest other); - } - - public interface _FinalStage { - GetTransferOrdersRequest build(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder implements TransferOrderIdStage, _FinalStage { - private String transferOrderId; - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - @java.lang.Override - public Builder from(GetTransferOrdersRequest other) { - transferOrderId(other.getTransferOrderId()); - return this; - } - - /** - *

The ID of the transfer order to retrieve

- *

The ID of the transfer order to retrieve

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - @JsonSetter("transfer_order_id") - public _FinalStage transferOrderId(@NotNull String transferOrderId) { - this.transferOrderId = Objects.requireNonNull(transferOrderId, "transferOrderId must not be null"); - return this; - } - - @java.lang.Override - public GetTransferOrdersRequest build() { - return new GetTransferOrdersRequest(transferOrderId, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/InvoiceFilter.java b/src/main/java/com/squareup/square/types/InvoiceFilter.java index c87dff96..f1a89006 100644 --- a/src/main/java/com/squareup/square/types/InvoiceFilter.java +++ b/src/main/java/com/squareup/square/types/InvoiceFilter.java @@ -119,9 +119,7 @@ public Builder from(InvoiceFilter other) { @JsonSetter(value = "location_ids", nulls = Nulls.SKIP) public Builder locationIds(List locationIds) { this.locationIds.clear(); - if (locationIds != null) { - this.locationIds.addAll(locationIds); - } + this.locationIds.addAll(locationIds); return this; } @@ -131,9 +129,7 @@ public Builder addLocationIds(String locationIds) { } public Builder addAllLocationIds(List locationIds) { - if (locationIds != null) { - this.locationIds.addAll(locationIds); - } + this.locationIds.addAll(locationIds); return this; } diff --git a/src/main/java/com/squareup/square/types/ListChannelsRequest.java b/src/main/java/com/squareup/square/types/ListChannelsRequest.java deleted file mode 100644 index 784e4783..00000000 --- a/src/main/java/com/squareup/square/types/ListChannelsRequest.java +++ /dev/null @@ -1,328 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.Nullable; -import com.squareup.square.core.NullableNonemptyFilter; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = ListChannelsRequest.Builder.class) -public final class ListChannelsRequest { - private final Optional referenceType; - - private final Optional referenceId; - - private final Optional status; - - private final Optional cursor; - - private final Optional limit; - - private final Map additionalProperties; - - private ListChannelsRequest( - Optional referenceType, - Optional referenceId, - Optional status, - Optional cursor, - Optional limit, - Map additionalProperties) { - this.referenceType = referenceType; - this.referenceId = referenceId; - this.status = status; - this.cursor = cursor; - this.limit = limit; - this.additionalProperties = additionalProperties; - } - - /** - * @return Type of reference associated to channel - */ - @JsonIgnore - public Optional getReferenceType() { - if (referenceType == null) { - return Optional.empty(); - } - return referenceType; - } - - /** - * @return id of reference associated to channel - */ - @JsonIgnore - public Optional getReferenceId() { - if (referenceId == null) { - return Optional.empty(); - } - return referenceId; - } - - /** - * @return Status of channel - */ - @JsonIgnore - public Optional getStatus() { - if (status == null) { - return Optional.empty(); - } - return status; - } - - /** - * @return Cursor to fetch the next result - */ - @JsonIgnore - public Optional getCursor() { - if (cursor == null) { - return Optional.empty(); - } - return cursor; - } - - /** - * @return Maximum number of results to return. - * When not provided the returned results will be cap at 100 channels. - */ - @JsonIgnore - public Optional getLimit() { - if (limit == null) { - return Optional.empty(); - } - return limit; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("reference_type") - private Optional _getReferenceType() { - return referenceType; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("reference_id") - private Optional _getReferenceId() { - return referenceId; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("status") - private Optional _getStatus() { - return status; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("cursor") - private Optional _getCursor() { - return cursor; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("limit") - private Optional _getLimit() { - return limit; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof ListChannelsRequest && equalTo((ListChannelsRequest) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(ListChannelsRequest other) { - return referenceType.equals(other.referenceType) - && referenceId.equals(other.referenceId) - && status.equals(other.status) - && cursor.equals(other.cursor) - && limit.equals(other.limit); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.referenceType, this.referenceId, this.status, this.cursor, this.limit); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional referenceType = Optional.empty(); - - private Optional referenceId = Optional.empty(); - - private Optional status = Optional.empty(); - - private Optional cursor = Optional.empty(); - - private Optional limit = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(ListChannelsRequest other) { - referenceType(other.getReferenceType()); - referenceId(other.getReferenceId()); - status(other.getStatus()); - cursor(other.getCursor()); - limit(other.getLimit()); - return this; - } - - /** - *

Type of reference associated to channel

- */ - @JsonSetter(value = "reference_type", nulls = Nulls.SKIP) - public Builder referenceType(Optional referenceType) { - this.referenceType = referenceType; - return this; - } - - public Builder referenceType(ReferenceType referenceType) { - this.referenceType = Optional.ofNullable(referenceType); - return this; - } - - public Builder referenceType(Nullable referenceType) { - if (referenceType.isNull()) { - this.referenceType = null; - } else if (referenceType.isEmpty()) { - this.referenceType = Optional.empty(); - } else { - this.referenceType = Optional.of(referenceType.get()); - } - return this; - } - - /** - *

id of reference associated to channel

- */ - @JsonSetter(value = "reference_id", nulls = Nulls.SKIP) - public Builder referenceId(Optional referenceId) { - this.referenceId = referenceId; - return this; - } - - public Builder referenceId(String referenceId) { - this.referenceId = Optional.ofNullable(referenceId); - return this; - } - - public Builder referenceId(Nullable referenceId) { - if (referenceId.isNull()) { - this.referenceId = null; - } else if (referenceId.isEmpty()) { - this.referenceId = Optional.empty(); - } else { - this.referenceId = Optional.of(referenceId.get()); - } - return this; - } - - /** - *

Status of channel

- */ - @JsonSetter(value = "status", nulls = Nulls.SKIP) - public Builder status(Optional status) { - this.status = status; - return this; - } - - public Builder status(ChannelStatus status) { - this.status = Optional.ofNullable(status); - return this; - } - - public Builder status(Nullable status) { - if (status.isNull()) { - this.status = null; - } else if (status.isEmpty()) { - this.status = Optional.empty(); - } else { - this.status = Optional.of(status.get()); - } - return this; - } - - /** - *

Cursor to fetch the next result

- */ - @JsonSetter(value = "cursor", nulls = Nulls.SKIP) - public Builder cursor(Optional cursor) { - this.cursor = cursor; - return this; - } - - public Builder cursor(String cursor) { - this.cursor = Optional.ofNullable(cursor); - return this; - } - - public Builder cursor(Nullable cursor) { - if (cursor.isNull()) { - this.cursor = null; - } else if (cursor.isEmpty()) { - this.cursor = Optional.empty(); - } else { - this.cursor = Optional.of(cursor.get()); - } - return this; - } - - /** - *

Maximum number of results to return. - * When not provided the returned results will be cap at 100 channels.

- */ - @JsonSetter(value = "limit", nulls = Nulls.SKIP) - public Builder limit(Optional limit) { - this.limit = limit; - return this; - } - - public Builder limit(Integer limit) { - this.limit = Optional.ofNullable(limit); - return this; - } - - public Builder limit(Nullable limit) { - if (limit.isNull()) { - this.limit = null; - } else if (limit.isEmpty()) { - this.limit = Optional.empty(); - } else { - this.limit = Optional.of(limit.get()); - } - return this; - } - - public ListChannelsRequest build() { - return new ListChannelsRequest(referenceType, referenceId, status, cursor, limit, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/ListChannelsResponse.java b/src/main/java/com/squareup/square/types/ListChannelsResponse.java deleted file mode 100644 index 20e37573..00000000 --- a/src/main/java/com/squareup/square/types/ListChannelsResponse.java +++ /dev/null @@ -1,162 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = ListChannelsResponse.Builder.class) -public final class ListChannelsResponse { - private final Optional> errors; - - private final Optional> channels; - - private final Optional cursor; - - private final Map additionalProperties; - - private ListChannelsResponse( - Optional> errors, - Optional> channels, - Optional cursor, - Map additionalProperties) { - this.errors = errors; - this.channels = channels; - this.cursor = cursor; - this.additionalProperties = additionalProperties; - } - - /** - * @return Information about errors encountered during the request. - */ - @JsonProperty("errors") - public Optional> getErrors() { - return errors; - } - - /** - * @return List of requested Channel. - */ - @JsonProperty("channels") - public Optional> getChannels() { - return channels; - } - - /** - * @return The token required to retrieve the next page of results. - */ - @JsonProperty("cursor") - public Optional getCursor() { - return cursor; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof ListChannelsResponse && equalTo((ListChannelsResponse) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(ListChannelsResponse other) { - return errors.equals(other.errors) && channels.equals(other.channels) && cursor.equals(other.cursor); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.errors, this.channels, this.cursor); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional> errors = Optional.empty(); - - private Optional> channels = Optional.empty(); - - private Optional cursor = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(ListChannelsResponse other) { - errors(other.getErrors()); - channels(other.getChannels()); - cursor(other.getCursor()); - return this; - } - - /** - *

Information about errors encountered during the request.

- */ - @JsonSetter(value = "errors", nulls = Nulls.SKIP) - public Builder errors(Optional> errors) { - this.errors = errors; - return this; - } - - public Builder errors(List errors) { - this.errors = Optional.ofNullable(errors); - return this; - } - - /** - *

List of requested Channel.

- */ - @JsonSetter(value = "channels", nulls = Nulls.SKIP) - public Builder channels(Optional> channels) { - this.channels = channels; - return this; - } - - public Builder channels(List channels) { - this.channels = Optional.ofNullable(channels); - return this; - } - - /** - *

The token required to retrieve the next page of results.

- */ - @JsonSetter(value = "cursor", nulls = Nulls.SKIP) - public Builder cursor(Optional cursor) { - this.cursor = cursor; - return this; - } - - public Builder cursor(String cursor) { - this.cursor = Optional.ofNullable(cursor); - return this; - } - - public ListChannelsResponse build() { - return new ListChannelsResponse(errors, channels, cursor, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/ListOrderCustomAttributeDefinitionsResponse.java b/src/main/java/com/squareup/square/types/ListOrderCustomAttributeDefinitionsResponse.java index 358c5b45..73bbc630 100644 --- a/src/main/java/com/squareup/square/types/ListOrderCustomAttributeDefinitionsResponse.java +++ b/src/main/java/com/squareup/square/types/ListOrderCustomAttributeDefinitionsResponse.java @@ -125,9 +125,7 @@ public Builder from(ListOrderCustomAttributeDefinitionsResponse other) { @JsonSetter(value = "custom_attribute_definitions", nulls = Nulls.SKIP) public Builder customAttributeDefinitions(List customAttributeDefinitions) { this.customAttributeDefinitions.clear(); - if (customAttributeDefinitions != null) { - this.customAttributeDefinitions.addAll(customAttributeDefinitions); - } + this.customAttributeDefinitions.addAll(customAttributeDefinitions); return this; } @@ -137,9 +135,7 @@ public Builder addCustomAttributeDefinitions(CustomAttributeDefinition customAtt } public Builder addAllCustomAttributeDefinitions(List customAttributeDefinitions) { - if (customAttributeDefinitions != null) { - this.customAttributeDefinitions.addAll(customAttributeDefinitions); - } + this.customAttributeDefinitions.addAll(customAttributeDefinitions); return this; } diff --git a/src/main/java/com/squareup/square/types/LoyaltyAccount.java b/src/main/java/com/squareup/square/types/LoyaltyAccount.java index 68d6382f..c76297d9 100644 --- a/src/main/java/com/squareup/square/types/LoyaltyAccount.java +++ b/src/main/java/com/squareup/square/types/LoyaltyAccount.java @@ -119,10 +119,9 @@ public Optional getCustomerId() { /** * @return The timestamp when the buyer joined the loyalty program, in RFC 3339 format. This field is used to display the Enrolled On or Member Since date in first-party Square products. *

If this field is not set in a CreateLoyaltyAccount request, Square populates it after the buyer's first action on their account - * (when AccumulateLoyaltyPoints or CreateLoyaltyReward is called). In first-party flows, Square populates the field when the buyer agrees to the terms of service on Square Point of Sale.

- *

If this field is set in a CreateLoyaltyAccount request, it is meant to be used when there is a loyalty migration from another system and into Square. - * In that case, the timestamp can reflect when the buyer originally enrolled in the previous system. It may represent a current or past date, but cannot be set in the future. - * Note: Setting this field in this scenario does not, by itself, impact the first-party enrollment flow on Square Point of Sale.

+ * (when AccumulateLoyaltyPoints or CreateLoyaltyReward is called). In first-party flows, Square populates the field when the buyer agrees to the terms of service in Square Point of Sale.

+ *

This field is typically specified in a CreateLoyaltyAccount request when creating a loyalty account for a buyer who already interacted with their account. + * For example, you would set this field when migrating accounts from an external system. The timestamp in the request can represent a current or previous date and time, but it cannot be set for the future.

*/ @JsonIgnore public Optional getEnrolledAt() { @@ -283,10 +282,9 @@ public interface _FinalStage { /** *

The timestamp when the buyer joined the loyalty program, in RFC 3339 format. This field is used to display the Enrolled On or Member Since date in first-party Square products.

*

If this field is not set in a CreateLoyaltyAccount request, Square populates it after the buyer's first action on their account - * (when AccumulateLoyaltyPoints or CreateLoyaltyReward is called). In first-party flows, Square populates the field when the buyer agrees to the terms of service on Square Point of Sale.

- *

If this field is set in a CreateLoyaltyAccount request, it is meant to be used when there is a loyalty migration from another system and into Square. - * In that case, the timestamp can reflect when the buyer originally enrolled in the previous system. It may represent a current or past date, but cannot be set in the future. - * Note: Setting this field in this scenario does not, by itself, impact the first-party enrollment flow on Square Point of Sale.

+ * (when AccumulateLoyaltyPoints or CreateLoyaltyReward is called). In first-party flows, Square populates the field when the buyer agrees to the terms of service in Square Point of Sale.

+ *

This field is typically specified in a CreateLoyaltyAccount request when creating a loyalty account for a buyer who already interacted with their account. + * For example, you would set this field when migrating accounts from an external system. The timestamp in the request can represent a current or previous date and time, but it cannot be set for the future.

*/ _FinalStage enrolledAt(Optional enrolledAt); @@ -493,10 +491,9 @@ public _FinalStage createdAt(Optional createdAt) { /** *

The timestamp when the buyer joined the loyalty program, in RFC 3339 format. This field is used to display the Enrolled On or Member Since date in first-party Square products.

*

If this field is not set in a CreateLoyaltyAccount request, Square populates it after the buyer's first action on their account - * (when AccumulateLoyaltyPoints or CreateLoyaltyReward is called). In first-party flows, Square populates the field when the buyer agrees to the terms of service on Square Point of Sale.

- *

If this field is set in a CreateLoyaltyAccount request, it is meant to be used when there is a loyalty migration from another system and into Square. - * In that case, the timestamp can reflect when the buyer originally enrolled in the previous system. It may represent a current or past date, but cannot be set in the future. - * Note: Setting this field in this scenario does not, by itself, impact the first-party enrollment flow on Square Point of Sale.

+ * (when AccumulateLoyaltyPoints or CreateLoyaltyReward is called). In first-party flows, Square populates the field when the buyer agrees to the terms of service in Square Point of Sale.

+ *

This field is typically specified in a CreateLoyaltyAccount request when creating a loyalty account for a buyer who already interacted with their account. + * For example, you would set this field when migrating accounts from an external system. The timestamp in the request can represent a current or previous date and time, but it cannot be set for the future.

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override @@ -514,10 +511,9 @@ public _FinalStage enrolledAt(Nullable enrolledAt) { /** *

The timestamp when the buyer joined the loyalty program, in RFC 3339 format. This field is used to display the Enrolled On or Member Since date in first-party Square products.

*

If this field is not set in a CreateLoyaltyAccount request, Square populates it after the buyer's first action on their account - * (when AccumulateLoyaltyPoints or CreateLoyaltyReward is called). In first-party flows, Square populates the field when the buyer agrees to the terms of service on Square Point of Sale.

- *

If this field is set in a CreateLoyaltyAccount request, it is meant to be used when there is a loyalty migration from another system and into Square. - * In that case, the timestamp can reflect when the buyer originally enrolled in the previous system. It may represent a current or past date, but cannot be set in the future. - * Note: Setting this field in this scenario does not, by itself, impact the first-party enrollment flow on Square Point of Sale.

+ * (when AccumulateLoyaltyPoints or CreateLoyaltyReward is called). In first-party flows, Square populates the field when the buyer agrees to the terms of service in Square Point of Sale.

+ *

This field is typically specified in a CreateLoyaltyAccount request when creating a loyalty account for a buyer who already interacted with their account. + * For example, you would set this field when migrating accounts from an external system. The timestamp in the request can represent a current or previous date and time, but it cannot be set for the future.

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override @@ -529,10 +525,9 @@ public _FinalStage enrolledAt(String enrolledAt) { /** *

The timestamp when the buyer joined the loyalty program, in RFC 3339 format. This field is used to display the Enrolled On or Member Since date in first-party Square products.

*

If this field is not set in a CreateLoyaltyAccount request, Square populates it after the buyer's first action on their account - * (when AccumulateLoyaltyPoints or CreateLoyaltyReward is called). In first-party flows, Square populates the field when the buyer agrees to the terms of service on Square Point of Sale.

- *

If this field is set in a CreateLoyaltyAccount request, it is meant to be used when there is a loyalty migration from another system and into Square. - * In that case, the timestamp can reflect when the buyer originally enrolled in the previous system. It may represent a current or past date, but cannot be set in the future. - * Note: Setting this field in this scenario does not, by itself, impact the first-party enrollment flow on Square Point of Sale.

+ * (when AccumulateLoyaltyPoints or CreateLoyaltyReward is called). In first-party flows, Square populates the field when the buyer agrees to the terms of service in Square Point of Sale.

+ *

This field is typically specified in a CreateLoyaltyAccount request when creating a loyalty account for a buyer who already interacted with their account. + * For example, you would set this field when migrating accounts from an external system. The timestamp in the request can represent a current or previous date and time, but it cannot be set for the future.

*/ @java.lang.Override @JsonSetter(value = "enrolled_at", nulls = Nulls.SKIP) diff --git a/src/main/java/com/squareup/square/types/LoyaltyEventLocationFilter.java b/src/main/java/com/squareup/square/types/LoyaltyEventLocationFilter.java index b1b5aa5f..34478473 100644 --- a/src/main/java/com/squareup/square/types/LoyaltyEventLocationFilter.java +++ b/src/main/java/com/squareup/square/types/LoyaltyEventLocationFilter.java @@ -91,9 +91,7 @@ public Builder from(LoyaltyEventLocationFilter other) { @JsonSetter(value = "location_ids", nulls = Nulls.SKIP) public Builder locationIds(List locationIds) { this.locationIds.clear(); - if (locationIds != null) { - this.locationIds.addAll(locationIds); - } + this.locationIds.addAll(locationIds); return this; } @@ -103,9 +101,7 @@ public Builder addLocationIds(String locationIds) { } public Builder addAllLocationIds(List locationIds) { - if (locationIds != null) { - this.locationIds.addAll(locationIds); - } + this.locationIds.addAll(locationIds); return this; } diff --git a/src/main/java/com/squareup/square/types/LoyaltyEventTypeFilter.java b/src/main/java/com/squareup/square/types/LoyaltyEventTypeFilter.java index ebefd4b0..b903e2f0 100644 --- a/src/main/java/com/squareup/square/types/LoyaltyEventTypeFilter.java +++ b/src/main/java/com/squareup/square/types/LoyaltyEventTypeFilter.java @@ -93,9 +93,7 @@ public Builder from(LoyaltyEventTypeFilter other) { @JsonSetter(value = "types", nulls = Nulls.SKIP) public Builder types(List types) { this.types.clear(); - if (types != null) { - this.types.addAll(types); - } + this.types.addAll(types); return this; } @@ -105,9 +103,7 @@ public Builder addTypes(LoyaltyEventType types) { } public Builder addAllTypes(List types) { - if (types != null) { - this.types.addAll(types); - } + this.types.addAll(types); return this; } diff --git a/src/main/java/com/squareup/square/types/LoyaltyPromotionAvailableTimeData.java b/src/main/java/com/squareup/square/types/LoyaltyPromotionAvailableTimeData.java index d216ac83..753fc7c4 100644 --- a/src/main/java/com/squareup/square/types/LoyaltyPromotionAvailableTimeData.java +++ b/src/main/java/com/squareup/square/types/LoyaltyPromotionAvailableTimeData.java @@ -172,9 +172,7 @@ public Builder endDate(String endDate) { @JsonSetter(value = "time_periods", nulls = Nulls.SKIP) public Builder timePeriods(List timePeriods) { this.timePeriods.clear(); - if (timePeriods != null) { - this.timePeriods.addAll(timePeriods); - } + this.timePeriods.addAll(timePeriods); return this; } @@ -184,9 +182,7 @@ public Builder addTimePeriods(String timePeriods) { } public Builder addAllTimePeriods(List timePeriods) { - if (timePeriods != null) { - this.timePeriods.addAll(timePeriods); - } + this.timePeriods.addAll(timePeriods); return this; } diff --git a/src/main/java/com/squareup/square/types/Payment.java b/src/main/java/com/squareup/square/types/Payment.java index 23dc2e35..54c8ae21 100644 --- a/src/main/java/com/squareup/square/types/Payment.java +++ b/src/main/java/com/squareup/square/types/Payment.java @@ -243,8 +243,7 @@ public Optional getAmountMoney() { } /** - * @return The amount designated as a tip for the seller's staff. - *

Tips for external vendors such as a 3rd party delivery courier must be recorded using Order.service_charges.

+ * @return The amount designated as a tip. *

This amount is specified in the smallest denomination of the applicable currency (for example, * US dollar amounts are specified in cents). For more information, see * Working with Monetary Amounts.

@@ -978,8 +977,7 @@ public Builder amountMoney(Money amountMoney) { } /** - *

The amount designated as a tip for the seller's staff.

- *

Tips for external vendors such as a 3rd party delivery courier must be recorded using Order.service_charges.

+ *

The amount designated as a tip.

*

This amount is specified in the smallest denomination of the applicable currency (for example, * US dollar amounts are specified in cents). For more information, see * Working with Monetary Amounts.

diff --git a/src/main/java/com/squareup/square/types/ReceiveTransferOrderRequest.java b/src/main/java/com/squareup/square/types/ReceiveTransferOrderRequest.java deleted file mode 100644 index af5807be..00000000 --- a/src/main/java/com/squareup/square/types/ReceiveTransferOrderRequest.java +++ /dev/null @@ -1,231 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import org.jetbrains.annotations.NotNull; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = ReceiveTransferOrderRequest.Builder.class) -public final class ReceiveTransferOrderRequest { - private final String transferOrderId; - - private final String idempotencyKey; - - private final TransferOrderGoodsReceipt receipt; - - private final Optional version; - - private final Map additionalProperties; - - private ReceiveTransferOrderRequest( - String transferOrderId, - String idempotencyKey, - TransferOrderGoodsReceipt receipt, - Optional version, - Map additionalProperties) { - this.transferOrderId = transferOrderId; - this.idempotencyKey = idempotencyKey; - this.receipt = receipt; - this.version = version; - this.additionalProperties = additionalProperties; - } - - /** - * @return The ID of the transfer order to receive items for - */ - @JsonProperty("transfer_order_id") - public String getTransferOrderId() { - return transferOrderId; - } - - /** - * @return A unique key to make this request idempotent - */ - @JsonProperty("idempotency_key") - public String getIdempotencyKey() { - return idempotencyKey; - } - - /** - * @return The receipt details - */ - @JsonProperty("receipt") - public TransferOrderGoodsReceipt getReceipt() { - return receipt; - } - - /** - * @return Version for optimistic concurrency - */ - @JsonProperty("version") - public Optional getVersion() { - return version; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof ReceiveTransferOrderRequest && equalTo((ReceiveTransferOrderRequest) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(ReceiveTransferOrderRequest other) { - return transferOrderId.equals(other.transferOrderId) - && idempotencyKey.equals(other.idempotencyKey) - && receipt.equals(other.receipt) - && version.equals(other.version); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.transferOrderId, this.idempotencyKey, this.receipt, this.version); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static TransferOrderIdStage builder() { - return new Builder(); - } - - public interface TransferOrderIdStage { - /** - *

The ID of the transfer order to receive items for

- */ - IdempotencyKeyStage transferOrderId(@NotNull String transferOrderId); - - Builder from(ReceiveTransferOrderRequest other); - } - - public interface IdempotencyKeyStage { - /** - *

A unique key to make this request idempotent

- */ - ReceiptStage idempotencyKey(@NotNull String idempotencyKey); - } - - public interface ReceiptStage { - /** - *

The receipt details

- */ - _FinalStage receipt(@NotNull TransferOrderGoodsReceipt receipt); - } - - public interface _FinalStage { - ReceiveTransferOrderRequest build(); - - /** - *

Version for optimistic concurrency

- */ - _FinalStage version(Optional version); - - _FinalStage version(Long version); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder implements TransferOrderIdStage, IdempotencyKeyStage, ReceiptStage, _FinalStage { - private String transferOrderId; - - private String idempotencyKey; - - private TransferOrderGoodsReceipt receipt; - - private Optional version = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - @java.lang.Override - public Builder from(ReceiveTransferOrderRequest other) { - transferOrderId(other.getTransferOrderId()); - idempotencyKey(other.getIdempotencyKey()); - receipt(other.getReceipt()); - version(other.getVersion()); - return this; - } - - /** - *

The ID of the transfer order to receive items for

- *

The ID of the transfer order to receive items for

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - @JsonSetter("transfer_order_id") - public IdempotencyKeyStage transferOrderId(@NotNull String transferOrderId) { - this.transferOrderId = Objects.requireNonNull(transferOrderId, "transferOrderId must not be null"); - return this; - } - - /** - *

A unique key to make this request idempotent

- *

A unique key to make this request idempotent

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - @JsonSetter("idempotency_key") - public ReceiptStage idempotencyKey(@NotNull String idempotencyKey) { - this.idempotencyKey = Objects.requireNonNull(idempotencyKey, "idempotencyKey must not be null"); - return this; - } - - /** - *

The receipt details

- *

The receipt details

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - @JsonSetter("receipt") - public _FinalStage receipt(@NotNull TransferOrderGoodsReceipt receipt) { - this.receipt = Objects.requireNonNull(receipt, "receipt must not be null"); - return this; - } - - /** - *

Version for optimistic concurrency

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - public _FinalStage version(Long version) { - this.version = Optional.ofNullable(version); - return this; - } - - /** - *

Version for optimistic concurrency

- */ - @java.lang.Override - @JsonSetter(value = "version", nulls = Nulls.SKIP) - public _FinalStage version(Optional version) { - this.version = version; - return this; - } - - @java.lang.Override - public ReceiveTransferOrderRequest build() { - return new ReceiveTransferOrderRequest( - transferOrderId, idempotencyKey, receipt, version, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/ReceiveTransferOrderResponse.java b/src/main/java/com/squareup/square/types/ReceiveTransferOrderResponse.java deleted file mode 100644 index 096ef3a5..00000000 --- a/src/main/java/com/squareup/square/types/ReceiveTransferOrderResponse.java +++ /dev/null @@ -1,133 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = ReceiveTransferOrderResponse.Builder.class) -public final class ReceiveTransferOrderResponse { - private final Optional transferOrder; - - private final Optional> errors; - - private final Map additionalProperties; - - private ReceiveTransferOrderResponse( - Optional transferOrder, - Optional> errors, - Map additionalProperties) { - this.transferOrder = transferOrder; - this.errors = errors; - this.additionalProperties = additionalProperties; - } - - /** - * @return The updated transfer order - */ - @JsonProperty("transfer_order") - public Optional getTransferOrder() { - return transferOrder; - } - - /** - * @return Any errors that occurred during the request - */ - @JsonProperty("errors") - public Optional> getErrors() { - return errors; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof ReceiveTransferOrderResponse && equalTo((ReceiveTransferOrderResponse) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(ReceiveTransferOrderResponse other) { - return transferOrder.equals(other.transferOrder) && errors.equals(other.errors); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.transferOrder, this.errors); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional transferOrder = Optional.empty(); - - private Optional> errors = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(ReceiveTransferOrderResponse other) { - transferOrder(other.getTransferOrder()); - errors(other.getErrors()); - return this; - } - - /** - *

The updated transfer order

- */ - @JsonSetter(value = "transfer_order", nulls = Nulls.SKIP) - public Builder transferOrder(Optional transferOrder) { - this.transferOrder = transferOrder; - return this; - } - - public Builder transferOrder(TransferOrder transferOrder) { - this.transferOrder = Optional.ofNullable(transferOrder); - return this; - } - - /** - *

Any errors that occurred during the request

- */ - @JsonSetter(value = "errors", nulls = Nulls.SKIP) - public Builder errors(Optional> errors) { - this.errors = errors; - return this; - } - - public Builder errors(List errors) { - this.errors = Optional.ofNullable(errors); - return this; - } - - public ReceiveTransferOrderResponse build() { - return new ReceiveTransferOrderResponse(transferOrder, errors, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/Reference.java b/src/main/java/com/squareup/square/types/Reference.java deleted file mode 100644 index 5f33591c..00000000 --- a/src/main/java/com/squareup/square/types/Reference.java +++ /dev/null @@ -1,131 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = Reference.Builder.class) -public final class Reference { - private final Optional type; - - private final Optional id; - - private final Map additionalProperties; - - private Reference(Optional type, Optional id, Map additionalProperties) { - this.type = type; - this.id = id; - this.additionalProperties = additionalProperties; - } - - /** - * @return The type of entity a channel is associated with. - * See Type for possible values - */ - @JsonProperty("type") - public Optional getType() { - return type; - } - - /** - * @return The id of the entity a channel is associated with. - */ - @JsonProperty("id") - public Optional getId() { - return id; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof Reference && equalTo((Reference) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(Reference other) { - return type.equals(other.type) && id.equals(other.id); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.type, this.id); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional type = Optional.empty(); - - private Optional id = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(Reference other) { - type(other.getType()); - id(other.getId()); - return this; - } - - /** - *

The type of entity a channel is associated with. - * See Type for possible values

- */ - @JsonSetter(value = "type", nulls = Nulls.SKIP) - public Builder type(Optional type) { - this.type = type; - return this; - } - - public Builder type(ReferenceType type) { - this.type = Optional.ofNullable(type); - return this; - } - - /** - *

The id of the entity a channel is associated with.

- */ - @JsonSetter(value = "id", nulls = Nulls.SKIP) - public Builder id(Optional id) { - this.id = id; - return this; - } - - public Builder id(String id) { - this.id = Optional.ofNullable(id); - return this; - } - - public Reference build() { - return new Reference(type, id, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/ReferenceType.java b/src/main/java/com/squareup/square/types/ReferenceType.java deleted file mode 100644 index 37d61ac5..00000000 --- a/src/main/java/com/squareup/square/types/ReferenceType.java +++ /dev/null @@ -1,218 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -public final class ReferenceType { - public static final ReferenceType ONLINE_SITE = new ReferenceType(Value.ONLINE_SITE, "ONLINE_SITE"); - - public static final ReferenceType FIRST_PARTY_INTEGRATION = - new ReferenceType(Value.FIRST_PARTY_INTEGRATION, "FIRST_PARTY_INTEGRATION"); - - public static final ReferenceType INVOICE = new ReferenceType(Value.INVOICE, "INVOICE"); - - public static final ReferenceType GIFT_CARD = new ReferenceType(Value.GIFT_CARD, "GIFT_CARD"); - - public static final ReferenceType UNKNOWN_TYPE = new ReferenceType(Value.UNKNOWN_TYPE, "UNKNOWN_TYPE"); - - public static final ReferenceType CASH_LOCAL = new ReferenceType(Value.CASH_LOCAL, "CASH_LOCAL"); - - public static final ReferenceType LOCATION = new ReferenceType(Value.LOCATION, "LOCATION"); - - public static final ReferenceType ONLINE_CHECKOUT = new ReferenceType(Value.ONLINE_CHECKOUT, "ONLINE_CHECKOUT"); - - public static final ReferenceType GIFT_CARD_MARKETPLACE = - new ReferenceType(Value.GIFT_CARD_MARKETPLACE, "GIFT_CARD_MARKETPLACE"); - - public static final ReferenceType KIOSK = new ReferenceType(Value.KIOSK, "KIOSK"); - - public static final ReferenceType POINT_OF_SALE = new ReferenceType(Value.POINT_OF_SALE, "POINT_OF_SALE"); - - public static final ReferenceType RECURRING_SUBSCRIPTION = - new ReferenceType(Value.RECURRING_SUBSCRIPTION, "RECURRING_SUBSCRIPTION"); - - public static final ReferenceType ONLINE_BOOKING_FLOW = - new ReferenceType(Value.ONLINE_BOOKING_FLOW, "ONLINE_BOOKING_FLOW"); - - public static final ReferenceType OAUTH_APPLICATION = - new ReferenceType(Value.OAUTH_APPLICATION, "OAUTH_APPLICATION"); - - public static final ReferenceType SQUARE_ASSISTANT = new ReferenceType(Value.SQUARE_ASSISTANT, "SQUARE_ASSISTANT"); - - private final Value value; - - private final String string; - - ReferenceType(Value value, String string) { - this.value = value; - this.string = string; - } - - public Value getEnumValue() { - return value; - } - - @java.lang.Override - @JsonValue - public String toString() { - return this.string; - } - - @java.lang.Override - public boolean equals(Object other) { - return (this == other) - || (other instanceof ReferenceType && this.string.equals(((ReferenceType) other).string)); - } - - @java.lang.Override - public int hashCode() { - return this.string.hashCode(); - } - - public T visit(Visitor visitor) { - switch (value) { - case ONLINE_SITE: - return visitor.visitOnlineSite(); - case FIRST_PARTY_INTEGRATION: - return visitor.visitFirstPartyIntegration(); - case INVOICE: - return visitor.visitInvoice(); - case GIFT_CARD: - return visitor.visitGiftCard(); - case UNKNOWN_TYPE: - return visitor.visitUnknownType(); - case CASH_LOCAL: - return visitor.visitCashLocal(); - case LOCATION: - return visitor.visitLocation(); - case ONLINE_CHECKOUT: - return visitor.visitOnlineCheckout(); - case GIFT_CARD_MARKETPLACE: - return visitor.visitGiftCardMarketplace(); - case KIOSK: - return visitor.visitKiosk(); - case POINT_OF_SALE: - return visitor.visitPointOfSale(); - case RECURRING_SUBSCRIPTION: - return visitor.visitRecurringSubscription(); - case ONLINE_BOOKING_FLOW: - return visitor.visitOnlineBookingFlow(); - case OAUTH_APPLICATION: - return visitor.visitOauthApplication(); - case SQUARE_ASSISTANT: - return visitor.visitSquareAssistant(); - case UNKNOWN: - default: - return visitor.visitUnknown(string); - } - } - - @JsonCreator(mode = JsonCreator.Mode.DELEGATING) - public static ReferenceType valueOf(String value) { - switch (value) { - case "ONLINE_SITE": - return ONLINE_SITE; - case "FIRST_PARTY_INTEGRATION": - return FIRST_PARTY_INTEGRATION; - case "INVOICE": - return INVOICE; - case "GIFT_CARD": - return GIFT_CARD; - case "UNKNOWN_TYPE": - return UNKNOWN_TYPE; - case "CASH_LOCAL": - return CASH_LOCAL; - case "LOCATION": - return LOCATION; - case "ONLINE_CHECKOUT": - return ONLINE_CHECKOUT; - case "GIFT_CARD_MARKETPLACE": - return GIFT_CARD_MARKETPLACE; - case "KIOSK": - return KIOSK; - case "POINT_OF_SALE": - return POINT_OF_SALE; - case "RECURRING_SUBSCRIPTION": - return RECURRING_SUBSCRIPTION; - case "ONLINE_BOOKING_FLOW": - return ONLINE_BOOKING_FLOW; - case "OAUTH_APPLICATION": - return OAUTH_APPLICATION; - case "SQUARE_ASSISTANT": - return SQUARE_ASSISTANT; - default: - return new ReferenceType(Value.UNKNOWN, value); - } - } - - public enum Value { - UNKNOWN_TYPE, - - LOCATION, - - FIRST_PARTY_INTEGRATION, - - OAUTH_APPLICATION, - - ONLINE_SITE, - - ONLINE_CHECKOUT, - - INVOICE, - - GIFT_CARD, - - GIFT_CARD_MARKETPLACE, - - RECURRING_SUBSCRIPTION, - - ONLINE_BOOKING_FLOW, - - SQUARE_ASSISTANT, - - CASH_LOCAL, - - POINT_OF_SALE, - - KIOSK, - - UNKNOWN - } - - public interface Visitor { - T visitUnknownType(); - - T visitLocation(); - - T visitFirstPartyIntegration(); - - T visitOauthApplication(); - - T visitOnlineSite(); - - T visitOnlineCheckout(); - - T visitInvoice(); - - T visitGiftCard(); - - T visitGiftCardMarketplace(); - - T visitRecurringSubscription(); - - T visitOnlineBookingFlow(); - - T visitSquareAssistant(); - - T visitCashLocal(); - - T visitPointOfSale(); - - T visitKiosk(); - - T visitUnknown(String unknownType); - } -} diff --git a/src/main/java/com/squareup/square/types/RetrieveChannelResponse.java b/src/main/java/com/squareup/square/types/RetrieveChannelResponse.java deleted file mode 100644 index 3519b563..00000000 --- a/src/main/java/com/squareup/square/types/RetrieveChannelResponse.java +++ /dev/null @@ -1,131 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = RetrieveChannelResponse.Builder.class) -public final class RetrieveChannelResponse { - private final Optional> errors; - - private final Optional channel; - - private final Map additionalProperties; - - private RetrieveChannelResponse( - Optional> errors, Optional channel, Map additionalProperties) { - this.errors = errors; - this.channel = channel; - this.additionalProperties = additionalProperties; - } - - /** - * @return Information about errors encountered during the request. - */ - @JsonProperty("errors") - public Optional> getErrors() { - return errors; - } - - /** - * @return The requested Channel. - */ - @JsonProperty("channel") - public Optional getChannel() { - return channel; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof RetrieveChannelResponse && equalTo((RetrieveChannelResponse) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(RetrieveChannelResponse other) { - return errors.equals(other.errors) && channel.equals(other.channel); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.errors, this.channel); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional> errors = Optional.empty(); - - private Optional channel = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(RetrieveChannelResponse other) { - errors(other.getErrors()); - channel(other.getChannel()); - return this; - } - - /** - *

Information about errors encountered during the request.

- */ - @JsonSetter(value = "errors", nulls = Nulls.SKIP) - public Builder errors(Optional> errors) { - this.errors = errors; - return this; - } - - public Builder errors(List errors) { - this.errors = Optional.ofNullable(errors); - return this; - } - - /** - *

The requested Channel.

- */ - @JsonSetter(value = "channel", nulls = Nulls.SKIP) - public Builder channel(Optional channel) { - this.channel = channel; - return this; - } - - public Builder channel(Channel channel) { - this.channel = Optional.ofNullable(channel); - return this; - } - - public RetrieveChannelResponse build() { - return new RetrieveChannelResponse(errors, channel, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/RetrieveTransferOrderResponse.java b/src/main/java/com/squareup/square/types/RetrieveTransferOrderResponse.java deleted file mode 100644 index c01efa96..00000000 --- a/src/main/java/com/squareup/square/types/RetrieveTransferOrderResponse.java +++ /dev/null @@ -1,133 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = RetrieveTransferOrderResponse.Builder.class) -public final class RetrieveTransferOrderResponse { - private final Optional transferOrder; - - private final Optional> errors; - - private final Map additionalProperties; - - private RetrieveTransferOrderResponse( - Optional transferOrder, - Optional> errors, - Map additionalProperties) { - this.transferOrder = transferOrder; - this.errors = errors; - this.additionalProperties = additionalProperties; - } - - /** - * @return The requested transfer order - */ - @JsonProperty("transfer_order") - public Optional getTransferOrder() { - return transferOrder; - } - - /** - * @return Any errors that occurred during the request - */ - @JsonProperty("errors") - public Optional> getErrors() { - return errors; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof RetrieveTransferOrderResponse && equalTo((RetrieveTransferOrderResponse) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(RetrieveTransferOrderResponse other) { - return transferOrder.equals(other.transferOrder) && errors.equals(other.errors); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.transferOrder, this.errors); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional transferOrder = Optional.empty(); - - private Optional> errors = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(RetrieveTransferOrderResponse other) { - transferOrder(other.getTransferOrder()); - errors(other.getErrors()); - return this; - } - - /** - *

The requested transfer order

- */ - @JsonSetter(value = "transfer_order", nulls = Nulls.SKIP) - public Builder transferOrder(Optional transferOrder) { - this.transferOrder = transferOrder; - return this; - } - - public Builder transferOrder(TransferOrder transferOrder) { - this.transferOrder = Optional.ofNullable(transferOrder); - return this; - } - - /** - *

Any errors that occurred during the request

- */ - @JsonSetter(value = "errors", nulls = Nulls.SKIP) - public Builder errors(Optional> errors) { - this.errors = errors; - return this; - } - - public Builder errors(List errors) { - this.errors = Optional.ofNullable(errors); - return this; - } - - public RetrieveTransferOrderResponse build() { - return new RetrieveTransferOrderResponse(transferOrder, errors, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/SearchOrdersStateFilter.java b/src/main/java/com/squareup/square/types/SearchOrdersStateFilter.java index 914f1669..89172027 100644 --- a/src/main/java/com/squareup/square/types/SearchOrdersStateFilter.java +++ b/src/main/java/com/squareup/square/types/SearchOrdersStateFilter.java @@ -89,9 +89,7 @@ public Builder from(SearchOrdersStateFilter other) { @JsonSetter(value = "states", nulls = Nulls.SKIP) public Builder states(List states) { this.states.clear(); - if (states != null) { - this.states.addAll(states); - } + this.states.addAll(states); return this; } @@ -101,9 +99,7 @@ public Builder addStates(OrderState states) { } public Builder addAllStates(List states) { - if (states != null) { - this.states.addAll(states); - } + this.states.addAll(states); return this; } diff --git a/src/main/java/com/squareup/square/types/SearchTransferOrdersRequest.java b/src/main/java/com/squareup/square/types/SearchTransferOrdersRequest.java deleted file mode 100644 index 3f5bc659..00000000 --- a/src/main/java/com/squareup/square/types/SearchTransferOrdersRequest.java +++ /dev/null @@ -1,161 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = SearchTransferOrdersRequest.Builder.class) -public final class SearchTransferOrdersRequest { - private final Optional query; - - private final Optional cursor; - - private final Optional limit; - - private final Map additionalProperties; - - private SearchTransferOrdersRequest( - Optional query, - Optional cursor, - Optional limit, - Map additionalProperties) { - this.query = query; - this.cursor = cursor; - this.limit = limit; - this.additionalProperties = additionalProperties; - } - - /** - * @return The search query - */ - @JsonProperty("query") - public Optional getQuery() { - return query; - } - - /** - * @return Pagination cursor from a previous search response - */ - @JsonProperty("cursor") - public Optional getCursor() { - return cursor; - } - - /** - * @return Maximum number of results to return (1-100) - */ - @JsonProperty("limit") - public Optional getLimit() { - return limit; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof SearchTransferOrdersRequest && equalTo((SearchTransferOrdersRequest) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(SearchTransferOrdersRequest other) { - return query.equals(other.query) && cursor.equals(other.cursor) && limit.equals(other.limit); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.query, this.cursor, this.limit); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional query = Optional.empty(); - - private Optional cursor = Optional.empty(); - - private Optional limit = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(SearchTransferOrdersRequest other) { - query(other.getQuery()); - cursor(other.getCursor()); - limit(other.getLimit()); - return this; - } - - /** - *

The search query

- */ - @JsonSetter(value = "query", nulls = Nulls.SKIP) - public Builder query(Optional query) { - this.query = query; - return this; - } - - public Builder query(TransferOrderQuery query) { - this.query = Optional.ofNullable(query); - return this; - } - - /** - *

Pagination cursor from a previous search response

- */ - @JsonSetter(value = "cursor", nulls = Nulls.SKIP) - public Builder cursor(Optional cursor) { - this.cursor = cursor; - return this; - } - - public Builder cursor(String cursor) { - this.cursor = Optional.ofNullable(cursor); - return this; - } - - /** - *

Maximum number of results to return (1-100)

- */ - @JsonSetter(value = "limit", nulls = Nulls.SKIP) - public Builder limit(Optional limit) { - this.limit = limit; - return this; - } - - public Builder limit(Integer limit) { - this.limit = Optional.ofNullable(limit); - return this; - } - - public SearchTransferOrdersRequest build() { - return new SearchTransferOrdersRequest(query, cursor, limit, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/SearchTransferOrdersResponse.java b/src/main/java/com/squareup/square/types/SearchTransferOrdersResponse.java deleted file mode 100644 index fbda5b4d..00000000 --- a/src/main/java/com/squareup/square/types/SearchTransferOrdersResponse.java +++ /dev/null @@ -1,164 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = SearchTransferOrdersResponse.Builder.class) -public final class SearchTransferOrdersResponse { - private final Optional> transferOrders; - - private final Optional cursor; - - private final Optional> errors; - - private final Map additionalProperties; - - private SearchTransferOrdersResponse( - Optional> transferOrders, - Optional cursor, - Optional> errors, - Map additionalProperties) { - this.transferOrders = transferOrders; - this.cursor = cursor; - this.errors = errors; - this.additionalProperties = additionalProperties; - } - - /** - * @return List of transfer orders matching the search criteria - */ - @JsonProperty("transfer_orders") - public Optional> getTransferOrders() { - return transferOrders; - } - - /** - * @return Pagination cursor for fetching the next page of results - */ - @JsonProperty("cursor") - public Optional getCursor() { - return cursor; - } - - /** - * @return Any errors that occurred during the request - */ - @JsonProperty("errors") - public Optional> getErrors() { - return errors; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof SearchTransferOrdersResponse && equalTo((SearchTransferOrdersResponse) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(SearchTransferOrdersResponse other) { - return transferOrders.equals(other.transferOrders) - && cursor.equals(other.cursor) - && errors.equals(other.errors); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.transferOrders, this.cursor, this.errors); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional> transferOrders = Optional.empty(); - - private Optional cursor = Optional.empty(); - - private Optional> errors = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(SearchTransferOrdersResponse other) { - transferOrders(other.getTransferOrders()); - cursor(other.getCursor()); - errors(other.getErrors()); - return this; - } - - /** - *

List of transfer orders matching the search criteria

- */ - @JsonSetter(value = "transfer_orders", nulls = Nulls.SKIP) - public Builder transferOrders(Optional> transferOrders) { - this.transferOrders = transferOrders; - return this; - } - - public Builder transferOrders(List transferOrders) { - this.transferOrders = Optional.ofNullable(transferOrders); - return this; - } - - /** - *

Pagination cursor for fetching the next page of results

- */ - @JsonSetter(value = "cursor", nulls = Nulls.SKIP) - public Builder cursor(Optional cursor) { - this.cursor = cursor; - return this; - } - - public Builder cursor(String cursor) { - this.cursor = Optional.ofNullable(cursor); - return this; - } - - /** - *

Any errors that occurred during the request

- */ - @JsonSetter(value = "errors", nulls = Nulls.SKIP) - public Builder errors(Optional> errors) { - this.errors = errors; - return this; - } - - public Builder errors(List errors) { - this.errors = Optional.ofNullable(errors); - return this; - } - - public SearchTransferOrdersResponse build() { - return new SearchTransferOrdersResponse(transferOrders, cursor, errors, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/SelectOptions.java b/src/main/java/com/squareup/square/types/SelectOptions.java index 5a352e1d..aefb518b 100644 --- a/src/main/java/com/squareup/square/types/SelectOptions.java +++ b/src/main/java/com/squareup/square/types/SelectOptions.java @@ -220,9 +220,7 @@ public _FinalStage selectedOption(Optional selectedOption) { */ @java.lang.Override public _FinalStage addAllOptions(List options) { - if (options != null) { - this.options.addAll(options); - } + this.options.addAll(options); return this; } @@ -243,9 +241,7 @@ public _FinalStage addOptions(SelectOption options) { @JsonSetter(value = "options", nulls = Nulls.SKIP) public _FinalStage options(List options) { this.options.clear(); - if (options != null) { - this.options.addAll(options); - } + this.options.addAll(options); return this; } diff --git a/src/main/java/com/squareup/square/types/StartTransferOrderRequest.java b/src/main/java/com/squareup/square/types/StartTransferOrderRequest.java deleted file mode 100644 index 00797a50..00000000 --- a/src/main/java/com/squareup/square/types/StartTransferOrderRequest.java +++ /dev/null @@ -1,199 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import org.jetbrains.annotations.NotNull; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = StartTransferOrderRequest.Builder.class) -public final class StartTransferOrderRequest { - private final String transferOrderId; - - private final String idempotencyKey; - - private final Optional version; - - private final Map additionalProperties; - - private StartTransferOrderRequest( - String transferOrderId, - String idempotencyKey, - Optional version, - Map additionalProperties) { - this.transferOrderId = transferOrderId; - this.idempotencyKey = idempotencyKey; - this.version = version; - this.additionalProperties = additionalProperties; - } - - /** - * @return The ID of the transfer order to start. Must be in DRAFT status. - */ - @JsonProperty("transfer_order_id") - public String getTransferOrderId() { - return transferOrderId; - } - - /** - * @return A unique string that identifies this UpdateTransferOrder request. Keys can be - * any valid string but must be unique for every UpdateTransferOrder request. - */ - @JsonProperty("idempotency_key") - public String getIdempotencyKey() { - return idempotencyKey; - } - - /** - * @return Version for optimistic concurrency - */ - @JsonProperty("version") - public Optional getVersion() { - return version; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof StartTransferOrderRequest && equalTo((StartTransferOrderRequest) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(StartTransferOrderRequest other) { - return transferOrderId.equals(other.transferOrderId) - && idempotencyKey.equals(other.idempotencyKey) - && version.equals(other.version); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.transferOrderId, this.idempotencyKey, this.version); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static TransferOrderIdStage builder() { - return new Builder(); - } - - public interface TransferOrderIdStage { - /** - *

The ID of the transfer order to start. Must be in DRAFT status.

- */ - IdempotencyKeyStage transferOrderId(@NotNull String transferOrderId); - - Builder from(StartTransferOrderRequest other); - } - - public interface IdempotencyKeyStage { - /** - *

A unique string that identifies this UpdateTransferOrder request. Keys can be - * any valid string but must be unique for every UpdateTransferOrder request.

- */ - _FinalStage idempotencyKey(@NotNull String idempotencyKey); - } - - public interface _FinalStage { - StartTransferOrderRequest build(); - - /** - *

Version for optimistic concurrency

- */ - _FinalStage version(Optional version); - - _FinalStage version(Long version); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder implements TransferOrderIdStage, IdempotencyKeyStage, _FinalStage { - private String transferOrderId; - - private String idempotencyKey; - - private Optional version = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - @java.lang.Override - public Builder from(StartTransferOrderRequest other) { - transferOrderId(other.getTransferOrderId()); - idempotencyKey(other.getIdempotencyKey()); - version(other.getVersion()); - return this; - } - - /** - *

The ID of the transfer order to start. Must be in DRAFT status.

- *

The ID of the transfer order to start. Must be in DRAFT status.

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - @JsonSetter("transfer_order_id") - public IdempotencyKeyStage transferOrderId(@NotNull String transferOrderId) { - this.transferOrderId = Objects.requireNonNull(transferOrderId, "transferOrderId must not be null"); - return this; - } - - /** - *

A unique string that identifies this UpdateTransferOrder request. Keys can be - * any valid string but must be unique for every UpdateTransferOrder request.

- *

A unique string that identifies this UpdateTransferOrder request. Keys can be - * any valid string but must be unique for every UpdateTransferOrder request.

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - @JsonSetter("idempotency_key") - public _FinalStage idempotencyKey(@NotNull String idempotencyKey) { - this.idempotencyKey = Objects.requireNonNull(idempotencyKey, "idempotencyKey must not be null"); - return this; - } - - /** - *

Version for optimistic concurrency

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - public _FinalStage version(Long version) { - this.version = Optional.ofNullable(version); - return this; - } - - /** - *

Version for optimistic concurrency

- */ - @java.lang.Override - @JsonSetter(value = "version", nulls = Nulls.SKIP) - public _FinalStage version(Optional version) { - this.version = version; - return this; - } - - @java.lang.Override - public StartTransferOrderRequest build() { - return new StartTransferOrderRequest(transferOrderId, idempotencyKey, version, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/StartTransferOrderResponse.java b/src/main/java/com/squareup/square/types/StartTransferOrderResponse.java deleted file mode 100644 index 17517fa3..00000000 --- a/src/main/java/com/squareup/square/types/StartTransferOrderResponse.java +++ /dev/null @@ -1,133 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = StartTransferOrderResponse.Builder.class) -public final class StartTransferOrderResponse { - private final Optional transferOrder; - - private final Optional> errors; - - private final Map additionalProperties; - - private StartTransferOrderResponse( - Optional transferOrder, - Optional> errors, - Map additionalProperties) { - this.transferOrder = transferOrder; - this.errors = errors; - this.additionalProperties = additionalProperties; - } - - /** - * @return The updated transfer order with status changed to STARTED - */ - @JsonProperty("transfer_order") - public Optional getTransferOrder() { - return transferOrder; - } - - /** - * @return Any errors that occurred during the request - */ - @JsonProperty("errors") - public Optional> getErrors() { - return errors; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof StartTransferOrderResponse && equalTo((StartTransferOrderResponse) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(StartTransferOrderResponse other) { - return transferOrder.equals(other.transferOrder) && errors.equals(other.errors); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.transferOrder, this.errors); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional transferOrder = Optional.empty(); - - private Optional> errors = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(StartTransferOrderResponse other) { - transferOrder(other.getTransferOrder()); - errors(other.getErrors()); - return this; - } - - /** - *

The updated transfer order with status changed to STARTED

- */ - @JsonSetter(value = "transfer_order", nulls = Nulls.SKIP) - public Builder transferOrder(Optional transferOrder) { - this.transferOrder = transferOrder; - return this; - } - - public Builder transferOrder(TransferOrder transferOrder) { - this.transferOrder = Optional.ofNullable(transferOrder); - return this; - } - - /** - *

Any errors that occurred during the request

- */ - @JsonSetter(value = "errors", nulls = Nulls.SKIP) - public Builder errors(Optional> errors) { - this.errors = errors; - return this; - } - - public Builder errors(List errors) { - this.errors = Optional.ofNullable(errors); - return this; - } - - public StartTransferOrderResponse build() { - return new StartTransferOrderResponse(transferOrder, errors, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/Subscription.java b/src/main/java/com/squareup/square/types/Subscription.java index a7068d72..9a9ad2e4 100644 --- a/src/main/java/com/squareup/square/types/Subscription.java +++ b/src/main/java/com/squareup/square/types/Subscription.java @@ -62,8 +62,6 @@ public final class Subscription { private final Optional> phases; - private final Optional completedDate; - private final Map additionalProperties; private Subscription( @@ -86,7 +84,6 @@ private Subscription( Optional> actions, Optional monthlyBillingAnchorDate, Optional> phases, - Optional completedDate, Map additionalProperties) { this.id = id; this.locationId = locationId; @@ -107,7 +104,6 @@ private Subscription( this.actions = actions; this.monthlyBillingAnchorDate = monthlyBillingAnchorDate; this.phases = phases; - this.completedDate = completedDate; this.additionalProperties = additionalProperties; } @@ -302,17 +298,6 @@ public Optional> getPhases() { return phases; } - /** - * @return The YYYY-MM-DD-formatted date when the subscription enters a terminal state. - */ - @JsonIgnore - public Optional getCompletedDate() { - if (completedDate == null) { - return Optional.empty(); - } - return completedDate; - } - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) @JsonProperty("canceled_date") private Optional _getCanceledDate() { @@ -337,12 +322,6 @@ private Optional> _getActions() { return actions; } - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("completed_date") - private Optional _getCompletedDate() { - return completedDate; - } - @java.lang.Override public boolean equals(Object other) { if (this == other) return true; @@ -373,8 +352,7 @@ private boolean equalTo(Subscription other) { && source.equals(other.source) && actions.equals(other.actions) && monthlyBillingAnchorDate.equals(other.monthlyBillingAnchorDate) - && phases.equals(other.phases) - && completedDate.equals(other.completedDate); + && phases.equals(other.phases); } @java.lang.Override @@ -398,8 +376,7 @@ public int hashCode() { this.source, this.actions, this.monthlyBillingAnchorDate, - this.phases, - this.completedDate); + this.phases); } @java.lang.Override @@ -451,8 +428,6 @@ public static final class Builder { private Optional> phases = Optional.empty(); - private Optional completedDate = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); @@ -478,7 +453,6 @@ public Builder from(Subscription other) { actions(other.getActions()); monthlyBillingAnchorDate(other.getMonthlyBillingAnchorDate()); phases(other.getPhases()); - completedDate(other.getCompletedDate()); return this; } @@ -819,31 +793,6 @@ public Builder phases(List phases) { return this; } - /** - *

The YYYY-MM-DD-formatted date when the subscription enters a terminal state.

- */ - @JsonSetter(value = "completed_date", nulls = Nulls.SKIP) - public Builder completedDate(Optional completedDate) { - this.completedDate = completedDate; - return this; - } - - public Builder completedDate(String completedDate) { - this.completedDate = Optional.ofNullable(completedDate); - return this; - } - - public Builder completedDate(Nullable completedDate) { - if (completedDate.isNull()) { - this.completedDate = null; - } else if (completedDate.isEmpty()) { - this.completedDate = Optional.empty(); - } else { - this.completedDate = Optional.of(completedDate.get()); - } - return this; - } - public Subscription build() { return new Subscription( id, @@ -865,7 +814,6 @@ public Subscription build() { actions, monthlyBillingAnchorDate, phases, - completedDate, additionalProperties); } } diff --git a/src/main/java/com/squareup/square/types/SubscriptionActionType.java b/src/main/java/com/squareup/square/types/SubscriptionActionType.java index 3718d08b..bff1d428 100644 --- a/src/main/java/com/squareup/square/types/SubscriptionActionType.java +++ b/src/main/java/com/squareup/square/types/SubscriptionActionType.java @@ -18,8 +18,6 @@ public final class SubscriptionActionType { public static final SubscriptionActionType PAUSE = new SubscriptionActionType(Value.PAUSE, "PAUSE"); - public static final SubscriptionActionType COMPLETE = new SubscriptionActionType(Value.COMPLETE, "COMPLETE"); - private final Value value; private final String string; @@ -63,8 +61,6 @@ public T visit(Visitor visitor) { return visitor.visitSwapPlan(); case PAUSE: return visitor.visitPause(); - case COMPLETE: - return visitor.visitComplete(); case UNKNOWN: default: return visitor.visitUnknown(string); @@ -84,8 +80,6 @@ public static SubscriptionActionType valueOf(String value) { return SWAP_PLAN; case "PAUSE": return PAUSE; - case "COMPLETE": - return COMPLETE; default: return new SubscriptionActionType(Value.UNKNOWN, value); } @@ -102,8 +96,6 @@ public enum Value { CHANGE_BILLING_ANCHOR_DATE, - COMPLETE, - UNKNOWN } @@ -118,8 +110,6 @@ public interface Visitor { T visitChangeBillingAnchorDate(); - T visitComplete(); - T visitUnknown(String unknownType); } } diff --git a/src/main/java/com/squareup/square/types/SubscriptionStatus.java b/src/main/java/com/squareup/square/types/SubscriptionStatus.java index 37d0d168..3716895b 100644 --- a/src/main/java/com/squareup/square/types/SubscriptionStatus.java +++ b/src/main/java/com/squareup/square/types/SubscriptionStatus.java @@ -15,8 +15,6 @@ public final class SubscriptionStatus { public static final SubscriptionStatus ACTIVE = new SubscriptionStatus(Value.ACTIVE, "ACTIVE"); - public static final SubscriptionStatus COMPLETED = new SubscriptionStatus(Value.COMPLETED, "COMPLETED"); - public static final SubscriptionStatus PENDING = new SubscriptionStatus(Value.PENDING, "PENDING"); private final Value value; @@ -59,8 +57,6 @@ public T visit(Visitor visitor) { return visitor.visitPaused(); case ACTIVE: return visitor.visitActive(); - case COMPLETED: - return visitor.visitCompleted(); case PENDING: return visitor.visitPending(); case UNKNOWN: @@ -80,8 +76,6 @@ public static SubscriptionStatus valueOf(String value) { return PAUSED; case "ACTIVE": return ACTIVE; - case "COMPLETED": - return COMPLETED; case "PENDING": return PENDING; default: @@ -100,8 +94,6 @@ public enum Value { PAUSED, - COMPLETED, - UNKNOWN } @@ -116,8 +108,6 @@ public interface Visitor { T visitPaused(); - T visitCompleted(); - T visitUnknown(String unknownType); } } diff --git a/src/main/java/com/squareup/square/types/TransferOrder.java b/src/main/java/com/squareup/square/types/TransferOrder.java deleted file mode 100644 index 23cfa9bd..00000000 --- a/src/main/java/com/squareup/square/types/TransferOrder.java +++ /dev/null @@ -1,714 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.Nullable; -import com.squareup.square.core.NullableNonemptyFilter; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = TransferOrder.Builder.class) -public final class TransferOrder { - private final Optional id; - - private final Optional sourceLocationId; - - private final Optional destinationLocationId; - - private final Optional status; - - private final Optional createdAt; - - private final Optional updatedAt; - - private final Optional expectedAt; - - private final Optional completedAt; - - private final Optional notes; - - private final Optional trackingNumber; - - private final Optional createdByTeamMemberId; - - private final Optional> lineItems; - - private final Optional version; - - private final Map additionalProperties; - - private TransferOrder( - Optional id, - Optional sourceLocationId, - Optional destinationLocationId, - Optional status, - Optional createdAt, - Optional updatedAt, - Optional expectedAt, - Optional completedAt, - Optional notes, - Optional trackingNumber, - Optional createdByTeamMemberId, - Optional> lineItems, - Optional version, - Map additionalProperties) { - this.id = id; - this.sourceLocationId = sourceLocationId; - this.destinationLocationId = destinationLocationId; - this.status = status; - this.createdAt = createdAt; - this.updatedAt = updatedAt; - this.expectedAt = expectedAt; - this.completedAt = completedAt; - this.notes = notes; - this.trackingNumber = trackingNumber; - this.createdByTeamMemberId = createdByTeamMemberId; - this.lineItems = lineItems; - this.version = version; - this.additionalProperties = additionalProperties; - } - - /** - * @return Unique system-generated identifier for this transfer order. Use this ID for: - *
    - *
  • Retrieving transfer order details
  • - *
  • Tracking status changes via webhooks
  • - *
  • Linking transfers in external systems
  • - *
- */ - @JsonProperty("id") - public Optional getId() { - return id; - } - - /** - * @return The source Location sending the CatalogItemVariations. - * This location must: - *
    - *
  • Be active in your Square organization
  • - *
  • Have sufficient inventory for the items being transferred
  • - *
  • Not be the same as the destination location
  • - *
- *

This field is not updatable.

- */ - @JsonIgnore - public Optional getSourceLocationId() { - if (sourceLocationId == null) { - return Optional.empty(); - } - return sourceLocationId; - } - - /** - * @return The destination Location receiving the CatalogItemVariations. - * This location must: - *
    - *
  • Be active in your Square organization
  • - *
  • Not be the same as the source location
  • - *
- *

This field is not updatable.

- */ - @JsonIgnore - public Optional getDestinationLocationId() { - if (destinationLocationId == null) { - return Optional.empty(); - } - return destinationLocationId; - } - - /** - * @return Current TransferOrderStatus indicating where the order is in its lifecycle. - * Status transitions follow this progression: - *
    - *
  1. DRAFT -> STARTED via StartTransferOrder
  2. - *
  3. STARTED -> PARTIALLY_RECEIVED via ReceiveTransferOrder
  4. - *
  5. PARTIALLY_RECEIVED -> COMPLETED after all items received
  6. - *
- *

Orders can be CANCELED from STARTED or - * PARTIALLY_RECEIVED status.

- *

This field is read-only and reflects the current state of the transfer order, and cannot be updated directly. Use the appropriate - * endpoints (e.g. StartPurchaseOrder, to change the status. - * See TransferOrderStatus for possible values

- */ - @JsonProperty("status") - public Optional getStatus() { - return status; - } - - /** - * @return Timestamp when the transfer order was created, in RFC 3339 format. - * Used for: - *
    - *
  • Auditing transfer history
  • - *
  • Tracking order age
  • - *
  • Reporting and analytics
  • - *
- */ - @JsonProperty("created_at") - public Optional getCreatedAt() { - return createdAt; - } - - /** - * @return Timestamp when the transfer order was last updated, in RFC 3339 format. - * Updated when: - *
    - *
  • Order status changes
  • - *
  • Items are received
  • - *
  • Notes or metadata are modified
  • - *
- */ - @JsonProperty("updated_at") - public Optional getUpdatedAt() { - return updatedAt; - } - - /** - * @return Expected transfer completion date, in RFC 3339 format. - * Used for: - *
    - *
  • Planning inventory availability
  • - *
  • Scheduling receiving staff
  • - *
  • Monitoring transfer timeliness
  • - *
- */ - @JsonIgnore - public Optional getExpectedAt() { - if (expectedAt == null) { - return Optional.empty(); - } - return expectedAt; - } - - /** - * @return Timestamp when the transfer order was completed or canceled, in RFC 3339 format (e.g. "2023-10-01T12:00:00Z"). - */ - @JsonProperty("completed_at") - public Optional getCompletedAt() { - return completedAt; - } - - /** - * @return Optional notes about the transfer. - */ - @JsonIgnore - public Optional getNotes() { - if (notes == null) { - return Optional.empty(); - } - return notes; - } - - /** - * @return Shipment tracking number for monitoring transfer progress. - */ - @JsonIgnore - public Optional getTrackingNumber() { - if (trackingNumber == null) { - return Optional.empty(); - } - return trackingNumber; - } - - /** - * @return ID of the TeamMember who created this transfer order. This field is not writeable by the Connect V2 API. - */ - @JsonProperty("created_by_team_member_id") - public Optional getCreatedByTeamMemberId() { - return createdByTeamMemberId; - } - - /** - * @return List of CatalogItemVariations being transferred. - */ - @JsonIgnore - public Optional> getLineItems() { - if (lineItems == null) { - return Optional.empty(); - } - return lineItems; - } - - /** - * @return Version for optimistic concurrency control. This is a monotonically increasing integer - * that changes whenever the transfer order is modified. Use this when calling - * UpdateTransferOrder and other endpoints to ensure you're - * not overwriting concurrent changes. - */ - @JsonProperty("version") - public Optional getVersion() { - return version; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("source_location_id") - private Optional _getSourceLocationId() { - return sourceLocationId; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("destination_location_id") - private Optional _getDestinationLocationId() { - return destinationLocationId; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("expected_at") - private Optional _getExpectedAt() { - return expectedAt; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("notes") - private Optional _getNotes() { - return notes; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("tracking_number") - private Optional _getTrackingNumber() { - return trackingNumber; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("line_items") - private Optional> _getLineItems() { - return lineItems; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof TransferOrder && equalTo((TransferOrder) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(TransferOrder other) { - return id.equals(other.id) - && sourceLocationId.equals(other.sourceLocationId) - && destinationLocationId.equals(other.destinationLocationId) - && status.equals(other.status) - && createdAt.equals(other.createdAt) - && updatedAt.equals(other.updatedAt) - && expectedAt.equals(other.expectedAt) - && completedAt.equals(other.completedAt) - && notes.equals(other.notes) - && trackingNumber.equals(other.trackingNumber) - && createdByTeamMemberId.equals(other.createdByTeamMemberId) - && lineItems.equals(other.lineItems) - && version.equals(other.version); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash( - this.id, - this.sourceLocationId, - this.destinationLocationId, - this.status, - this.createdAt, - this.updatedAt, - this.expectedAt, - this.completedAt, - this.notes, - this.trackingNumber, - this.createdByTeamMemberId, - this.lineItems, - this.version); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional id = Optional.empty(); - - private Optional sourceLocationId = Optional.empty(); - - private Optional destinationLocationId = Optional.empty(); - - private Optional status = Optional.empty(); - - private Optional createdAt = Optional.empty(); - - private Optional updatedAt = Optional.empty(); - - private Optional expectedAt = Optional.empty(); - - private Optional completedAt = Optional.empty(); - - private Optional notes = Optional.empty(); - - private Optional trackingNumber = Optional.empty(); - - private Optional createdByTeamMemberId = Optional.empty(); - - private Optional> lineItems = Optional.empty(); - - private Optional version = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(TransferOrder other) { - id(other.getId()); - sourceLocationId(other.getSourceLocationId()); - destinationLocationId(other.getDestinationLocationId()); - status(other.getStatus()); - createdAt(other.getCreatedAt()); - updatedAt(other.getUpdatedAt()); - expectedAt(other.getExpectedAt()); - completedAt(other.getCompletedAt()); - notes(other.getNotes()); - trackingNumber(other.getTrackingNumber()); - createdByTeamMemberId(other.getCreatedByTeamMemberId()); - lineItems(other.getLineItems()); - version(other.getVersion()); - return this; - } - - /** - *

Unique system-generated identifier for this transfer order. Use this ID for:

- *
    - *
  • Retrieving transfer order details
  • - *
  • Tracking status changes via webhooks
  • - *
  • Linking transfers in external systems
  • - *
- */ - @JsonSetter(value = "id", nulls = Nulls.SKIP) - public Builder id(Optional id) { - this.id = id; - return this; - } - - public Builder id(String id) { - this.id = Optional.ofNullable(id); - return this; - } - - /** - *

The source Location sending the CatalogItemVariations. - * This location must:

- *
    - *
  • Be active in your Square organization
  • - *
  • Have sufficient inventory for the items being transferred
  • - *
  • Not be the same as the destination location
  • - *
- *

This field is not updatable.

- */ - @JsonSetter(value = "source_location_id", nulls = Nulls.SKIP) - public Builder sourceLocationId(Optional sourceLocationId) { - this.sourceLocationId = sourceLocationId; - return this; - } - - public Builder sourceLocationId(String sourceLocationId) { - this.sourceLocationId = Optional.ofNullable(sourceLocationId); - return this; - } - - public Builder sourceLocationId(Nullable sourceLocationId) { - if (sourceLocationId.isNull()) { - this.sourceLocationId = null; - } else if (sourceLocationId.isEmpty()) { - this.sourceLocationId = Optional.empty(); - } else { - this.sourceLocationId = Optional.of(sourceLocationId.get()); - } - return this; - } - - /** - *

The destination Location receiving the CatalogItemVariations. - * This location must:

- *
    - *
  • Be active in your Square organization
  • - *
  • Not be the same as the source location
  • - *
- *

This field is not updatable.

- */ - @JsonSetter(value = "destination_location_id", nulls = Nulls.SKIP) - public Builder destinationLocationId(Optional destinationLocationId) { - this.destinationLocationId = destinationLocationId; - return this; - } - - public Builder destinationLocationId(String destinationLocationId) { - this.destinationLocationId = Optional.ofNullable(destinationLocationId); - return this; - } - - public Builder destinationLocationId(Nullable destinationLocationId) { - if (destinationLocationId.isNull()) { - this.destinationLocationId = null; - } else if (destinationLocationId.isEmpty()) { - this.destinationLocationId = Optional.empty(); - } else { - this.destinationLocationId = Optional.of(destinationLocationId.get()); - } - return this; - } - - /** - *

Current TransferOrderStatus indicating where the order is in its lifecycle. - * Status transitions follow this progression:

- *
    - *
  1. DRAFT -> STARTED via StartTransferOrder
  2. - *
  3. STARTED -> PARTIALLY_RECEIVED via ReceiveTransferOrder
  4. - *
  5. PARTIALLY_RECEIVED -> COMPLETED after all items received
  6. - *
- *

Orders can be CANCELED from STARTED or - * PARTIALLY_RECEIVED status.

- *

This field is read-only and reflects the current state of the transfer order, and cannot be updated directly. Use the appropriate - * endpoints (e.g. StartPurchaseOrder, to change the status. - * See TransferOrderStatus for possible values

- */ - @JsonSetter(value = "status", nulls = Nulls.SKIP) - public Builder status(Optional status) { - this.status = status; - return this; - } - - public Builder status(TransferOrderStatus status) { - this.status = Optional.ofNullable(status); - return this; - } - - /** - *

Timestamp when the transfer order was created, in RFC 3339 format. - * Used for:

- *
    - *
  • Auditing transfer history
  • - *
  • Tracking order age
  • - *
  • Reporting and analytics
  • - *
- */ - @JsonSetter(value = "created_at", nulls = Nulls.SKIP) - public Builder createdAt(Optional createdAt) { - this.createdAt = createdAt; - return this; - } - - public Builder createdAt(String createdAt) { - this.createdAt = Optional.ofNullable(createdAt); - return this; - } - - /** - *

Timestamp when the transfer order was last updated, in RFC 3339 format. - * Updated when:

- *
    - *
  • Order status changes
  • - *
  • Items are received
  • - *
  • Notes or metadata are modified
  • - *
- */ - @JsonSetter(value = "updated_at", nulls = Nulls.SKIP) - public Builder updatedAt(Optional updatedAt) { - this.updatedAt = updatedAt; - return this; - } - - public Builder updatedAt(String updatedAt) { - this.updatedAt = Optional.ofNullable(updatedAt); - return this; - } - - /** - *

Expected transfer completion date, in RFC 3339 format. - * Used for:

- *
    - *
  • Planning inventory availability
  • - *
  • Scheduling receiving staff
  • - *
  • Monitoring transfer timeliness
  • - *
- */ - @JsonSetter(value = "expected_at", nulls = Nulls.SKIP) - public Builder expectedAt(Optional expectedAt) { - this.expectedAt = expectedAt; - return this; - } - - public Builder expectedAt(String expectedAt) { - this.expectedAt = Optional.ofNullable(expectedAt); - return this; - } - - public Builder expectedAt(Nullable expectedAt) { - if (expectedAt.isNull()) { - this.expectedAt = null; - } else if (expectedAt.isEmpty()) { - this.expectedAt = Optional.empty(); - } else { - this.expectedAt = Optional.of(expectedAt.get()); - } - return this; - } - - /** - *

Timestamp when the transfer order was completed or canceled, in RFC 3339 format (e.g. "2023-10-01T12:00:00Z").

- */ - @JsonSetter(value = "completed_at", nulls = Nulls.SKIP) - public Builder completedAt(Optional completedAt) { - this.completedAt = completedAt; - return this; - } - - public Builder completedAt(String completedAt) { - this.completedAt = Optional.ofNullable(completedAt); - return this; - } - - /** - *

Optional notes about the transfer.

- */ - @JsonSetter(value = "notes", nulls = Nulls.SKIP) - public Builder notes(Optional notes) { - this.notes = notes; - return this; - } - - public Builder notes(String notes) { - this.notes = Optional.ofNullable(notes); - return this; - } - - public Builder notes(Nullable notes) { - if (notes.isNull()) { - this.notes = null; - } else if (notes.isEmpty()) { - this.notes = Optional.empty(); - } else { - this.notes = Optional.of(notes.get()); - } - return this; - } - - /** - *

Shipment tracking number for monitoring transfer progress.

- */ - @JsonSetter(value = "tracking_number", nulls = Nulls.SKIP) - public Builder trackingNumber(Optional trackingNumber) { - this.trackingNumber = trackingNumber; - return this; - } - - public Builder trackingNumber(String trackingNumber) { - this.trackingNumber = Optional.ofNullable(trackingNumber); - return this; - } - - public Builder trackingNumber(Nullable trackingNumber) { - if (trackingNumber.isNull()) { - this.trackingNumber = null; - } else if (trackingNumber.isEmpty()) { - this.trackingNumber = Optional.empty(); - } else { - this.trackingNumber = Optional.of(trackingNumber.get()); - } - return this; - } - - /** - *

ID of the TeamMember who created this transfer order. This field is not writeable by the Connect V2 API.

- */ - @JsonSetter(value = "created_by_team_member_id", nulls = Nulls.SKIP) - public Builder createdByTeamMemberId(Optional createdByTeamMemberId) { - this.createdByTeamMemberId = createdByTeamMemberId; - return this; - } - - public Builder createdByTeamMemberId(String createdByTeamMemberId) { - this.createdByTeamMemberId = Optional.ofNullable(createdByTeamMemberId); - return this; - } - - /** - *

List of CatalogItemVariations being transferred.

- */ - @JsonSetter(value = "line_items", nulls = Nulls.SKIP) - public Builder lineItems(Optional> lineItems) { - this.lineItems = lineItems; - return this; - } - - public Builder lineItems(List lineItems) { - this.lineItems = Optional.ofNullable(lineItems); - return this; - } - - public Builder lineItems(Nullable> lineItems) { - if (lineItems.isNull()) { - this.lineItems = null; - } else if (lineItems.isEmpty()) { - this.lineItems = Optional.empty(); - } else { - this.lineItems = Optional.of(lineItems.get()); - } - return this; - } - - /** - *

Version for optimistic concurrency control. This is a monotonically increasing integer - * that changes whenever the transfer order is modified. Use this when calling - * UpdateTransferOrder and other endpoints to ensure you're - * not overwriting concurrent changes.

- */ - @JsonSetter(value = "version", nulls = Nulls.SKIP) - public Builder version(Optional version) { - this.version = version; - return this; - } - - public Builder version(Long version) { - this.version = Optional.ofNullable(version); - return this; - } - - public TransferOrder build() { - return new TransferOrder( - id, - sourceLocationId, - destinationLocationId, - status, - createdAt, - updatedAt, - expectedAt, - completedAt, - notes, - trackingNumber, - createdByTeamMemberId, - lineItems, - version, - additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/TransferOrderCreatedEvent.java b/src/main/java/com/squareup/square/types/TransferOrderCreatedEvent.java deleted file mode 100644 index a0f89be4..00000000 --- a/src/main/java/com/squareup/square/types/TransferOrderCreatedEvent.java +++ /dev/null @@ -1,286 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.Nullable; -import com.squareup.square.core.NullableNonemptyFilter; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = TransferOrderCreatedEvent.Builder.class) -public final class TransferOrderCreatedEvent { - private final Optional merchantId; - - private final Optional type; - - private final Optional eventId; - - private final Optional createdAt; - - private final Optional data; - - private final Map additionalProperties; - - private TransferOrderCreatedEvent( - Optional merchantId, - Optional type, - Optional eventId, - Optional createdAt, - Optional data, - Map additionalProperties) { - this.merchantId = merchantId; - this.type = type; - this.eventId = eventId; - this.createdAt = createdAt; - this.data = data; - this.additionalProperties = additionalProperties; - } - - /** - * @return The ID of the target merchant associated with the event. - */ - @JsonIgnore - public Optional getMerchantId() { - if (merchantId == null) { - return Optional.empty(); - } - return merchantId; - } - - /** - * @return The type of event this represents, "transfer_order.created". - */ - @JsonIgnore - public Optional getType() { - if (type == null) { - return Optional.empty(); - } - return type; - } - - /** - * @return A unique ID for the event. - */ - @JsonIgnore - public Optional getEventId() { - if (eventId == null) { - return Optional.empty(); - } - return eventId; - } - - /** - * @return Timestamp of when the event was created, in RFC 3339 format. - */ - @JsonProperty("created_at") - public Optional getCreatedAt() { - return createdAt; - } - - /** - * @return Data associated with the event. - */ - @JsonProperty("data") - public Optional getData() { - return data; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("merchant_id") - private Optional _getMerchantId() { - return merchantId; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("type") - private Optional _getType() { - return type; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("event_id") - private Optional _getEventId() { - return eventId; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof TransferOrderCreatedEvent && equalTo((TransferOrderCreatedEvent) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(TransferOrderCreatedEvent other) { - return merchantId.equals(other.merchantId) - && type.equals(other.type) - && eventId.equals(other.eventId) - && createdAt.equals(other.createdAt) - && data.equals(other.data); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.merchantId, this.type, this.eventId, this.createdAt, this.data); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional merchantId = Optional.empty(); - - private Optional type = Optional.empty(); - - private Optional eventId = Optional.empty(); - - private Optional createdAt = Optional.empty(); - - private Optional data = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(TransferOrderCreatedEvent other) { - merchantId(other.getMerchantId()); - type(other.getType()); - eventId(other.getEventId()); - createdAt(other.getCreatedAt()); - data(other.getData()); - return this; - } - - /** - *

The ID of the target merchant associated with the event.

- */ - @JsonSetter(value = "merchant_id", nulls = Nulls.SKIP) - public Builder merchantId(Optional merchantId) { - this.merchantId = merchantId; - return this; - } - - public Builder merchantId(String merchantId) { - this.merchantId = Optional.ofNullable(merchantId); - return this; - } - - public Builder merchantId(Nullable merchantId) { - if (merchantId.isNull()) { - this.merchantId = null; - } else if (merchantId.isEmpty()) { - this.merchantId = Optional.empty(); - } else { - this.merchantId = Optional.of(merchantId.get()); - } - return this; - } - - /** - *

The type of event this represents, "transfer_order.created".

- */ - @JsonSetter(value = "type", nulls = Nulls.SKIP) - public Builder type(Optional type) { - this.type = type; - return this; - } - - public Builder type(String type) { - this.type = Optional.ofNullable(type); - return this; - } - - public Builder type(Nullable type) { - if (type.isNull()) { - this.type = null; - } else if (type.isEmpty()) { - this.type = Optional.empty(); - } else { - this.type = Optional.of(type.get()); - } - return this; - } - - /** - *

A unique ID for the event.

- */ - @JsonSetter(value = "event_id", nulls = Nulls.SKIP) - public Builder eventId(Optional eventId) { - this.eventId = eventId; - return this; - } - - public Builder eventId(String eventId) { - this.eventId = Optional.ofNullable(eventId); - return this; - } - - public Builder eventId(Nullable eventId) { - if (eventId.isNull()) { - this.eventId = null; - } else if (eventId.isEmpty()) { - this.eventId = Optional.empty(); - } else { - this.eventId = Optional.of(eventId.get()); - } - return this; - } - - /** - *

Timestamp of when the event was created, in RFC 3339 format.

- */ - @JsonSetter(value = "created_at", nulls = Nulls.SKIP) - public Builder createdAt(Optional createdAt) { - this.createdAt = createdAt; - return this; - } - - public Builder createdAt(String createdAt) { - this.createdAt = Optional.ofNullable(createdAt); - return this; - } - - /** - *

Data associated with the event.

- */ - @JsonSetter(value = "data", nulls = Nulls.SKIP) - public Builder data(Optional data) { - this.data = data; - return this; - } - - public Builder data(TransferOrderCreatedEventData data) { - this.data = Optional.ofNullable(data); - return this; - } - - public TransferOrderCreatedEvent build() { - return new TransferOrderCreatedEvent(merchantId, type, eventId, createdAt, data, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/TransferOrderCreatedEventData.java b/src/main/java/com/squareup/square/types/TransferOrderCreatedEventData.java deleted file mode 100644 index 17c31749..00000000 --- a/src/main/java/com/squareup/square/types/TransferOrderCreatedEventData.java +++ /dev/null @@ -1,184 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.Nullable; -import com.squareup.square.core.NullableNonemptyFilter; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = TransferOrderCreatedEventData.Builder.class) -public final class TransferOrderCreatedEventData { - private final Optional type; - - private final Optional id; - - private final Optional object; - - private final Map additionalProperties; - - private TransferOrderCreatedEventData( - Optional type, - Optional id, - Optional object, - Map additionalProperties) { - this.type = type; - this.id = id; - this.object = object; - this.additionalProperties = additionalProperties; - } - - /** - * @return Name of the affected object’s type, "transfer_order". - */ - @JsonIgnore - public Optional getType() { - if (type == null) { - return Optional.empty(); - } - return type; - } - - /** - * @return ID of the affected transfer_order. - */ - @JsonProperty("id") - public Optional getId() { - return id; - } - - /** - * @return An object containing the created transfer_order. - */ - @JsonProperty("object") - public Optional getObject() { - return object; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("type") - private Optional _getType() { - return type; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof TransferOrderCreatedEventData && equalTo((TransferOrderCreatedEventData) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(TransferOrderCreatedEventData other) { - return type.equals(other.type) && id.equals(other.id) && object.equals(other.object); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.type, this.id, this.object); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional type = Optional.empty(); - - private Optional id = Optional.empty(); - - private Optional object = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(TransferOrderCreatedEventData other) { - type(other.getType()); - id(other.getId()); - object(other.getObject()); - return this; - } - - /** - *

Name of the affected object’s type, "transfer_order".

- */ - @JsonSetter(value = "type", nulls = Nulls.SKIP) - public Builder type(Optional type) { - this.type = type; - return this; - } - - public Builder type(String type) { - this.type = Optional.ofNullable(type); - return this; - } - - public Builder type(Nullable type) { - if (type.isNull()) { - this.type = null; - } else if (type.isEmpty()) { - this.type = Optional.empty(); - } else { - this.type = Optional.of(type.get()); - } - return this; - } - - /** - *

ID of the affected transfer_order.

- */ - @JsonSetter(value = "id", nulls = Nulls.SKIP) - public Builder id(Optional id) { - this.id = id; - return this; - } - - public Builder id(String id) { - this.id = Optional.ofNullable(id); - return this; - } - - /** - *

An object containing the created transfer_order.

- */ - @JsonSetter(value = "object", nulls = Nulls.SKIP) - public Builder object(Optional object) { - this.object = object; - return this; - } - - public Builder object(TransferOrderCreatedEventObject object) { - this.object = Optional.ofNullable(object); - return this; - } - - public TransferOrderCreatedEventData build() { - return new TransferOrderCreatedEventData(type, id, object, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/TransferOrderCreatedEventObject.java b/src/main/java/com/squareup/square/types/TransferOrderCreatedEventObject.java deleted file mode 100644 index 1e455596..00000000 --- a/src/main/java/com/squareup/square/types/TransferOrderCreatedEventObject.java +++ /dev/null @@ -1,102 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = TransferOrderCreatedEventObject.Builder.class) -public final class TransferOrderCreatedEventObject { - private final Optional transferOrder; - - private final Map additionalProperties; - - private TransferOrderCreatedEventObject( - Optional transferOrder, Map additionalProperties) { - this.transferOrder = transferOrder; - this.additionalProperties = additionalProperties; - } - - /** - * @return The created transfer_order. - */ - @JsonProperty("transfer_order") - public Optional getTransferOrder() { - return transferOrder; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof TransferOrderCreatedEventObject && equalTo((TransferOrderCreatedEventObject) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(TransferOrderCreatedEventObject other) { - return transferOrder.equals(other.transferOrder); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.transferOrder); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional transferOrder = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(TransferOrderCreatedEventObject other) { - transferOrder(other.getTransferOrder()); - return this; - } - - /** - *

The created transfer_order.

- */ - @JsonSetter(value = "transfer_order", nulls = Nulls.SKIP) - public Builder transferOrder(Optional transferOrder) { - this.transferOrder = transferOrder; - return this; - } - - public Builder transferOrder(TransferOrder transferOrder) { - this.transferOrder = Optional.ofNullable(transferOrder); - return this; - } - - public TransferOrderCreatedEventObject build() { - return new TransferOrderCreatedEventObject(transferOrder, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/TransferOrderDeletedEvent.java b/src/main/java/com/squareup/square/types/TransferOrderDeletedEvent.java deleted file mode 100644 index 4e85b206..00000000 --- a/src/main/java/com/squareup/square/types/TransferOrderDeletedEvent.java +++ /dev/null @@ -1,286 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.Nullable; -import com.squareup.square.core.NullableNonemptyFilter; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = TransferOrderDeletedEvent.Builder.class) -public final class TransferOrderDeletedEvent { - private final Optional merchantId; - - private final Optional type; - - private final Optional eventId; - - private final Optional createdAt; - - private final Optional data; - - private final Map additionalProperties; - - private TransferOrderDeletedEvent( - Optional merchantId, - Optional type, - Optional eventId, - Optional createdAt, - Optional data, - Map additionalProperties) { - this.merchantId = merchantId; - this.type = type; - this.eventId = eventId; - this.createdAt = createdAt; - this.data = data; - this.additionalProperties = additionalProperties; - } - - /** - * @return The ID of the target merchant associated with the event. - */ - @JsonIgnore - public Optional getMerchantId() { - if (merchantId == null) { - return Optional.empty(); - } - return merchantId; - } - - /** - * @return The type of event this represents, "transfer_order.deleted". - */ - @JsonIgnore - public Optional getType() { - if (type == null) { - return Optional.empty(); - } - return type; - } - - /** - * @return A unique ID for the event. - */ - @JsonIgnore - public Optional getEventId() { - if (eventId == null) { - return Optional.empty(); - } - return eventId; - } - - /** - * @return Timestamp of when the event was created, in RFC 3339 format. - */ - @JsonProperty("created_at") - public Optional getCreatedAt() { - return createdAt; - } - - /** - * @return Data associated with the event. - */ - @JsonProperty("data") - public Optional getData() { - return data; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("merchant_id") - private Optional _getMerchantId() { - return merchantId; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("type") - private Optional _getType() { - return type; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("event_id") - private Optional _getEventId() { - return eventId; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof TransferOrderDeletedEvent && equalTo((TransferOrderDeletedEvent) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(TransferOrderDeletedEvent other) { - return merchantId.equals(other.merchantId) - && type.equals(other.type) - && eventId.equals(other.eventId) - && createdAt.equals(other.createdAt) - && data.equals(other.data); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.merchantId, this.type, this.eventId, this.createdAt, this.data); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional merchantId = Optional.empty(); - - private Optional type = Optional.empty(); - - private Optional eventId = Optional.empty(); - - private Optional createdAt = Optional.empty(); - - private Optional data = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(TransferOrderDeletedEvent other) { - merchantId(other.getMerchantId()); - type(other.getType()); - eventId(other.getEventId()); - createdAt(other.getCreatedAt()); - data(other.getData()); - return this; - } - - /** - *

The ID of the target merchant associated with the event.

- */ - @JsonSetter(value = "merchant_id", nulls = Nulls.SKIP) - public Builder merchantId(Optional merchantId) { - this.merchantId = merchantId; - return this; - } - - public Builder merchantId(String merchantId) { - this.merchantId = Optional.ofNullable(merchantId); - return this; - } - - public Builder merchantId(Nullable merchantId) { - if (merchantId.isNull()) { - this.merchantId = null; - } else if (merchantId.isEmpty()) { - this.merchantId = Optional.empty(); - } else { - this.merchantId = Optional.of(merchantId.get()); - } - return this; - } - - /** - *

The type of event this represents, "transfer_order.deleted".

- */ - @JsonSetter(value = "type", nulls = Nulls.SKIP) - public Builder type(Optional type) { - this.type = type; - return this; - } - - public Builder type(String type) { - this.type = Optional.ofNullable(type); - return this; - } - - public Builder type(Nullable type) { - if (type.isNull()) { - this.type = null; - } else if (type.isEmpty()) { - this.type = Optional.empty(); - } else { - this.type = Optional.of(type.get()); - } - return this; - } - - /** - *

A unique ID for the event.

- */ - @JsonSetter(value = "event_id", nulls = Nulls.SKIP) - public Builder eventId(Optional eventId) { - this.eventId = eventId; - return this; - } - - public Builder eventId(String eventId) { - this.eventId = Optional.ofNullable(eventId); - return this; - } - - public Builder eventId(Nullable eventId) { - if (eventId.isNull()) { - this.eventId = null; - } else if (eventId.isEmpty()) { - this.eventId = Optional.empty(); - } else { - this.eventId = Optional.of(eventId.get()); - } - return this; - } - - /** - *

Timestamp of when the event was created, in RFC 3339 format.

- */ - @JsonSetter(value = "created_at", nulls = Nulls.SKIP) - public Builder createdAt(Optional createdAt) { - this.createdAt = createdAt; - return this; - } - - public Builder createdAt(String createdAt) { - this.createdAt = Optional.ofNullable(createdAt); - return this; - } - - /** - *

Data associated with the event.

- */ - @JsonSetter(value = "data", nulls = Nulls.SKIP) - public Builder data(Optional data) { - this.data = data; - return this; - } - - public Builder data(TransferOrderDeletedEventData data) { - this.data = Optional.ofNullable(data); - return this; - } - - public TransferOrderDeletedEvent build() { - return new TransferOrderDeletedEvent(merchantId, type, eventId, createdAt, data, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/TransferOrderDeletedEventData.java b/src/main/java/com/squareup/square/types/TransferOrderDeletedEventData.java deleted file mode 100644 index b4a91784..00000000 --- a/src/main/java/com/squareup/square/types/TransferOrderDeletedEventData.java +++ /dev/null @@ -1,204 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.Nullable; -import com.squareup.square.core.NullableNonemptyFilter; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = TransferOrderDeletedEventData.Builder.class) -public final class TransferOrderDeletedEventData { - private final Optional type; - - private final Optional id; - - private final Optional deleted; - - private final Map additionalProperties; - - private TransferOrderDeletedEventData( - Optional type, - Optional id, - Optional deleted, - Map additionalProperties) { - this.type = type; - this.id = id; - this.deleted = deleted; - this.additionalProperties = additionalProperties; - } - - /** - * @return Name of the affected object’s type, "transfer_order". - */ - @JsonIgnore - public Optional getType() { - if (type == null) { - return Optional.empty(); - } - return type; - } - - /** - * @return ID of the affected transfer_order. - */ - @JsonProperty("id") - public Optional getId() { - return id; - } - - /** - * @return Is true if the affected object was deleted. Otherwise absent. - */ - @JsonIgnore - public Optional getDeleted() { - if (deleted == null) { - return Optional.empty(); - } - return deleted; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("type") - private Optional _getType() { - return type; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("deleted") - private Optional _getDeleted() { - return deleted; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof TransferOrderDeletedEventData && equalTo((TransferOrderDeletedEventData) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(TransferOrderDeletedEventData other) { - return type.equals(other.type) && id.equals(other.id) && deleted.equals(other.deleted); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.type, this.id, this.deleted); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional type = Optional.empty(); - - private Optional id = Optional.empty(); - - private Optional deleted = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(TransferOrderDeletedEventData other) { - type(other.getType()); - id(other.getId()); - deleted(other.getDeleted()); - return this; - } - - /** - *

Name of the affected object’s type, "transfer_order".

- */ - @JsonSetter(value = "type", nulls = Nulls.SKIP) - public Builder type(Optional type) { - this.type = type; - return this; - } - - public Builder type(String type) { - this.type = Optional.ofNullable(type); - return this; - } - - public Builder type(Nullable type) { - if (type.isNull()) { - this.type = null; - } else if (type.isEmpty()) { - this.type = Optional.empty(); - } else { - this.type = Optional.of(type.get()); - } - return this; - } - - /** - *

ID of the affected transfer_order.

- */ - @JsonSetter(value = "id", nulls = Nulls.SKIP) - public Builder id(Optional id) { - this.id = id; - return this; - } - - public Builder id(String id) { - this.id = Optional.ofNullable(id); - return this; - } - - /** - *

Is true if the affected object was deleted. Otherwise absent.

- */ - @JsonSetter(value = "deleted", nulls = Nulls.SKIP) - public Builder deleted(Optional deleted) { - this.deleted = deleted; - return this; - } - - public Builder deleted(Boolean deleted) { - this.deleted = Optional.ofNullable(deleted); - return this; - } - - public Builder deleted(Nullable deleted) { - if (deleted.isNull()) { - this.deleted = null; - } else if (deleted.isEmpty()) { - this.deleted = Optional.empty(); - } else { - this.deleted = Optional.of(deleted.get()); - } - return this; - } - - public TransferOrderDeletedEventData build() { - return new TransferOrderDeletedEventData(type, id, deleted, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/TransferOrderFilter.java b/src/main/java/com/squareup/square/types/TransferOrderFilter.java deleted file mode 100644 index 2e1c52ce..00000000 --- a/src/main/java/com/squareup/square/types/TransferOrderFilter.java +++ /dev/null @@ -1,229 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.Nullable; -import com.squareup.square.core.NullableNonemptyFilter; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = TransferOrderFilter.Builder.class) -public final class TransferOrderFilter { - private final Optional> sourceLocationIds; - - private final Optional> destinationLocationIds; - - private final Optional> statuses; - - private final Map additionalProperties; - - private TransferOrderFilter( - Optional> sourceLocationIds, - Optional> destinationLocationIds, - Optional> statuses, - Map additionalProperties) { - this.sourceLocationIds = sourceLocationIds; - this.destinationLocationIds = destinationLocationIds; - this.statuses = statuses; - this.additionalProperties = additionalProperties; - } - - /** - * @return Filter by source location IDs - */ - @JsonIgnore - public Optional> getSourceLocationIds() { - if (sourceLocationIds == null) { - return Optional.empty(); - } - return sourceLocationIds; - } - - /** - * @return Filter by destination location IDs - */ - @JsonIgnore - public Optional> getDestinationLocationIds() { - if (destinationLocationIds == null) { - return Optional.empty(); - } - return destinationLocationIds; - } - - /** - * @return Filter by order statuses - * See TransferOrderStatus for possible values - */ - @JsonIgnore - public Optional> getStatuses() { - if (statuses == null) { - return Optional.empty(); - } - return statuses; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("source_location_ids") - private Optional> _getSourceLocationIds() { - return sourceLocationIds; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("destination_location_ids") - private Optional> _getDestinationLocationIds() { - return destinationLocationIds; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("statuses") - private Optional> _getStatuses() { - return statuses; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof TransferOrderFilter && equalTo((TransferOrderFilter) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(TransferOrderFilter other) { - return sourceLocationIds.equals(other.sourceLocationIds) - && destinationLocationIds.equals(other.destinationLocationIds) - && statuses.equals(other.statuses); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.sourceLocationIds, this.destinationLocationIds, this.statuses); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional> sourceLocationIds = Optional.empty(); - - private Optional> destinationLocationIds = Optional.empty(); - - private Optional> statuses = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(TransferOrderFilter other) { - sourceLocationIds(other.getSourceLocationIds()); - destinationLocationIds(other.getDestinationLocationIds()); - statuses(other.getStatuses()); - return this; - } - - /** - *

Filter by source location IDs

- */ - @JsonSetter(value = "source_location_ids", nulls = Nulls.SKIP) - public Builder sourceLocationIds(Optional> sourceLocationIds) { - this.sourceLocationIds = sourceLocationIds; - return this; - } - - public Builder sourceLocationIds(List sourceLocationIds) { - this.sourceLocationIds = Optional.ofNullable(sourceLocationIds); - return this; - } - - public Builder sourceLocationIds(Nullable> sourceLocationIds) { - if (sourceLocationIds.isNull()) { - this.sourceLocationIds = null; - } else if (sourceLocationIds.isEmpty()) { - this.sourceLocationIds = Optional.empty(); - } else { - this.sourceLocationIds = Optional.of(sourceLocationIds.get()); - } - return this; - } - - /** - *

Filter by destination location IDs

- */ - @JsonSetter(value = "destination_location_ids", nulls = Nulls.SKIP) - public Builder destinationLocationIds(Optional> destinationLocationIds) { - this.destinationLocationIds = destinationLocationIds; - return this; - } - - public Builder destinationLocationIds(List destinationLocationIds) { - this.destinationLocationIds = Optional.ofNullable(destinationLocationIds); - return this; - } - - public Builder destinationLocationIds(Nullable> destinationLocationIds) { - if (destinationLocationIds.isNull()) { - this.destinationLocationIds = null; - } else if (destinationLocationIds.isEmpty()) { - this.destinationLocationIds = Optional.empty(); - } else { - this.destinationLocationIds = Optional.of(destinationLocationIds.get()); - } - return this; - } - - /** - *

Filter by order statuses - * See TransferOrderStatus for possible values

- */ - @JsonSetter(value = "statuses", nulls = Nulls.SKIP) - public Builder statuses(Optional> statuses) { - this.statuses = statuses; - return this; - } - - public Builder statuses(List statuses) { - this.statuses = Optional.ofNullable(statuses); - return this; - } - - public Builder statuses(Nullable> statuses) { - if (statuses.isNull()) { - this.statuses = null; - } else if (statuses.isEmpty()) { - this.statuses = Optional.empty(); - } else { - this.statuses = Optional.of(statuses.get()); - } - return this; - } - - public TransferOrderFilter build() { - return new TransferOrderFilter(sourceLocationIds, destinationLocationIds, statuses, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/TransferOrderGoodsReceipt.java b/src/main/java/com/squareup/square/types/TransferOrderGoodsReceipt.java deleted file mode 100644 index d9474aba..00000000 --- a/src/main/java/com/squareup/square/types/TransferOrderGoodsReceipt.java +++ /dev/null @@ -1,152 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.Nullable; -import com.squareup.square.core.NullableNonemptyFilter; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = TransferOrderGoodsReceipt.Builder.class) -public final class TransferOrderGoodsReceipt { - private final Optional> lineItems; - - private final Map additionalProperties; - - private TransferOrderGoodsReceipt( - Optional> lineItems, Map additionalProperties) { - this.lineItems = lineItems; - this.additionalProperties = additionalProperties; - } - - /** - * @return Line items being received. Each line item specifies: - *
    - *
  • The item being received
  • - *
  • Quantity received in good condition
  • - *
  • Quantity received damaged
  • - *
  • Quantity canceled
  • - *
- *

Constraints:

- *
    - *
  • Must include at least one line item
  • - *
  • Maximum of 1000 line items per receipt
  • - *
  • Each line item must reference a valid item from the transfer order
  • - *
  • Total of received, damaged, and canceled quantities cannot exceed ordered quantity
  • - *
- */ - @JsonIgnore - public Optional> getLineItems() { - if (lineItems == null) { - return Optional.empty(); - } - return lineItems; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("line_items") - private Optional> _getLineItems() { - return lineItems; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof TransferOrderGoodsReceipt && equalTo((TransferOrderGoodsReceipt) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(TransferOrderGoodsReceipt other) { - return lineItems.equals(other.lineItems); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.lineItems); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional> lineItems = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(TransferOrderGoodsReceipt other) { - lineItems(other.getLineItems()); - return this; - } - - /** - *

Line items being received. Each line item specifies:

- *
    - *
  • The item being received
  • - *
  • Quantity received in good condition
  • - *
  • Quantity received damaged
  • - *
  • Quantity canceled
  • - *
- *

Constraints:

- *
    - *
  • Must include at least one line item
  • - *
  • Maximum of 1000 line items per receipt
  • - *
  • Each line item must reference a valid item from the transfer order
  • - *
  • Total of received, damaged, and canceled quantities cannot exceed ordered quantity
  • - *
- */ - @JsonSetter(value = "line_items", nulls = Nulls.SKIP) - public Builder lineItems(Optional> lineItems) { - this.lineItems = lineItems; - return this; - } - - public Builder lineItems(List lineItems) { - this.lineItems = Optional.ofNullable(lineItems); - return this; - } - - public Builder lineItems(Nullable> lineItems) { - if (lineItems.isNull()) { - this.lineItems = null; - } else if (lineItems.isEmpty()) { - this.lineItems = Optional.empty(); - } else { - this.lineItems = Optional.of(lineItems.get()); - } - return this; - } - - public TransferOrderGoodsReceipt build() { - return new TransferOrderGoodsReceipt(lineItems, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/TransferOrderGoodsReceiptLineItem.java b/src/main/java/com/squareup/square/types/TransferOrderGoodsReceiptLineItem.java deleted file mode 100644 index 8b777afa..00000000 --- a/src/main/java/com/squareup/square/types/TransferOrderGoodsReceiptLineItem.java +++ /dev/null @@ -1,343 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.Nullable; -import com.squareup.square.core.NullableNonemptyFilter; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import org.jetbrains.annotations.NotNull; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = TransferOrderGoodsReceiptLineItem.Builder.class) -public final class TransferOrderGoodsReceiptLineItem { - private final String transferOrderLineUid; - - private final Optional quantityReceived; - - private final Optional quantityDamaged; - - private final Optional quantityCanceled; - - private final Map additionalProperties; - - private TransferOrderGoodsReceiptLineItem( - String transferOrderLineUid, - Optional quantityReceived, - Optional quantityDamaged, - Optional quantityCanceled, - Map additionalProperties) { - this.transferOrderLineUid = transferOrderLineUid; - this.quantityReceived = quantityReceived; - this.quantityDamaged = quantityDamaged; - this.quantityCanceled = quantityCanceled; - this.additionalProperties = additionalProperties; - } - - /** - * @return The unique identifier of the Transfer Order line being received - */ - @JsonProperty("transfer_order_line_uid") - public String getTransferOrderLineUid() { - return transferOrderLineUid; - } - - /** - * @return The quantity received for this line item as a decimal string (e.g. "10.5"). - * These items will be added to the destination Location's inventory with InventoryState of IN_STOCK. - */ - @JsonIgnore - public Optional getQuantityReceived() { - if (quantityReceived == null) { - return Optional.empty(); - } - return quantityReceived; - } - - /** - * @return The quantity that was damaged during shipping/handling as a decimal string (e.g. "1.5"). - * These items will be added to the destination Location's inventory with InventoryState of WASTE. - */ - @JsonIgnore - public Optional getQuantityDamaged() { - if (quantityDamaged == null) { - return Optional.empty(); - } - return quantityDamaged; - } - - /** - * @return The quantity that was canceled during shipping/handling as a decimal string (e.g. "1.5"). These will be immediately added to inventory in the source location. - */ - @JsonIgnore - public Optional getQuantityCanceled() { - if (quantityCanceled == null) { - return Optional.empty(); - } - return quantityCanceled; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("quantity_received") - private Optional _getQuantityReceived() { - return quantityReceived; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("quantity_damaged") - private Optional _getQuantityDamaged() { - return quantityDamaged; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("quantity_canceled") - private Optional _getQuantityCanceled() { - return quantityCanceled; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof TransferOrderGoodsReceiptLineItem && equalTo((TransferOrderGoodsReceiptLineItem) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(TransferOrderGoodsReceiptLineItem other) { - return transferOrderLineUid.equals(other.transferOrderLineUid) - && quantityReceived.equals(other.quantityReceived) - && quantityDamaged.equals(other.quantityDamaged) - && quantityCanceled.equals(other.quantityCanceled); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash( - this.transferOrderLineUid, this.quantityReceived, this.quantityDamaged, this.quantityCanceled); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static TransferOrderLineUidStage builder() { - return new Builder(); - } - - public interface TransferOrderLineUidStage { - /** - *

The unique identifier of the Transfer Order line being received

- */ - _FinalStage transferOrderLineUid(@NotNull String transferOrderLineUid); - - Builder from(TransferOrderGoodsReceiptLineItem other); - } - - public interface _FinalStage { - TransferOrderGoodsReceiptLineItem build(); - - /** - *

The quantity received for this line item as a decimal string (e.g. "10.5"). - * These items will be added to the destination Location's inventory with InventoryState of IN_STOCK.

- */ - _FinalStage quantityReceived(Optional quantityReceived); - - _FinalStage quantityReceived(String quantityReceived); - - _FinalStage quantityReceived(Nullable quantityReceived); - - /** - *

The quantity that was damaged during shipping/handling as a decimal string (e.g. "1.5"). - * These items will be added to the destination Location's inventory with InventoryState of WASTE.

- */ - _FinalStage quantityDamaged(Optional quantityDamaged); - - _FinalStage quantityDamaged(String quantityDamaged); - - _FinalStage quantityDamaged(Nullable quantityDamaged); - - /** - *

The quantity that was canceled during shipping/handling as a decimal string (e.g. "1.5"). These will be immediately added to inventory in the source location.

- */ - _FinalStage quantityCanceled(Optional quantityCanceled); - - _FinalStage quantityCanceled(String quantityCanceled); - - _FinalStage quantityCanceled(Nullable quantityCanceled); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder implements TransferOrderLineUidStage, _FinalStage { - private String transferOrderLineUid; - - private Optional quantityCanceled = Optional.empty(); - - private Optional quantityDamaged = Optional.empty(); - - private Optional quantityReceived = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - @java.lang.Override - public Builder from(TransferOrderGoodsReceiptLineItem other) { - transferOrderLineUid(other.getTransferOrderLineUid()); - quantityReceived(other.getQuantityReceived()); - quantityDamaged(other.getQuantityDamaged()); - quantityCanceled(other.getQuantityCanceled()); - return this; - } - - /** - *

The unique identifier of the Transfer Order line being received

- *

The unique identifier of the Transfer Order line being received

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - @JsonSetter("transfer_order_line_uid") - public _FinalStage transferOrderLineUid(@NotNull String transferOrderLineUid) { - this.transferOrderLineUid = - Objects.requireNonNull(transferOrderLineUid, "transferOrderLineUid must not be null"); - return this; - } - - /** - *

The quantity that was canceled during shipping/handling as a decimal string (e.g. "1.5"). These will be immediately added to inventory in the source location.

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - public _FinalStage quantityCanceled(Nullable quantityCanceled) { - if (quantityCanceled.isNull()) { - this.quantityCanceled = null; - } else if (quantityCanceled.isEmpty()) { - this.quantityCanceled = Optional.empty(); - } else { - this.quantityCanceled = Optional.of(quantityCanceled.get()); - } - return this; - } - - /** - *

The quantity that was canceled during shipping/handling as a decimal string (e.g. "1.5"). These will be immediately added to inventory in the source location.

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - public _FinalStage quantityCanceled(String quantityCanceled) { - this.quantityCanceled = Optional.ofNullable(quantityCanceled); - return this; - } - - /** - *

The quantity that was canceled during shipping/handling as a decimal string (e.g. "1.5"). These will be immediately added to inventory in the source location.

- */ - @java.lang.Override - @JsonSetter(value = "quantity_canceled", nulls = Nulls.SKIP) - public _FinalStage quantityCanceled(Optional quantityCanceled) { - this.quantityCanceled = quantityCanceled; - return this; - } - - /** - *

The quantity that was damaged during shipping/handling as a decimal string (e.g. "1.5"). - * These items will be added to the destination Location's inventory with InventoryState of WASTE.

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - public _FinalStage quantityDamaged(Nullable quantityDamaged) { - if (quantityDamaged.isNull()) { - this.quantityDamaged = null; - } else if (quantityDamaged.isEmpty()) { - this.quantityDamaged = Optional.empty(); - } else { - this.quantityDamaged = Optional.of(quantityDamaged.get()); - } - return this; - } - - /** - *

The quantity that was damaged during shipping/handling as a decimal string (e.g. "1.5"). - * These items will be added to the destination Location's inventory with InventoryState of WASTE.

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - public _FinalStage quantityDamaged(String quantityDamaged) { - this.quantityDamaged = Optional.ofNullable(quantityDamaged); - return this; - } - - /** - *

The quantity that was damaged during shipping/handling as a decimal string (e.g. "1.5"). - * These items will be added to the destination Location's inventory with InventoryState of WASTE.

- */ - @java.lang.Override - @JsonSetter(value = "quantity_damaged", nulls = Nulls.SKIP) - public _FinalStage quantityDamaged(Optional quantityDamaged) { - this.quantityDamaged = quantityDamaged; - return this; - } - - /** - *

The quantity received for this line item as a decimal string (e.g. "10.5"). - * These items will be added to the destination Location's inventory with InventoryState of IN_STOCK.

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - public _FinalStage quantityReceived(Nullable quantityReceived) { - if (quantityReceived.isNull()) { - this.quantityReceived = null; - } else if (quantityReceived.isEmpty()) { - this.quantityReceived = Optional.empty(); - } else { - this.quantityReceived = Optional.of(quantityReceived.get()); - } - return this; - } - - /** - *

The quantity received for this line item as a decimal string (e.g. "10.5"). - * These items will be added to the destination Location's inventory with InventoryState of IN_STOCK.

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - public _FinalStage quantityReceived(String quantityReceived) { - this.quantityReceived = Optional.ofNullable(quantityReceived); - return this; - } - - /** - *

The quantity received for this line item as a decimal string (e.g. "10.5"). - * These items will be added to the destination Location's inventory with InventoryState of IN_STOCK.

- */ - @java.lang.Override - @JsonSetter(value = "quantity_received", nulls = Nulls.SKIP) - public _FinalStage quantityReceived(Optional quantityReceived) { - this.quantityReceived = quantityReceived; - return this; - } - - @java.lang.Override - public TransferOrderGoodsReceiptLineItem build() { - return new TransferOrderGoodsReceiptLineItem( - transferOrderLineUid, quantityReceived, quantityDamaged, quantityCanceled, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/TransferOrderLine.java b/src/main/java/com/squareup/square/types/TransferOrderLine.java deleted file mode 100644 index 11ba0959..00000000 --- a/src/main/java/com/squareup/square/types/TransferOrderLine.java +++ /dev/null @@ -1,410 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import org.jetbrains.annotations.NotNull; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = TransferOrderLine.Builder.class) -public final class TransferOrderLine { - private final Optional uid; - - private final String itemVariationId; - - private final String quantityOrdered; - - private final Optional quantityPending; - - private final Optional quantityReceived; - - private final Optional quantityDamaged; - - private final Optional quantityCanceled; - - private final Map additionalProperties; - - private TransferOrderLine( - Optional uid, - String itemVariationId, - String quantityOrdered, - Optional quantityPending, - Optional quantityReceived, - Optional quantityDamaged, - Optional quantityCanceled, - Map additionalProperties) { - this.uid = uid; - this.itemVariationId = itemVariationId; - this.quantityOrdered = quantityOrdered; - this.quantityPending = quantityPending; - this.quantityReceived = quantityReceived; - this.quantityDamaged = quantityDamaged; - this.quantityCanceled = quantityCanceled; - this.additionalProperties = additionalProperties; - } - - /** - * @return Unique system-generated identifier for the line item. Provide when updating/removing a line via UpdateTransferOrder. - */ - @JsonProperty("uid") - public Optional getUid() { - return uid; - } - - /** - * @return The required identifier of the CatalogItemVariation being transferred. Must reference - * a valid catalog item variation that exists in the Catalog. - */ - @JsonProperty("item_variation_id") - public String getItemVariationId() { - return itemVariationId; - } - - /** - * @return Total quantity ordered, formatted as a decimal string (e.g. "10 or 10.0000"). Required to be a positive number. - *

To remove a line item, set remove to true in UpdateTransferOrder.

- */ - @JsonProperty("quantity_ordered") - public String getQuantityOrdered() { - return quantityOrdered; - } - - /** - * @return Calculated quantity of this line item's yet to be received stock. This is the difference between the total quantity ordered and the sum of quantities received, canceled, and damaged. - */ - @JsonProperty("quantity_pending") - public Optional getQuantityPending() { - return quantityPending; - } - - /** - * @return Quantity received at destination. These items are added to the destination - * Location's inventory with InventoryState of IN_STOCK. - *

This field cannot be updated directly in Create/Update operations, instead use ReceiveTransferOrder.

- */ - @JsonProperty("quantity_received") - public Optional getQuantityReceived() { - return quantityReceived; - } - - /** - * @return Quantity received in damaged condition. These items are added to the destination - * Location's inventory with InventoryState of WASTE. - *

This field cannot be updated directly in Create/Update operations, instead use ReceiveTransferOrder.

- */ - @JsonProperty("quantity_damaged") - public Optional getQuantityDamaged() { - return quantityDamaged; - } - - /** - * @return Quantity that was canceled. These items will be immediately added to inventory in the source location. - *

This field cannot be updated directly in Create/Update operations, instead use ReceiveTransferOrder or CancelTransferOrder.

- */ - @JsonProperty("quantity_canceled") - public Optional getQuantityCanceled() { - return quantityCanceled; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof TransferOrderLine && equalTo((TransferOrderLine) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(TransferOrderLine other) { - return uid.equals(other.uid) - && itemVariationId.equals(other.itemVariationId) - && quantityOrdered.equals(other.quantityOrdered) - && quantityPending.equals(other.quantityPending) - && quantityReceived.equals(other.quantityReceived) - && quantityDamaged.equals(other.quantityDamaged) - && quantityCanceled.equals(other.quantityCanceled); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash( - this.uid, - this.itemVariationId, - this.quantityOrdered, - this.quantityPending, - this.quantityReceived, - this.quantityDamaged, - this.quantityCanceled); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static ItemVariationIdStage builder() { - return new Builder(); - } - - public interface ItemVariationIdStage { - /** - *

The required identifier of the CatalogItemVariation being transferred. Must reference - * a valid catalog item variation that exists in the Catalog.

- */ - QuantityOrderedStage itemVariationId(@NotNull String itemVariationId); - - Builder from(TransferOrderLine other); - } - - public interface QuantityOrderedStage { - /** - *

Total quantity ordered, formatted as a decimal string (e.g. "10 or 10.0000"). Required to be a positive number.

- *

To remove a line item, set remove to true in UpdateTransferOrder.

- */ - _FinalStage quantityOrdered(@NotNull String quantityOrdered); - } - - public interface _FinalStage { - TransferOrderLine build(); - - /** - *

Unique system-generated identifier for the line item. Provide when updating/removing a line via UpdateTransferOrder.

- */ - _FinalStage uid(Optional uid); - - _FinalStage uid(String uid); - - /** - *

Calculated quantity of this line item's yet to be received stock. This is the difference between the total quantity ordered and the sum of quantities received, canceled, and damaged.

- */ - _FinalStage quantityPending(Optional quantityPending); - - _FinalStage quantityPending(String quantityPending); - - /** - *

Quantity received at destination. These items are added to the destination - * Location's inventory with InventoryState of IN_STOCK.

- *

This field cannot be updated directly in Create/Update operations, instead use ReceiveTransferOrder.

- */ - _FinalStage quantityReceived(Optional quantityReceived); - - _FinalStage quantityReceived(String quantityReceived); - - /** - *

Quantity received in damaged condition. These items are added to the destination - * Location's inventory with InventoryState of WASTE.

- *

This field cannot be updated directly in Create/Update operations, instead use ReceiveTransferOrder.

- */ - _FinalStage quantityDamaged(Optional quantityDamaged); - - _FinalStage quantityDamaged(String quantityDamaged); - - /** - *

Quantity that was canceled. These items will be immediately added to inventory in the source location.

- *

This field cannot be updated directly in Create/Update operations, instead use ReceiveTransferOrder or CancelTransferOrder.

- */ - _FinalStage quantityCanceled(Optional quantityCanceled); - - _FinalStage quantityCanceled(String quantityCanceled); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder implements ItemVariationIdStage, QuantityOrderedStage, _FinalStage { - private String itemVariationId; - - private String quantityOrdered; - - private Optional quantityCanceled = Optional.empty(); - - private Optional quantityDamaged = Optional.empty(); - - private Optional quantityReceived = Optional.empty(); - - private Optional quantityPending = Optional.empty(); - - private Optional uid = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - @java.lang.Override - public Builder from(TransferOrderLine other) { - uid(other.getUid()); - itemVariationId(other.getItemVariationId()); - quantityOrdered(other.getQuantityOrdered()); - quantityPending(other.getQuantityPending()); - quantityReceived(other.getQuantityReceived()); - quantityDamaged(other.getQuantityDamaged()); - quantityCanceled(other.getQuantityCanceled()); - return this; - } - - /** - *

The required identifier of the CatalogItemVariation being transferred. Must reference - * a valid catalog item variation that exists in the Catalog.

- *

The required identifier of the CatalogItemVariation being transferred. Must reference - * a valid catalog item variation that exists in the Catalog.

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - @JsonSetter("item_variation_id") - public QuantityOrderedStage itemVariationId(@NotNull String itemVariationId) { - this.itemVariationId = Objects.requireNonNull(itemVariationId, "itemVariationId must not be null"); - return this; - } - - /** - *

Total quantity ordered, formatted as a decimal string (e.g. "10 or 10.0000"). Required to be a positive number.

- *

To remove a line item, set remove to true in UpdateTransferOrder.

- *

Total quantity ordered, formatted as a decimal string (e.g. "10 or 10.0000"). Required to be a positive number.

- *

To remove a line item, set remove to true in UpdateTransferOrder.

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - @JsonSetter("quantity_ordered") - public _FinalStage quantityOrdered(@NotNull String quantityOrdered) { - this.quantityOrdered = Objects.requireNonNull(quantityOrdered, "quantityOrdered must not be null"); - return this; - } - - /** - *

Quantity that was canceled. These items will be immediately added to inventory in the source location.

- *

This field cannot be updated directly in Create/Update operations, instead use ReceiveTransferOrder or CancelTransferOrder.

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - public _FinalStage quantityCanceled(String quantityCanceled) { - this.quantityCanceled = Optional.ofNullable(quantityCanceled); - return this; - } - - /** - *

Quantity that was canceled. These items will be immediately added to inventory in the source location.

- *

This field cannot be updated directly in Create/Update operations, instead use ReceiveTransferOrder or CancelTransferOrder.

- */ - @java.lang.Override - @JsonSetter(value = "quantity_canceled", nulls = Nulls.SKIP) - public _FinalStage quantityCanceled(Optional quantityCanceled) { - this.quantityCanceled = quantityCanceled; - return this; - } - - /** - *

Quantity received in damaged condition. These items are added to the destination - * Location's inventory with InventoryState of WASTE.

- *

This field cannot be updated directly in Create/Update operations, instead use ReceiveTransferOrder.

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - public _FinalStage quantityDamaged(String quantityDamaged) { - this.quantityDamaged = Optional.ofNullable(quantityDamaged); - return this; - } - - /** - *

Quantity received in damaged condition. These items are added to the destination - * Location's inventory with InventoryState of WASTE.

- *

This field cannot be updated directly in Create/Update operations, instead use ReceiveTransferOrder.

- */ - @java.lang.Override - @JsonSetter(value = "quantity_damaged", nulls = Nulls.SKIP) - public _FinalStage quantityDamaged(Optional quantityDamaged) { - this.quantityDamaged = quantityDamaged; - return this; - } - - /** - *

Quantity received at destination. These items are added to the destination - * Location's inventory with InventoryState of IN_STOCK.

- *

This field cannot be updated directly in Create/Update operations, instead use ReceiveTransferOrder.

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - public _FinalStage quantityReceived(String quantityReceived) { - this.quantityReceived = Optional.ofNullable(quantityReceived); - return this; - } - - /** - *

Quantity received at destination. These items are added to the destination - * Location's inventory with InventoryState of IN_STOCK.

- *

This field cannot be updated directly in Create/Update operations, instead use ReceiveTransferOrder.

- */ - @java.lang.Override - @JsonSetter(value = "quantity_received", nulls = Nulls.SKIP) - public _FinalStage quantityReceived(Optional quantityReceived) { - this.quantityReceived = quantityReceived; - return this; - } - - /** - *

Calculated quantity of this line item's yet to be received stock. This is the difference between the total quantity ordered and the sum of quantities received, canceled, and damaged.

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - public _FinalStage quantityPending(String quantityPending) { - this.quantityPending = Optional.ofNullable(quantityPending); - return this; - } - - /** - *

Calculated quantity of this line item's yet to be received stock. This is the difference between the total quantity ordered and the sum of quantities received, canceled, and damaged.

- */ - @java.lang.Override - @JsonSetter(value = "quantity_pending", nulls = Nulls.SKIP) - public _FinalStage quantityPending(Optional quantityPending) { - this.quantityPending = quantityPending; - return this; - } - - /** - *

Unique system-generated identifier for the line item. Provide when updating/removing a line via UpdateTransferOrder.

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - public _FinalStage uid(String uid) { - this.uid = Optional.ofNullable(uid); - return this; - } - - /** - *

Unique system-generated identifier for the line item. Provide when updating/removing a line via UpdateTransferOrder.

- */ - @java.lang.Override - @JsonSetter(value = "uid", nulls = Nulls.SKIP) - public _FinalStage uid(Optional uid) { - this.uid = uid; - return this; - } - - @java.lang.Override - public TransferOrderLine build() { - return new TransferOrderLine( - uid, - itemVariationId, - quantityOrdered, - quantityPending, - quantityReceived, - quantityDamaged, - quantityCanceled, - additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/TransferOrderQuery.java b/src/main/java/com/squareup/square/types/TransferOrderQuery.java deleted file mode 100644 index 735cffe8..00000000 --- a/src/main/java/com/squareup/square/types/TransferOrderQuery.java +++ /dev/null @@ -1,132 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = TransferOrderQuery.Builder.class) -public final class TransferOrderQuery { - private final Optional filter; - - private final Optional sort; - - private final Map additionalProperties; - - private TransferOrderQuery( - Optional filter, - Optional sort, - Map additionalProperties) { - this.filter = filter; - this.sort = sort; - this.additionalProperties = additionalProperties; - } - - /** - * @return Filter criteria - */ - @JsonProperty("filter") - public Optional getFilter() { - return filter; - } - - /** - * @return Sort configuration - */ - @JsonProperty("sort") - public Optional getSort() { - return sort; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof TransferOrderQuery && equalTo((TransferOrderQuery) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(TransferOrderQuery other) { - return filter.equals(other.filter) && sort.equals(other.sort); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.filter, this.sort); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional filter = Optional.empty(); - - private Optional sort = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(TransferOrderQuery other) { - filter(other.getFilter()); - sort(other.getSort()); - return this; - } - - /** - *

Filter criteria

- */ - @JsonSetter(value = "filter", nulls = Nulls.SKIP) - public Builder filter(Optional filter) { - this.filter = filter; - return this; - } - - public Builder filter(TransferOrderFilter filter) { - this.filter = Optional.ofNullable(filter); - return this; - } - - /** - *

Sort configuration

- */ - @JsonSetter(value = "sort", nulls = Nulls.SKIP) - public Builder sort(Optional sort) { - this.sort = sort; - return this; - } - - public Builder sort(TransferOrderSort sort) { - this.sort = Optional.ofNullable(sort); - return this; - } - - public TransferOrderQuery build() { - return new TransferOrderQuery(filter, sort, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/TransferOrderSort.java b/src/main/java/com/squareup/square/types/TransferOrderSort.java deleted file mode 100644 index 748a3763..00000000 --- a/src/main/java/com/squareup/square/types/TransferOrderSort.java +++ /dev/null @@ -1,136 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = TransferOrderSort.Builder.class) -public final class TransferOrderSort { - private final Optional field; - - private final Optional order; - - private final Map additionalProperties; - - private TransferOrderSort( - Optional field, - Optional order, - Map additionalProperties) { - this.field = field; - this.order = order; - this.additionalProperties = additionalProperties; - } - - /** - * @return Field to sort by - * See TransferOrderSortField for possible values - */ - @JsonProperty("field") - public Optional getField() { - return field; - } - - /** - * @return Sort order direction - * See SortOrder for possible values - */ - @JsonProperty("order") - public Optional getOrder() { - return order; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof TransferOrderSort && equalTo((TransferOrderSort) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(TransferOrderSort other) { - return field.equals(other.field) && order.equals(other.order); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.field, this.order); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional field = Optional.empty(); - - private Optional order = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(TransferOrderSort other) { - field(other.getField()); - order(other.getOrder()); - return this; - } - - /** - *

Field to sort by - * See TransferOrderSortField for possible values

- */ - @JsonSetter(value = "field", nulls = Nulls.SKIP) - public Builder field(Optional field) { - this.field = field; - return this; - } - - public Builder field(TransferOrderSortField field) { - this.field = Optional.ofNullable(field); - return this; - } - - /** - *

Sort order direction - * See SortOrder for possible values

- */ - @JsonSetter(value = "order", nulls = Nulls.SKIP) - public Builder order(Optional order) { - this.order = order; - return this; - } - - public Builder order(SortOrder order) { - this.order = Optional.ofNullable(order); - return this; - } - - public TransferOrderSort build() { - return new TransferOrderSort(field, order, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/TransferOrderSortField.java b/src/main/java/com/squareup/square/types/TransferOrderSortField.java deleted file mode 100644 index 37061f51..00000000 --- a/src/main/java/com/squareup/square/types/TransferOrderSortField.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -public final class TransferOrderSortField { - public static final TransferOrderSortField UPDATED_AT = new TransferOrderSortField(Value.UPDATED_AT, "UPDATED_AT"); - - public static final TransferOrderSortField CREATED_AT = new TransferOrderSortField(Value.CREATED_AT, "CREATED_AT"); - - private final Value value; - - private final String string; - - TransferOrderSortField(Value value, String string) { - this.value = value; - this.string = string; - } - - public Value getEnumValue() { - return value; - } - - @java.lang.Override - @JsonValue - public String toString() { - return this.string; - } - - @java.lang.Override - public boolean equals(Object other) { - return (this == other) - || (other instanceof TransferOrderSortField - && this.string.equals(((TransferOrderSortField) other).string)); - } - - @java.lang.Override - public int hashCode() { - return this.string.hashCode(); - } - - public T visit(Visitor visitor) { - switch (value) { - case UPDATED_AT: - return visitor.visitUpdatedAt(); - case CREATED_AT: - return visitor.visitCreatedAt(); - case UNKNOWN: - default: - return visitor.visitUnknown(string); - } - } - - @JsonCreator(mode = JsonCreator.Mode.DELEGATING) - public static TransferOrderSortField valueOf(String value) { - switch (value) { - case "UPDATED_AT": - return UPDATED_AT; - case "CREATED_AT": - return CREATED_AT; - default: - return new TransferOrderSortField(Value.UNKNOWN, value); - } - } - - public enum Value { - CREATED_AT, - - UPDATED_AT, - - UNKNOWN - } - - public interface Visitor { - T visitCreatedAt(); - - T visitUpdatedAt(); - - T visitUnknown(String unknownType); - } -} diff --git a/src/main/java/com/squareup/square/types/TransferOrderStatus.java b/src/main/java/com/squareup/square/types/TransferOrderStatus.java deleted file mode 100644 index 2cc6285a..00000000 --- a/src/main/java/com/squareup/square/types/TransferOrderStatus.java +++ /dev/null @@ -1,114 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -public final class TransferOrderStatus { - public static final TransferOrderStatus CANCELED = new TransferOrderStatus(Value.CANCELED, "CANCELED"); - - public static final TransferOrderStatus PARTIALLY_RECEIVED = - new TransferOrderStatus(Value.PARTIALLY_RECEIVED, "PARTIALLY_RECEIVED"); - - public static final TransferOrderStatus STARTED = new TransferOrderStatus(Value.STARTED, "STARTED"); - - public static final TransferOrderStatus DRAFT = new TransferOrderStatus(Value.DRAFT, "DRAFT"); - - public static final TransferOrderStatus COMPLETED = new TransferOrderStatus(Value.COMPLETED, "COMPLETED"); - - private final Value value; - - private final String string; - - TransferOrderStatus(Value value, String string) { - this.value = value; - this.string = string; - } - - public Value getEnumValue() { - return value; - } - - @java.lang.Override - @JsonValue - public String toString() { - return this.string; - } - - @java.lang.Override - public boolean equals(Object other) { - return (this == other) - || (other instanceof TransferOrderStatus && this.string.equals(((TransferOrderStatus) other).string)); - } - - @java.lang.Override - public int hashCode() { - return this.string.hashCode(); - } - - public T visit(Visitor visitor) { - switch (value) { - case CANCELED: - return visitor.visitCanceled(); - case PARTIALLY_RECEIVED: - return visitor.visitPartiallyReceived(); - case STARTED: - return visitor.visitStarted(); - case DRAFT: - return visitor.visitDraft(); - case COMPLETED: - return visitor.visitCompleted(); - case UNKNOWN: - default: - return visitor.visitUnknown(string); - } - } - - @JsonCreator(mode = JsonCreator.Mode.DELEGATING) - public static TransferOrderStatus valueOf(String value) { - switch (value) { - case "CANCELED": - return CANCELED; - case "PARTIALLY_RECEIVED": - return PARTIALLY_RECEIVED; - case "STARTED": - return STARTED; - case "DRAFT": - return DRAFT; - case "COMPLETED": - return COMPLETED; - default: - return new TransferOrderStatus(Value.UNKNOWN, value); - } - } - - public enum Value { - DRAFT, - - STARTED, - - PARTIALLY_RECEIVED, - - COMPLETED, - - CANCELED, - - UNKNOWN - } - - public interface Visitor { - T visitDraft(); - - T visitStarted(); - - T visitPartiallyReceived(); - - T visitCompleted(); - - T visitCanceled(); - - T visitUnknown(String unknownType); - } -} diff --git a/src/main/java/com/squareup/square/types/TransferOrderUpdatedEvent.java b/src/main/java/com/squareup/square/types/TransferOrderUpdatedEvent.java deleted file mode 100644 index f87698f0..00000000 --- a/src/main/java/com/squareup/square/types/TransferOrderUpdatedEvent.java +++ /dev/null @@ -1,286 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.Nullable; -import com.squareup.square.core.NullableNonemptyFilter; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = TransferOrderUpdatedEvent.Builder.class) -public final class TransferOrderUpdatedEvent { - private final Optional merchantId; - - private final Optional type; - - private final Optional eventId; - - private final Optional createdAt; - - private final Optional data; - - private final Map additionalProperties; - - private TransferOrderUpdatedEvent( - Optional merchantId, - Optional type, - Optional eventId, - Optional createdAt, - Optional data, - Map additionalProperties) { - this.merchantId = merchantId; - this.type = type; - this.eventId = eventId; - this.createdAt = createdAt; - this.data = data; - this.additionalProperties = additionalProperties; - } - - /** - * @return The ID of the target merchant associated with the event. - */ - @JsonIgnore - public Optional getMerchantId() { - if (merchantId == null) { - return Optional.empty(); - } - return merchantId; - } - - /** - * @return The type of event this represents, "transfer_order.updated". - */ - @JsonIgnore - public Optional getType() { - if (type == null) { - return Optional.empty(); - } - return type; - } - - /** - * @return A unique ID for the event. - */ - @JsonIgnore - public Optional getEventId() { - if (eventId == null) { - return Optional.empty(); - } - return eventId; - } - - /** - * @return Timestamp of when the event was created, in RFC 3339 format. - */ - @JsonProperty("created_at") - public Optional getCreatedAt() { - return createdAt; - } - - /** - * @return Data associated with the event. - */ - @JsonProperty("data") - public Optional getData() { - return data; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("merchant_id") - private Optional _getMerchantId() { - return merchantId; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("type") - private Optional _getType() { - return type; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("event_id") - private Optional _getEventId() { - return eventId; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof TransferOrderUpdatedEvent && equalTo((TransferOrderUpdatedEvent) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(TransferOrderUpdatedEvent other) { - return merchantId.equals(other.merchantId) - && type.equals(other.type) - && eventId.equals(other.eventId) - && createdAt.equals(other.createdAt) - && data.equals(other.data); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.merchantId, this.type, this.eventId, this.createdAt, this.data); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional merchantId = Optional.empty(); - - private Optional type = Optional.empty(); - - private Optional eventId = Optional.empty(); - - private Optional createdAt = Optional.empty(); - - private Optional data = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(TransferOrderUpdatedEvent other) { - merchantId(other.getMerchantId()); - type(other.getType()); - eventId(other.getEventId()); - createdAt(other.getCreatedAt()); - data(other.getData()); - return this; - } - - /** - *

The ID of the target merchant associated with the event.

- */ - @JsonSetter(value = "merchant_id", nulls = Nulls.SKIP) - public Builder merchantId(Optional merchantId) { - this.merchantId = merchantId; - return this; - } - - public Builder merchantId(String merchantId) { - this.merchantId = Optional.ofNullable(merchantId); - return this; - } - - public Builder merchantId(Nullable merchantId) { - if (merchantId.isNull()) { - this.merchantId = null; - } else if (merchantId.isEmpty()) { - this.merchantId = Optional.empty(); - } else { - this.merchantId = Optional.of(merchantId.get()); - } - return this; - } - - /** - *

The type of event this represents, "transfer_order.updated".

- */ - @JsonSetter(value = "type", nulls = Nulls.SKIP) - public Builder type(Optional type) { - this.type = type; - return this; - } - - public Builder type(String type) { - this.type = Optional.ofNullable(type); - return this; - } - - public Builder type(Nullable type) { - if (type.isNull()) { - this.type = null; - } else if (type.isEmpty()) { - this.type = Optional.empty(); - } else { - this.type = Optional.of(type.get()); - } - return this; - } - - /** - *

A unique ID for the event.

- */ - @JsonSetter(value = "event_id", nulls = Nulls.SKIP) - public Builder eventId(Optional eventId) { - this.eventId = eventId; - return this; - } - - public Builder eventId(String eventId) { - this.eventId = Optional.ofNullable(eventId); - return this; - } - - public Builder eventId(Nullable eventId) { - if (eventId.isNull()) { - this.eventId = null; - } else if (eventId.isEmpty()) { - this.eventId = Optional.empty(); - } else { - this.eventId = Optional.of(eventId.get()); - } - return this; - } - - /** - *

Timestamp of when the event was created, in RFC 3339 format.

- */ - @JsonSetter(value = "created_at", nulls = Nulls.SKIP) - public Builder createdAt(Optional createdAt) { - this.createdAt = createdAt; - return this; - } - - public Builder createdAt(String createdAt) { - this.createdAt = Optional.ofNullable(createdAt); - return this; - } - - /** - *

Data associated with the event.

- */ - @JsonSetter(value = "data", nulls = Nulls.SKIP) - public Builder data(Optional data) { - this.data = data; - return this; - } - - public Builder data(TransferOrderUpdatedEventData data) { - this.data = Optional.ofNullable(data); - return this; - } - - public TransferOrderUpdatedEvent build() { - return new TransferOrderUpdatedEvent(merchantId, type, eventId, createdAt, data, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/TransferOrderUpdatedEventData.java b/src/main/java/com/squareup/square/types/TransferOrderUpdatedEventData.java deleted file mode 100644 index b2ee5242..00000000 --- a/src/main/java/com/squareup/square/types/TransferOrderUpdatedEventData.java +++ /dev/null @@ -1,184 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.Nullable; -import com.squareup.square.core.NullableNonemptyFilter; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = TransferOrderUpdatedEventData.Builder.class) -public final class TransferOrderUpdatedEventData { - private final Optional type; - - private final Optional id; - - private final Optional object; - - private final Map additionalProperties; - - private TransferOrderUpdatedEventData( - Optional type, - Optional id, - Optional object, - Map additionalProperties) { - this.type = type; - this.id = id; - this.object = object; - this.additionalProperties = additionalProperties; - } - - /** - * @return Name of the affected object’s type, "transfer_order". - */ - @JsonIgnore - public Optional getType() { - if (type == null) { - return Optional.empty(); - } - return type; - } - - /** - * @return ID of the affected transfer_order. - */ - @JsonProperty("id") - public Optional getId() { - return id; - } - - /** - * @return An object containing the updated transfer_order. - */ - @JsonProperty("object") - public Optional getObject() { - return object; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("type") - private Optional _getType() { - return type; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof TransferOrderUpdatedEventData && equalTo((TransferOrderUpdatedEventData) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(TransferOrderUpdatedEventData other) { - return type.equals(other.type) && id.equals(other.id) && object.equals(other.object); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.type, this.id, this.object); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional type = Optional.empty(); - - private Optional id = Optional.empty(); - - private Optional object = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(TransferOrderUpdatedEventData other) { - type(other.getType()); - id(other.getId()); - object(other.getObject()); - return this; - } - - /** - *

Name of the affected object’s type, "transfer_order".

- */ - @JsonSetter(value = "type", nulls = Nulls.SKIP) - public Builder type(Optional type) { - this.type = type; - return this; - } - - public Builder type(String type) { - this.type = Optional.ofNullable(type); - return this; - } - - public Builder type(Nullable type) { - if (type.isNull()) { - this.type = null; - } else if (type.isEmpty()) { - this.type = Optional.empty(); - } else { - this.type = Optional.of(type.get()); - } - return this; - } - - /** - *

ID of the affected transfer_order.

- */ - @JsonSetter(value = "id", nulls = Nulls.SKIP) - public Builder id(Optional id) { - this.id = id; - return this; - } - - public Builder id(String id) { - this.id = Optional.ofNullable(id); - return this; - } - - /** - *

An object containing the updated transfer_order.

- */ - @JsonSetter(value = "object", nulls = Nulls.SKIP) - public Builder object(Optional object) { - this.object = object; - return this; - } - - public Builder object(TransferOrderUpdatedEventObject object) { - this.object = Optional.ofNullable(object); - return this; - } - - public TransferOrderUpdatedEventData build() { - return new TransferOrderUpdatedEventData(type, id, object, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/TransferOrderUpdatedEventObject.java b/src/main/java/com/squareup/square/types/TransferOrderUpdatedEventObject.java deleted file mode 100644 index 9ee30429..00000000 --- a/src/main/java/com/squareup/square/types/TransferOrderUpdatedEventObject.java +++ /dev/null @@ -1,102 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = TransferOrderUpdatedEventObject.Builder.class) -public final class TransferOrderUpdatedEventObject { - private final Optional transferOrder; - - private final Map additionalProperties; - - private TransferOrderUpdatedEventObject( - Optional transferOrder, Map additionalProperties) { - this.transferOrder = transferOrder; - this.additionalProperties = additionalProperties; - } - - /** - * @return The updated transfer_order. - */ - @JsonProperty("transfer_order") - public Optional getTransferOrder() { - return transferOrder; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof TransferOrderUpdatedEventObject && equalTo((TransferOrderUpdatedEventObject) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(TransferOrderUpdatedEventObject other) { - return transferOrder.equals(other.transferOrder); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.transferOrder); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional transferOrder = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(TransferOrderUpdatedEventObject other) { - transferOrder(other.getTransferOrder()); - return this; - } - - /** - *

The updated transfer_order.

- */ - @JsonSetter(value = "transfer_order", nulls = Nulls.SKIP) - public Builder transferOrder(Optional transferOrder) { - this.transferOrder = transferOrder; - return this; - } - - public Builder transferOrder(TransferOrder transferOrder) { - this.transferOrder = Optional.ofNullable(transferOrder); - return this; - } - - public TransferOrderUpdatedEventObject build() { - return new TransferOrderUpdatedEventObject(transferOrder, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/UpdateItemModifierListsRequest.java b/src/main/java/com/squareup/square/types/UpdateItemModifierListsRequest.java index e522ccbb..81adf3fb 100644 --- a/src/main/java/com/squareup/square/types/UpdateItemModifierListsRequest.java +++ b/src/main/java/com/squareup/square/types/UpdateItemModifierListsRequest.java @@ -145,9 +145,7 @@ public Builder from(UpdateItemModifierListsRequest other) { @JsonSetter(value = "item_ids", nulls = Nulls.SKIP) public Builder itemIds(List itemIds) { this.itemIds.clear(); - if (itemIds != null) { - this.itemIds.addAll(itemIds); - } + this.itemIds.addAll(itemIds); return this; } @@ -157,9 +155,7 @@ public Builder addItemIds(String itemIds) { } public Builder addAllItemIds(List itemIds) { - if (itemIds != null) { - this.itemIds.addAll(itemIds); - } + this.itemIds.addAll(itemIds); return this; } diff --git a/src/main/java/com/squareup/square/types/UpdateItemTaxesRequest.java b/src/main/java/com/squareup/square/types/UpdateItemTaxesRequest.java index f329fc23..fd144aca 100644 --- a/src/main/java/com/squareup/square/types/UpdateItemTaxesRequest.java +++ b/src/main/java/com/squareup/square/types/UpdateItemTaxesRequest.java @@ -147,9 +147,7 @@ public Builder from(UpdateItemTaxesRequest other) { @JsonSetter(value = "item_ids", nulls = Nulls.SKIP) public Builder itemIds(List itemIds) { this.itemIds.clear(); - if (itemIds != null) { - this.itemIds.addAll(itemIds); - } + this.itemIds.addAll(itemIds); return this; } @@ -159,9 +157,7 @@ public Builder addItemIds(String itemIds) { } public Builder addAllItemIds(List itemIds) { - if (itemIds != null) { - this.itemIds.addAll(itemIds); - } + this.itemIds.addAll(itemIds); return this; } diff --git a/src/main/java/com/squareup/square/types/UpdateTransferOrderData.java b/src/main/java/com/squareup/square/types/UpdateTransferOrderData.java deleted file mode 100644 index 04b2e88f..00000000 --- a/src/main/java/com/squareup/square/types/UpdateTransferOrderData.java +++ /dev/null @@ -1,394 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.Nullable; -import com.squareup.square.core.NullableNonemptyFilter; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = UpdateTransferOrderData.Builder.class) -public final class UpdateTransferOrderData { - private final Optional sourceLocationId; - - private final Optional destinationLocationId; - - private final Optional expectedAt; - - private final Optional notes; - - private final Optional trackingNumber; - - private final Optional> lineItems; - - private final Map additionalProperties; - - private UpdateTransferOrderData( - Optional sourceLocationId, - Optional destinationLocationId, - Optional expectedAt, - Optional notes, - Optional trackingNumber, - Optional> lineItems, - Map additionalProperties) { - this.sourceLocationId = sourceLocationId; - this.destinationLocationId = destinationLocationId; - this.expectedAt = expectedAt; - this.notes = notes; - this.trackingNumber = trackingNumber; - this.lineItems = lineItems; - this.additionalProperties = additionalProperties; - } - - /** - * @return The source Location that will send the items. Must be an active location - * in your Square account with sufficient inventory of the requested items. - */ - @JsonIgnore - public Optional getSourceLocationId() { - if (sourceLocationId == null) { - return Optional.empty(); - } - return sourceLocationId; - } - - /** - * @return The destination Location that will receive the items. Must be an active location - * in your Square account. - */ - @JsonIgnore - public Optional getDestinationLocationId() { - if (destinationLocationId == null) { - return Optional.empty(); - } - return destinationLocationId; - } - - /** - * @return Expected transfer date in RFC 3339 format (e.g. "2023-10-01T12:00:00Z"). - */ - @JsonIgnore - public Optional getExpectedAt() { - if (expectedAt == null) { - return Optional.empty(); - } - return expectedAt; - } - - /** - * @return Optional notes about the transfer - */ - @JsonIgnore - public Optional getNotes() { - if (notes == null) { - return Optional.empty(); - } - return notes; - } - - /** - * @return Shipment tracking number - */ - @JsonIgnore - public Optional getTrackingNumber() { - if (trackingNumber == null) { - return Optional.empty(); - } - return trackingNumber; - } - - /** - * @return List of items being transferred - */ - @JsonIgnore - public Optional> getLineItems() { - if (lineItems == null) { - return Optional.empty(); - } - return lineItems; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("source_location_id") - private Optional _getSourceLocationId() { - return sourceLocationId; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("destination_location_id") - private Optional _getDestinationLocationId() { - return destinationLocationId; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("expected_at") - private Optional _getExpectedAt() { - return expectedAt; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("notes") - private Optional _getNotes() { - return notes; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("tracking_number") - private Optional _getTrackingNumber() { - return trackingNumber; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("line_items") - private Optional> _getLineItems() { - return lineItems; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof UpdateTransferOrderData && equalTo((UpdateTransferOrderData) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(UpdateTransferOrderData other) { - return sourceLocationId.equals(other.sourceLocationId) - && destinationLocationId.equals(other.destinationLocationId) - && expectedAt.equals(other.expectedAt) - && notes.equals(other.notes) - && trackingNumber.equals(other.trackingNumber) - && lineItems.equals(other.lineItems); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash( - this.sourceLocationId, - this.destinationLocationId, - this.expectedAt, - this.notes, - this.trackingNumber, - this.lineItems); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional sourceLocationId = Optional.empty(); - - private Optional destinationLocationId = Optional.empty(); - - private Optional expectedAt = Optional.empty(); - - private Optional notes = Optional.empty(); - - private Optional trackingNumber = Optional.empty(); - - private Optional> lineItems = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(UpdateTransferOrderData other) { - sourceLocationId(other.getSourceLocationId()); - destinationLocationId(other.getDestinationLocationId()); - expectedAt(other.getExpectedAt()); - notes(other.getNotes()); - trackingNumber(other.getTrackingNumber()); - lineItems(other.getLineItems()); - return this; - } - - /** - *

The source Location that will send the items. Must be an active location - * in your Square account with sufficient inventory of the requested items.

- */ - @JsonSetter(value = "source_location_id", nulls = Nulls.SKIP) - public Builder sourceLocationId(Optional sourceLocationId) { - this.sourceLocationId = sourceLocationId; - return this; - } - - public Builder sourceLocationId(String sourceLocationId) { - this.sourceLocationId = Optional.ofNullable(sourceLocationId); - return this; - } - - public Builder sourceLocationId(Nullable sourceLocationId) { - if (sourceLocationId.isNull()) { - this.sourceLocationId = null; - } else if (sourceLocationId.isEmpty()) { - this.sourceLocationId = Optional.empty(); - } else { - this.sourceLocationId = Optional.of(sourceLocationId.get()); - } - return this; - } - - /** - *

The destination Location that will receive the items. Must be an active location - * in your Square account.

- */ - @JsonSetter(value = "destination_location_id", nulls = Nulls.SKIP) - public Builder destinationLocationId(Optional destinationLocationId) { - this.destinationLocationId = destinationLocationId; - return this; - } - - public Builder destinationLocationId(String destinationLocationId) { - this.destinationLocationId = Optional.ofNullable(destinationLocationId); - return this; - } - - public Builder destinationLocationId(Nullable destinationLocationId) { - if (destinationLocationId.isNull()) { - this.destinationLocationId = null; - } else if (destinationLocationId.isEmpty()) { - this.destinationLocationId = Optional.empty(); - } else { - this.destinationLocationId = Optional.of(destinationLocationId.get()); - } - return this; - } - - /** - *

Expected transfer date in RFC 3339 format (e.g. "2023-10-01T12:00:00Z").

- */ - @JsonSetter(value = "expected_at", nulls = Nulls.SKIP) - public Builder expectedAt(Optional expectedAt) { - this.expectedAt = expectedAt; - return this; - } - - public Builder expectedAt(String expectedAt) { - this.expectedAt = Optional.ofNullable(expectedAt); - return this; - } - - public Builder expectedAt(Nullable expectedAt) { - if (expectedAt.isNull()) { - this.expectedAt = null; - } else if (expectedAt.isEmpty()) { - this.expectedAt = Optional.empty(); - } else { - this.expectedAt = Optional.of(expectedAt.get()); - } - return this; - } - - /** - *

Optional notes about the transfer

- */ - @JsonSetter(value = "notes", nulls = Nulls.SKIP) - public Builder notes(Optional notes) { - this.notes = notes; - return this; - } - - public Builder notes(String notes) { - this.notes = Optional.ofNullable(notes); - return this; - } - - public Builder notes(Nullable notes) { - if (notes.isNull()) { - this.notes = null; - } else if (notes.isEmpty()) { - this.notes = Optional.empty(); - } else { - this.notes = Optional.of(notes.get()); - } - return this; - } - - /** - *

Shipment tracking number

- */ - @JsonSetter(value = "tracking_number", nulls = Nulls.SKIP) - public Builder trackingNumber(Optional trackingNumber) { - this.trackingNumber = trackingNumber; - return this; - } - - public Builder trackingNumber(String trackingNumber) { - this.trackingNumber = Optional.ofNullable(trackingNumber); - return this; - } - - public Builder trackingNumber(Nullable trackingNumber) { - if (trackingNumber.isNull()) { - this.trackingNumber = null; - } else if (trackingNumber.isEmpty()) { - this.trackingNumber = Optional.empty(); - } else { - this.trackingNumber = Optional.of(trackingNumber.get()); - } - return this; - } - - /** - *

List of items being transferred

- */ - @JsonSetter(value = "line_items", nulls = Nulls.SKIP) - public Builder lineItems(Optional> lineItems) { - this.lineItems = lineItems; - return this; - } - - public Builder lineItems(List lineItems) { - this.lineItems = Optional.ofNullable(lineItems); - return this; - } - - public Builder lineItems(Nullable> lineItems) { - if (lineItems.isNull()) { - this.lineItems = null; - } else if (lineItems.isEmpty()) { - this.lineItems = Optional.empty(); - } else { - this.lineItems = Optional.of(lineItems.get()); - } - return this; - } - - public UpdateTransferOrderData build() { - return new UpdateTransferOrderData( - sourceLocationId, - destinationLocationId, - expectedAt, - notes, - trackingNumber, - lineItems, - additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/UpdateTransferOrderLineData.java b/src/main/java/com/squareup/square/types/UpdateTransferOrderLineData.java deleted file mode 100644 index ab1bf4a9..00000000 --- a/src/main/java/com/squareup/square/types/UpdateTransferOrderLineData.java +++ /dev/null @@ -1,278 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.Nullable; -import com.squareup.square.core.NullableNonemptyFilter; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = UpdateTransferOrderLineData.Builder.class) -public final class UpdateTransferOrderLineData { - private final Optional uid; - - private final Optional itemVariationId; - - private final Optional quantityOrdered; - - private final Optional remove; - - private final Map additionalProperties; - - private UpdateTransferOrderLineData( - Optional uid, - Optional itemVariationId, - Optional quantityOrdered, - Optional remove, - Map additionalProperties) { - this.uid = uid; - this.itemVariationId = itemVariationId; - this.quantityOrdered = quantityOrdered; - this.remove = remove; - this.additionalProperties = additionalProperties; - } - - /** - * @return Line item id being updated. Required for updating/removing existing line items, but should not be set for new line items. - */ - @JsonIgnore - public Optional getUid() { - if (uid == null) { - return Optional.empty(); - } - return uid; - } - - /** - * @return Catalog item variation being transferred - *

Required for new line items, but otherwise is not updatable.

- */ - @JsonIgnore - public Optional getItemVariationId() { - if (itemVariationId == null) { - return Optional.empty(); - } - return itemVariationId; - } - - /** - * @return Total quantity ordered - */ - @JsonIgnore - public Optional getQuantityOrdered() { - if (quantityOrdered == null) { - return Optional.empty(); - } - return quantityOrdered; - } - - /** - * @return Flag to remove the line item during update. Must include uid in removal request - */ - @JsonIgnore - public Optional getRemove() { - if (remove == null) { - return Optional.empty(); - } - return remove; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("uid") - private Optional _getUid() { - return uid; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("item_variation_id") - private Optional _getItemVariationId() { - return itemVariationId; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("quantity_ordered") - private Optional _getQuantityOrdered() { - return quantityOrdered; - } - - @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class) - @JsonProperty("remove") - private Optional _getRemove() { - return remove; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof UpdateTransferOrderLineData && equalTo((UpdateTransferOrderLineData) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(UpdateTransferOrderLineData other) { - return uid.equals(other.uid) - && itemVariationId.equals(other.itemVariationId) - && quantityOrdered.equals(other.quantityOrdered) - && remove.equals(other.remove); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.uid, this.itemVariationId, this.quantityOrdered, this.remove); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional uid = Optional.empty(); - - private Optional itemVariationId = Optional.empty(); - - private Optional quantityOrdered = Optional.empty(); - - private Optional remove = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(UpdateTransferOrderLineData other) { - uid(other.getUid()); - itemVariationId(other.getItemVariationId()); - quantityOrdered(other.getQuantityOrdered()); - remove(other.getRemove()); - return this; - } - - /** - *

Line item id being updated. Required for updating/removing existing line items, but should not be set for new line items.

- */ - @JsonSetter(value = "uid", nulls = Nulls.SKIP) - public Builder uid(Optional uid) { - this.uid = uid; - return this; - } - - public Builder uid(String uid) { - this.uid = Optional.ofNullable(uid); - return this; - } - - public Builder uid(Nullable uid) { - if (uid.isNull()) { - this.uid = null; - } else if (uid.isEmpty()) { - this.uid = Optional.empty(); - } else { - this.uid = Optional.of(uid.get()); - } - return this; - } - - /** - *

Catalog item variation being transferred

- *

Required for new line items, but otherwise is not updatable.

- */ - @JsonSetter(value = "item_variation_id", nulls = Nulls.SKIP) - public Builder itemVariationId(Optional itemVariationId) { - this.itemVariationId = itemVariationId; - return this; - } - - public Builder itemVariationId(String itemVariationId) { - this.itemVariationId = Optional.ofNullable(itemVariationId); - return this; - } - - public Builder itemVariationId(Nullable itemVariationId) { - if (itemVariationId.isNull()) { - this.itemVariationId = null; - } else if (itemVariationId.isEmpty()) { - this.itemVariationId = Optional.empty(); - } else { - this.itemVariationId = Optional.of(itemVariationId.get()); - } - return this; - } - - /** - *

Total quantity ordered

- */ - @JsonSetter(value = "quantity_ordered", nulls = Nulls.SKIP) - public Builder quantityOrdered(Optional quantityOrdered) { - this.quantityOrdered = quantityOrdered; - return this; - } - - public Builder quantityOrdered(String quantityOrdered) { - this.quantityOrdered = Optional.ofNullable(quantityOrdered); - return this; - } - - public Builder quantityOrdered(Nullable quantityOrdered) { - if (quantityOrdered.isNull()) { - this.quantityOrdered = null; - } else if (quantityOrdered.isEmpty()) { - this.quantityOrdered = Optional.empty(); - } else { - this.quantityOrdered = Optional.of(quantityOrdered.get()); - } - return this; - } - - /** - *

Flag to remove the line item during update. Must include uid in removal request

- */ - @JsonSetter(value = "remove", nulls = Nulls.SKIP) - public Builder remove(Optional remove) { - this.remove = remove; - return this; - } - - public Builder remove(Boolean remove) { - this.remove = Optional.ofNullable(remove); - return this; - } - - public Builder remove(Nullable remove) { - if (remove.isNull()) { - this.remove = null; - } else if (remove.isEmpty()) { - this.remove = Optional.empty(); - } else { - this.remove = Optional.of(remove.get()); - } - return this; - } - - public UpdateTransferOrderLineData build() { - return new UpdateTransferOrderLineData(uid, itemVariationId, quantityOrdered, remove, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/UpdateTransferOrderRequest.java b/src/main/java/com/squareup/square/types/UpdateTransferOrderRequest.java deleted file mode 100644 index a6e0b568..00000000 --- a/src/main/java/com/squareup/square/types/UpdateTransferOrderRequest.java +++ /dev/null @@ -1,232 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import org.jetbrains.annotations.NotNull; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = UpdateTransferOrderRequest.Builder.class) -public final class UpdateTransferOrderRequest { - private final String transferOrderId; - - private final String idempotencyKey; - - private final UpdateTransferOrderData transferOrder; - - private final Optional version; - - private final Map additionalProperties; - - private UpdateTransferOrderRequest( - String transferOrderId, - String idempotencyKey, - UpdateTransferOrderData transferOrder, - Optional version, - Map additionalProperties) { - this.transferOrderId = transferOrderId; - this.idempotencyKey = idempotencyKey; - this.transferOrder = transferOrder; - this.version = version; - this.additionalProperties = additionalProperties; - } - - /** - * @return The ID of the transfer order to update - */ - @JsonProperty("transfer_order_id") - public String getTransferOrderId() { - return transferOrderId; - } - - /** - * @return A unique string that identifies this UpdateTransferOrder request. Keys must contain only alphanumeric characters, dashes and underscores - */ - @JsonProperty("idempotency_key") - public String getIdempotencyKey() { - return idempotencyKey; - } - - /** - * @return The transfer order updates to apply - */ - @JsonProperty("transfer_order") - public UpdateTransferOrderData getTransferOrder() { - return transferOrder; - } - - /** - * @return Version for optimistic concurrency - */ - @JsonProperty("version") - public Optional getVersion() { - return version; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof UpdateTransferOrderRequest && equalTo((UpdateTransferOrderRequest) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(UpdateTransferOrderRequest other) { - return transferOrderId.equals(other.transferOrderId) - && idempotencyKey.equals(other.idempotencyKey) - && transferOrder.equals(other.transferOrder) - && version.equals(other.version); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.transferOrderId, this.idempotencyKey, this.transferOrder, this.version); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static TransferOrderIdStage builder() { - return new Builder(); - } - - public interface TransferOrderIdStage { - /** - *

The ID of the transfer order to update

- */ - IdempotencyKeyStage transferOrderId(@NotNull String transferOrderId); - - Builder from(UpdateTransferOrderRequest other); - } - - public interface IdempotencyKeyStage { - /** - *

A unique string that identifies this UpdateTransferOrder request. Keys must contain only alphanumeric characters, dashes and underscores

- */ - TransferOrderStage idempotencyKey(@NotNull String idempotencyKey); - } - - public interface TransferOrderStage { - /** - *

The transfer order updates to apply

- */ - _FinalStage transferOrder(@NotNull UpdateTransferOrderData transferOrder); - } - - public interface _FinalStage { - UpdateTransferOrderRequest build(); - - /** - *

Version for optimistic concurrency

- */ - _FinalStage version(Optional version); - - _FinalStage version(Long version); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder - implements TransferOrderIdStage, IdempotencyKeyStage, TransferOrderStage, _FinalStage { - private String transferOrderId; - - private String idempotencyKey; - - private UpdateTransferOrderData transferOrder; - - private Optional version = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - @java.lang.Override - public Builder from(UpdateTransferOrderRequest other) { - transferOrderId(other.getTransferOrderId()); - idempotencyKey(other.getIdempotencyKey()); - transferOrder(other.getTransferOrder()); - version(other.getVersion()); - return this; - } - - /** - *

The ID of the transfer order to update

- *

The ID of the transfer order to update

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - @JsonSetter("transfer_order_id") - public IdempotencyKeyStage transferOrderId(@NotNull String transferOrderId) { - this.transferOrderId = Objects.requireNonNull(transferOrderId, "transferOrderId must not be null"); - return this; - } - - /** - *

A unique string that identifies this UpdateTransferOrder request. Keys must contain only alphanumeric characters, dashes and underscores

- *

A unique string that identifies this UpdateTransferOrder request. Keys must contain only alphanumeric characters, dashes and underscores

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - @JsonSetter("idempotency_key") - public TransferOrderStage idempotencyKey(@NotNull String idempotencyKey) { - this.idempotencyKey = Objects.requireNonNull(idempotencyKey, "idempotencyKey must not be null"); - return this; - } - - /** - *

The transfer order updates to apply

- *

The transfer order updates to apply

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - @JsonSetter("transfer_order") - public _FinalStage transferOrder(@NotNull UpdateTransferOrderData transferOrder) { - this.transferOrder = Objects.requireNonNull(transferOrder, "transferOrder must not be null"); - return this; - } - - /** - *

Version for optimistic concurrency

- * @return Reference to {@code this} so that method calls can be chained together. - */ - @java.lang.Override - public _FinalStage version(Long version) { - this.version = Optional.ofNullable(version); - return this; - } - - /** - *

Version for optimistic concurrency

- */ - @java.lang.Override - @JsonSetter(value = "version", nulls = Nulls.SKIP) - public _FinalStage version(Optional version) { - this.version = version; - return this; - } - - @java.lang.Override - public UpdateTransferOrderRequest build() { - return new UpdateTransferOrderRequest( - transferOrderId, idempotencyKey, transferOrder, version, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/types/UpdateTransferOrderResponse.java b/src/main/java/com/squareup/square/types/UpdateTransferOrderResponse.java deleted file mode 100644 index 06fafaa5..00000000 --- a/src/main/java/com/squareup/square/types/UpdateTransferOrderResponse.java +++ /dev/null @@ -1,133 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.squareup.square.types; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.squareup.square.core.ObjectMappers; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = UpdateTransferOrderResponse.Builder.class) -public final class UpdateTransferOrderResponse { - private final Optional transferOrder; - - private final Optional> errors; - - private final Map additionalProperties; - - private UpdateTransferOrderResponse( - Optional transferOrder, - Optional> errors, - Map additionalProperties) { - this.transferOrder = transferOrder; - this.errors = errors; - this.additionalProperties = additionalProperties; - } - - /** - * @return The updated transfer order - */ - @JsonProperty("transfer_order") - public Optional getTransferOrder() { - return transferOrder; - } - - /** - * @return Any errors that occurred during the request - */ - @JsonProperty("errors") - public Optional> getErrors() { - return errors; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof UpdateTransferOrderResponse && equalTo((UpdateTransferOrderResponse) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(UpdateTransferOrderResponse other) { - return transferOrder.equals(other.transferOrder) && errors.equals(other.errors); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.transferOrder, this.errors); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional transferOrder = Optional.empty(); - - private Optional> errors = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(UpdateTransferOrderResponse other) { - transferOrder(other.getTransferOrder()); - errors(other.getErrors()); - return this; - } - - /** - *

The updated transfer order

- */ - @JsonSetter(value = "transfer_order", nulls = Nulls.SKIP) - public Builder transferOrder(Optional transferOrder) { - this.transferOrder = transferOrder; - return this; - } - - public Builder transferOrder(TransferOrder transferOrder) { - this.transferOrder = Optional.ofNullable(transferOrder); - return this; - } - - /** - *

Any errors that occurred during the request

- */ - @JsonSetter(value = "errors", nulls = Nulls.SKIP) - public Builder errors(Optional> errors) { - this.errors = errors; - return this; - } - - public Builder errors(List errors) { - this.errors = Optional.ofNullable(errors); - return this; - } - - public UpdateTransferOrderResponse build() { - return new UpdateTransferOrderResponse(transferOrder, errors, additionalProperties); - } - } -} diff --git a/src/main/java/com/squareup/square/webhooks/AsyncRawEventTypesClient.java b/src/main/java/com/squareup/square/webhooks/AsyncRawEventTypesClient.java index 1d5df07c..7cbe8421 100644 --- a/src/main/java/com/squareup/square/webhooks/AsyncRawEventTypesClient.java +++ b/src/main/java/com/squareup/square/webhooks/AsyncRawEventTypesClient.java @@ -73,17 +73,19 @@ public CompletableFuture @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, ListWebhookEventTypesResponse.class), + responseBody.string(), ListWebhookEventTypesResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/webhooks/AsyncRawSubscriptionsClient.java b/src/main/java/com/squareup/square/webhooks/AsyncRawSubscriptionsClient.java index 4199a25a..7afa5f80 100644 --- a/src/main/java/com/squareup/square/webhooks/AsyncRawSubscriptionsClient.java +++ b/src/main/java/com/squareup/square/webhooks/AsyncRawSubscriptionsClient.java @@ -107,10 +107,9 @@ public CompletableFuture startingAfter = parsedResponse.getCursor(); ListSubscriptionsRequest nextRequest = ListSubscriptionsRequest.builder() .from(request) @@ -119,22 +118,24 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO List result = parsedResponse.getSubscriptions().orElse(Collections.emptyList()); future.complete(new SquareClientHttpResponse<>( - new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> { - try { - return list(nextRequest, requestOptions) - .get() - .body(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - }), + new SyncPagingIterable(startingAfter.isPresent(), result, () -> { + try { + return list(nextRequest, requestOptions) + .get() + .body(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -190,17 +191,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateWebhookSubscriptionResponse.class), + responseBody.string(), CreateWebhookSubscriptionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -248,17 +251,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, GetWebhookSubscriptionResponse.class), + responseBody.string(), GetWebhookSubscriptionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -315,17 +320,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpdateWebhookSubscriptionResponse.class), + responseBody.string(), UpdateWebhookSubscriptionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -374,17 +381,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DeleteWebhookSubscriptionResponse.class), + responseBody.string(), DeleteWebhookSubscriptionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -442,17 +451,19 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpdateWebhookSubscriptionSignatureKeyResponse.class), + responseBody.string(), UpdateWebhookSubscriptionSignatureKeyResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); @@ -509,17 +520,19 @@ public CompletableFuture( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, TestWebhookSubscriptionResponse.class), + responseBody.string(), TestWebhookSubscriptionResponse.class), response)); return; } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; future.completeExceptionally(new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response)); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); return; } catch (IOException e) { future.completeExceptionally(new SquareException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/squareup/square/webhooks/RawEventTypesClient.java b/src/main/java/com/squareup/square/webhooks/RawEventTypesClient.java index 5b84df24..352befa9 100644 --- a/src/main/java/com/squareup/square/webhooks/RawEventTypesClient.java +++ b/src/main/java/com/squareup/square/webhooks/RawEventTypesClient.java @@ -65,15 +65,17 @@ public SquareClientHttpResponse list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListWebhookEventTypesResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListWebhookEventTypesResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/squareup/square/webhooks/RawSubscriptionsClient.java b/src/main/java/com/squareup/square/webhooks/RawSubscriptionsClient.java index 110636eb..20bc345d 100644 --- a/src/main/java/com/squareup/square/webhooks/RawSubscriptionsClient.java +++ b/src/main/java/com/squareup/square/webhooks/RawSubscriptionsClient.java @@ -97,10 +97,9 @@ public SquareClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { - ListWebhookSubscriptionsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListWebhookSubscriptionsResponse.class); + ListWebhookSubscriptionsResponse parsedResponse = ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), ListWebhookSubscriptionsResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListSubscriptionsRequest nextRequest = ListSubscriptionsRequest.builder() .from(request) @@ -110,14 +109,16 @@ public SquareClientHttpResponse> list( parsedResponse.getSubscriptions().orElse(Collections.emptyList()); return new SquareClientHttpResponse<>( new SyncPagingIterable( - startingAfter.isPresent(), result, parsedResponse, () -> list( - nextRequest, requestOptions) + startingAfter.isPresent(), result, () -> list(nextRequest, requestOptions) .body()), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -160,16 +161,18 @@ public SquareClientHttpResponse create( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, CreateWebhookSubscriptionResponse.class), + responseBody.string(), CreateWebhookSubscriptionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -204,15 +207,18 @@ public SquareClientHttpResponse get( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetWebhookSubscriptionResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), GetWebhookSubscriptionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -256,16 +262,18 @@ public SquareClientHttpResponse update( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpdateWebhookSubscriptionResponse.class), + responseBody.string(), UpdateWebhookSubscriptionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -300,16 +308,18 @@ public SquareClientHttpResponse delete( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, DeleteWebhookSubscriptionResponse.class), + responseBody.string(), DeleteWebhookSubscriptionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -354,16 +364,18 @@ public SquareClientHttpResponse u } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBodyString, UpdateWebhookSubscriptionSignatureKeyResponse.class), + responseBody.string(), UpdateWebhookSubscriptionSignatureKeyResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); } @@ -407,15 +419,18 @@ public SquareClientHttpResponse test( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new SquareClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, TestWebhookSubscriptionResponse.class), + ObjectMappers.JSON_MAPPER.readValue( + responseBody.string(), TestWebhookSubscriptionResponse.class), response); } - Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; throw new SquareApiException( - "Error with status code " + response.code(), response.code(), errorBody, response); + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); } catch (IOException e) { throw new SquareException("Network error executing HTTP request", e); }