Skip to content

Commit

Permalink
adds merchant adapter for pos and merchant operations (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlicanAkkus authored Dec 5, 2023
1 parent fdf6dee commit d2da746
Show file tree
Hide file tree
Showing 29 changed files with 712 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/main/java/io/craftgate/Craftgate.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class Craftgate {
private final HookAdapter hookAdapter;
private final MasterpassPaymentAdapter masterpassPaymentAdapter;
private final BankAccountTrackingAdapter bankAccountTrackingAdapter;
private final MerchantAdapter merchantAdapter;


public Craftgate(String apiKey, String secretKey) {
Expand Down Expand Up @@ -53,6 +54,7 @@ public Craftgate(String apiKey, String secretKey, String baseUrl, String languag
this.hookAdapter = new HookAdapter(requestOptions);
this.masterpassPaymentAdapter = new MasterpassPaymentAdapter(requestOptions);
this.bankAccountTrackingAdapter = new BankAccountTrackingAdapter(requestOptions);
this.merchantAdapter = new MerchantAdapter(requestOptions);
}

public PaymentAdapter payment() {
Expand Down Expand Up @@ -110,4 +112,8 @@ public MasterpassPaymentAdapter masterpass() {
public BankAccountTrackingAdapter bankAccountTracking() {
return bankAccountTrackingAdapter;
}

public MerchantAdapter merchant() {
return merchantAdapter;
}
}
65 changes: 65 additions & 0 deletions src/main/java/io/craftgate/adapter/MerchantAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package io.craftgate.adapter;

import io.craftgate.model.PosStatus;
import io.craftgate.net.HttpClient;
import io.craftgate.request.CreateMerchantPosRequest;
import io.craftgate.request.SearchMerchantPosRequest;
import io.craftgate.request.UpdateMerchantPosCommissionsRequest;
import io.craftgate.request.UpdateMerchantPosRequest;
import io.craftgate.request.common.RequestOptions;
import io.craftgate.request.common.RequestQueryParamsBuilder;
import io.craftgate.response.MerchantPosCommissionListResponse;
import io.craftgate.response.MerchantPosListResponse;
import io.craftgate.response.MerchantPosResponse;

public class MerchantAdapter extends BaseAdapter {

public MerchantAdapter(RequestOptions requestOptions) {
super(requestOptions);
}

public MerchantPosResponse createMerchantPos(CreateMerchantPosRequest createMerchantPosRequest) {
String path = "/merchant/v1/merchant-poses";
return HttpClient.post(requestOptions.getBaseUrl() + path, createHeaders(createMerchantPosRequest, path, requestOptions),
createMerchantPosRequest, MerchantPosResponse.class);
}

public MerchantPosResponse updateMerchantPos(Long merchantPosId, UpdateMerchantPosRequest updateMerchantPosRequest) {
String path = "/merchant/v1/merchant-poses/" + merchantPosId;
return HttpClient.put(requestOptions.getBaseUrl() + path, createHeaders(updateMerchantPosRequest, path, requestOptions),
updateMerchantPosRequest, MerchantPosResponse.class);
}

public void updateMerchantPosStatus(Long merchantPosId, PosStatus posStatus) {
String path = "/merchant/v1/merchant-poses/" + merchantPosId + "/status/" + posStatus.name();
HttpClient.put(requestOptions.getBaseUrl() + path, createHeaders(path, requestOptions), Void.class);
}

public MerchantPosListResponse searchMerchantPos(SearchMerchantPosRequest searchMerchantPosRequest) {
String query = RequestQueryParamsBuilder.buildQueryParam(searchMerchantPosRequest);
String path = "/merchant/v1/merchant-poses" + query;
return HttpClient.get(requestOptions.getBaseUrl() + path, createHeaders(path, requestOptions), MerchantPosListResponse.class);
}

public MerchantPosResponse retrieve(Long merchantPosId) {
String path = "/merchant/v1/merchant-poses/" + merchantPosId;
return HttpClient.get(requestOptions.getBaseUrl() + path, createHeaders(path, requestOptions), MerchantPosResponse.class);
}

public void deleteMerchantPos(Long merchantPosId) {
String path = "/merchant/v1/merchant-poses/" + merchantPosId;
HttpClient.delete(requestOptions.getBaseUrl() + path, createHeaders(path, requestOptions));
}

public MerchantPosCommissionListResponse retrieveMerchantPosCommissions(Long merchantPosId) {
String path = "/merchant/v1/merchant-poses/" + merchantPosId + "/commissions";
return HttpClient.get(requestOptions.getBaseUrl() + path, createHeaders(path, requestOptions), MerchantPosCommissionListResponse.class);
}
/*
* This endpoint using for creating and updating merchant pos commissions. The HTTP method is POST due to this requirement.
* */
public MerchantPosCommissionListResponse updateMerchantPosCommissions(Long merchantPosId, UpdateMerchantPosCommissionsRequest updateMerchantPosCommissionsRequest) {
String path = "/merchant/v1/merchant-poses/" + merchantPosId + "/commissions";
return HttpClient.post(requestOptions.getBaseUrl() + path, createHeaders(updateMerchantPosCommissionsRequest, path, requestOptions), updateMerchantPosCommissionsRequest, MerchantPosCommissionListResponse.class);
}
}
7 changes: 7 additions & 0 deletions src/main/java/io/craftgate/adapter/OnboardingAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import io.craftgate.net.HttpClient;
import io.craftgate.request.CreateMemberRequest;
import io.craftgate.request.CreateMerchantRequest;
import io.craftgate.request.SearchMembersRequest;
import io.craftgate.request.UpdateMemberRequest;
import io.craftgate.request.common.RequestOptions;
import io.craftgate.request.common.RequestQueryParamsBuilder;
import io.craftgate.response.CreateMerchantResponse;
import io.craftgate.response.MemberListResponse;
import io.craftgate.response.MemberResponse;

Expand Down Expand Up @@ -37,4 +39,9 @@ public MemberListResponse searchMembers(SearchMembersRequest searchMembersReques
String path = "/onboarding/v1/members" + query;
return HttpClient.get(requestOptions.getBaseUrl() + path, createHeaders(path, requestOptions), MemberListResponse.class);
}

public CreateMerchantResponse createMerchant(CreateMerchantRequest createMerchantRequest) {
String path = "/onboarding/v1/merchants";
return HttpClient.post(requestOptions.getBaseUrl() + path, createHeaders(createMerchantRequest, path, requestOptions), createMerchantRequest, CreateMerchantResponse.class);
}
}
9 changes: 9 additions & 0 deletions src/main/java/io/craftgate/model/AutopilotState.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.craftgate.model;

import lombok.Data;

@Data
public class AutopilotState {
private Boolean isThreeDsUp;
private Boolean isNonThreeDsUp;
}
23 changes: 23 additions & 0 deletions src/main/java/io/craftgate/model/CardBrand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.craftgate.model;

public enum CardBrand {
BONUS("Bonus"),
AXESS("Axess"),
MAXIMUM("Maximum"),
WORLD("World"),
PARAF("Paraf"),
CARD_FINANS("CardFinans"),
BANKKART_COMBO("Bankkart Combo"),
ADVANTAGE("Advantage"),
SAGLAM_KART("Sağlam Kart");

private final String cardBrandName;

CardBrand(String cardBrandName) {
this.cardBrandName = cardBrandName;
}

public String toName() {
return this.cardBrandName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.craftgate.model;

public enum PaymentAuthenticationType {

THREE_DS,
NON_THREE_DS
}
39 changes: 39 additions & 0 deletions src/main/java/io/craftgate/model/PosIntegrator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.craftgate.model;

public enum PosIntegrator {

YKB,
GARANTI,
ISBANK,
AKBANK,
ZIRAATBANK,
ZIRAATBANK_INNOVA,
ZIRAATKATILIM,
KUVEYTTURK,
HALKBANK,
DENIZBANK,
VAKIFBANK,
VAKIFKATILIM,
FINANSBANK,
FIBABANK,
FIBABANK_ASSECO,
ANADOLUBANK,
PARAM_POS,
IYZICO,
SIPAY,
PAYNET,
PAYTR,
BIRLESIK_ODEME,
MOKA,
STRIPE,
TEB,
IPARA,
OZAN,
BRAINTREE,
NKOLAY,
PAYTABS,
PAYBULL,
ELEKSE,
ALGORITMA,
PAYCELL
}
11 changes: 11 additions & 0 deletions src/main/java/io/craftgate/model/PosOperationType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.craftgate.model;

public enum PosOperationType {

STANDARD,
PROVAUT,
PROVRFN,
PAYMENT,
REFUND,
INQUIRY
}
10 changes: 10 additions & 0 deletions src/main/java/io/craftgate/model/PosStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.craftgate.model;

public enum PosStatus {

DELETED,
PASSIVE,
ACTIVE,
REFUND_ONLY,
AUTOPILOT;
}
5 changes: 5 additions & 0 deletions src/main/java/io/craftgate/model/PosUserType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.craftgate.model;

public enum PosUserType {
API
}
3 changes: 2 additions & 1 deletion src/main/java/io/craftgate/model/WebhookEventType.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ public enum WebhookEventType {
AUTOPILOT,
WALLET_CREATED,
WALLET_TX_CREATED,
BNPL_NOTIFICATION
BNPL_NOTIFICATION,
BANK_ACCOUNT_TRACKING_RECORD
}
4 changes: 4 additions & 0 deletions src/main/java/io/craftgate/net/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public static <T> T put(String url, Map<String, String> headers, Object request,
return exchange(url, HttpMethod.PUT, headers, request, responseType);
}

public static <T> T put(String url, Map<String, String> headers, Class<T> responseType) {
return exchange(url, HttpMethod.PUT, headers, null, responseType);
}

public static void delete(String url, Map<String, String> headers) {
exchange(url, HttpMethod.DELETE, headers, null, Void.class);
}
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/io/craftgate/request/CreateMerchantPosRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.craftgate.request;

import io.craftgate.model.Currency;
import io.craftgate.model.PaymentAuthenticationType;
import io.craftgate.model.PosIntegrator;
import io.craftgate.model.PosStatus;
import io.craftgate.request.dto.CreateMerchantPosUser;
import lombok.Builder;
import lombok.Data;

import java.util.List;

@Data
@Builder
public class CreateMerchantPosRequest {

@Builder.Default
private PosStatus status = PosStatus.AUTOPILOT;
private String name;
private String clientId;
private Currency currency;
private String posnetId;
private String terminalId;
private String threedsPosnetId;
private String threedsTerminalId;
private String threedsKey;
private Boolean enableForeignCard;
private Boolean enableInstallment;
private Boolean enablePaymentWithoutCvc;
private Boolean newIntegration;
private Integer orderNumber;
private PosIntegrator posIntegrator;
private List<PaymentAuthenticationType> enabledPaymentAuthenticationTypes;
private List<CreateMerchantPosUser> merchantPosUsers;
}
19 changes: 19 additions & 0 deletions src/main/java/io/craftgate/request/CreateMerchantRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.craftgate.request;

import lombok.Data;
import lombok.experimental.SuperBuilder;

@Data
@SuperBuilder
public class CreateMerchantRequest {

private String name;
private String legalCompanyTitle;
private String email;
private String secretWord;
private String website;
private String phoneNumber;
private String contactName;
private String contactSurname;
private String contactPhoneNumber;
}
19 changes: 19 additions & 0 deletions src/main/java/io/craftgate/request/SearchMerchantPosRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.craftgate.request;

import io.craftgate.model.Currency;
import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class SearchMerchantPosRequest {
private String name;
private String alias;
private Currency currency;
private Boolean enableInstallment;
private Boolean enableForeignCard;
private String bankName;
private Integer page;
private Integer size;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.craftgate.request;

import io.craftgate.request.dto.UpdateMerchantPosCommission;
import lombok.Builder;
import lombok.Data;

import java.util.List;

@Data
@Builder
public class UpdateMerchantPosCommissionsRequest {

private List<UpdateMerchantPosCommission> commissions;

}
34 changes: 34 additions & 0 deletions src/main/java/io/craftgate/request/UpdateMerchantPosRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.craftgate.request;

import io.craftgate.model.CardAssociation;
import io.craftgate.model.PaymentAuthenticationType;
import io.craftgate.request.dto.UpdateMerchantPosUser;
import lombok.Builder;
import lombok.Data;

import java.util.List;

@Data
@Builder
public class UpdateMerchantPosRequest {
private String name;
private String hostname;
private String clientId;
private String mode;
private String path;
private Integer port;
private String posnetId;
private String terminalId;
private String threedsPosnetId;
private String threedsTerminalId;
private String threedsKey;
private String threedsPath;
private Boolean enableForeignCard;
private Boolean enableInstallment;
private Boolean enablePaymentWithoutCvc;
private Boolean newIntegration;
private Integer orderNumber;
private List<CardAssociation> supportedCardAssociations;
private List<PaymentAuthenticationType> enabledPaymentAuthenticationTypes;
private List<UpdateMerchantPosUser> merchantPosUsers;
}
15 changes: 15 additions & 0 deletions src/main/java/io/craftgate/request/dto/CreateMerchantPosUser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.craftgate.request.dto;

import io.craftgate.model.PosOperationType;
import io.craftgate.model.PosUserType;
import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class CreateMerchantPosUser {
private String posUsername;
private String posPassword;
private PosUserType posUserType;
private PosOperationType posOperationType;
}
Loading

0 comments on commit d2da746

Please sign in to comment.