Search in sources :

Example 1 with CreditTransferTransactionInformation

use of net.petafuel.jsepa.model.CreditTransferTransactionInformation in project styx by petafuel.

the class PaymentXMLSerializer method serialize.

public PAIN00100303Document serialize(String messageId, SinglePayment payment) {
    // Necessary variables for creating a PAIN00100303Document
    Date creationTime = new Date();
    double controlSum = 0d;
    String paymentMethod = "TRF";
    String debtorName = payment.getDebtorAccount().getName();
    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(1);
    groupHeader.setInitiatingPartyName(debtorName);
    ArrayList<CreditTransferTransactionInformation> list = new ArrayList<>();
    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());
    list.add(cdtTrfTxInf);
    groupHeader.setControlSum(controlSum);
    pii.setPmtInfId(NOT_PROVIDED);
    pii.setPaymentMethod(paymentMethod);
    pii.setNoTxns(1);
    pii.setCtrlSum(controlSum);
    pii.setDebtorName(debtorName);
    pii.setDebtorAccountIBAN(payment.getDebtorAccount().getIban());
    pii.setChargeBearer(chargeBearer);
    pii.setCreditTransferTransactionInformationVector(list);
    if (payment.getRequestedExecutionDate() == null) {
        pii.setRequestedExecutionDate(requestedExecutionDateFormat.format(creationTime));
    } else {
        pii.setRequestedExecutionDate(requestedExecutionDateFormat.format(payment.getRequestedExecutionDate()));
    }
    pmtInfos.add(pii);
    ccInitation.setGrpHeader(groupHeader);
    ccInitation.setPmtInfos(pmtInfos);
    document.setCctInitiation(ccInitation);
    return document;
}
Also used : ArrayList(java.util.ArrayList) CreditTransferTransactionInformation(net.petafuel.jsepa.model.CreditTransferTransactionInformation) Date(java.util.Date)

Example 2 with CreditTransferTransactionInformation

use of net.petafuel.jsepa.model.CreditTransferTransactionInformation 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;
}
Also used : ArrayList(java.util.ArrayList) CreditTransferTransactionInformation(net.petafuel.jsepa.model.CreditTransferTransactionInformation) SinglePayment(net.petafuel.styx.core.xs2a.entities.SinglePayment) Date(java.util.Date)

Example 3 with CreditTransferTransactionInformation

use of net.petafuel.jsepa.model.CreditTransferTransactionInformation 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);
}
Also used : Amount(net.petafuel.styx.core.xs2a.entities.Amount) ArrayList(java.util.ArrayList) CreditTransferTransactionInformation(net.petafuel.jsepa.model.CreditTransferTransactionInformation) AccountReference(net.petafuel.styx.core.xs2a.entities.AccountReference) BulkPayment(net.petafuel.styx.core.xs2a.entities.BulkPayment) SinglePayment(net.petafuel.styx.core.xs2a.entities.SinglePayment) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 CreditTransferTransactionInformation (net.petafuel.jsepa.model.CreditTransferTransactionInformation)3 SinglePayment (net.petafuel.styx.core.xs2a.entities.SinglePayment)2 SimpleDateFormat (java.text.SimpleDateFormat)1 AccountReference (net.petafuel.styx.core.xs2a.entities.AccountReference)1 Amount (net.petafuel.styx.core.xs2a.entities.Amount)1 BulkPayment (net.petafuel.styx.core.xs2a.entities.BulkPayment)1