Skip to content

Commit

Permalink
Add BKM Express Integration (#191)
Browse files Browse the repository at this point in the history
* BKM Express integration

* Add BKM Express integration

* update

---------

Co-authored-by: Alican Akkuş <[email protected]>
  • Loading branch information
deryacakmak and AlicanAkkus authored Jul 3, 2024
1 parent a55af45 commit d8b61e6
Show file tree
Hide file tree
Showing 8 changed files with 186 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 @@ -23,6 +23,7 @@ public class Craftgate {
private final BankAccountTrackingAdapter bankAccountTrackingAdapter;
private final MerchantAdapter merchantAdapter;
private final JuzdanPaymentAdapter juzdanPaymentAdapter;
private final BkmExpressPaymentAdapter bkmExpressPaymentAdapter;


public Craftgate(String apiKey, String secretKey) {
Expand Down Expand Up @@ -57,6 +58,7 @@ public Craftgate(String apiKey, String secretKey, String baseUrl, String languag
this.bankAccountTrackingAdapter = new BankAccountTrackingAdapter(requestOptions);
this.merchantAdapter = new MerchantAdapter(requestOptions);
this.juzdanPaymentAdapter = new JuzdanPaymentAdapter(requestOptions);
this.bkmExpressPaymentAdapter = new BkmExpressPaymentAdapter(requestOptions);
}

public PaymentAdapter payment() {
Expand Down Expand Up @@ -122,4 +124,8 @@ public MerchantAdapter merchant() {
public JuzdanPaymentAdapter juzdan() {
return juzdanPaymentAdapter;
}

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

import io.craftgate.net.HttpClient;
import io.craftgate.request.*;
import io.craftgate.request.common.RequestOptions;
import io.craftgate.response.*;

public class BkmExpressPaymentAdapter extends BaseAdapter {

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

public InitBkmExpressResponse init(InitBkmExpressRequest initBkmExpressRequest) {
String path = "/payment/v1/bkm-express/init";
return HttpClient.post(requestOptions.getBaseUrl() + path, createHeaders(initBkmExpressRequest, path, requestOptions),
initBkmExpressRequest, InitBkmExpressResponse.class);
}

public PaymentResponse complete(CompleteBkmExpressRequest completeRequest) {
String path = "/payment/v1/bkm-express/complete";
return HttpClient.post(requestOptions.getBaseUrl() + path, createHeaders(completeRequest, path, requestOptions),
completeRequest, PaymentResponse.class);
}

public PaymentResponse retrievePayment(String ticketId) {
String path = "/payment/v1/bkm-express/payments/" + ticketId;
return HttpClient.get(requestOptions.getBaseUrl() + path, createHeaders(path, requestOptions), PaymentResponse.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
public enum PaymentAuthenticationType {

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

import lombok.*;

@Data
@Builder
public class CompleteBkmExpressRequest {

private boolean status;
private String message;
private String ticketId;
}
26 changes: 26 additions & 0 deletions src/main/java/io/craftgate/request/InitBkmExpressRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.craftgate.request;

import io.craftgate.model.Currency;
import io.craftgate.model.PaymentGroup;
import io.craftgate.model.PaymentPhase;
import io.craftgate.request.dto.PaymentItem;
import lombok.*;

import java.math.BigDecimal;
import java.util.List;

@Data
@Builder
public class InitBkmExpressRequest {

private BigDecimal price;
private BigDecimal paidPrice;
private PaymentGroup paymentGroup;
private String conversationId;
private PaymentPhase paymentPhase;
private List<PaymentItem> items;
private List<Integer> enabledInstallments;
private Long buyerMemberId;
private Currency currency;
private String bankOrderId;
}
13 changes: 13 additions & 0 deletions src/main/java/io/craftgate/response/InitBkmExpressResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.craftgate.response;

import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class InitBkmExpressResponse {

private String id;
private String path;
private String token;
}
13 changes: 13 additions & 0 deletions src/main/java/io/craftgate/response/dto/BkmExpressToken.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.craftgate.response.dto;

import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class BkmExpressToken {

private String id;
private String path;
private String token;
}
84 changes: 84 additions & 0 deletions src/test/java/io/craftgate/sample/BkmExpressSample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package io.craftgate.sample;

import io.craftgate.Craftgate;
import io.craftgate.model.Currency;
import io.craftgate.model.PaymentGroup;
import io.craftgate.model.PaymentPhase;
import io.craftgate.request.*;
import io.craftgate.request.dto.PaymentItem;
import io.craftgate.response.*;
import org.junit.jupiter.api.Test;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import static org.junit.jupiter.api.Assertions.*;

public class BkmExpressSample {

private final Craftgate craftgate = new Craftgate("api-key", "secret-key", "https://sandbox-api.craftgate.io");

@Test
void init_bkm_express() {
List<PaymentItem> items = new ArrayList<>();

items.add(PaymentItem.builder()
.name("item 1")
.externalId(UUID.randomUUID().toString())
.price(BigDecimal.valueOf(0.3))
.build());

items.add(PaymentItem.builder()
.name("item 2")
.externalId(UUID.randomUUID().toString())
.price(BigDecimal.valueOf(0.5))
.build());

items.add(PaymentItem.builder()
.name("item 3")
.externalId(UUID.randomUUID().toString())
.price(BigDecimal.valueOf(0.2))
.build());

InitBkmExpressRequest request = InitBkmExpressRequest.builder()
.price(BigDecimal.ONE)
.paidPrice(BigDecimal.ONE)
.paymentGroup(PaymentGroup.LISTING_OR_SUBSCRIPTION)
.conversationId("d1811bb0-25a2-40c7-ba71-c8b605259611")
.currency(Currency.TRY)
.items(items)
.paymentPhase(PaymentPhase.AUTH)
.build();

InitBkmExpressResponse response = craftgate.bkmExpressPaymentAdapter().init(request);
assertNotNull(response);
assertNotNull(response.getToken());
assertNotNull(response.getPath());
assertNotNull(response.getId());
}

@Test
void complete_bkm_express() {

CompleteBkmExpressRequest completeBkmExpressRequest = CompleteBkmExpressRequest.builder()
.message("İşlem Başarılı")
.status(true)
.ticketId("dcfdc163-0545-46d7-8f86-5a11718e56ec")
.build();

PaymentResponse response = craftgate.bkmExpressPaymentAdapter().complete(completeBkmExpressRequest);
assertNotNull(response);
assertNotNull(response.getOrderId());
}

@Test
void retrieve_bkm_express_payment() {

String ticketId = "b9bd7b93-662f-4460-9ef3-8fc735853cf1";

PaymentResponse response = craftgate.bkmExpressPaymentAdapter().retrievePayment(ticketId);
assertNotNull(response);
}
}

0 comments on commit d8b61e6

Please sign in to comment.