Search in sources :

Example 1 with PaymentContext

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

the class TicketReservationManagerTest method neverReturnADateInThePast.

@Test
void neverReturnADateInThePast() {
    initOfflinePaymentTest();
    when(event.getBegin()).thenReturn(ZonedDateTime.now(ClockProvider.clock()));
    ZonedDateTime offlinePaymentDeadline = BankTransferManager.getOfflinePaymentDeadline(new PaymentContext(event), configurationManager);
    Assertions.assertTrue(offlinePaymentDeadline.isAfter(ZonedDateTime.now(ClockProvider.clock())));
}
Also used : PaymentContext(alfio.model.transaction.PaymentContext) Test(org.junit.jupiter.api.Test)

Example 2 with PaymentContext

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

the class TicketReservationManagerTest method returnTheExpiredDateAsConfigured.

@Test
void returnTheExpiredDateAsConfigured() {
    initOfflinePaymentTest();
    when(event.getBegin()).thenReturn(ZonedDateTime.now(ClockProvider.clock()).plusDays(3));
    ZonedDateTime offlinePaymentDeadline = BankTransferManager.getOfflinePaymentDeadline(new PaymentContext(event), configurationManager);
    ZonedDateTime expectedDate = ZonedDateTime.now(ClockProvider.clock()).plusDays(2L).truncatedTo(ChronoUnit.HALF_DAYS).with(WorkingDaysAdjusters.defaultWorkingDays());
    Assertions.assertEquals(expectedDate, offlinePaymentDeadline);
}
Also used : PaymentContext(alfio.model.transaction.PaymentContext) Test(org.junit.jupiter.api.Test)

Example 3 with PaymentContext

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

the class RevolutBankTransferManagerTest method noMatches.

@Test
void noMatches() {
    var pendingReservations = List.of(first, second, third);
    var single = mock(RevolutTransactionDescriptor.class);
    when(single.getReference()).thenReturn("Very long description but no reference");
    when(single.getTransactionBalance()).thenReturn(BigDecimal.ONE);
    var leg = mock(RevolutTransactionDescriptor.TransactionLeg.class);
    when(leg.getAmount()).thenReturn(BigDecimal.ONE);
    when(single.getLegs()).thenReturn(List.of(leg));
    var result = revolutBankTransferManager.matchTransactions(pendingReservations, List.of(single), new PaymentContext(event), true);
    assertTrue(result.isSuccess());
    assertEquals(0, result.getData().size());
}
Also used : RevolutTransactionDescriptor(alfio.model.transaction.provider.RevolutTransactionDescriptor) PaymentContext(alfio.model.transaction.PaymentContext) Test(org.junit.jupiter.api.Test)

Example 4 with PaymentContext

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

the class MolliePaymentWebhookController method receivePaymentConfirmation.

@SuppressWarnings("MVCPathVariableInspection")
@PostMapping(WEBHOOK_URL_TEMPLATE)
public ResponseEntity<String> receivePaymentConfirmation(HttpServletRequest request, @PathVariable("reservationId") String reservationId) {
    return Optional.ofNullable(StringUtils.trimToNull(request.getParameter("id"))).flatMap(id -> purchaseContextManager.findByReservationId(reservationId).map(purchaseContext -> {
        var content = "id=" + id;
        var result = ticketReservationManager.processTransactionWebhook(content, null, PaymentProxy.MOLLIE, Map.of(ADDITIONAL_INFO_PURCHASE_CONTEXT_TYPE, purchaseContext.getType().getUrlComponent(), ADDITIONAL_INFO_PURCHASE_IDENTIFIER, purchaseContext.getPublicIdentifier(), ADDITIONAL_INFO_RESERVATION_ID, reservationId), new PaymentContext(purchaseContext, reservationId));
        if (result.isSuccessful()) {
            return ResponseEntity.ok("OK");
        } else if (result.isError()) {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(result.getReason());
        }
        return ResponseEntity.ok(result.getReason());
    })).orElseGet(() -> ResponseEntity.badRequest().body("NOK"));
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) PostMapping(org.springframework.web.bind.annotation.PostMapping) MollieWebhookPaymentManager(alfio.manager.payment.MollieWebhookPaymentManager) PaymentProxy(alfio.model.transaction.PaymentProxy) StringUtils(org.apache.commons.lang3.StringUtils) RestController(org.springframework.web.bind.annotation.RestController) HttpStatus(org.springframework.http.HttpStatus) PurchaseContextManager(alfio.manager.PurchaseContextManager) TicketReservationManager(alfio.manager.TicketReservationManager) HttpServletRequest(javax.servlet.http.HttpServletRequest) PaymentContext(alfio.model.transaction.PaymentContext) Map(java.util.Map) Log4j2(lombok.extern.log4j.Log4j2) Optional(java.util.Optional) ResponseEntity(org.springframework.http.ResponseEntity) AllArgsConstructor(lombok.AllArgsConstructor) PaymentContext(alfio.model.transaction.PaymentContext) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 5 with PaymentContext

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

the class BaseStripeManager method refund.

// https://stripe.com/docs/api#create_refund
boolean refund(Transaction transaction, PurchaseContext purchaseContext, Integer amountToRefund) {
    Optional<Integer> amount = Optional.ofNullable(amountToRefund);
    String chargeId = transaction.getTransactionId();
    try {
        String amountOrFull = amount.map(p -> MonetaryUtil.formatCents(p, transaction.getCurrency())).orElse("full");
        log.info("Stripe: trying to do a refund for payment {} with amount: {}", chargeId, amountOrFull);
        Map<String, Object> params = new HashMap<>();
        params.put("charge", chargeId);
        amount.ifPresent(a -> params.put("amount", a));
        if (transaction.getPlatformFee() > 0 && isConnectEnabled(new PaymentContext(purchaseContext))) {
            params.put("refund_application_fee", true);
        }
        Optional<RequestOptions> requestOptionsOptional = options(purchaseContext);
        if (requestOptionsOptional.isPresent()) {
            RequestOptions options = requestOptionsOptional.get();
            Refund r = Refund.create(params, options);
            boolean pending = PENDING.equals(r.getStatus());
            if (SUCCEEDED.equals(r.getStatus()) || pending) {
                log.info("Stripe: refund for payment {} {} for amount: {}", chargeId, pending ? "registered" : "executed with success", amountOrFull);
                return true;
            } else {
                log.warn("Stripe: was not able to refund payment with id {}, returned status is not 'succeded' but {}", chargeId, r.getStatus());
                return false;
            }
        }
        return false;
    } catch (StripeException e) {
        log.warn("Stripe: was not able to refund payment with id " + chargeId, e);
        return false;
    }
}
Also used : Transaction(alfio.model.transaction.Transaction) RequestOptions(com.stripe.net.RequestOptions) java.util(java.util) PaymentProxy(alfio.model.transaction.PaymentProxy) PaymentResult(alfio.manager.support.PaymentResult) PurchaseContext(alfio.model.PurchaseContext) PurchaseContextType(alfio.model.PurchaseContext.PurchaseContextType) UnaryOperator(java.util.function.UnaryOperator) ConfigurationManager(alfio.manager.system.ConfigurationManager) PaymentInformation(alfio.model.PaymentInformation) Charge(com.stripe.model.Charge) Profiles(org.springframework.core.env.Profiles) Configurable(alfio.model.Configurable) Refund(com.stripe.model.Refund) TicketRepository(alfio.repository.TicketRepository) Predicate(java.util.function.Predicate) FeeCalculator(alfio.manager.support.FeeCalculator) PaymentMethod(alfio.model.transaction.PaymentMethod) Stripe(com.stripe.Stripe) ErrorsCode(alfio.util.ErrorsCode) ConfigurationRepository(alfio.repository.system.ConfigurationRepository) PaymentContext(alfio.model.transaction.PaymentContext) MonetaryUtil(alfio.util.MonetaryUtil) Environment(org.springframework.core.env.Environment) UserManager(alfio.manager.user.UserManager) Log4j2(lombok.extern.log4j.Log4j2) ConfigurationPathLevel(alfio.model.system.ConfigurationPathLevel) com.stripe.exception(com.stripe.exception) AllArgsConstructor(lombok.AllArgsConstructor) ConfigurationKeys(alfio.model.system.ConfigurationKeys) BalanceTransaction(com.stripe.model.BalanceTransaction) Webhook(com.stripe.net.Webhook) RequestOptions(com.stripe.net.RequestOptions) PaymentContext(alfio.model.transaction.PaymentContext) Refund(com.stripe.model.Refund)

Aggregations

PaymentContext (alfio.model.transaction.PaymentContext)8 Test (org.junit.jupiter.api.Test)6 PaymentProxy (alfio.model.transaction.PaymentProxy)2 AllArgsConstructor (lombok.AllArgsConstructor)2 Log4j2 (lombok.extern.log4j.Log4j2)2 PurchaseContextManager (alfio.manager.PurchaseContextManager)1 TicketReservationManager (alfio.manager.TicketReservationManager)1 MollieWebhookPaymentManager (alfio.manager.payment.MollieWebhookPaymentManager)1 FeeCalculator (alfio.manager.support.FeeCalculator)1 PaymentResult (alfio.manager.support.PaymentResult)1 ConfigurationManager (alfio.manager.system.ConfigurationManager)1 UserManager (alfio.manager.user.UserManager)1 Configurable (alfio.model.Configurable)1 PaymentInformation (alfio.model.PaymentInformation)1 PurchaseContext (alfio.model.PurchaseContext)1 PurchaseContextType (alfio.model.PurchaseContext.PurchaseContextType)1 ConfigurationKeys (alfio.model.system.ConfigurationKeys)1 ConfigurationPathLevel (alfio.model.system.ConfigurationPathLevel)1 PaymentMethod (alfio.model.transaction.PaymentMethod)1 Transaction (alfio.model.transaction.Transaction)1