From b328569420e689da7619589523384fd7518d3d9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alican=20Akku=C5=9F?= Date: Mon, 13 Nov 2023 13:12:53 +0300 Subject: [PATCH] adds bank account tracking adapter to retrieve bank account tracking record (#130) --- README.md | 18 +--------- src/main/java/io/craftgate/Craftgate.java | 7 ++++ .../adapter/BankAccountTrackingAdapter.java | 26 ++++++++++++++ .../model/BankAccountTrackingSource.java | 5 +++ .../java/io/craftgate/model/RecordType.java | 7 ++++ ...archBankAccountTrackingRecordsRequest.java | 28 +++++++++++++++ ...BankAccountTrackingRecordListResponse.java | 11 ++++++ .../BankAccountTrackingRecordResponse.java | 24 +++++++++++++ .../sample/BankAccountTrackingSample.java | 36 +++++++++++++++++++ 9 files changed, 145 insertions(+), 17 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/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/Craftgate.java b/src/main/java/io/craftgate/Craftgate.java index e629cefa..3888866f 100644 --- a/src/main/java/io/craftgate/Craftgate.java +++ b/src/main/java/io/craftgate/Craftgate.java @@ -20,6 +20,8 @@ public class Craftgate { private final FraudAdapter fraudAdapter; private final HookAdapter hookAdapter; private final MasterpassPaymentAdapter masterpassPaymentAdapter; + private final BankAccountTrackingAdapter bankAccountTrackingAdapter; + public Craftgate(String apiKey, String secretKey) { this(apiKey, secretKey, BASE_URL, null); @@ -50,6 +52,7 @@ public Craftgate(String apiKey, String secretKey, String baseUrl, String languag this.fraudAdapter = new FraudAdapter(requestOptions); this.hookAdapter = new HookAdapter(requestOptions); this.masterpassPaymentAdapter = new MasterpassPaymentAdapter(requestOptions); + this.bankAccountTrackingAdapter = new BankAccountTrackingAdapter(requestOptions); } public PaymentAdapter payment() { @@ -103,4 +106,8 @@ public HookAdapter hook() { public MasterpassPaymentAdapter masterpass() { return masterpassPaymentAdapter; } + + 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..d62d2c44 --- /dev/null +++ b/src/main/java/io/craftgate/adapter/BankAccountTrackingAdapter.java @@ -0,0 +1,26 @@ +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; +import io.craftgate.response.BankAccountTrackingRecordResponse; + +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); + } + + 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/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..26dbd0e9 --- /dev/null +++ b/src/test/java/io/craftgate/sample/BankAccountTrackingSample.java @@ -0,0 +1,36 @@ +package io.craftgate.sample; + +import io.craftgate.Craftgate; +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.*; + +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); + 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); + } +}