use of net.petafuel.styx.core.xs2a.entities.SinglePayment in project styx by petafuel.
the class PaymentXMLSerializer method serialize.
public PAIN00100303Document serialize(String messageId, BulkPayment bulkPayment) {
// Necessary variables for creating a PAIN00100303Document
Date creationTime = new Date();
double controlSum = 0d;
String paymentMethod = "TRF";
String chargeBearer = "SLEV";
// Setting values for each instance
groupHeader.setMessageId(messageId.substring(0, Math.min(messageId.length(), 35)));
groupHeader.setCreationTime(creationTimeFormat.format(creationTime));
groupHeader.setNoOfTransactions(bulkPayment.getPayments().size());
groupHeader.setInitiatingPartyName(NOT_PROVIDED);
ArrayList<CreditTransferTransactionInformation> list = new ArrayList<>();
for (SinglePayment payment : bulkPayment.getPayments()) {
CreditTransferTransactionInformation cdtTrfTxInf = new CreditTransferTransactionInformation();
controlSum += Double.parseDouble(payment.getInstructedAmount().getAmount());
cdtTrfTxInf.setEndToEndID(payment.getEndToEndIdentification() != null ? payment.getEndToEndIdentification() : UUID.randomUUID().toString());
cdtTrfTxInf.setAmount(Double.parseDouble(payment.getInstructedAmount().getAmount()));
cdtTrfTxInf.setCreditorName(payment.getCreditorName());
cdtTrfTxInf.setCreditorIBAN(payment.getCreditorAccount().getIban());
cdtTrfTxInf.setVwz(payment.getRemittanceInformationUnstructured());
cdtTrfTxInf.setCreditorAgent(payment.getCreditorName());
list.add(cdtTrfTxInf);
}
groupHeader.setControlSum(controlSum);
pii.setPmtInfId(NOT_PROVIDED);
pii.setPaymentMethod(paymentMethod);
pii.setNoTxns(bulkPayment.getPayments().size());
pii.setCtrlSum(controlSum);
pii.setDebtorName(NOT_PROVIDED);
pii.setDebtorAccountIBAN(bulkPayment.getDebtorAccount().getIban());
pii.setChargeBearer(chargeBearer);
pii.setBatchBooking(bulkPayment.getBatchBookingPreferred());
pii.setCreditTransferTransactionInformationVector(list);
if (bulkPayment.getRequestedExecutionDate() == null) {
pii.setRequestedExecutionDate(requestedExecutionDateFormat.format(creationTime));
} else {
pii.setRequestedExecutionDate(requestedExecutionDateFormat.format(bulkPayment.getRequestedExecutionDate()));
}
pmtInfos.add(pii);
ccInitation.setGrpHeader(groupHeader);
ccInitation.setPmtInfos(pmtInfos);
document.setCctInitiation(ccInitation);
return document;
}
use of net.petafuel.styx.core.xs2a.entities.SinglePayment in project styx by petafuel.
the class PaymentSerializer method xmlDeserialize.
public static InitializablePayment xmlDeserialize(Document sepaDocument, PaymentService paymentService) throws ParseException {
ArrayList<SinglePayment> payments = new ArrayList<>();
AccountReference debtorAccount = new AccountReference();
debtorAccount.setName(sepaDocument.getCctInitiation().getPmtInfos().get(0).getDebtorName());
debtorAccount.setIban(sepaDocument.getCctInitiation().getPmtInfos().get(0).getDebtorAccountIBAN());
debtorAccount.setCurrency(Currency.EUR);
Date requestedExecutionDate = new SimpleDateFormat(XS2AJsonKeys.DATE_FORMAT.value()).parse(sepaDocument.getCctInitiation().getPmtInfos().get(0).getRequestedExecutionDate());
for (CreditTransferTransactionInformation ctti : sepaDocument.getCctInitiation().getPmtInfos().get(0).getCreditTransferTransactionInformationVector()) {
String creditorAccountName = ctti.getCreditorName();
String creditorAccountIdentifier = ctti.getCreditorIBAN();
AccountReference creditorAccount = new AccountReference(creditorAccountIdentifier, AccountReference.Type.IBAN);
creditorAccount.setName(creditorAccountName);
creditorAccount.setCurrency(Currency.EUR);
String amount = Double.toString(ctti.getAmount());
String remittanceInformationUnstructured = ctti.getVwz();
String endToEndIdentification = ctti.getEndToEndID();
SinglePayment payment = new SinglePayment();
payment.setInstructedAmount(new Amount(amount, Currency.EUR));
payment.setCreditorAccount(creditorAccount);
payment.setDebtorAccount(debtorAccount);
payment.setRemittanceInformationUnstructured(remittanceInformationUnstructured);
payment.setEndToEndIdentification(endToEndIdentification);
payment.setRequestedExecutionDate(requestedExecutionDate);
payments.add(payment);
}
if (paymentService.equals(PaymentService.BULK_PAYMENTS)) {
BulkPayment bulkPayment = new BulkPayment();
bulkPayment.setPayments(payments);
bulkPayment.setDebtorAccount(debtorAccount);
bulkPayment.setRequestedExecutionDate(requestedExecutionDate);
return bulkPayment;
}
return payments.get(0);
}
use of net.petafuel.styx.core.xs2a.entities.SinglePayment in project styx by petafuel.
the class PaymentInitiationResource method initiateSinglePayment.
/**
* Initiate single or future dated payments
*
* @param paymentTypeBean contains which payment product is used
* @param singlePaymentBody contains the request body as parsed json
* @return 201 if successful
* @throws BankRequestFailedException in case the communication between styx and aspsp was not successful
*/
@POST
@Path("/payments/{paymentProduct}")
@RequiresMandatoryHeader
@AcceptsPreStepAuth
public Response initiateSinglePayment(@BeanParam PaymentTypeBean paymentTypeBean, @Valid SinglePaymentInitiation singlePaymentBody) throws BankRequestFailedException {
Optional<SinglePayment> singlePayment = singlePaymentBody.getPayments().stream().findFirst();
if (!singlePayment.isPresent()) {
throw new StyxException(new ResponseEntity("No valid single payment object was found within the payments array", ResponseConstant.BAD_REQUEST, ResponseCategory.ERROR, ResponseOrigin.CLIENT));
}
SinglePayment payment = singlePayment.get();
XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
xs2AFactoryInput.setPayment(payment);
xs2AFactoryInput.setPsu(getPsu());
xs2AFactoryInput.setPaymentService(PaymentService.PAYMENTS);
xs2AFactoryInput.setPaymentProduct(paymentTypeBean.getPaymentProduct());
IOProcessor ioProcessor = new IOProcessor(getXS2AStandard());
ioProcessor.modifyInput(xs2AFactoryInput);
PISRequest paymentInitiationRequest = new PISRequestFactory().create(getXS2AStandard().getRequestClassProvider().paymentInitiation(), xs2AFactoryInput);
paymentInitiationRequest.getHeaders().putAll(getAdditionalHeaders());
paymentInitiationRequest.setTppRedirectPreferred(getRedirectPreferred());
paymentInitiationRequest.setXrequestId(ThreadContext.get(RequestUUIDAdapter.REQUEST_UUID));
ioProcessor.modifyRequest(paymentInitiationRequest, xs2AFactoryInput);
InitiatedPayment initiatedPayment = getXS2AStandard().getPis().initiatePayment(paymentInitiationRequest);
PersistentPayment.create(paymentInitiationRequest.getXrequestId(), initiatedPayment.getPaymentId(), (String) getContainerRequestContext().getProperty(AbstractTokenFilter.class.getName()), getXS2AStandard().getAspsp().getBic(), initiatedPayment.getStatus(), PaymentService.PAYMENTS, paymentTypeBean.getPaymentProduct());
if (containerRequestContext.getProperty(PreAuthAccessFilter.class.getName()) != null) {
initiatedPayment.setxRequestId(UUID.fromString(containerRequestContext.getHeaderString(PreAuthAccessFilter.PRE_AUTH_ID)));
}
xs2AFactoryInput.setPaymentId(initiatedPayment.getPaymentId());
ioProcessor.modifyResponse(initiatedPayment, xs2AFactoryInput);
PaymentResponse paymentResponse = new PaymentResponse(initiatedPayment);
SCAApproach approach = SCAHandler.decision(initiatedPayment);
if (approach instanceof OAuth2) {
paymentResponse.getLinks().getScaOAuth().setUrl(((OAuth2) approach).getAuthoriseLink());
}
LOG.info("Initiate single payment bic={} aspsp_name={} aspsp_id={} paymentId={} xrequestid={}", getXS2AStandard().getAspsp().getBic(), getXS2AStandard().getAspsp().getName(), getXS2AStandard().getAspsp().getId(), paymentResponse.getPaymentId(), paymentInitiationRequest.getXrequestId());
AspspUrlMapper aspspUrlMapper = new AspspUrlMapper(PaymentService.PAYMENTS, paymentTypeBean.getPaymentProduct(), paymentResponse.getPaymentId(), null);
paymentResponse.setLinks(aspspUrlMapper.map(paymentResponse.getLinks()));
return Response.status(ResponseConstant.CREATED).entity(paymentResponse).build();
}
use of net.petafuel.styx.core.xs2a.entities.SinglePayment in project styx by petafuel.
the class UniCreditPISIntegrationTest method getSinglePayment.
@Test
@Category(IntegrationTest.class)
public void getSinglePayment() 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).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();
SinglePayment payment = jsonb.fromJson(IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8), SinglePayment.class);
Assertions.assertNotNull(payment.getCreditorAccount().getCurrency());
Assertions.assertNotNull(payment.getCreditorAccount().getIban());
Assertions.assertNotNull(payment.getCreditorName());
Assertions.assertNotNull(payment.getDebtorAccount().getCurrency());
Assertions.assertNotNull(payment.getDebtorAccount().getIban());
Assertions.assertNotNull(payment.getInstructedAmount().getAmount());
Assertions.assertNotNull(payment.getInstructedAmount().getCurrency());
Assertions.assertNotNull(payment.getRemittanceInformationUnstructured());
Assertions.assertEquals("Styx PIS Test mit Umlaut ÄöÜ", payment.getRemittanceInformationUnstructured());
}
}
use of net.petafuel.styx.core.xs2a.entities.SinglePayment in project styx by petafuel.
the class UniCreditPISIntegrationTest method createPayment.
@Test
@Category(IntegrationTest.class)
public void createPayment() {
for (Map<String, String> testEntry : testData) {
String bic = testEntry.get("bic");
String debtorIban = testEntry.get("debtorIban");
String creditorIban = testEntry.get("creditorIban");
Invocation.Builder invocationBuilder = target("/v1/payments/sepa-credit-transfers").request();
invocationBuilder.header("token", pisAccessToken);
invocationBuilder.header("PSU-ID", "bgdemo");
invocationBuilder.header("PSU-BIC", bic);
invocationBuilder.header("PSU-ID-Type", "ALL");
invocationBuilder.header("redirectPreferred", true);
SinglePayment singlePayment = new SinglePayment();
singlePayment.setDebtorAccount(new AccountReference(debtorIban, AccountReference.Type.IBAN));
singlePayment.setCreditorAccount(new AccountReference(creditorIban, AccountReference.Type.IBAN));
singlePayment.setInstructedAmount(new Amount("0.01"));
singlePayment.setCreditorName("Test Creditor Name");
singlePayment.setRemittanceInformationUnstructured("Styx PIS Test mit Umlaut ÄöÜ");
SinglePaymentInitiation singlePaymentInitiation = new SinglePaymentInitiation();
singlePaymentInitiation.setPayments(Collections.singletonList(singlePayment));
Invocation invocation = invocationBuilder.buildPost(Entity.entity(singlePaymentInitiation, MediaType.APPLICATION_JSON));
Response response = invocation.invoke(Response.class);
Assertions.assertEquals(201, response.getStatus());
try {
Jsonb jsonb = JsonbBuilder.create();
PaymentResponse paymentResponse = jsonb.fromJson(IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8), PaymentResponse.class);
String singlePaymentId = paymentResponse.getPaymentId();
Assertions.assertNotNull(singlePaymentId);
testEntry.put("paymentId", singlePaymentId);
} catch (IOException e) {
Assertions.fail("exception while parsing response");
}
}
}
Aggregations