Skip to content

Commit

Permalink
Adds instant transfer integration as apm (#164)
Browse files Browse the repository at this point in the history
* Adds instant transfer with Compay integration as apm

* Update
  • Loading branch information
semihshn authored Mar 21, 2024
1 parent 770dc36 commit 8c66efa
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 0 deletions.
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,
INSTANT_TRANSFER,
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,
INSTANT_TRANSFER,
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 {
PAYONEER,
SODEXO,
EDENRED,
INSTANT_TRANSFER,
ALIPAY,
PAYPAL,
KLARNA,
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_instant_transfer_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.INSTANT_TRANSFER)
.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());
}
}

0 comments on commit 8c66efa

Please sign in to comment.