use of net.petafuel.styx.spi.paymentstatushook.api.HookStatus in project styx by petafuel.
the class PaymentStatusPoll method poll.
private void poll() {
if (((new Date().getTime()) - startTimestamp) >= maxExecutionTime) {
throw new TaskFinalFailureException(String.format("Max execution time of %s was reached", maxExecutionTime), TaskFinalFailureCode.EXCEEDED_MAX_EXECUTION_TIME);
} else if (maxRequestFailures != 0 && currentRequestFailures >= maxRequestFailures) {
throw new TaskFinalFailureException(String.format("Max xs2a request failures reached %s out of %s", currentRequestFailures, maxRequestFailures), TaskFinalFailureCode.EXCEEDED_MAX_XS2A_REQUEST_FAILURES);
}
HookStatus hookStatus;
PaymentStatus paymentStatus;
try {
String authorisationHeader = this.checkAccessToken(xRequestId);
paymentStatusRequest.setAuthorization(authorisationHeader);
this.ioProcessor.modifyRequest(paymentStatusRequest, xs2aFactoryInput);
paymentStatus = xs2AStandard.getPis().getPaymentStatus(paymentStatusRequest);
this.ioProcessor.modifyResponse(paymentStatus, xs2aFactoryInput);
hookStatus = hookImpl.onStatusUpdate(paymentStatus);
} catch (BankRequestFailedException e) {
currentRequestFailures += 1;
LOG.warn("Request towards the ASPSP failed. maxRequestFailures={}, currentRequestFailures={}", maxRequestFailures, currentRequestFailures, e);
return;
}
if (hookStatus == HookStatus.SUCCESS) {
LOG.info("PaymentStatus Hook was successful, calling Service Provider onSuccess and cancel task execution");
hookImpl.onSuccess(payment);
future.cancel(true);
} else if (hookStatus == HookStatus.FAILURE) {
LOG.info("PaymentStatus Hook failed, calling Service Provider onFailure and cancel task execution");
hookImpl.onFailure(payment);
future.cancel(true);
}
}
use of net.petafuel.styx.spi.paymentstatushook.api.HookStatus in project styx by petafuel.
the class PaymentStatusHookImpl method onStatusUpdate.
@Override
public HookStatus onStatusUpdate(PaymentStatus paymentStatus) {
LOG.debug("Received Status update from Keep Alive Task. transactionStatus={}", paymentStatus.getTransactionStatus());
HookStatus status;
switch(paymentStatus.getTransactionStatus()) {
case ACCC:
case ACCP:
case ACSC:
case ACSP:
case ACTC:
case ACWC:
case ACWP:
case ACFC:
LOG.debug("transactionStatus={} payment is successful", paymentStatus.getTransactionStatus());
status = HookStatus.SUCCESS;
break;
case RCVD:
case PDNG:
case PATC:
case PART:
LOG.debug("transactionStatus={} payment is still not processed by the aspsp", paymentStatus.getTransactionStatus());
status = HookStatus.RETRY;
break;
case RJCT:
case CANC:
LOG.debug("transactionStatus={} payment was rejected by the ASPSP or cancelled by the PSU", paymentStatus.getTransactionStatus());
status = HookStatus.FAILURE;
break;
default:
LOG.debug("transactionStatus={} no case specified for this status, aborting", paymentStatus.getTransactionStatus());
status = HookStatus.FAILURE;
}
return status;
}
Aggregations