-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* BKM Express integration * Add BKM Express integration * update --------- Co-authored-by: Alican Akkuş <[email protected]>
- Loading branch information
1 parent
a55af45
commit d8b61e6
Showing
8 changed files
with
186 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/io/craftgate/adapter/BkmExpressPaymentAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,6 @@ | |
public enum PaymentAuthenticationType { | ||
|
||
THREE_DS, | ||
NON_THREE_DS | ||
NON_THREE_DS, | ||
BKM_EXPRESS | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/io/craftgate/request/CompleteBkmExpressRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
26
src/main/java/io/craftgate/request/InitBkmExpressRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
src/main/java/io/craftgate/response/InitBkmExpressResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
src/main/java/io/craftgate/response/dto/BkmExpressToken.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |