Skip to content

Commit

Permalink
adds cpp methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Berkay Dinçer committed Jan 22, 2021
1 parent 8bb86b6 commit 455f608
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/io/craftgate/adapter/PaymentAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ public PaymentResponse complete3DSPayment(CompleteThreeDSPaymentRequest complete
completeThreeDSPaymentRequest, PaymentResponse.class);
}

public InitCheckoutPaymentResponse initCheckoutPayment(InitCheckoutPaymentRequest initCheckoutPaymentRequest) {
String path = "/payment/v1/checkout-payment/init";
return HttpClient.post(requestOptions.getBaseUrl() + path, createHeaders(initCheckoutPaymentRequest, path, requestOptions),
initCheckoutPaymentRequest, InitCheckoutPaymentResponse.class);
}

public PaymentResponse retrieveCheckoutPayment(String token) {
String path = "/payment/v1/checkout-payment?token=" + token;
return HttpClient.get(requestOptions.getBaseUrl() + path, createHeaders(path, requestOptions), PaymentResponse.class);
}

public DepositPaymentResponse createDepositPayment(CreateDepositPaymentRequest createDepositPaymentRequest) {
String path = "/payment/v1/deposits";
return HttpClient.post(requestOptions.getBaseUrl() + path, createHeaders(createDepositPaymentRequest, path, requestOptions),
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/io/craftgate/request/InitCheckoutPaymentRequest.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 lombok.experimental.SuperBuilder;

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

@Data
@SuperBuilder
public class InitCheckoutPaymentRequest {

protected BigDecimal price;
protected BigDecimal paidPrice;

@Builder.Default
protected BigDecimal walletPrice = BigDecimal.ZERO;

protected Currency currency;
protected PaymentGroup paymentGroup;
protected String conversationId;
protected Integer installment;
protected String callbackUrl;

@Builder.Default
protected PaymentPhase paymentPhase = PaymentPhase.AUTH;

protected String cardUserKey;

protected Long buyerMemberId;
protected List<PaymentItem> items;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.craftgate.response;

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

@Data
@SuperBuilder
public class InitCheckoutPaymentResponse {

protected String token;
protected String pageUrl;
}
50 changes: 50 additions & 0 deletions src/test/java/io/craftgate/sample/PaymentSample.java
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,56 @@ void complete_3DS_payment() {
assertNotNull(response);
}

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

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

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

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

InitCheckoutPaymentRequest request = InitCheckoutPaymentRequest.builder()
.price(BigDecimal.valueOf(100))
.paidPrice(BigDecimal.valueOf(100))
.walletPrice(BigDecimal.ZERO)
.installment(1)
.currency(Currency.TRY)
.conversationId("456d1297-908e-4bd6-a13b-4be31a6e47d5")
.paymentGroup(PaymentGroup.LISTING_OR_SUBSCRIPTION)
.paymentPhase(PaymentPhase.AUTH)
.items(items)
.build();

InitCheckoutPaymentResponse response = craftgate.payment().initCheckoutPayment(request);

assertNotNull(response);
assertNotNull(response.getPageUrl());
assertNotNull(response.getToken());
}

@Test
void retrieve_checkout_payment() {
String token = "456d1297-908e-4bd6-a13b-4be31a6e47d5";

PaymentResponse response = craftgate.payment().retrieveCheckoutPayment(token);

assertNotNull(response);
}

@Test
void create_deposit_payment() {
CreateDepositPaymentRequest request = CreateDepositPaymentRequest.builder()
Expand Down

0 comments on commit 455f608

Please sign in to comment.