Skip to content

Commit

Permalink
#419 - log terms and conditions / privacy policy acceptance
Browse files Browse the repository at this point in the history
(cherry picked from commit 405860e)
  • Loading branch information
cbellone committed Jun 1, 2018
1 parent e470e3a commit 32232ce
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/main/java/alfio/controller/ReservationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ public String handleReservation(@PathVariable("eventName") String eventName,
final PaymentResult status = ticketReservationManager.confirm(paymentForm.getToken(), paymentForm.getPaypalPayerID(), event, reservationId, paymentForm.getEmail(),
customerName, locale, paymentForm.getBillingAddress(), paymentForm.getCustomerReference(), reservationCost, SessionUtil.retrieveSpecialPriceSessionId(request),
Optional.ofNullable(paymentForm.getPaymentMethod()), paymentForm.isInvoiceRequested(), paymentForm.getVatCountryCode(),
paymentForm.getVatNr(), ticketReservation.get().getVatStatus());
paymentForm.getVatNr(), ticketReservation.get().getVatStatus(), paymentForm.getTermAndConditionsAccepted(), Optional.ofNullable(paymentForm.getPrivacyPolicyAccepted()).orElse(false));

if(!status.isSuccessful()) {
String errorMessageCode = status.getErrorCode().get();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/alfio/manager/AdminReservationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ private Result<Triple<TicketReservation, List<Ticket>, Event>> loadReservation(S

private Result<Triple<TicketReservation, List<Ticket>, Event>> performConfirmation(String reservationId, Event event, TicketReservation original) {
try {
ticketReservationManager.completeReservation(event.getId(), reservationId, original.getEmail(), new CustomerName(original.getFullName(), original.getFirstName(), original.getLastName(), event),
Locale.forLanguageTag(original.getUserLanguage()), original.getBillingAddress(), Optional.empty(), PaymentProxy.ADMIN, original.getCustomerReference());
ticketReservationManager.completeReservation(event, reservationId, original.getEmail(), new CustomerName(original.getFullName(), original.getFirstName(), original.getLastName(), event),
Locale.forLanguageTag(original.getUserLanguage()), original.getBillingAddress(), Optional.empty(), PaymentProxy.ADMIN, original.getCustomerReference(), false, false);
return loadReservation(reservationId);
} catch(Exception e) {
return Result.error(ErrorCode.ReservationError.UPDATE_FAILED);
Expand Down
22 changes: 17 additions & 5 deletions src/main/java/alfio/manager/TicketReservationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
import static alfio.util.OptionalWrapper.optionally;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static java.util.stream.Collectors.*;
import static org.apache.commons.lang3.time.DateUtils.addHours;
import static org.apache.commons.lang3.time.DateUtils.truncate;
Expand Down Expand Up @@ -340,7 +341,8 @@ Optional<SpecialPrice> fixToken(Optional<SpecialPrice> token, int ticketCategory
public PaymentResult confirm(String gatewayToken, String payerId, Event event, String reservationId,
String email, CustomerName customerName, Locale userLanguage, String billingAddress, String customerReference,
TotalPrice reservationCost, Optional<String> specialPriceSessionId, Optional<PaymentProxy> method,
boolean invoiceRequested, String vatCountryCode, String vatNr, PriceContainer.VatStatus vatStatus) {
boolean invoiceRequested, String vatCountryCode, String vatNr, PriceContainer.VatStatus vatStatus,
boolean tcAccepted, boolean privacyPolicyAccepted) {
PaymentProxy paymentProxy = evaluatePaymentProxy(method, reservationCost);
if(!initPaymentProcess(reservationCost, paymentProxy, reservationId, email, customerName, userLanguage, billingAddress, customerReference)) {
return PaymentResult.unsuccessful("error.STEP2_UNABLE_TO_TRANSITION");
Expand Down Expand Up @@ -395,7 +397,7 @@ public PaymentResult confirm(String gatewayToken, String payerId, Event event, S
} else {
paymentResult = PaymentResult.successful(NOT_YET_PAID_TRANSACTION_ID);
}
completeReservation(event.getId(), reservationId, email, customerName, userLanguage, billingAddress, specialPriceSessionId, paymentProxy, customerReference);
completeReservation(event, reservationId, email, customerName, userLanguage, billingAddress, specialPriceSessionId, paymentProxy, customerReference, tcAccepted, privacyPolicyAccepted);
return paymentResult;
} catch(Exception ex) {
//it is guaranteed that in this case we're dealing with "local" error (e.g. database failure),
Expand Down Expand Up @@ -632,9 +634,10 @@ public Optional<Triple<Event, TicketReservation, Ticket>> from(String eventName,
/**
* Set the tickets attached to the reservation to the ACQUIRED state and the ticket reservation to the COMPLETE state. Additionally it will save email/fullName/billingaddress/userLanguage.
*/
void completeReservation(int eventId, String reservationId, String email, CustomerName customerName,
void completeReservation(Event event, String reservationId, String email, CustomerName customerName,
Locale userLanguage, String billingAddress, Optional<String> specialPriceSessionId,
PaymentProxy paymentProxy, String customerReference) {
PaymentProxy paymentProxy, String customerReference, boolean tcAccepted, boolean privacyAccepted) {
int eventId = event.getId();
if(paymentProxy != PaymentProxy.OFFLINE) {
TicketStatus ticketStatus = paymentProxy.isDeskPaymentRequired() ? TicketStatus.TO_BE_PAID : TicketStatus.ACQUIRED;
AdditionalServiceItemStatus asStatus = paymentProxy.isDeskPaymentRequired() ? AdditionalServiceItemStatus.TO_BE_PAID : AdditionalServiceItemStatus.ACQUIRED;
Expand All @@ -645,7 +648,16 @@ void completeReservation(int eventId, String reservationId, String email, Custom
specialPriceSessionId.ifPresent(specialPriceRepository::unbindFromSession);
}

auditingRepository.insert(reservationId, null, eventId, Audit.EventType.RESERVATION_COMPLETE, new Date(), Audit.EntityType.RESERVATION, reservationId);
Date timestamp = new Date();
auditingRepository.insert(reservationId, null, eventId, Audit.EventType.RESERVATION_COMPLETE, timestamp, Audit.EntityType.RESERVATION, reservationId);

if(tcAccepted) {
auditingRepository.insert(reservationId, null, eventId, Audit.EventType.TERMS_CONDITION_ACCEPTED, timestamp, Audit.EntityType.RESERVATION, reservationId, singletonList(singletonMap("termsAndConditionsUrl", event.getTermsAndConditionsUrl())));
}

if(StringUtils.isNotBlank(event.getPrivacyPolicyLinkOrNull()) && privacyAccepted) {
auditingRepository.insert(reservationId, null, eventId, Audit.EventType.PRIVACY_POLICY_ACCEPTED, timestamp, Audit.EntityType.RESERVATION, reservationId, singletonList(singletonMap("privacyPolicyUrl", event.getPrivacyPolicyUrl())));
}
}

private void acquireItems(TicketStatus ticketStatus, AdditionalServiceItemStatus asStatus, PaymentProxy paymentProxy,
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/alfio/model/Audit.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public enum EventType {
UPDATE_TICKET,
UPDATE_TICKET_CATEGORY,
UPDATE_INVOICE,
FORCED_UPDATE_INVOICE
FORCED_UPDATE_INVOICE,
TERMS_CONDITION_ACCEPTED,
PRIVACY_POLICY_ACCEPTED
}

private final String reservationId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public void testTicketSelection() {
assertEquals(0, ticketReservationManager.getPendingPayments(event).size());

PaymentResult confirm = ticketReservationManager.confirm(null, null, event, reservationId, "[email protected]", new CustomerName("full name", "full", "name", event), Locale.ENGLISH, "billing address", "reference",
totalPrice, Optional.empty(), Optional.of(PaymentProxy.OFFLINE), false, null, null, null);
totalPrice, Optional.empty(), Optional.of(PaymentProxy.OFFLINE), false, null, null, null, false, false);


assertTrue(confirm.isSuccessful());
Expand Down Expand Up @@ -207,7 +207,7 @@ public void testTicketSelection() {
String reservationId2 = ticketReservationManager.createTicketReservation(event, Collections.singletonList(modForDelete), Collections.emptyList(), DateUtils.addDays(new Date(), 1), Optional.empty(), Optional.empty(), Locale.ENGLISH, false);

ticketReservationManager.confirm(null, null, event, reservationId2, "[email protected]", new CustomerName("full name", "full", "name", event), Locale.ENGLISH, "billing address", "reference",
totalPrice, Optional.empty(), Optional.of(PaymentProxy.OFFLINE), false, null, null, null);
totalPrice, Optional.empty(), Optional.of(PaymentProxy.OFFLINE), false, null, null, null, false, false);

assertTrue(ticketReservationManager.findById(reservationId2).isPresent());

Expand Down Expand Up @@ -359,15 +359,15 @@ public void testDeletePendingPaymentUnboundedCategory() {
TicketReservationWithOptionalCodeModification mod = new TicketReservationWithOptionalCodeModification(tr, Optional.empty());
String reservationId = ticketReservationManager.createTicketReservation(event, Collections.singletonList(mod), Collections.emptyList(), DateUtils.addDays(new Date(), 1), Optional.empty(), Optional.empty(), Locale.ENGLISH, false);
TotalPrice reservationCost = ticketReservationManager.totalReservationCostWithVAT(reservationId);
PaymentResult result = ticketReservationManager.confirm("", null, event, reservationId, "[email protected]", new CustomerName("full name", "full", "name", event), Locale.ENGLISH, "", "", reservationCost, Optional.empty(), Optional.of(PaymentProxy.OFFLINE), false, null, null, null);
PaymentResult result = ticketReservationManager.confirm("", null, event, reservationId, "[email protected]", new CustomerName("full name", "full", "name", event), Locale.ENGLISH, "", "", reservationCost, Optional.empty(), Optional.of(PaymentProxy.OFFLINE), false, null, null, null, false, false);
assertTrue(result.isSuccessful());
ticketReservationManager.deleteOfflinePayment(event, reservationId, false);
waitingQueueManager.distributeSeats(event);

mod = new TicketReservationWithOptionalCodeModification(tr, Optional.empty());
reservationId = ticketReservationManager.createTicketReservation(event, Collections.singletonList(mod), Collections.emptyList(), DateUtils.addDays(new Date(), 1), Optional.empty(), Optional.empty(), Locale.ENGLISH, false);
reservationCost = ticketReservationManager.totalReservationCostWithVAT(reservationId);
result = ticketReservationManager.confirm("", null, event, reservationId, "[email protected]", new CustomerName("full name", "full", "name", event), Locale.ENGLISH, "", "", reservationCost, Optional.empty(), Optional.of(PaymentProxy.OFFLINE), false, null, null, null);
result = ticketReservationManager.confirm("", null, event, reservationId, "[email protected]", new CustomerName("full name", "full", "name", event), Locale.ENGLISH, "", "", reservationCost, Optional.empty(), Optional.of(PaymentProxy.OFFLINE), false, null, null, null, false, false);
assertTrue(result.isSuccessful());
}
}
8 changes: 4 additions & 4 deletions src/test/java/alfio/manager/TicketReservationManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ public void confirmPaidReservation() {
when(ticketRepository.updateTicketsStatusWithReservationId(eq(RESERVATION_ID), eq(TicketStatus.ACQUIRED.toString()))).thenReturn(1);
when(ticketReservationRepository.updateTicketReservation(eq(RESERVATION_ID), eq(IN_PAYMENT.toString()), anyString(), anyString(), anyString(), anyString(),anyString(), anyString(), isNull(ZonedDateTime.class), eq(PaymentProxy.STRIPE.toString()), anyString())).thenReturn(1);
when(paymentManager.processStripePayment(eq(RESERVATION_ID), eq(GATEWAY_TOKEN), anyInt(), eq(event), anyString(), any(CustomerName.class), anyString())).thenReturn(PaymentResult.successful(TRANSACTION_ID));
PaymentResult result = trm.confirm(GATEWAY_TOKEN, null, event, RESERVATION_ID, "", new CustomerName("Full Name", null, null, event), Locale.ENGLISH, "", "", new TotalPrice(100, 0, 0, 0), Optional.empty(), Optional.of(PaymentProxy.STRIPE), true, null, null, null);
PaymentResult result = trm.confirm(GATEWAY_TOKEN, null, event, RESERVATION_ID, "", new CustomerName("Full Name", null, null, event), Locale.ENGLISH, "", "", new TotalPrice(100, 0, 0, 0), Optional.empty(), Optional.of(PaymentProxy.STRIPE), true, null, null, null, false, false);
assertTrue(result.isSuccessful());
assertEquals(Optional.of(TRANSACTION_ID), result.getGatewayTransactionId());
verify(ticketReservationRepository).updateTicketReservation(eq(RESERVATION_ID), eq(TicketReservationStatus.IN_PAYMENT.toString()), anyString(), anyString(), anyString(),anyString(), anyString(), anyString(), any(), eq(PaymentProxy.STRIPE.toString()), anyString());
Expand All @@ -714,7 +714,7 @@ public void returnFailureCodeIfPaymentNotSuccesful() {
when(ticketReservationRepository.updateTicketReservation(eq(RESERVATION_ID), eq(IN_PAYMENT.toString()), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), isNull(ZonedDateTime.class), eq(PaymentProxy.STRIPE.toString()), anyString())).thenReturn(1);
when(ticketReservationRepository.updateReservationStatus(eq(RESERVATION_ID), eq(TicketReservationStatus.PENDING.toString()))).thenReturn(1);
when(paymentManager.processStripePayment(eq(RESERVATION_ID), eq(GATEWAY_TOKEN), anyInt(), eq(event), anyString(), any(CustomerName.class), anyString())).thenReturn(PaymentResult.unsuccessful("error-code"));
PaymentResult result = trm.confirm(GATEWAY_TOKEN, null, event, RESERVATION_ID, "", new CustomerName("Full Name", null, null, event), Locale.ENGLISH, "", "", new TotalPrice(100, 0, 0, 0), Optional.empty(), Optional.of(PaymentProxy.STRIPE), true, null, null, null);
PaymentResult result = trm.confirm(GATEWAY_TOKEN, null, event, RESERVATION_ID, "", new CustomerName("Full Name", null, null, event), Locale.ENGLISH, "", "", new TotalPrice(100, 0, 0, 0), Optional.empty(), Optional.of(PaymentProxy.STRIPE), true, null, null, null, false, false);
assertFalse(result.isSuccessful());
assertFalse(result.getGatewayTransactionId().isPresent());
assertEquals(Optional.of("error-code"), result.getErrorCode());
Expand All @@ -733,7 +733,7 @@ public void handleOnSitePaymentMethod() {
when(ticketRepository.updateTicketsStatusWithReservationId(eq(RESERVATION_ID), eq(TicketStatus.TO_BE_PAID.toString()))).thenReturn(1);
when(ticketReservationRepository.updateTicketReservation(eq(RESERVATION_ID), eq(COMPLETE.toString()), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), any(ZonedDateTime.class), eq(PaymentProxy.ON_SITE.toString()), anyString())).thenReturn(1);
when(paymentManager.processStripePayment(eq(RESERVATION_ID), eq(GATEWAY_TOKEN), anyInt(), eq(event), anyString(), any(CustomerName.class), anyString())).thenReturn(PaymentResult.unsuccessful("error-code"));
PaymentResult result = trm.confirm(GATEWAY_TOKEN, null, event, RESERVATION_ID, "", new CustomerName("Full Name", null, null, event), Locale.ENGLISH, "", "", new TotalPrice(100, 0, 0, 0), Optional.empty(), Optional.of(PaymentProxy.ON_SITE), true, null, null, null);
PaymentResult result = trm.confirm(GATEWAY_TOKEN, null, event, RESERVATION_ID, "", new CustomerName("Full Name", null, null, event), Locale.ENGLISH, "", "", new TotalPrice(100, 0, 0, 0), Optional.empty(), Optional.of(PaymentProxy.ON_SITE), true, null, null, null, false, false);
assertTrue(result.isSuccessful());
assertEquals(Optional.of(TicketReservationManager.NOT_YET_PAID_TRANSACTION_ID), result.getGatewayTransactionId());
verify(ticketReservationRepository).updateTicketReservation(eq(RESERVATION_ID), eq(TicketReservationStatus.COMPLETE.toString()), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), any(), eq(PaymentProxy.ON_SITE.toString()), anyString());
Expand All @@ -752,7 +752,7 @@ public void handleOnSitePaymentMethod() {
public void handleOfflinePaymentMethod() {
initConfirmReservation();
when(ticketReservationRepository.postponePayment(eq(RESERVATION_ID), any(Date.class), anyString(), anyString(), anyString(), anyString(), anyString(), anyString())).thenReturn(1);
PaymentResult result = trm.confirm(GATEWAY_TOKEN, null, event, RESERVATION_ID, "", new CustomerName("Full Name", null, null, event), Locale.ENGLISH, "", "", new TotalPrice(100, 0, 0, 0), Optional.empty(), Optional.of(PaymentProxy.OFFLINE), true, null, null, null);
PaymentResult result = trm.confirm(GATEWAY_TOKEN, null, event, RESERVATION_ID, "", new CustomerName("Full Name", null, null, event), Locale.ENGLISH, "", "", new TotalPrice(100, 0, 0, 0), Optional.empty(), Optional.of(PaymentProxy.OFFLINE), true, null, null, null, false, false);
assertTrue(result.isSuccessful());
assertEquals(Optional.of(TicketReservationManager.NOT_YET_PAID_TRANSACTION_ID), result.getGatewayTransactionId());
verify(waitingQueueManager, never()).fireReservationConfirmed(eq(RESERVATION_ID));
Expand Down
Loading

0 comments on commit 32232ce

Please sign in to comment.