Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds instant transfer with Compay integration as apm #163

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/main/java/io/craftgate/adapter/PaymentAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ public void approveBnplPayment(Long paymentId) {
HttpClient.post(requestOptions.getBaseUrl() + path, createHeaders(path, requestOptions), Void.class);
}

public InstantTransferBanksResponse retrieveActiveBanks() {
String path = "/payment/v1/instant-transfer-banks";
return HttpClient.get(requestOptions.getBaseUrl() + path, createHeaders(path, requestOptions),
InstantTransferBanksResponse.class);
}

public boolean is3DSecureCallbackVerified(String threeDSecureCallbackKey, Map<String, String> params) {
String hash = params.get("hash");
String hashString = threeDSecureCallbackKey +
Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/craftgate/model/ApmAdditionalAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public enum ApmAdditionalAction {
REDIRECT_TO_URL,

OTP_REQUIRED,
SHOW_HTML_CONTENT,
WAIT_FOR_WEBHOOK,
APPROVAL_REQUIRED,
NONE
Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/craftgate/model/ApmType.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public enum ApmType {
KLARNA,
AFTERPAY,
KASPI,
COMPAY,
STRIPE,
TOMPAY,
MASLAK,
Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/craftgate/model/PaymentMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public enum PaymentMethod {
KLARNA,
AFTERPAY,
KASPI,
COMPAY,
TOMPAY,
STRIPE
}
1 change: 1 addition & 0 deletions src/main/java/io/craftgate/model/PaymentProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public enum PaymentProvider {
SODEXO,
EDENRED,
KASPI,
COMPAY,
YKB_WORLD_PAY,
APPLEPAY,
GOOGLEPAY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class ApmPaymentInitResponse {

private Long paymentId;
private String redirectUrl;
private String htmlContent;
private PaymentStatus paymentStatus;
private ApmAdditionalAction additionalAction;
private PaymentError paymentError;
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/io/craftgate/response/InstantTransferBank.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.craftgate.response;

import lombok.*;

@Data
public class InstantTransferBank {

private String bankCode;
private String bankName;
private String bankLogoUrl;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.craftgate.response;

import lombok.Data;

import java.util.List;

@Data
public class InstantTransferBanksResponse {

private List<InstantTransferBank> items;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package io.craftgate.sample;

import io.craftgate.Craftgate;
import io.craftgate.model.*;
import io.craftgate.request.InitApmPaymentRequest;
import io.craftgate.request.dto.PaymentItem;
import io.craftgate.response.ApmPaymentInitResponse;
import io.craftgate.response.InstantTransferBank;
import io.craftgate.response.InstantTransferBanksResponse;
import org.junit.jupiter.api.Test;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;

import static org.junit.jupiter.api.Assertions.*;

public class InstantTransferPaymentSample {

private final Craftgate craftgate = new Craftgate("api-key", "secret-key", "https://sandbox-api.craftgate.io");

@Test
void retrieve_active_banks() {
InstantTransferBanksResponse response = craftgate.payment().retrieveActiveBanks();
assertNotNull(response.getItems());
InstantTransferBank instantTransferBank = response.getItems().get(0);
assertNotNull(instantTransferBank);
}

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

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

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

InitApmPaymentRequest request = InitApmPaymentRequest.builder()
.apmType(ApmType.COMPAY)
.price(BigDecimal.valueOf(1))
.paidPrice(BigDecimal.valueOf(1))
.currency(Currency.TRY)
.paymentGroup(PaymentGroup.LISTING_OR_SUBSCRIPTION)
.conversationId("456d1297-908e-4bd6-a13b-4be31a6e47d5")
.externalId("optional-externalId")
.callbackUrl("https://www.your-website.com/craftgate-apm-callback")
.additionalParams(new HashMap() {{
put("bankCode", "0");
}})
.items(items)
.build();

ApmPaymentInitResponse response = craftgate.payment().initApmPayment(request);
assertNotNull(response.getPaymentId());
assertNull(response.getRedirectUrl());
assertNotNull(response.getHtmlContent());
assertEquals(PaymentStatus.WAITING, response.getPaymentStatus());
assertEquals(ApmAdditionalAction.SHOW_HTML_CONTENT, response.getAdditionalAction());
}
}
Loading