From a1a1f3072348d5e7ab09aa8ed9f330e4807aac97 Mon Sep 17 00:00:00 2001 From: Alican Akkus Date: Fri, 21 Jul 2023 17:31:27 +0300 Subject: [PATCH 1/2] adds bank account tracking adapter to retrieve bank account tracking record --- src/main/java/io/craftgate/Craftgate.java | 10 +++++-- .../adapter/BankAccountTrackingAdapter.java | 20 +++++++++++++ .../model/BankAccountTrackingSource.java | 5 ++++ .../java/io/craftgate/model/RecordType.java | 7 +++++ ...archBankAccountTrackingRecordsRequest.java | 28 +++++++++++++++++++ ...BankAccountTrackingRecordListResponse.java | 11 ++++++++ .../BankAccountTrackingRecordResponse.java | 24 ++++++++++++++++ .../sample/BankAccountTrackingSample.java | 28 +++++++++++++++++++ 8 files changed, 130 insertions(+), 3 deletions(-) create mode 100644 src/main/java/io/craftgate/adapter/BankAccountTrackingAdapter.java create mode 100644 src/main/java/io/craftgate/model/BankAccountTrackingSource.java create mode 100644 src/main/java/io/craftgate/model/RecordType.java create mode 100644 src/main/java/io/craftgate/request/SearchBankAccountTrackingRecordsRequest.java create mode 100644 src/main/java/io/craftgate/response/BankAccountTrackingRecordListResponse.java create mode 100644 src/main/java/io/craftgate/response/BankAccountTrackingRecordResponse.java create mode 100644 src/test/java/io/craftgate/sample/BankAccountTrackingSample.java diff --git a/src/main/java/io/craftgate/Craftgate.java b/src/main/java/io/craftgate/Craftgate.java index 6cfcc0b8..10084e4c 100644 --- a/src/main/java/io/craftgate/Craftgate.java +++ b/src/main/java/io/craftgate/Craftgate.java @@ -1,11 +1,8 @@ package io.craftgate; import io.craftgate.adapter.*; -import io.craftgate.request.common.HashGenerator; import io.craftgate.request.common.RequestOptions; -import java.util.Map; - public class Craftgate { private static final String BASE_URL = "https://api.craftgate.io"; @@ -21,6 +18,8 @@ public class Craftgate { private final PayByLinkAdapter payByLinkAdapter; private final FraudAdapter fraudAdapter; private final HookAdapter hookAdapter; + private final BankAccountTrackingAdapter bankAccountTrackingAdapter; + public Craftgate(String apiKey, String secretKey) { this(apiKey, secretKey, BASE_URL, null); @@ -49,6 +48,7 @@ public Craftgate(String apiKey, String secretKey, String baseUrl, String languag this.payByLinkAdapter = new PayByLinkAdapter(requestOptions); this.fraudAdapter = new FraudAdapter(requestOptions); this.hookAdapter = new HookAdapter(requestOptions); + this.bankAccountTrackingAdapter = new BankAccountTrackingAdapter(requestOptions); } public PaymentAdapter payment() { @@ -94,4 +94,8 @@ public FraudAdapter fraud() { public HookAdapter hook() { return hookAdapter; } + + public BankAccountTrackingAdapter bankAccountTracking() { + return bankAccountTrackingAdapter; + } } diff --git a/src/main/java/io/craftgate/adapter/BankAccountTrackingAdapter.java b/src/main/java/io/craftgate/adapter/BankAccountTrackingAdapter.java new file mode 100644 index 00000000..56ad61db --- /dev/null +++ b/src/main/java/io/craftgate/adapter/BankAccountTrackingAdapter.java @@ -0,0 +1,20 @@ +package io.craftgate.adapter; + +import io.craftgate.net.HttpClient; +import io.craftgate.request.SearchBankAccountTrackingRecordsRequest; +import io.craftgate.request.common.RequestOptions; +import io.craftgate.request.common.RequestQueryParamsBuilder; +import io.craftgate.response.BankAccountTrackingRecordListResponse; + +public class BankAccountTrackingAdapter extends BaseAdapter { + + public BankAccountTrackingAdapter(RequestOptions requestOptions) { + super(requestOptions); + } + + public BankAccountTrackingRecordListResponse searchRecords(SearchBankAccountTrackingRecordsRequest request) { + String query = RequestQueryParamsBuilder.buildQueryParam(request); + String path = "/bank-account-tracking/v1/merchant-bank-account-trackings/records" + query; + return HttpClient.get(requestOptions.getBaseUrl() + path, createHeaders(path, requestOptions), BankAccountTrackingRecordListResponse.class); + } +} \ No newline at end of file diff --git a/src/main/java/io/craftgate/model/BankAccountTrackingSource.java b/src/main/java/io/craftgate/model/BankAccountTrackingSource.java new file mode 100644 index 00000000..2f4f7aba --- /dev/null +++ b/src/main/java/io/craftgate/model/BankAccountTrackingSource.java @@ -0,0 +1,5 @@ +package io.craftgate.model; + +public enum BankAccountTrackingSource { + YKB +} diff --git a/src/main/java/io/craftgate/model/RecordType.java b/src/main/java/io/craftgate/model/RecordType.java new file mode 100644 index 00000000..20712ba9 --- /dev/null +++ b/src/main/java/io/craftgate/model/RecordType.java @@ -0,0 +1,7 @@ +package io.craftgate.model; + +public enum RecordType { + + SEND, + RECEIVE +} diff --git a/src/main/java/io/craftgate/request/SearchBankAccountTrackingRecordsRequest.java b/src/main/java/io/craftgate/request/SearchBankAccountTrackingRecordsRequest.java new file mode 100644 index 00000000..a1483b50 --- /dev/null +++ b/src/main/java/io/craftgate/request/SearchBankAccountTrackingRecordsRequest.java @@ -0,0 +1,28 @@ +package io.craftgate.request; + +import io.craftgate.model.CardAssociation; +import io.craftgate.model.CardExpiryStatus; +import io.craftgate.model.CardType; +import io.craftgate.model.Currency; +import lombok.Builder; +import lombok.Data; + +import java.time.LocalDateTime; + +@Data +@Builder +public class SearchBankAccountTrackingRecordsRequest { + + private Currency currency; + private String description; + private String senderName; + private String senderIban; + private LocalDateTime minRecordDate; + private LocalDateTime maxRecordDate; + + @Builder.Default + private Integer page = 0; + + @Builder.Default + private Integer size = 10; +} diff --git a/src/main/java/io/craftgate/response/BankAccountTrackingRecordListResponse.java b/src/main/java/io/craftgate/response/BankAccountTrackingRecordListResponse.java new file mode 100644 index 00000000..917c4331 --- /dev/null +++ b/src/main/java/io/craftgate/response/BankAccountTrackingRecordListResponse.java @@ -0,0 +1,11 @@ +package io.craftgate.response; + +import io.craftgate.response.common.ListResponse; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@Data +@EqualsAndHashCode(callSuper = true) +public class BankAccountTrackingRecordListResponse extends ListResponse { + +} diff --git a/src/main/java/io/craftgate/response/BankAccountTrackingRecordResponse.java b/src/main/java/io/craftgate/response/BankAccountTrackingRecordResponse.java new file mode 100644 index 00000000..981a74eb --- /dev/null +++ b/src/main/java/io/craftgate/response/BankAccountTrackingRecordResponse.java @@ -0,0 +1,24 @@ +package io.craftgate.response; + +import io.craftgate.model.BankAccountTrackingSource; +import io.craftgate.model.Currency; +import io.craftgate.model.RecordType; +import lombok.Data; + +import java.math.BigDecimal; +import java.time.LocalDateTime; + +@Data +public class BankAccountTrackingRecordResponse { + + private Long id; + private String key; + private Currency currency; + private RecordType recordType; + private String senderName; + private String senderIban; + private String description; + private LocalDateTime recordDate; + private BigDecimal amount; + private BankAccountTrackingSource bankAccountTrackingSource; +} diff --git a/src/test/java/io/craftgate/sample/BankAccountTrackingSample.java b/src/test/java/io/craftgate/sample/BankAccountTrackingSample.java new file mode 100644 index 00000000..a80e19fa --- /dev/null +++ b/src/test/java/io/craftgate/sample/BankAccountTrackingSample.java @@ -0,0 +1,28 @@ +package io.craftgate.sample; + +import io.craftgate.Craftgate; +import io.craftgate.model.Currency; +import io.craftgate.request.SearchBankAccountTrackingRecordsRequest; +import io.craftgate.response.BankAccountTrackingRecordListResponse; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class BankAccountTrackingSample { + + private final Craftgate craftgate = new Craftgate("api-key", "secret-key", "https://sandbox-api.craftgate.io"); + + @Test + void search_bank_account_tracking_records() { + SearchBankAccountTrackingRecordsRequest request = SearchBankAccountTrackingRecordsRequest.builder() + .page(0) + .size(10) + .currency(Currency.TRY) + .build(); + + BankAccountTrackingRecordListResponse response = craftgate.bankAccountTracking().searchRecords(request); + assertNotNull(response); + assertTrue(response.getItems().size() > 0); + } +} From 495d34a7f40b03badaa134d57b364223e4f2f057 Mon Sep 17 00:00:00 2001 From: Alican Akkus Date: Thu, 9 Nov 2023 15:40:47 +0300 Subject: [PATCH 2/2] adds bank account tracking adapter --- README.md | 18 +----------------- .../adapter/BankAccountTrackingAdapter.java | 6 ++++++ .../sample/BankAccountTrackingSample.java | 14 +++++++++++--- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 00201916..48a14dc4 100644 --- a/README.md +++ b/README.md @@ -107,24 +107,8 @@ PaymentResponse response = craftgate.payment().createPayment(request); System.out.println(String.format("Create Payment Result: %s", response)); ``` -### Advanced Usage: Adapters -In reality, the `Craftgate` class serves as a collection of adapters that integrates with different parts of the API. While the intended usage for most use-cases is to instantiate a `Craftgate` instance (as illustrated in the examples above) and use its adapter accessors (e.g. `payment()`), you can also manually import a certain adapter class and instantiate it. - -**Note:** When instantiating an adapter, you can use the same options as you would when instantiating a `Craftgate` - -For all adapters in the `Craftgate`, their purposes, accessors, as well as direct import paths, refer to the list below: - -| Adapter Name | Purpose | Accessor | -|--------------|---------|----------| -| `InstallmentAdapter` | Retrieving per-installment pricing information based on installment count or BIN number | `installment()` | -| `OnboardingAdapter` | Conducting CRUD operations on buyers and submerchants | `onboarding()` | -| `PaymentAdapter` | Conducting payments, retrieving payment information, managing stored cards | `payment()` | -| `WalletAdapter` | Wallet operations like send, receive remittance and search wallets or wallet transactions of member's | `wallet()` | -| `SettlementReportingAdapter` | Settlement operations like search payout completed transactions, search bounced payout transactions | `settlementReporting()` | -| `SettlementAdapter` | Settlement operations like create instant wallet settlement | `settlement()` | - ### Contributions - For all contributions to this client please see the contribution guide [here](CONTRIBUTING.md). + ## License MIT diff --git a/src/main/java/io/craftgate/adapter/BankAccountTrackingAdapter.java b/src/main/java/io/craftgate/adapter/BankAccountTrackingAdapter.java index 56ad61db..d62d2c44 100644 --- a/src/main/java/io/craftgate/adapter/BankAccountTrackingAdapter.java +++ b/src/main/java/io/craftgate/adapter/BankAccountTrackingAdapter.java @@ -5,6 +5,7 @@ import io.craftgate.request.common.RequestOptions; import io.craftgate.request.common.RequestQueryParamsBuilder; import io.craftgate.response.BankAccountTrackingRecordListResponse; +import io.craftgate.response.BankAccountTrackingRecordResponse; public class BankAccountTrackingAdapter extends BaseAdapter { @@ -17,4 +18,9 @@ public BankAccountTrackingRecordListResponse searchRecords(SearchBankAccountTrac String path = "/bank-account-tracking/v1/merchant-bank-account-trackings/records" + query; return HttpClient.get(requestOptions.getBaseUrl() + path, createHeaders(path, requestOptions), BankAccountTrackingRecordListResponse.class); } + + public BankAccountTrackingRecordResponse retrieveRecord(Long id) { + String path = "/bank-account-tracking/v1/merchant-bank-account-trackings/records/" + id; + return HttpClient.get(requestOptions.getBaseUrl() + path, createHeaders(path, requestOptions), BankAccountTrackingRecordResponse.class); + } } \ No newline at end of file diff --git a/src/test/java/io/craftgate/sample/BankAccountTrackingSample.java b/src/test/java/io/craftgate/sample/BankAccountTrackingSample.java index a80e19fa..26dbd0e9 100644 --- a/src/test/java/io/craftgate/sample/BankAccountTrackingSample.java +++ b/src/test/java/io/craftgate/sample/BankAccountTrackingSample.java @@ -4,10 +4,10 @@ import io.craftgate.model.Currency; import io.craftgate.request.SearchBankAccountTrackingRecordsRequest; import io.craftgate.response.BankAccountTrackingRecordListResponse; +import io.craftgate.response.BankAccountTrackingRecordResponse; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; public class BankAccountTrackingSample { @@ -23,6 +23,14 @@ void search_bank_account_tracking_records() { BankAccountTrackingRecordListResponse response = craftgate.bankAccountTracking().searchRecords(request); assertNotNull(response); - assertTrue(response.getItems().size() > 0); + assertFalse(response.getItems().isEmpty()); + } + + @Test + void retrieve_bank_account_tracking_record() { + Long recordId = 326L; + BankAccountTrackingRecordResponse response = craftgate.bankAccountTracking().retrieveRecord(recordId); + assertNotNull(response); + assertEquals(response.getId(), recordId); } }