use of com.paypal.api.payments.Currency in project alf.io by alfio-event.
the class PaypalManager method getInfo.
Optional<PaymentInformation> getInfo(String paymentId, String transactionId, Event event, Supplier<String> platformFeeSupplier) {
try {
String refund = null;
APIContext apiContext = getApiContext(event);
// check for backward compatibility reason...
if (paymentId != null) {
// navigate in all refund objects and sum their amount
refund = Payment.get(apiContext, paymentId).getTransactions().stream().map(Transaction::getRelatedResources).flatMap(List::stream).filter(f -> f.getRefund() != null).map(RelatedResources::getRefund).map(Refund::getAmount).map(Amount::getTotal).map(BigDecimal::new).reduce(BigDecimal.ZERO, BigDecimal::add).toPlainString();
//
}
Capture c = Capture.get(apiContext, transactionId);
String gatewayFee = Optional.ofNullable(c.getTransactionFee()).map(Currency::getValue).map(BigDecimal::new).map(MonetaryUtil::unitToCents).map(String::valueOf).orElse(null);
return Optional.of(new PaymentInformation(c.getAmount().getTotal(), refund, gatewayFee, platformFeeSupplier.get()));
} catch (PayPalRESTException ex) {
log.warn("Paypal: error while fetching information for payment id " + transactionId, ex);
return Optional.empty();
}
}
Aggregations