-
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.
Adds Juzdan integration to the Java client (#158)
* Juzdan is added to Java client * Client type is added to same class and CreatePaymentItemRequest.java is deleted * renaming of testing variable
- Loading branch information
1 parent
426cae3
commit b474dee
Showing
6 changed files
with
144 additions
and
0 deletions.
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
25 changes: 25 additions & 0 deletions
25
src/main/java/io/craftgate/adapter/JuzdanPaymentAdapter.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,25 @@ | ||
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 JuzdanPaymentAdapter extends BaseAdapter { | ||
|
||
public JuzdanPaymentAdapter(RequestOptions requestOptions) { | ||
super(requestOptions); | ||
} | ||
|
||
public InitJuzdanPaymentResponse init(InitJuzdanPaymentRequest initJuzdanPaymentRequest) { | ||
String path = "/payment/v1/juzdan-payments/init"; | ||
return HttpClient.post(requestOptions.getBaseUrl() + path, createHeaders(initJuzdanPaymentRequest, path, requestOptions), | ||
initJuzdanPaymentRequest, InitJuzdanPaymentResponse.class); | ||
} | ||
|
||
public PaymentResponse retrieve(String referenceId) { | ||
String path = "/payment/v1/juzdan-payments/" + referenceId; | ||
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 |
---|---|---|
|
@@ -5,4 +5,5 @@ public enum PaymentSource { | |
API, | ||
CHECKOUT_FORM, | ||
PAY_BY_LINK, | ||
JUZDAN | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/io/craftgate/request/InitJuzdanPaymentRequest.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,37 @@ | ||
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.Builder; | ||
import lombok.Data; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.List; | ||
|
||
@Data | ||
@Builder | ||
public class InitJuzdanPaymentRequest { | ||
private BigDecimal price; | ||
private BigDecimal paidPrice; | ||
private Currency currency; | ||
private PaymentGroup paymentGroup; | ||
private String conversationId; | ||
private String externalId; | ||
private String callbackUrl; | ||
|
||
@Builder.Default | ||
private PaymentPhase paymentPhase = PaymentPhase.AUTH; | ||
private String paymentChannel; | ||
private Long buyerMemberId; | ||
private String bankOrderId; | ||
private List<PaymentItem> items; | ||
private ClientType clientType; | ||
private Long loanCampaignId; | ||
|
||
public enum ClientType { | ||
M, | ||
W | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/io/craftgate/response/InitJuzdanPaymentResponse.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,9 @@ | ||
package io.craftgate.response; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class InitJuzdanPaymentResponse { | ||
private String referenceId; | ||
private String juzdanQrUrl; | ||
} |
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,66 @@ | ||
package io.craftgate.sample; | ||
|
||
import io.craftgate.Craftgate; | ||
import io.craftgate.model.*; | ||
import io.craftgate.request.InitJuzdanPaymentRequest; | ||
import io.craftgate.request.dto.PaymentItem; | ||
import io.craftgate.response.InitJuzdanPaymentResponse; | ||
import io.craftgate.response.PaymentResponse; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class JuzdanSample { | ||
|
||
private final Craftgate craftgate = new Craftgate("api-key", "secret-key", "https://sandbox-api.craftgate.io"); | ||
|
||
@Test | ||
void init() { | ||
List<PaymentItem> items = new LinkedList<>(); | ||
|
||
PaymentItem paymentItem = PaymentItem.builder() | ||
.price(BigDecimal.ONE) | ||
.name("test123") | ||
.externalId("test2") | ||
.build(); | ||
|
||
items.add(paymentItem); | ||
|
||
InitJuzdanPaymentRequest initJuzdanPaymentRequest = InitJuzdanPaymentRequest.builder() | ||
.price(BigDecimal.ONE) | ||
.paidPrice(BigDecimal.ONE) | ||
.currency(Currency.TRY) | ||
.paymentGroup(PaymentGroup.PRODUCT) | ||
.conversationId("testConversationId") | ||
.externalId("testExternalId") | ||
.callbackUrl("www.testCallbackUrl.com") | ||
.clientType(InitJuzdanPaymentRequest.ClientType.W) | ||
.items(items) | ||
.paymentPhase(PaymentPhase.AUTH) | ||
.paymentChannel("testPaymentChannel") | ||
.bankOrderId("testBankOrderId") | ||
.build(); | ||
|
||
InitJuzdanPaymentResponse initResponse = assertDoesNotThrow(() -> craftgate.juzdan().init(initJuzdanPaymentRequest)); | ||
assertNotNull(initResponse); | ||
assertNotNull(initResponse.getJuzdanQrUrl()); | ||
assertNotNull(initResponse.getReferenceId()); | ||
} | ||
|
||
@Test | ||
void retrieve() { | ||
|
||
String referenceId = "5493c7a7-4d8b-4517-887d-f8b8f826a3d0"; | ||
|
||
PaymentResponse paymentResponse = assertDoesNotThrow(() -> craftgate.juzdan().retrieve(referenceId)); | ||
|
||
assertNotNull(paymentResponse); | ||
assertEquals(PaymentSource.JUZDAN, paymentResponse.getPaymentSource()); | ||
assertEquals(PaymentType.CARD_PAYMENT, paymentResponse.getPaymentType()); | ||
} | ||
|
||
} |