Search in sources :

Example 1 with BulkPaymentAdapter

use of net.petafuel.styx.core.xs2a.entities.BulkPaymentAdapter in project styx by petafuel.

the class PaymentInitiationRequest method createBulkPayment.

private Optional<String> createBulkPayment() {
    if (getPaymentProduct().isXml()) {
        PAIN00100303Document document = (new PaymentXMLSerializer()).serialize(UUID.randomUUID().toString(), (BulkPayment) payment);
        PaymentInstructionInformation xmlPayment = document.getCctInitiation().getPmtInfos().get(0);
        if (this.getPaymentProduct().equals(PaymentProduct.PAIN_001_SEPA_CREDIT_TRANSFERS) && (xmlPayment.getRequestedExecutionDate() == null || "".equals(xmlPayment.getRequestedExecutionDate()))) {
            xmlPayment.setRequestedExecutionDate(document.getCctInitiation().getGrpHeader().getCreationTime());
            document.getCctInitiation().getPmtInfos().set(0, xmlPayment);
        }
        SEPAWriter writer = new SEPAWriter(document);
        try {
            return Optional.of(new String(writer.writeSEPA()));
        } catch (SEPAWriteException exception) {
            LOG.warn("Error creating raw body for PaymentInitiationPain001Request message={} cause={}", exception.getMessage(), exception.getCause().getCause());
            return Optional.empty();
        }
    } else {
        try (Jsonb jsonb = JsonbBuilder.create(new JsonbConfig().withAdapters(new BulkPaymentAdapter()))) {
            return Optional.ofNullable(jsonb.toJson(payment));
        } catch (Exception e) {
            return Optional.empty();
        }
    }
}
Also used : PaymentInstructionInformation(net.petafuel.jsepa.model.PaymentInstructionInformation) SEPAWriteException(net.petafuel.jsepa.exception.SEPAWriteException) Jsonb(javax.json.bind.Jsonb) JsonbConfig(javax.json.bind.JsonbConfig) BulkPaymentAdapter(net.petafuel.styx.core.xs2a.entities.BulkPaymentAdapter) SEPAWriter(net.petafuel.jsepa.SEPAWriter) PAIN00100303Document(net.petafuel.jsepa.model.PAIN00100303Document) PaymentXMLSerializer(net.petafuel.styx.core.xs2a.utils.PaymentXMLSerializer) SerializerException(net.petafuel.styx.core.xs2a.exceptions.SerializerException) IOException(java.io.IOException) SEPAWriteException(net.petafuel.jsepa.exception.SEPAWriteException)

Aggregations

IOException (java.io.IOException)1 Jsonb (javax.json.bind.Jsonb)1 JsonbConfig (javax.json.bind.JsonbConfig)1 SEPAWriter (net.petafuel.jsepa.SEPAWriter)1 SEPAWriteException (net.petafuel.jsepa.exception.SEPAWriteException)1 PAIN00100303Document (net.petafuel.jsepa.model.PAIN00100303Document)1 PaymentInstructionInformation (net.petafuel.jsepa.model.PaymentInstructionInformation)1 BulkPaymentAdapter (net.petafuel.styx.core.xs2a.entities.BulkPaymentAdapter)1 SerializerException (net.petafuel.styx.core.xs2a.exceptions.SerializerException)1 PaymentXMLSerializer (net.petafuel.styx.core.xs2a.utils.PaymentXMLSerializer)1