Skip to content

Commit ffedc1f

Browse files
Adds query and extensions in statements endpoints
1 parent 8e30b5e commit ffedc1f

File tree

9 files changed

+188
-17
lines changed

9 files changed

+188
-17
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.checkout.reconciliation.previous;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Builder;
5+
import lombok.Data;
6+
7+
@Data
8+
@Builder
9+
public class CurrentPeriodBreakdown {
10+
11+
@SerializedName("processed_amount")
12+
private Long processedAmount;
13+
14+
@SerializedName("refund_amount")
15+
private Long refundAmount;
16+
17+
@SerializedName("chargeback_amount")
18+
private Long chargebackAmount;
19+
20+
@SerializedName("payouts_to_card_amount")
21+
private Long payoutsToCardAmount;
22+
23+
@SerializedName("processing_fees")
24+
private Integer processingFees;
25+
26+
@SerializedName("processing_fees_breakdown")
27+
private ProcessingFeesBreakdown processingFeesBreakdown;
28+
29+
@SerializedName("rolling_reserve_amount")
30+
private Integer rollingReserveAmount;
31+
32+
private Integer tax;
33+
34+
@SerializedName("admin_fees")
35+
private Integer adminFees;
36+
37+
@SerializedName("general_adjustments")
38+
private Integer generalAdjustments;
39+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.checkout.reconciliation.previous;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
5+
public enum IncludePayouts {
6+
7+
@SerializedName("payout_breakdown")
8+
PAYOUT_BREAKDOWN,
9+
}

src/main/java/com/checkout/reconciliation/previous/PayoutStatement.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,8 @@ public final class PayoutStatement extends Resource {
3737

3838
@SerializedName("period_end")
3939
private String periodEnd;
40+
41+
@SerializedName("current_period_breakdown")
42+
private CurrentPeriodBreakdown currentPeriodBreakdown;
4043

4144
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.checkout.reconciliation.previous;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Builder;
5+
import lombok.Data;
6+
7+
@Data
8+
@Builder
9+
public class ProcessingFeesBreakdown {
10+
11+
@SerializedName("interchange_fees")
12+
private Integer interchangeFees;
13+
14+
@SerializedName("scheme_and_other_network_fees")
15+
private Integer schemeAndOtherNetworkFees;
16+
17+
@SerializedName("premium_and_apm_fees")
18+
private Integer premiumAndApmFees;
19+
20+
@SerializedName("chargeback_fees")
21+
private Integer chargebackFees;
22+
23+
@SerializedName("payout_to_card_fees")
24+
private Integer payoutToCardFees;
25+
26+
@SerializedName("payment_gateway_fees")
27+
private Integer paymentGatewayFees;
28+
}

src/main/java/com/checkout/reconciliation/previous/ReconciliationClient.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public interface ReconciliationClient {
1111

1212
CompletableFuture<ReconciliationPaymentReportResponse> singlePaymentReportAsync(String paymentId);
1313

14-
CompletableFuture<StatementReportResponse> queryStatementsReport(QueryFilterDateRange filter);
14+
CompletableFuture<StatementReportResponse> queryStatementsReport(StatementsQueryFilter filter);
1515

1616
/**
1717
* More information in:
@@ -21,6 +21,14 @@ public interface ReconciliationClient {
2121
* */
2222
CompletableFuture<StatementReportResponse> getStatementsReportById(String statementId);
2323

24+
/**
25+
* More information in:
26+
* <a href="https://www.checkout.com/docs/previous/reporting-and-insights/reconciliation-api/statements-endpoint#2._Statement_ID_/_Payments">
27+
* Statements endpoint
28+
* </a>
29+
* */
30+
CompletableFuture<StatementReportResponse> getStatementsReportByIdQuery(String statementId, StatementsQueryFilter filter);
31+
2432
/**
2533
* @param targetFile Optional parameter that specifies the path where a file with the content returned is saved. If
2634
* the file does not exist, the client will attempt to create a new one, otherwise the existing
@@ -43,6 +51,6 @@ public interface ReconciliationClient {
4351
* file will be rewritten.
4452
* @return CSV content
4553
*/
46-
CompletableFuture<ContentResponse> retrieveCSVStatementsReport(final QueryFilterDateRange filter, final String targetFile);
54+
CompletableFuture<ContentResponse> retrieveCSVStatementsReport(final StatementsQueryFilter filter, final String targetFile);
4755

4856
}

src/main/java/com/checkout/reconciliation/previous/ReconciliationClientImpl.java

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,43 +25,87 @@ public ReconciliationClientImpl(final ApiClient apiClient, final CheckoutConfigu
2525
@Override
2626
public CompletableFuture<ReconciliationPaymentReportResponse> queryPaymentsReport(final ReconciliationQueryPaymentsFilter filter) {
2727
validateParams("filter", filter);
28-
return apiClient.queryAsync(buildPath(REPORTING_PATH, PAYMENTS_PATH), sdkAuthorization(), filter, ReconciliationPaymentReportResponse.class);
28+
return apiClient.queryAsync(
29+
buildPath(REPORTING_PATH, PAYMENTS_PATH),
30+
sdkAuthorization(),
31+
filter,
32+
ReconciliationPaymentReportResponse.class
33+
);
2934
}
3035

3136
@Override
3237
public CompletableFuture<ReconciliationPaymentReportResponse> singlePaymentReportAsync(final String paymentId) {
3338
validateParams("paymentId", paymentId);
34-
return apiClient.getAsync(buildPath(REPORTING_PATH, PAYMENTS_PATH, paymentId), sdkAuthorization(), ReconciliationPaymentReportResponse.class);
39+
return apiClient.getAsync(
40+
buildPath(REPORTING_PATH, PAYMENTS_PATH, paymentId),
41+
sdkAuthorization(),
42+
ReconciliationPaymentReportResponse.class
43+
);
3544
}
3645

3746
@Override
38-
public CompletableFuture<StatementReportResponse> queryStatementsReport(final QueryFilterDateRange filter) {
47+
public CompletableFuture<StatementReportResponse> queryStatementsReport(final StatementsQueryFilter filter) {
3948
validateParams("filter", filter);
40-
return apiClient.queryAsync(buildPath(REPORTING_PATH, STATEMENTS_PATH), sdkAuthorization(), filter, StatementReportResponse.class);
49+
return apiClient.queryAsync(
50+
buildPath(REPORTING_PATH, STATEMENTS_PATH),
51+
sdkAuthorization(),
52+
filter,
53+
StatementReportResponse.class
54+
);
4155
}
4256

4357
@Override
4458
public CompletableFuture<StatementReportResponse> getStatementsReportById(final String statementId) {
4559
validateParams("statementId", statementId);
46-
return apiClient.getAsync(buildPath(REPORTING_PATH, STATEMENTS_PATH, statementId, PAYMENTS_PATH), sdkAuthorization(), StatementReportResponse.class);
60+
return apiClient.getAsync(
61+
buildPath(REPORTING_PATH, STATEMENTS_PATH, statementId, PAYMENTS_PATH),
62+
sdkAuthorization(),
63+
StatementReportResponse.class
64+
);
65+
}
66+
67+
@Override
68+
public CompletableFuture<StatementReportResponse> getStatementsReportByIdQuery(final String statementId, final StatementsQueryFilter filter) {
69+
validateParams("statementId", statementId, "filter", filter);
70+
return apiClient.queryAsync(
71+
buildPath(REPORTING_PATH, STATEMENTS_PATH, statementId, PAYMENTS_PATH),
72+
sdkAuthorization(),
73+
filter,
74+
StatementReportResponse.class
75+
);
4776
}
4877

4978
@Override
5079
public CompletableFuture<ContentResponse> retrieveCSVPaymentReport(final QueryFilterDateRange filter, final String targetFile) {
5180
validateParams("filter", filter);
52-
return apiClient.queryCsvContentAsync(buildPath(REPORTING_PATH, PAYMENTS_PATH, DOWNLOAD_PATH), sdkAuthorization(), filter, targetFile);
81+
return apiClient.queryCsvContentAsync(
82+
buildPath(REPORTING_PATH, PAYMENTS_PATH, DOWNLOAD_PATH),
83+
sdkAuthorization(),
84+
filter,
85+
targetFile
86+
);
5387
}
5488

5589
@Override
5690
public CompletableFuture<ContentResponse> retrieveCSVSingleStatementReport(final String statementId, final String targetFile) {
5791
validateParams("statementId", statementId);
58-
return apiClient.queryCsvContentAsync(buildPath(REPORTING_PATH, STATEMENTS_PATH, statementId, PAYMENTS_PATH, DOWNLOAD_PATH), sdkAuthorization(), null, targetFile);
92+
return apiClient.queryCsvContentAsync(
93+
buildPath(REPORTING_PATH, STATEMENTS_PATH, statementId, PAYMENTS_PATH, DOWNLOAD_PATH),
94+
sdkAuthorization(),
95+
null,
96+
targetFile
97+
);
5998
}
6099

61100
@Override
62-
public CompletableFuture<ContentResponse> retrieveCSVStatementsReport(final QueryFilterDateRange filter, final String targetFile) {
101+
public CompletableFuture<ContentResponse> retrieveCSVStatementsReport(final StatementsQueryFilter filter, final String targetFile) {
63102
validateParams("filter", filter);
64-
return apiClient.queryCsvContentAsync(buildPath(REPORTING_PATH, STATEMENTS_PATH, DOWNLOAD_PATH), sdkAuthorization(), filter, targetFile);
103+
return apiClient.queryCsvContentAsync(
104+
buildPath(REPORTING_PATH, STATEMENTS_PATH, DOWNLOAD_PATH),
105+
sdkAuthorization(),
106+
filter,
107+
targetFile
108+
);
65109
}
66110

67111
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.checkout.reconciliation.previous;
2+
3+
import com.checkout.common.Currency;
4+
import com.google.gson.annotations.SerializedName;
5+
import lombok.Builder;
6+
import lombok.Data;
7+
8+
import java.time.Instant;
9+
10+
@Data
11+
@Builder
12+
public class StatementsQueryFilter {
13+
14+
@SerializedName("payout_id")
15+
private String payoutId;
16+
17+
@SerializedName("payout_currency")
18+
private Currency payoutCurrency;
19+
20+
private Instant from;
21+
22+
private Instant to;
23+
24+
private IncludePayouts include;
25+
}

src/test/java/com/checkout/reconciliation/previous/ReconciliationClientImplTest.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void shouldSinglePaymentReportAsync() throws ExecutionException, InterruptedExce
7878

7979
@Test
8080
void shouldQueryStatementsReport() throws ExecutionException, InterruptedException {
81-
final QueryFilterDateRange request = mock(QueryFilterDateRange.class);
81+
final StatementsQueryFilter request = mock(StatementsQueryFilter.class);
8282
final StatementReportResponse response = mock(StatementReportResponse.class);
8383

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

108+
@Test
109+
void shouldGetStatementsReportByIdWithQuery() throws ExecutionException, InterruptedException {
110+
final StatementsQueryFilter filter = mock(StatementsQueryFilter.class);
111+
final StatementReportResponse response = mock(StatementReportResponse.class);
112+
113+
when(apiClient.queryAsync(eq("reporting/statements/statement_id/payments"), any(SdkAuthorization.class), eq(filter),
114+
eq(StatementReportResponse.class)))
115+
.thenReturn(CompletableFuture.completedFuture(response));
116+
117+
final CompletableFuture<StatementReportResponse> future = client.getStatementsReportByIdQuery("statement_id", filter);
118+
119+
assertNotNull(future.get());
120+
assertEquals(response, future.get());
121+
}
122+
108123
@Test
109124
void shouldRetrieveCSVPaymentReport() throws ExecutionException, InterruptedException {
110125
final String report = "/etc/foo/payment_report.csv";
@@ -139,7 +154,7 @@ void shouldRetrieveCSVSingleStatementReport() throws ExecutionException, Interru
139154
@Test
140155
void shouldRetrieveCSVStatementsReport() throws ExecutionException, InterruptedException {
141156
final String report = "/etc/foo/statement_report.csv";
142-
final QueryFilterDateRange request = mock(QueryFilterDateRange.class);
157+
final StatementsQueryFilter request = mock(StatementsQueryFilter.class);
143158
final ContentResponse response = mock(ContentResponse.class);
144159

145160
when(apiClient.queryCsvContentAsync(eq("reporting/statements/download"), any(SdkAuthorization.class), eq(request),

src/test/java/com/checkout/reconciliation/previous/ReconciliationTestIT.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
class ReconciliationTestIT {
2323

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

114-
final StatementReportResponse response = getProductionCheckoutApi().reconciliationClient().queryStatementsReport(queryFilterDateRange).get();
114+
final StatementReportResponse response = getProductionCheckoutApi().reconciliationClient().queryStatementsReport(statementsQueryFilter).get();
115115

116116
assertNotNull(response);
117117
assertNotNull(response.getLinks());
@@ -235,7 +235,7 @@ void shouldRetrieveCsvSingleStatementReport_saveFile() throws ExecutionException
235235
@Disabled("Only works in production")
236236
void shouldRetrieveCsvStatementsReport() throws ExecutionException, InterruptedException {
237237

238-
final ContentResponse ContentResponse = getProductionCheckoutApi().reconciliationClient().retrieveCSVStatementsReport(queryFilterDateRange, null).get();
238+
final ContentResponse ContentResponse = getProductionCheckoutApi().reconciliationClient().retrieveCSVStatementsReport(statementsQueryFilter, null).get();
239239

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

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

253253
assertNotNull(ContentResponse);
254254
assertFalse(ContentResponse.getContent().isEmpty());

0 commit comments

Comments
 (0)