11package it .gov .pagopa .receipt .pdf .datastore .utils ;
22
3- import com .microsoft .azure .functions .HttpRequestMessage ;
4- import com .microsoft .azure .functions .HttpResponseMessage ;
5- import com .microsoft .azure .functions .HttpStatus ;
63import it .gov .pagopa .receipt .pdf .datastore .entity .cart .CartForReceipt ;
74import it .gov .pagopa .receipt .pdf .datastore .entity .cart .CartStatusType ;
85import it .gov .pagopa .receipt .pdf .datastore .entity .event .BizEvent ;
1310import it .gov .pagopa .receipt .pdf .datastore .entity .receipt .EventData ;
1411import it .gov .pagopa .receipt .pdf .datastore .entity .receipt .Receipt ;
1512import it .gov .pagopa .receipt .pdf .datastore .entity .receipt .enumeration .ReceiptStatusType ;
16- import it .gov .pagopa .receipt .pdf .datastore .model .ProblemJson ;
1713import it .gov .pagopa .receipt .pdf .datastore .service .BizEventToReceiptService ;
1814import lombok .Builder ;
1915import org .slf4j .Logger ;
2521import java .util .Collections ;
2622import java .util .List ;
2723import java .util .Locale ;
28- import java .util .Optional ;
2924import java .util .UUID ;
3025import java .util .regex .Matcher ;
3126import java .util .regex .Pattern ;
@@ -39,7 +34,7 @@ public class BizEventToReceiptUtils {
3934 "AUTHENTICATED_CHANNELS" , "IO,CHECKOUT,WISP,CHECKOUT_CART" ).split ("," ));
4035 private static final List <String > UNWANTED_REMITTANCE_INFO = Arrays .asList (System .getenv ().getOrDefault (
4136 "UNWANTED_REMITTANCE_INFO" , "pagamento multibeneficiario,pagamento bpay" ).split ("," ));
42- private static final String ECOMMERCE = "CHECKOUT" ;
37+ private static final List < String > ECOMMERCE = Arrays . asList ( "CHECKOUT" , "CHECKOUT_CART" ) ;
4338
4439
4540 private BizEventToReceiptUtils () {
@@ -118,7 +113,7 @@ public static BizEventValidityCheck isBizEventInvalid(BizEvent bizEvent) {
118113 if (Boolean .TRUE .equals (ECOMMERCE_FILTER_ENABLED )
119114 && bizEvent .getTransactionDetails () != null
120115 && bizEvent .getTransactionDetails ().getInfo () != null
121- && ECOMMERCE .equals (bizEvent .getTransactionDetails ().getInfo ().getClientId ())
116+ && ECOMMERCE .contains (bizEvent .getTransactionDetails ().getInfo ().getClientId ())
122117 ) {
123118 return BizEventValidityCheck .builder ()
124119 .invalid (true )
@@ -294,30 +289,31 @@ public static boolean isCartMod1(BizEvent bizEvent) {
294289 }
295290
296291 public static boolean isValidChannelOrigin (BizEvent bizEvent ) {
297- if (bizEvent .getTransactionDetails () == null ) {
292+ var details = bizEvent .getTransactionDetails ();
293+ if (details == null ) {
298294 return false ;
299295 }
300296
301- var transactionDetails = bizEvent .getTransactionDetails ();
302- var transaction = transactionDetails .getTransaction ();
303- var info = transactionDetails .getInfo ();
304- var user = transactionDetails .getUser ();
297+ String origin = details .getTransaction () != null
298+ ? details .getTransaction ().getOrigin ()
299+ : null ;
305300
306- String origin = ( transaction != null ) ? transaction . getOrigin () : null ;
307- String clientId = ( info != null ) ? info . getClientId () : null ;
308- UserType userType = ( user != null ) ? user . getType () : null ;
301+ String clientId = details . getInfo () != null
302+ ? details . getInfo (). getClientId ()
303+ : null ;
309304
310- boolean originMatches = origin != null && AUTHENTICATED_CHANNELS .contains (origin );
311- boolean clientIdMatches = clientId != null && AUTHENTICATED_CHANNELS .contains (clientId );
305+ UserType userType = details .getUser () != null
306+ ? details .getUser ().getType ()
307+ : null ;
312308
313- boolean isCheckoutOrigin = ECOMMERCE . equalsIgnoreCase (origin );
314- boolean isCheckoutClientId = ECOMMERCE .equalsIgnoreCase (clientId );
309+ boolean isAuthenticated = AUTHENTICATED_CHANNELS . contains (origin ) || AUTHENTICATED_CHANNELS . contains ( clientId );
310+ boolean isCheckout = ECOMMERCE .contains ( origin ) || ECOMMERCE . contains (clientId );
315311 boolean isRegisteredUser = UserType .REGISTERED .equals (userType );
316312
317- if (( isCheckoutOrigin || isCheckoutClientId ) && !isRegisteredUser ) {
313+ if (isCheckout && !isRegisteredUser ) {
318314 return false ;
319315 }
320316
321- return originMatches || clientIdMatches ;
317+ return isAuthenticated ;
322318 }
323319}
0 commit comments