Skip to content

Commit

Permalink
adds bank account tracking adapter to retrieve bank account tracking …
Browse files Browse the repository at this point in the history
…record (#130)
  • Loading branch information
AlicanAkkus authored Nov 13, 2023
1 parent fa82269 commit b328569
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 17 deletions.
18 changes: 1 addition & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions src/main/java/io/craftgate/Craftgate.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -103,4 +106,8 @@ public HookAdapter hook() {
public MasterpassPaymentAdapter masterpass() {
return masterpassPaymentAdapter;
}

public BankAccountTrackingAdapter bankAccountTracking() {
return bankAccountTrackingAdapter;
}
}
26 changes: 26 additions & 0 deletions src/main/java/io/craftgate/adapter/BankAccountTrackingAdapter.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.craftgate.model;

public enum BankAccountTrackingSource {
YKB
}
7 changes: 7 additions & 0 deletions src/main/java/io/craftgate/model/RecordType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.craftgate.model;

public enum RecordType {

SEND,
RECEIVE
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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<BankAccountTrackingRecordResponse> {

}
Original file line number Diff line number Diff line change
@@ -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;
}
36 changes: 36 additions & 0 deletions src/test/java/io/craftgate/sample/BankAccountTrackingSample.java
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit b328569

Please sign in to comment.