use of net.petafuel.styx.core.xs2a.entities.PaymentStatus in project styx by petafuel.
the class BerlinGroupPIS method getPaymentStatus.
@Override
public PaymentStatus getPaymentStatus(PISRequest xs2AGetRequest) throws BankRequestFailedException {
this.setUrl(this.url + xs2AGetRequest.getServicePath());
this.createBody(RequestType.GET);
if (xs2AGetRequest.getPaymentProduct().isXml()) {
xs2AGetRequest.addHeader(XS2AHeader.ACCEPT, XML.toString());
} else {
xs2AGetRequest.addHeader(XS2AHeader.ACCEPT, JSON.toString());
}
this.createHeaders(xs2AGetRequest);
try (Response response = this.execute();
Jsonb jsonb = JsonbBuilder.create()) {
String contentType;
if ((contentType = response.headers().get("content-type")) == null) {
throw new BankRequestFailedException("Content-Type Header is not set, parsing of json or xml is not possible", response.code());
}
String responseBody = extractResponseBody(response, 200);
if (contentType.contains(MediaType.APPLICATION_JSON)) {
return jsonb.fromJson(responseBody, PaymentStatus.class);
} else {
ReportConverter converter = new ReportConverter();
TransactionReport report = converter.processReport(responseBody);
return new PaymentStatus(TransactionStatus.valueOf(report.getStatus()), null);
}
} catch (IOException | SEPAParsingException e) {
throw new BankRequestFailedException(e.getMessage(), e);
} catch (Exception e) {
throw new SerializerException("Unable to deserialize json to PaymentStatus", e);
}
}
use of net.petafuel.styx.core.xs2a.entities.PaymentStatus in project styx by petafuel.
the class UniCreditPISIntegrationTest method getSinglePaymentStatus.
@Test
@Category(IntegrationTest.class)
public void getSinglePaymentStatus() throws IOException {
for (Map<String, String> testEntry : testData) {
String singlePaymentId = testEntry.get("paymentId");
String bic = testEntry.get("bic");
Invocation invocation = target("/v1/payments/sepa-credit-transfers/" + singlePaymentId + "/status").request().header("token", pisAccessToken).header("PSU-ID", "bgdemo").header("PSU-BIC", bic).buildGet();
Response response = invocation.invoke(Response.class);
Assertions.assertEquals(200, response.getStatus());
Jsonb jsonb = JsonbBuilder.create();
PaymentStatus paymentStatus = jsonb.fromJson(IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8), PaymentStatus.class);
Assertions.assertEquals(TransactionStatus.RCVD.getName(), paymentStatus.getTransactionStatus().getName());
}
}
use of net.petafuel.styx.core.xs2a.entities.PaymentStatus 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.core.xs2a.entities.PaymentStatus in project styx by petafuel.
the class PaymentStatusResource method getSinglePaymentStatus.
/**
* Returns the status of a payment
*
* @param paymentTypeBean payment-service and payment-product
* @param paymentId id of the target payment
* @return a PaymentStatus object
* @throws BankRequestFailedException if something went wrong between the core service and the aspsp
*/
@AcceptsPreStepAuth
@GET
@Path("/{paymentService}/{paymentProduct}/{paymentId}/status")
public Response getSinglePaymentStatus(@BeanParam PaymentTypeBean paymentTypeBean, @PathParam("paymentId") @NotEmpty @NotBlank String paymentId) throws BankRequestFailedException {
XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
xs2AFactoryInput.setPaymentService(paymentTypeBean.getPaymentService());
xs2AFactoryInput.setPaymentProduct(paymentTypeBean.getPaymentProduct());
xs2AFactoryInput.setPaymentId(paymentId);
xs2AFactoryInput.setPsu(getPsu());
IOProcessor ioProcessor = new IOProcessor(getXS2AStandard());
ioProcessor.modifyInput(xs2AFactoryInput);
PISRequest readPaymentStatusRequest = new PISRequestFactory().create(getXS2AStandard().getRequestClassProvider().paymentStatus(), xs2AFactoryInput);
readPaymentStatusRequest.getHeaders().putAll(getAdditionalHeaders());
ioProcessor.modifyRequest(readPaymentStatusRequest, xs2AFactoryInput);
PaymentStatus status = getXS2AStandard().getPis().getPaymentStatus(readPaymentStatusRequest);
if (PersistentPayment.getByPaymentId(paymentId) == null) {
PersistentPayment.create(ThreadContext.get("requestUUID"), paymentId, (String) getContainerRequestContext().getProperty(AbstractTokenFilter.class.getName()), getXS2AStandard().getAspsp().getBic(), status.getTransactionStatus(), paymentTypeBean.getPaymentService(), paymentTypeBean.getPaymentProduct());
} else {
PersistentPayment.updateStatusByPaymentId(paymentId, status.getTransactionStatus());
}
LOG.info("Successfully read the payment status entity for bic={}, paymentId={}", getXS2AStandard().getAspsp().getBic(), paymentId);
return Response.status(200).entity(status).build();
}
Aggregations