use of net.petafuel.jsepa.model.PaymentInstructionInformation in project styx by petafuel.
the class PaymentInitiationRequest method createSinglePayment.
/*
* @return payment request body for sepa-single-payments in xml or json as String
*/
private Optional<String> createSinglePayment() {
if (getPaymentProduct().isXml()) {
PAIN00100303Document document = (new PaymentXMLSerializer()).serialize(UUID.randomUUID().toString(), (SinglePayment) 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 single payment initiation message={} cause={}", exception.getMessage(), exception.getCause().getCause());
return Optional.empty();
}
} else {
JsonbConfig jsonbConfig = new JsonbConfig();
jsonbConfig.withNullValues(false);
jsonbConfig.withLocale(Locale.GERMANY);
jsonbConfig.withDateFormat("yyyy-MM-dd", Locale.GERMANY);
try (Jsonb jsonb = JsonbBuilder.create(jsonbConfig)) {
String paymentBodyJson = jsonb.toJson(payment);
LOG.debug("Outgoing Single Payment Body={}", paymentBodyJson);
return Optional.ofNullable(paymentBodyJson);
} catch (Exception e) {
return Optional.empty();
}
}
}
use of net.petafuel.jsepa.model.PaymentInstructionInformation 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();
}
}
}
Aggregations