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())));
}
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);
}
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());
}
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"));
}
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;
}
}
Aggregations