Skip to content

Commit

Permalink
Adds statement id extension
Browse files Browse the repository at this point in the history
  • Loading branch information
armando-rodriguez-cko committed Sep 13, 2023
1 parent 77fa09f commit faec67d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import com.checkout.ContentResponse;
import com.checkout.common.QueryFilterDateRange;
import com.checkout.payments.VoidResponse;

import java.util.concurrent.CompletableFuture;

Expand All @@ -14,6 +15,8 @@ public interface ReconciliationClient {

CompletableFuture<StatementReportResponse> queryStatementsReport(QueryFilterDateRange filter);

CompletableFuture<StatementReportResponse> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.checkout.ContentResponse;
import com.checkout.SdkAuthorizationType;
import com.checkout.common.QueryFilterDateRange;
import com.checkout.payments.VoidResponse;

import java.util.concurrent.CompletableFuture;

Expand Down Expand Up @@ -40,11 +41,16 @@ public CompletableFuture<StatementReportResponse> queryStatementsReport(final Qu
return apiClient.queryAsync(buildPath(REPORTING_PATH, STATEMENTS_PATH), sdkAuthorization(), filter, StatementReportResponse.class);
}

@Override
public CompletableFuture<StatementReportResponse> getStatementsReportById(final String statementId) {
validateParams("statementId", statementId);
return apiClient.getAsync(buildPath(REPORTING_PATH, STATEMENTS_PATH, statementId, PAYMENTS_PATH), sdkAuthorization(), StatementReportResponse.class);
}

@Override
public CompletableFuture<ContentResponse> retrieveCSVPaymentReport(final QueryFilterDateRange filter, final String targetFile) {
validateParams("filter", filter);
return apiClient.queryCsvContentAsync(buildPath(REPORTING_PATH, PAYMENTS_PATH, DOWNLOAD_PATH), sdkAuthorization(), filter, targetFile);

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<StatementReportResponse> 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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down

0 comments on commit faec67d

Please sign in to comment.