Skip to content

Commit

Permalink
Adds Juzdan integration to the Java client (#158)
Browse files Browse the repository at this point in the history
* 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
beransantur authored Feb 13, 2024
1 parent 426cae3 commit b474dee
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 0 deletions.
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 @@ -22,6 +22,7 @@ public class Craftgate {
private final MasterpassPaymentAdapter masterpassPaymentAdapter;
private final BankAccountTrackingAdapter bankAccountTrackingAdapter;
private final MerchantAdapter merchantAdapter;
private final JuzdanPaymentAdapter juzdanPaymentAdapter;


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

public PaymentAdapter payment() {
Expand Down Expand Up @@ -116,4 +118,8 @@ public BankAccountTrackingAdapter bankAccountTracking() {
public MerchantAdapter merchant() {
return merchantAdapter;
}

public JuzdanPaymentAdapter juzdan() {
return juzdanPaymentAdapter;
}
}
25 changes: 25 additions & 0 deletions src/main/java/io/craftgate/adapter/JuzdanPaymentAdapter.java
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);
}

}
1 change: 1 addition & 0 deletions src/main/java/io/craftgate/model/PaymentSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ public enum PaymentSource {
API,
CHECKOUT_FORM,
PAY_BY_LINK,
JUZDAN
}
37 changes: 37 additions & 0 deletions src/main/java/io/craftgate/request/InitJuzdanPaymentRequest.java
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
}
}
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;
}
66 changes: 66 additions & 0 deletions src/test/java/io/craftgate/sample/JuzdanSample.java
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());
}

}

0 comments on commit b474dee

Please sign in to comment.