updating status changes
This commit is contained in:
@@ -196,7 +196,8 @@ public class VelocityPaymentService {
|
||||
|
||||
if ("MPGS".equalsIgnoreCase(transaction.getPaymentProcessorLabel())) {
|
||||
payload.setCancelUrl(velocityApiProperties.getCancelUrl() + "/" + transaction.getOrderId());
|
||||
payload.setSuccessUrl(velocityApiProperties.getSuccessUrl() + "/" + transaction.getOrderId());
|
||||
// not sending successUrl for now
|
||||
// payload.setSuccessUrl(velocityApiProperties.getSuccessUrl() + "/" + transaction.getOrderId());
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -216,6 +217,7 @@ public class VelocityPaymentService {
|
||||
String redirectUrl = body.containsKey("redirectUrl") ? (String) body.get("redirectUrl") : null;
|
||||
|
||||
if ("SUCCESS".equalsIgnoreCase(transactionStatus)) {
|
||||
transaction.setStatus(Status.SUCCESS);
|
||||
transaction.setErpSalesPaymentRef(transactionName);
|
||||
transaction.setOrderTransactionTrace(tranTrace);
|
||||
transaction.setOrderTransactionId(tranId);
|
||||
@@ -257,7 +259,6 @@ public class VelocityPaymentService {
|
||||
throw new IllegalStateException("Error initiating payment: " + errorMessage);
|
||||
}
|
||||
transaction.setStatus(Status.valueOf((String) body.get("status")));
|
||||
transaction.setPaymentStatus(Status.valueOf((String) body.get("paymentStatus")));
|
||||
transaction.setPollingStatus(Status.valueOf((String) body.get("pollStatus")));
|
||||
transaction.setDebitRef((String) body.get("debitRef"));
|
||||
transaction.setPaymentProcessorRef((String) body.get("paymentProcessorRef"));
|
||||
|
||||
@@ -50,6 +50,10 @@ public class MPGSWebPaymentProcessor implements TransactionProcessorInterface {
|
||||
try {
|
||||
// velocity expects VMC
|
||||
transaction = velocityPaymentService.processPayment(transaction);
|
||||
|
||||
// payment status comes back as pending for VMC,
|
||||
// set it to SUCCESS
|
||||
transaction.setPaymentStatus(Status.SUCCESS);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("Network error during payment processing: {}", e.getMessage(), e);
|
||||
|
||||
@@ -35,6 +35,9 @@ public class GatewayPaymentHandler implements HandlerInterface {
|
||||
new ApiException("Transaction not found for ID: " + incomingTransaction.getId()));
|
||||
transaction.setType(incomingTransaction.getType()); // type should be REQUEST here
|
||||
transaction.setAuthType(incomingTransaction.getAuthType());
|
||||
transaction.setErrorMessage(null);
|
||||
transaction.setSystemErrorMessage(null);
|
||||
transaction.setStatus(Status.PROCESSING);
|
||||
}
|
||||
|
||||
// if we've done this before then return
|
||||
@@ -58,9 +61,10 @@ public class GatewayPaymentHandler implements HandlerInterface {
|
||||
|
||||
try {
|
||||
// MAIN TRANSACTION LOGIC!
|
||||
transactionProcessorInterface.process(transaction);
|
||||
transaction.setPaymentStatus(transaction.getStatus());
|
||||
transaction = (Transaction) transactionProcessorInterface.process(transaction);
|
||||
transaction.setPaymentStatus(transaction.getPaymentStatus());
|
||||
transaction.setPollingStatus(Status.PENDING);
|
||||
transactionService.save(transaction);
|
||||
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package zw.qantra.tm.domain.services.processors.workflows.handlers;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -13,6 +14,7 @@ import zw.qantra.tm.domain.services.factories.PaymentProcessorFactory;
|
||||
import zw.qantra.tm.domain.services.processors.TransactionProcessorInterface;
|
||||
import zw.qantra.tm.exceptions.ApiException;
|
||||
|
||||
@Slf4j
|
||||
@Service("pollStatus")
|
||||
@RequiredArgsConstructor
|
||||
public class PollStatusHandler implements HandlerInterface {
|
||||
@@ -24,7 +26,14 @@ public class PollStatusHandler implements HandlerInterface {
|
||||
|
||||
@Override
|
||||
public Object process(Transaction transaction) throws Exception {
|
||||
Logger logger = LoggerFactory.getLogger(TransactionService.class);
|
||||
|
||||
// don't poll unless payment was success
|
||||
if(transaction.getPaymentStatus() != Status.SUCCESS) {
|
||||
transaction.setPollingStatus(Status.PENDING);
|
||||
transaction.setErrorMessage("Transaction not yet successful");
|
||||
transactionService.save(transaction);
|
||||
return transaction;
|
||||
}
|
||||
|
||||
// if the transaction is already successful, return it
|
||||
if(transaction.getPollingStatus() == Status.SUCCESS){
|
||||
@@ -40,7 +49,7 @@ public class PollStatusHandler implements HandlerInterface {
|
||||
|
||||
// no persistence happens during polling unless the transaction status changes
|
||||
String label = "REQUEST_" + transaction.getPaymentProcessorLabel() + "_" + transaction.getAuthType();
|
||||
logger.info("label: {}", label);
|
||||
log.info("label: {}", label);
|
||||
|
||||
TransactionProcessorInterface transactionProcessorInterface =
|
||||
(TransactionProcessorInterface) paymentProcessorFactory.getPaymentProcessor(label);
|
||||
@@ -52,11 +61,9 @@ public class PollStatusHandler implements HandlerInterface {
|
||||
transactionEvent.setMessage(transaction.getErrorMessage());
|
||||
transactionEventService.save(transactionEvent);
|
||||
|
||||
transaction.setPollingStatus(transaction.getStatus());
|
||||
transaction.setPaymentStatus(transaction.getStatus());
|
||||
|
||||
// if transaction wasn't successful, throw and halt workflow
|
||||
if(transaction.getStatus() != Status.SUCCESS){
|
||||
if(transaction.getPollingStatus() != Status.SUCCESS){
|
||||
log.info("Verification pending: {}", transaction.getErrorMessage());
|
||||
transactionService.save(transaction);
|
||||
throw new ApiException("Verification pending: " + transaction.getErrorMessage() );
|
||||
}else {
|
||||
|
||||
Reference in New Issue
Block a user