From b7bef162df64c06541c5c6072413ca8273ec3117 Mon Sep 17 00:00:00 2001 From: hugh-unicenta Date: Wed, 8 Nov 2023 19:21:17 +0000 Subject: [PATCH] teya integration / payment --- .../payment/PaymentGatewayPaymentSense.java | 2 +- .../pos/payment/PaymentGatewayTeya.java | 49 +++++++++++++------ 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/unicenta/pos/payment/PaymentGatewayPaymentSense.java b/src/main/java/com/unicenta/pos/payment/PaymentGatewayPaymentSense.java index 5926253..055a4bd 100644 --- a/src/main/java/com/unicenta/pos/payment/PaymentGatewayPaymentSense.java +++ b/src/main/java/com/unicenta/pos/payment/PaymentGatewayPaymentSense.java @@ -36,7 +36,7 @@ public class PaymentGatewayPaymentSense implements PaymentGateway { Window getPaymentWindow() { for (Window window : Window.getWindows()) { - if (window instanceof JPaymentSelectReceipt) { + if (window.isActive()) { return window; } } diff --git a/src/main/java/com/unicenta/pos/payment/PaymentGatewayTeya.java b/src/main/java/com/unicenta/pos/payment/PaymentGatewayTeya.java index bfb75c1..91b78f8 100644 --- a/src/main/java/com/unicenta/pos/payment/PaymentGatewayTeya.java +++ b/src/main/java/com/unicenta/pos/payment/PaymentGatewayTeya.java @@ -25,6 +25,7 @@ import com.unicenta.pos.util.RoundUtils; import lombok.extern.slf4j.Slf4j; import java.awt.*; +import java.util.ArrayList; @Slf4j public class PaymentGatewayTeya implements PaymentGateway { @@ -33,13 +34,26 @@ public class PaymentGatewayTeya implements PaymentGateway { public PaymentGatewayTeya() { } - Window getPaymentWindow() { - for (Window window : Window.getWindows()) { - if (window instanceof JPaymentSelectReceipt) { - return window; + Window getPaymentWindow(double amount) { + if (amount > 0) { + ArrayList paymentWindows = new ArrayList<>(); + for (Window window : Window.getWindows()) { + if (window instanceof JPaymentSelectReceipt) { + paymentWindows.add((JPaymentSelectReceipt) window); + } } + return paymentWindows.get(paymentWindows.size()-1); } - return null; + else { + ArrayList paymentWindows = new ArrayList<>(); + for (Window window : Window.getWindows()) { + if (window instanceof JPaymentSelectRefund) { + paymentWindows.add((JPaymentSelectRefund) window); + } + } + return paymentWindows.get(paymentWindows.size()-1); + } + } /** @@ -54,7 +68,7 @@ public class PaymentGatewayTeya implements PaymentGateway { double roundedValue = RoundUtils.round(payinfo.getTotal()); - new Application().teyaTransaction(roundedValue, getPaymentWindow(), payinfo.m_sTransactionID); + new Application().teyaTransaction(roundedValue, getPaymentWindow(roundedValue), payinfo.getTransactionID()); while (AppContext.getTeyaPaymentResult() == null) { try { @@ -67,14 +81,21 @@ public class PaymentGatewayTeya implements PaymentGateway { } } - payinfo.setCardName("Teya"); - payinfo.setVerification("Chip and Pin"); - payinfo.setChipAndPin(true); - payinfo.paymentOK( - AppContext.getTeyaPaymentResult().getReferenceId(), - AppContext.getTeyaPaymentResult().getGatewayPaymentId(), - AppContext.getTeyaPaymentResult().getStatus() - ); + if (AppContext.getTeyaPaymentResult().getStatus().equals("SUCCESSFUL")) { + payinfo.setCardName("Teya"); + payinfo.setVerification("Chip and Pin"); + payinfo.setChipAndPin(true); + payinfo.paymentOK( + roundedValue > 0 ? AppContext.getTeyaPaymentResult().getReferenceId() : "", + roundedValue > 0 ? AppContext.getTeyaPaymentResult().getGatewayPaymentId() : "", + AppContext.getTeyaPaymentResult().getStatus() + ); + } + else { + payinfo.paymentError("Transaction Error! Please try again", AppContext.getTeyaPaymentResult().getStatus()); + } + + } }