diff --git a/src/main/java/com/checkout/reconciliation/previous/ReconciliationClient.java b/src/main/java/com/checkout/reconciliation/previous/ReconciliationClient.java index 2091f254..a447a1d7 100644 --- a/src/main/java/com/checkout/reconciliation/previous/ReconciliationClient.java +++ b/src/main/java/com/checkout/reconciliation/previous/ReconciliationClient.java @@ -1,6 +1,5 @@ package com.checkout.reconciliation.previous; - import com.checkout.ContentResponse; import com.checkout.common.QueryFilterDateRange; @@ -14,6 +13,14 @@ public interface ReconciliationClient { CompletableFuture queryStatementsReport(QueryFilterDateRange filter); + /** + * More information in: + * + * Statements endpoint + * + * */ + CompletableFuture getStatementsReportById(String statementId); + /** * @param targetFile Optional parameter that specifies the path where a file with the content returned is saved. If * the file does not exist, the client will attempt to create a new one, otherwise the existing diff --git a/src/main/java/com/checkout/reconciliation/previous/ReconciliationClientImpl.java b/src/main/java/com/checkout/reconciliation/previous/ReconciliationClientImpl.java index 6df7e3bf..65177a35 100644 --- a/src/main/java/com/checkout/reconciliation/previous/ReconciliationClientImpl.java +++ b/src/main/java/com/checkout/reconciliation/previous/ReconciliationClientImpl.java @@ -40,11 +40,16 @@ public CompletableFuture queryStatementsReport(final Qu return apiClient.queryAsync(buildPath(REPORTING_PATH, STATEMENTS_PATH), sdkAuthorization(), filter, StatementReportResponse.class); } + @Override + public CompletableFuture getStatementsReportById(final String statementId) { + validateParams("statementId", statementId); + return apiClient.getAsync(buildPath(REPORTING_PATH, STATEMENTS_PATH, statementId, PAYMENTS_PATH), sdkAuthorization(), StatementReportResponse.class); + } + @Override public CompletableFuture retrieveCSVPaymentReport(final QueryFilterDateRange filter, final String targetFile) { validateParams("filter", filter); return apiClient.queryCsvContentAsync(buildPath(REPORTING_PATH, PAYMENTS_PATH, DOWNLOAD_PATH), sdkAuthorization(), filter, targetFile); - } @Override diff --git a/src/test/java/com/checkout/reconciliation/previous/ReconciliationClientImplTest.java b/src/test/java/com/checkout/reconciliation/previous/ReconciliationClientImplTest.java index 8e8a25dd..e7fbe4f9 100644 --- a/src/test/java/com/checkout/reconciliation/previous/ReconciliationClientImplTest.java +++ b/src/test/java/com/checkout/reconciliation/previous/ReconciliationClientImplTest.java @@ -91,6 +91,20 @@ void shouldQueryStatementsReport() throws ExecutionException, InterruptedExcepti assertEquals(response, future.get()); } + @Test + void shouldGetStatementsReportById() throws ExecutionException, InterruptedException { + final StatementReportResponse response = mock(StatementReportResponse.class); + + when(apiClient.getAsync(eq("reporting/statements/statement_id/payments"), any(SdkAuthorization.class), + eq(StatementReportResponse.class))) + .thenReturn(CompletableFuture.completedFuture(response)); + + final CompletableFuture future = client.getStatementsReportById("statement_id"); + + assertNotNull(future.get()); + assertEquals(response, future.get()); + } + @Test void shouldRetrieveCSVPaymentReport() throws ExecutionException, InterruptedException { final String report = "/etc/foo/payment_report.csv"; diff --git a/src/test/java/com/checkout/reconciliation/previous/ReconciliationTestIT.java b/src/test/java/com/checkout/reconciliation/previous/ReconciliationTestIT.java index 4deef086..689a2d74 100644 --- a/src/test/java/com/checkout/reconciliation/previous/ReconciliationTestIT.java +++ b/src/test/java/com/checkout/reconciliation/previous/ReconciliationTestIT.java @@ -138,6 +138,37 @@ void shouldQueryStatementsReport() throws ExecutionException, InterruptedExcepti }); } + @Test + @Disabled("Only works in production") + void shouldGetStatementsReportById() throws ExecutionException, InterruptedException { + + final StatementReportResponse response = getProductionCheckoutApi().reconciliationClient().getStatementsReportById("statement_id").get(); + + assertNotNull(response); + assertNotNull(response.getLinks()); + assertTrue(response.getCount() >= 1); + response.getData().forEach(statementData -> { + assertNotNull(statementData.getId()); + assertNotNull(statementData.getPeriodStart()); + assertNotNull(statementData.getPeriodEnd()); + assertNotNull(statementData.getDate()); + assertNotNull(statementData.getPayouts()); + assertNotNull(statementData.getLinks()); + statementData.getPayouts().forEach(payoutStatement -> { + assertNotNull(payoutStatement.getCurrency()); + assertNotNull(payoutStatement.getCarriedForwardAmount()); + assertNotNull(payoutStatement.getCurrentPeriodAmount()); + assertNotNull(payoutStatement.getNetAmount()); + assertNotNull(payoutStatement.getPeriodStart()); + assertNotNull(payoutStatement.getPeriodEnd()); + assertNotNull(payoutStatement.getId()); + assertNotNull(payoutStatement.getStatus()); + assertNotNull(payoutStatement.getPayoutFee()); + assertNotNull(payoutStatement.getLinks()); + }); + }); + } + @Test @Disabled("Only works in production") void shouldRetrieveCsvPaymentReport() throws ExecutionException, InterruptedException { @@ -178,7 +209,7 @@ void shouldRetrieveCsvPaymentReport_saveFile() throws ExecutionException, Interr @Disabled("Only works in production") void shouldRetrieveCsvSingleStatementReport() throws ExecutionException, InterruptedException { - final ContentResponse ContentResponse = getProductionCheckoutApi().reconciliationClient().retrieveCSVSingleStatementReport("id", null).get(); + final ContentResponse ContentResponse = getProductionCheckoutApi().reconciliationClient().retrieveCSVSingleStatementReport("statement_id", null).get(); assertNotNull(ContentResponse); assertFalse(ContentResponse.getContent().isEmpty()); @@ -191,7 +222,7 @@ void shouldRetrieveCsvSingleStatementReport() throws ExecutionException, Interru @Disabled("Only works in production") void shouldRetrieveCsvSingleStatementReport_saveFile() throws ExecutionException, InterruptedException { - final ContentResponse ContentResponse = getProductionCheckoutApi().reconciliationClient().retrieveCSVSingleStatementReport("id", "file_path").get(); + final ContentResponse ContentResponse = getProductionCheckoutApi().reconciliationClient().retrieveCSVSingleStatementReport("statement_id", "file_path").get(); assertNotNull(ContentResponse); assertFalse(ContentResponse.getContent().isEmpty());