Search in sources :

Example 1 with RefundRequest

use of alfio.model.transaction.capabilities.RefundRequest in project alf.io by alfio-event.

the class PaymentManager method refund.

public boolean refund(TicketReservation reservation, PurchaseContext purchaseContext, Integer amount, String username) {
    Transaction transaction = transactionRepository.loadByReservationId(reservation.getId());
    boolean res = lookupProviderByTransactionAndCapabilities(transaction, List.of(RefundRequest.class)).map(paymentProvider -> ((RefundRequest) paymentProvider).refund(transaction, purchaseContext, amount)).orElse(false);
    Map<String, Object> changes = Map.of("refund", amount != null ? amount.toString() : "full", "paymentMethod", reservation.getPaymentMethod().toString());
    if (res) {
        auditingRepository.insert(reservation.getId(), userRepository.findIdByUserName(username).orElse(null), purchaseContext, Audit.EventType.REFUND, new Date(), Audit.EntityType.RESERVATION, reservation.getId(), Collections.singletonList(changes));
        extensionManager.handleRefund(purchaseContext, reservation, getInfo(reservation, purchaseContext));
    } else {
        auditingRepository.insert(reservation.getId(), userRepository.findIdByUserName(username).orElse(null), purchaseContext, Audit.EventType.REFUND_ATTEMPT_FAILED, new Date(), Audit.EntityType.RESERVATION, reservation.getId(), Collections.singletonList(changes));
    }
    return res;
}
Also used : java.util(java.util) ConfigurationLevel(alfio.manager.system.ConfigurationLevel) Predicate(java.util.function.Predicate) ExtractPaymentTokenFromTransaction(alfio.model.transaction.capabilities.ExtractPaymentTokenFromTransaction) PaymentResult(alfio.manager.support.PaymentResult) ConfigurationManager(alfio.manager.system.ConfigurationManager) PaymentInfo(alfio.model.transaction.capabilities.PaymentInfo) Collectors(java.util.stream.Collectors) Component(org.springframework.stereotype.Component) Stream(java.util.stream.Stream) Pair(org.apache.commons.lang3.tuple.Pair) alfio.model(alfio.model) UserRepository(alfio.repository.user.UserRepository) alfio.model.transaction(alfio.model.transaction) TransactionRepository(alfio.repository.TransactionRepository) Data(lombok.Data) Log4j2(lombok.extern.log4j.Log4j2) ClientServerTokenRequest(alfio.model.transaction.capabilities.ClientServerTokenRequest) AuditingRepository(alfio.repository.AuditingRepository) AllArgsConstructor(lombok.AllArgsConstructor) ConfigurationKeys(alfio.model.system.ConfigurationKeys) RefundRequest(alfio.model.transaction.capabilities.RefundRequest) ExtractPaymentTokenFromTransaction(alfio.model.transaction.capabilities.ExtractPaymentTokenFromTransaction) RefundRequest(alfio.model.transaction.capabilities.RefundRequest)

Aggregations

PaymentResult (alfio.manager.support.PaymentResult)1 ConfigurationLevel (alfio.manager.system.ConfigurationLevel)1 ConfigurationManager (alfio.manager.system.ConfigurationManager)1 alfio.model (alfio.model)1 ConfigurationKeys (alfio.model.system.ConfigurationKeys)1 alfio.model.transaction (alfio.model.transaction)1 ClientServerTokenRequest (alfio.model.transaction.capabilities.ClientServerTokenRequest)1 ExtractPaymentTokenFromTransaction (alfio.model.transaction.capabilities.ExtractPaymentTokenFromTransaction)1 PaymentInfo (alfio.model.transaction.capabilities.PaymentInfo)1 RefundRequest (alfio.model.transaction.capabilities.RefundRequest)1 AuditingRepository (alfio.repository.AuditingRepository)1 TransactionRepository (alfio.repository.TransactionRepository)1 UserRepository (alfio.repository.user.UserRepository)1 java.util (java.util)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 AllArgsConstructor (lombok.AllArgsConstructor)1 Data (lombok.Data)1 Log4j2 (lombok.extern.log4j.Log4j2)1