Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List payments from a payout #348 #355

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.checkout.reconciliation.previous;


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

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

CompletableFuture<StatementReportResponse> queryStatementsReport(QueryFilterDateRange filter);

/**
* More information in:
* <a href="https://www.checkout.com/docs/previous/reporting-and-insights/reconciliation-api/statements-endpoint#2._Statement_ID_/_Payments">
* Statements endpoint
* </a>
* */
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 @@ -40,11 +40,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