Skip to content

Commit

Permalink
Adds query and extensions in statements endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
armando-rodriguez-cko committed Oct 24, 2023
1 parent 5647726 commit ed82474
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.checkout.reconciliation.previous;

import com.google.gson.annotations.SerializedName;
import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class CurrentPeriodBreakdown {

@SerializedName("processed_amount")
private Long processedAmount;

@SerializedName("refund_amount")
private Long refundAmount;

@SerializedName("chargeback_amount")
private Long chargebackAmount;

@SerializedName("payouts_to_card_amount")
private Long payoutsToCardAmount;

@SerializedName("processing_fees")
private Integer processingFees;

@SerializedName("processing_fees_breakdown")
private ProcessingFeesBreakdown processingFeesBreakdown;

@SerializedName("rolling_reserve_amount")
private Integer rollingReserveAmount;

private Integer tax;

@SerializedName("admin_fees")
private Integer adminFees;

@SerializedName("general_adjustments")
private Integer generalAdjustments;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.checkout.reconciliation.previous;

import com.google.gson.annotations.SerializedName;

public enum IncludePayouts {

@SerializedName("payout_breakdown")
PAYOUT_BREAKDOWN,
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@ public final class PayoutStatement extends Resource {

@SerializedName("period_end")
private String periodEnd;

@SerializedName("current_period_breakdown")
private CurrentPeriodBreakdown currentPeriodBreakdown;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.checkout.reconciliation.previous;

import com.google.gson.annotations.SerializedName;
import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class ProcessingFeesBreakdown {

@SerializedName("interchange_fees")
private Integer interchangeFees;

@SerializedName("scheme_and_other_network_fees")
private Integer schemeAndOtherNetworkFees;

@SerializedName("premium_and_apm_fees")
private Integer premiumAndApmFees;

@SerializedName("chargeback_fees")
private Integer chargebackFees;

@SerializedName("payout_to_card_fees")
private Integer payoutToCardFees;

@SerializedName("payment_gateway_fees")
private Integer paymentGatewayFees;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface ReconciliationClient {

CompletableFuture<ReconciliationPaymentReportResponse> singlePaymentReportAsync(String paymentId);

CompletableFuture<StatementReportResponse> queryStatementsReport(QueryFilterDateRange filter);
CompletableFuture<StatementReportResponse> queryStatementsReport(StatementsQueryFilter filter);

/**
* More information in:
Expand All @@ -21,6 +21,14 @@ public interface ReconciliationClient {
* */
CompletableFuture<StatementReportResponse> getStatementsReportById(String statementId);

/**
* 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> getStatementsReportByIdQuery(String statementId, StatementsQueryFilter filter);

/**
* @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 All @@ -43,6 +51,6 @@ public interface ReconciliationClient {
* file will be rewritten.
* @return CSV content
*/
CompletableFuture<ContentResponse> retrieveCSVStatementsReport(final QueryFilterDateRange filter, final String targetFile);
CompletableFuture<ContentResponse> retrieveCSVStatementsReport(final StatementsQueryFilter filter, final String targetFile);

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,43 +25,87 @@ public ReconciliationClientImpl(final ApiClient apiClient, final CheckoutConfigu
@Override
public CompletableFuture<ReconciliationPaymentReportResponse> queryPaymentsReport(final ReconciliationQueryPaymentsFilter filter) {
validateParams("filter", filter);
return apiClient.queryAsync(buildPath(REPORTING_PATH, PAYMENTS_PATH), sdkAuthorization(), filter, ReconciliationPaymentReportResponse.class);
return apiClient.queryAsync(
buildPath(REPORTING_PATH, PAYMENTS_PATH),
sdkAuthorization(),
filter,
ReconciliationPaymentReportResponse.class
);
}

@Override
public CompletableFuture<ReconciliationPaymentReportResponse> singlePaymentReportAsync(final String paymentId) {
validateParams("paymentId", paymentId);
return apiClient.getAsync(buildPath(REPORTING_PATH, PAYMENTS_PATH, paymentId), sdkAuthorization(), ReconciliationPaymentReportResponse.class);
return apiClient.getAsync(
buildPath(REPORTING_PATH, PAYMENTS_PATH, paymentId),
sdkAuthorization(),
ReconciliationPaymentReportResponse.class
);
}

@Override
public CompletableFuture<StatementReportResponse> queryStatementsReport(final QueryFilterDateRange filter) {
public CompletableFuture<StatementReportResponse> queryStatementsReport(final StatementsQueryFilter filter) {
validateParams("filter", filter);
return apiClient.queryAsync(buildPath(REPORTING_PATH, STATEMENTS_PATH), sdkAuthorization(), filter, StatementReportResponse.class);
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);
return apiClient.getAsync(
buildPath(REPORTING_PATH, STATEMENTS_PATH, statementId, PAYMENTS_PATH),
sdkAuthorization(),
StatementReportResponse.class
);
}

@Override
public CompletableFuture<StatementReportResponse> getStatementsReportByIdQuery(final String statementId, final StatementsQueryFilter filter) {
validateParams("statementId", statementId, "filter", filter);
return apiClient.queryAsync(
buildPath(REPORTING_PATH, STATEMENTS_PATH, statementId, PAYMENTS_PATH),
sdkAuthorization(),
filter,
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);
return apiClient.queryCsvContentAsync(
buildPath(REPORTING_PATH, PAYMENTS_PATH, DOWNLOAD_PATH),
sdkAuthorization(),
filter,
targetFile
);
}

@Override
public CompletableFuture<ContentResponse> retrieveCSVSingleStatementReport(final String statementId, final String targetFile) {
validateParams("statementId", statementId);
return apiClient.queryCsvContentAsync(buildPath(REPORTING_PATH, STATEMENTS_PATH, statementId, PAYMENTS_PATH, DOWNLOAD_PATH), sdkAuthorization(), null, targetFile);
return apiClient.queryCsvContentAsync(
buildPath(REPORTING_PATH, STATEMENTS_PATH, statementId, PAYMENTS_PATH, DOWNLOAD_PATH),
sdkAuthorization(),
null,
targetFile
);
}

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.checkout.reconciliation.previous;

import com.checkout.common.Currency;
import com.google.gson.annotations.SerializedName;
import lombok.Builder;
import lombok.Data;

import java.time.Instant;

@Data
@Builder
public class StatementsQueryFilter {

@SerializedName("payout_id")
private String payoutId;

@SerializedName("payout_currency")
private Currency payoutCurrency;

private Instant from;

private Instant to;

private IncludePayouts include;
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void shouldSinglePaymentReportAsync() throws ExecutionException, InterruptedExce

@Test
void shouldQueryStatementsReport() throws ExecutionException, InterruptedException {
final QueryFilterDateRange request = mock(QueryFilterDateRange.class);
final StatementsQueryFilter request = mock(StatementsQueryFilter.class);
final StatementReportResponse response = mock(StatementReportResponse.class);

when(apiClient.queryAsync(eq("reporting/statements"), any(SdkAuthorization.class), eq(request),
Expand All @@ -105,6 +105,21 @@ void shouldGetStatementsReportById() throws ExecutionException, InterruptedExcep
assertEquals(response, future.get());
}

@Test
void shouldGetStatementsReportByIdWithQuery() throws ExecutionException, InterruptedException {
final StatementsQueryFilter filter = mock(StatementsQueryFilter.class);
final StatementReportResponse response = mock(StatementReportResponse.class);

when(apiClient.queryAsync(eq("reporting/statements/statement_id/payments"), any(SdkAuthorization.class), eq(filter),
eq(StatementReportResponse.class)))
.thenReturn(CompletableFuture.completedFuture(response));

final CompletableFuture<StatementReportResponse> future = client.getStatementsReportByIdQuery("statement_id", filter);

assertNotNull(future.get());
assertEquals(response, future.get());
}

@Test
void shouldRetrieveCSVPaymentReport() throws ExecutionException, InterruptedException {
final String report = "/etc/foo/payment_report.csv";
Expand Down Expand Up @@ -139,7 +154,7 @@ void shouldRetrieveCSVSingleStatementReport() throws ExecutionException, Interru
@Test
void shouldRetrieveCSVStatementsReport() throws ExecutionException, InterruptedException {
final String report = "/etc/foo/statement_report.csv";
final QueryFilterDateRange request = mock(QueryFilterDateRange.class);
final StatementsQueryFilter request = mock(StatementsQueryFilter.class);
final ContentResponse response = mock(ContentResponse.class);

when(apiClient.queryCsvContentAsync(eq("reporting/statements/download"), any(SdkAuthorization.class), eq(request),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

class ReconciliationTestIT {

private final QueryFilterDateRange queryFilterDateRange = QueryFilterDateRange.builder()
private final StatementsQueryFilter statementsQueryFilter = StatementsQueryFilter.builder()
.from(LocalDateTime.now().minus(1, ChronoUnit.MONTHS).toInstant(ZoneOffset.UTC))
.to(Instant.now())
.build();
Expand Down Expand Up @@ -111,7 +111,7 @@ void shouldGetSinglePaymentReport() throws ExecutionException, InterruptedExcept
@Disabled("Only works in production")
void shouldQueryStatementsReport() throws ExecutionException, InterruptedException {

final StatementReportResponse response = getProductionCheckoutApi().reconciliationClient().queryStatementsReport(queryFilterDateRange).get();
final StatementReportResponse response = getProductionCheckoutApi().reconciliationClient().queryStatementsReport(statementsQueryFilter).get();

assertNotNull(response);
assertNotNull(response.getLinks());
Expand Down Expand Up @@ -235,7 +235,7 @@ void shouldRetrieveCsvSingleStatementReport_saveFile() throws ExecutionException
@Disabled("Only works in production")
void shouldRetrieveCsvStatementsReport() throws ExecutionException, InterruptedException {

final ContentResponse ContentResponse = getProductionCheckoutApi().reconciliationClient().retrieveCSVStatementsReport(queryFilterDateRange, null).get();
final ContentResponse ContentResponse = getProductionCheckoutApi().reconciliationClient().retrieveCSVStatementsReport(statementsQueryFilter, null).get();

assertNotNull(ContentResponse);
assertFalse(ContentResponse.getContent().isEmpty());
Expand All @@ -248,7 +248,7 @@ void shouldRetrieveCsvStatementsReport() throws ExecutionException, InterruptedE
@Disabled("Only works in production")
void shouldRetrieveCsvStatementsReport_saveFile() throws ExecutionException, InterruptedException {

final ContentResponse ContentResponse = getProductionCheckoutApi().reconciliationClient().retrieveCSVStatementsReport(queryFilterDateRange, "file_path").get();
final ContentResponse ContentResponse = getProductionCheckoutApi().reconciliationClient().retrieveCSVStatementsReport(statementsQueryFilter, "file_path").get();

assertNotNull(ContentResponse);
assertFalse(ContentResponse.getContent().isEmpty());
Expand Down

0 comments on commit ed82474

Please sign in to comment.