use of net.petafuel.styx.core.xs2a.entities.Amount in project styx by petafuel.
the class PeriodicPaymentMultipartBodySerializer method xmlDeserialize.
public static PeriodicPayment xmlDeserialize(Document sepaDocument, PeriodicPayment periodicPayment) throws ParseException {
if (periodicPayment.getDebtorAccount() == null) {
periodicPayment.setDebtorAccount(new AccountReference());
}
AccountReference debtorAccount = periodicPayment.getDebtorAccount();
periodicPayment.setDebtorName(sepaDocument.getCctInitiation().getPmtInfos().get(0).getDebitor().getName());
debtorAccount.setIban(sepaDocument.getCctInitiation().getPmtInfos().get(0).getDebtorAccountIBAN());
debtorAccount.setCurrency(Currency.EUR);
String creditorAccountName = sepaDocument.getCctInitiation().getPmtInfos().get(0).getCreditTransferTransactionInformationVector().get(0).getCreditorName();
String creditorAccountIdentifier = sepaDocument.getCctInitiation().getPmtInfos().get(0).getCreditTransferTransactionInformationVector().get(0).getCreditorIBAN();
String creditorAgent = sepaDocument.getCctInitiation().getPmtInfos().get(0).getCreditTransferTransactionInformationVector().get(0).getCreditorAgent();
if (periodicPayment.getCreditorAccount() == null) {
periodicPayment.setCreditorAccount(new AccountReference());
}
AccountReference creditorAccount = periodicPayment.getCreditorAccount();
periodicPayment.setCreditorName(creditorAccountName);
creditorAccount.setIban(creditorAccountIdentifier);
creditorAccount.setCurrency(Currency.EUR);
periodicPayment.setCreditorAgent(creditorAgent);
String amount = Double.toString(sepaDocument.getCctInitiation().getPmtInfos().get(0).getCreditTransferTransactionInformationVector().get(0).getAmount());
String remittanceInformationUnstructured = sepaDocument.getCctInitiation().getPmtInfos().get(0).getCreditTransferTransactionInformationVector().get(0).getVwz();
String endToEndIdentification = sepaDocument.getCctInitiation().getPmtInfos().get(0).getCreditTransferTransactionInformationVector().get(0).getEndToEndID();
Date requestExecutionDate = new SimpleDateFormat(XS2AJsonKeys.DATE_FORMAT.value()).parse(sepaDocument.getCctInitiation().getPmtInfos().get(0).getRequestedExecutionDate());
periodicPayment.setInstructedAmount(new Amount(amount));
periodicPayment.setRemittanceInformationUnstructured(remittanceInformationUnstructured);
periodicPayment.setEndToEndIdentification(endToEndIdentification);
periodicPayment.setRequestedExecutionDate(requestExecutionDate);
return periodicPayment;
}
use of net.petafuel.styx.core.xs2a.entities.Amount 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.Amount in project styx by petafuel.
the class Camt052Converter method convertTransaction.
private void convertTransaction(AccountReport accountReport, ReportEntry2 originalPayment) {
List<EntryDetails1> entryDetails = originalPayment.getNtryDtls();
if (entryDetails != null && !entryDetails.isEmpty()) {
List<EntryTransaction2> transactionDetails = entryDetails.get(0).getTxDtls();
if (transactionDetails.isEmpty()) {
LOG.info("Transaction has no IBAN/BIC, sender/receiver information");
return;
}
if (transactionDetails.size() > 1) {
LOG.error("Input contains more than one NtryDtls/TxDtls, only FIRST processed!");
}
// this will be the new transaction element in JSON array
Transaction transaction = new Transaction();
// from here, extract data from XML and map to JSON object
// status
EntryStatus2Code camtBookingStatus = originalPayment.getSts();
if (camtBookingStatus.equals(EntryStatus2Code.BOOK) || camtBookingStatus.equals(EntryStatus2Code.INFO)) {
accountReport.getBooked().add(transaction);
} else {
accountReport.getPending().add(transaction);
}
// bookingDate if present
Optional.ofNullable(originalPayment.getBookgDt()).map(DateAndDateTimeChoice::getDt).map(XMLGregorianCalendar::toGregorianCalendar).map(GregorianCalendar::getTime).ifPresent(transaction::setBookingDate);
// valueDate if present
Optional.ofNullable(originalPayment.getValDt()).map(DateAndDateTimeChoice::getDt).map(XMLGregorianCalendar::toGregorianCalendar).map(GregorianCalendar::getTime).ifPresent(transaction::setValueDate);
// creditDebit
// amount
// currency
transaction.setTransactionAmount(new Amount());
if (originalPayment.getCdtDbtInd().equals(CreditDebitCode.DBIT)) {
BigDecimal amount = originalPayment.getAmt().getValue().negate();
transaction.getTransactionAmount().setAmount(amount.toString());
transaction.getTransactionAmount().setCurrency(Currency.valueOf(originalPayment.getAmt().getCcy()));
}
EntryTransaction2 firstTransactionDetails = transactionDetails.get(0);
// debtor account
TransactionParty2 transactionParty = firstTransactionDetails.getRltdPties();
transaction.setDebtorAccount(new AccountReference(transactionParty.getDbtrAcct().getId().getIBAN(), AccountReference.Type.IBAN));
// optionally set debtor name
Optional.ofNullable(transactionParty.getDbtr()).map(PartyIdentification32::getNm).ifPresent(transaction::setDebtorName);
// set debtor agent if present
Optional.ofNullable(firstTransactionDetails.getRltdAgts()).map(TransactionAgents2::getDbtrAgt).map(BranchAndFinancialInstitutionIdentification4::getFinInstnId).map(FinancialInstitutionIdentification7::getBIC).ifPresent(transaction::setDebtorAgent);
// creditor account
transaction.setCreditorAccount(new AccountReference(firstTransactionDetails.getRltdPties().getCdtrAcct().getId().getIBAN(), AccountReference.Type.IBAN));
// set creditor name if present
Optional.ofNullable(transactionParty.getCdtr()).map(PartyIdentification32::getNm).ifPresent(transaction::setCreditorName);
// set creditor agent if present
Optional.ofNullable(firstTransactionDetails.getRltdAgts()).map(TransactionAgents2::getCdtrAgt).map(BranchAndFinancialInstitutionIdentification4::getFinInstnId).map(FinancialInstitutionIdentification7::getBIC).ifPresent(transaction::setCreditorAgent);
// reference
transaction.setRemittanceInformationUnstructured(String.join("\n", firstTransactionDetails.getRmtInf().getUstrd()));
// set e2e reference if present
Optional.ofNullable(firstTransactionDetails.getRefs()).map(TransactionReferences2::getEndToEndId).ifPresent(transaction::setEndToEndId);
// set additional information
transaction.setAdditionalInformation(originalPayment.getAddtlNtryInf());
}
}
use of net.petafuel.styx.core.xs2a.entities.Amount 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");
}
}
}
use of net.petafuel.styx.core.xs2a.entities.Amount in project styx by petafuel.
the class SparkassePISIntegrationTest method test_INIT_SCTSinglePayment_SCA_OAUTH.
@Category(IntegrationTest.class)
@ParameterizedTest
@ArgumentsSource(SparkassePSUProvider.class)
void test_INIT_SCTSinglePayment_SCA_OAUTH(String psuBic, String psuId, String creditorIban, String debtorIban) {
Assume.assumeNotNull(PIS_TOKEN);
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(psuId);
singlePayment.setRemittanceInformationUnstructured("Styx PIS Test unixstamp: " + new Date().getTime());
SinglePaymentInitiation singlePaymentInitiation = new SinglePaymentInitiation();
singlePaymentInitiation.setPayments(Collections.singletonList(singlePayment));
given().contentType(ContentType.JSON).header("token", PIS_TOKEN).header("psu-id", psuId).header("psu-bic", psuBic).header("redirectPreferred", "true").body(singlePaymentInitiation).post("/v1/payments/sepa-credit-transfers").then().assertThat().header("content-type", Matchers.containsString("application/json")).statusCode(201).body("transactionStatus", Matchers.is(TransactionStatus.RCVD.name())).body("paymentId", Matchers.notNullValue()).body("links.scaOAuth.href", Matchers.notNullValue());
}
Aggregations