use of net.petafuel.styx.core.xs2a.entities.BulkPayment 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.BulkPayment in project styx by petafuel.
the class PaymentInitiationResource method initiateBulkPayment.
/**
* Initiate multiple payments as bulk
*
* @param paymentTypeBean contains which payment product is used
* @param bulkPaymentBody 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("/bulk-payments/{paymentProduct}")
@RequiresMandatoryHeader
@AcceptsPreStepAuth
public Response initiateBulkPayment(@BeanParam PaymentTypeBean paymentTypeBean, @Valid BulkPaymentInitiation bulkPaymentBody) throws BankRequestFailedException {
// Debtors should all be the same within the payments, we take one of them
Optional<SinglePayment> singlePayment = bulkPaymentBody.getPayments().stream().findAny();
if (!singlePayment.isPresent()) {
throw new StyxException(new ResponseEntity("No valid payment object was found within the bulk payments array", ResponseConstant.BAD_REQUEST, ResponseCategory.ERROR, ResponseOrigin.CLIENT));
}
AccountReference debtor = bulkPaymentBody.getDebtorAccount();
BulkPayment bulkPayment = new BulkPayment();
bulkPayment.setBatchBookingPreferred(bulkPaymentBody.getBatchBookingPreferred());
bulkPayment.setDebtorAccount(debtor);
bulkPayment.setPayments(bulkPaymentBody.getPayments());
bulkPayment.setRequestedExecutionDate(bulkPaymentBody.getRequestedExecutionDate());
XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
xs2AFactoryInput.setPayment(bulkPayment);
xs2AFactoryInput.setPsu(getPsu());
xs2AFactoryInput.setPaymentService(PaymentService.BULK_PAYMENTS);
xs2AFactoryInput.setPaymentProduct(paymentTypeBean.getPaymentProduct());
IOProcessor ioProcessor = new IOProcessor(getXS2AStandard());
ioProcessor.modifyInput(xs2AFactoryInput);
PISRequest bulkpaymentInitiationRequest = new PISRequestFactory().create(getXS2AStandard().getRequestClassProvider().paymentInitiation(), xs2AFactoryInput);
bulkpaymentInitiationRequest.getHeaders().putAll(getAdditionalHeaders());
ioProcessor.modifyRequest(bulkpaymentInitiationRequest, xs2AFactoryInput);
bulkpaymentInitiationRequest.setTppRedirectPreferred(getRedirectPreferred());
bulkpaymentInitiationRequest.setXrequestId(ThreadContext.get(RequestUUIDAdapter.REQUEST_UUID));
InitiatedPayment initiatedPayment = getXS2AStandard().getPis().initiatePayment(bulkpaymentInitiationRequest);
PaymentResponse paymentResponse = new PaymentResponse(initiatedPayment);
SCAApproach approach = SCAHandler.decision(initiatedPayment);
if (approach instanceof OAuth2) {
paymentResponse.getLinks().getScaOAuth().setUrl(((OAuth2) approach).getAuthoriseLink());
}
LOG.info("Initiate bulk payment bic={} aspsp_name={} aspsp_id={} paymentId={}", getXS2AStandard().getAspsp().getBic(), getXS2AStandard().getAspsp().getName(), getXS2AStandard().getAspsp().getId(), paymentResponse.getPaymentId());
AspspUrlMapper aspspUrlMapper = new AspspUrlMapper(PaymentService.BULK_PAYMENTS, paymentTypeBean.getPaymentProduct(), paymentResponse.getPaymentId(), null);
paymentResponse.setLinks(aspspUrlMapper.map(paymentResponse.getLinks()));
PersistentPayment.create(bulkpaymentInitiationRequest.getXrequestId(), paymentResponse.getPaymentId(), (String) getContainerRequestContext().getProperty(AbstractTokenFilter.class.getName()), getXS2AStandard().getAspsp().getBic(), paymentResponse.getTransactionStatus(), PaymentService.BULK_PAYMENTS, paymentTypeBean.getPaymentProduct());
return Response.status(ResponseConstant.CREATED).entity(paymentResponse).build();
}
Aggregations