From 455f6086cf9669bf75aa4f804a38b54753637f4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berkay=20Din=C3=A7er?= Date: Fri, 22 Jan 2021 13:43:24 +0300 Subject: [PATCH] adds cpp methods --- .../io/craftgate/adapter/PaymentAdapter.java | 11 ++++ .../request/InitCheckoutPaymentRequest.java | 37 ++++++++++++++ .../response/InitCheckoutPaymentResponse.java | 12 +++++ .../io/craftgate/sample/PaymentSample.java | 50 +++++++++++++++++++ 4 files changed, 110 insertions(+) create mode 100644 src/main/java/io/craftgate/request/InitCheckoutPaymentRequest.java create mode 100644 src/main/java/io/craftgate/response/InitCheckoutPaymentResponse.java diff --git a/src/main/java/io/craftgate/adapter/PaymentAdapter.java b/src/main/java/io/craftgate/adapter/PaymentAdapter.java index a375af6a..d1405115 100644 --- a/src/main/java/io/craftgate/adapter/PaymentAdapter.java +++ b/src/main/java/io/craftgate/adapter/PaymentAdapter.java @@ -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), diff --git a/src/main/java/io/craftgate/request/InitCheckoutPaymentRequest.java b/src/main/java/io/craftgate/request/InitCheckoutPaymentRequest.java new file mode 100644 index 00000000..873211a7 --- /dev/null +++ b/src/main/java/io/craftgate/request/InitCheckoutPaymentRequest.java @@ -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 items; +} \ No newline at end of file diff --git a/src/main/java/io/craftgate/response/InitCheckoutPaymentResponse.java b/src/main/java/io/craftgate/response/InitCheckoutPaymentResponse.java new file mode 100644 index 00000000..ee752665 --- /dev/null +++ b/src/main/java/io/craftgate/response/InitCheckoutPaymentResponse.java @@ -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; +} \ No newline at end of file diff --git a/src/test/java/io/craftgate/sample/PaymentSample.java b/src/test/java/io/craftgate/sample/PaymentSample.java index 1f120aa1..fd3a4926 100644 --- a/src/test/java/io/craftgate/sample/PaymentSample.java +++ b/src/test/java/io/craftgate/sample/PaymentSample.java @@ -488,6 +488,56 @@ void complete_3DS_payment() { assertNotNull(response); } + @Test + void init_checkout_payment() { + List 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()