From 20dd97f807b6244821bdcf2efaf1181a54991685 Mon Sep 17 00:00:00 2001 From: gcatanese Date: Fri, 8 Aug 2025 16:41:53 +0200 Subject: [PATCH 1/7] Apply stricter matching in oneOf deserialization --- .../model/checkout/CheckoutPaymentMethod.java | 104 +++++++++--------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/src/main/java/com/adyen/model/checkout/CheckoutPaymentMethod.java b/src/main/java/com/adyen/model/checkout/CheckoutPaymentMethod.java index 515ba637e..9d130568d 100644 --- a/src/main/java/com/adyen/model/checkout/CheckoutPaymentMethod.java +++ b/src/main/java/com/adyen/model/checkout/CheckoutPaymentMethod.java @@ -80,7 +80,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(AchDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(AchDetails.class); @@ -103,7 +103,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(AffirmDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(AffirmDetails.class); @@ -126,7 +126,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(AfterpayDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(AfterpayDetails.class); @@ -149,7 +149,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(AmazonPayDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(AmazonPayDetails.class); @@ -172,7 +172,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(AncvDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(AncvDetails.class); @@ -195,7 +195,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(AndroidPayDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(AndroidPayDetails.class); @@ -218,7 +218,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(ApplePayDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(ApplePayDetails.class); @@ -241,7 +241,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(BacsDirectDebitDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(BacsDirectDebitDetails.class); @@ -264,7 +264,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(BillDeskDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(BillDeskDetails.class); @@ -287,7 +287,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(BlikDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(BlikDetails.class); @@ -310,7 +310,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(CardDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(CardDetails.class); @@ -333,7 +333,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(CashAppDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(CashAppDetails.class); @@ -356,7 +356,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(CellulantDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(CellulantDetails.class); @@ -379,7 +379,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(DokuDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(DokuDetails.class); @@ -402,7 +402,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(DragonpayDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(DragonpayDetails.class); @@ -425,7 +425,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(EBankingFinlandDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(EBankingFinlandDetails.class); @@ -448,7 +448,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(EcontextVoucherDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(EcontextVoucherDetails.class); @@ -471,7 +471,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(EftDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(EftDetails.class); @@ -494,7 +494,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(FastlaneDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(FastlaneDetails.class); @@ -517,7 +517,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(GenericIssuerPaymentMethodDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = @@ -542,7 +542,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(GooglePayDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(GooglePayDetails.class); @@ -565,7 +565,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(IdealDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(IdealDetails.class); @@ -588,7 +588,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(KlarnaDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(KlarnaDetails.class); @@ -611,7 +611,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(MasterpassDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(MasterpassDetails.class); @@ -634,7 +634,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(MbwayDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(MbwayDetails.class); @@ -657,7 +657,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(MobilePayDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(MobilePayDetails.class); @@ -680,7 +680,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(MolPayDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(MolPayDetails.class); @@ -703,7 +703,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(OpenInvoiceDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(OpenInvoiceDetails.class); @@ -726,7 +726,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(PayByBankAISDirectDebitDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = @@ -751,7 +751,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(PayByBankDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(PayByBankDetails.class); @@ -774,7 +774,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(PayPalDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(PayPalDetails.class); @@ -797,7 +797,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(PayPayDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(PayPayDetails.class); @@ -820,7 +820,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(PayToDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(PayToDetails.class); @@ -843,7 +843,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(PayUUpiDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(PayUUpiDetails.class); @@ -866,7 +866,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(PayWithGoogleDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(PayWithGoogleDetails.class); @@ -889,7 +889,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(PaymentDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(PaymentDetails.class); @@ -912,7 +912,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(PixDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(PixDetails.class); @@ -935,7 +935,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(PseDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(PseDetails.class); @@ -958,7 +958,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(RakutenPayDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(RakutenPayDetails.class); @@ -981,7 +981,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(RatepayDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(RatepayDetails.class); @@ -1004,7 +1004,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(RivertyDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(RivertyDetails.class); @@ -1027,7 +1027,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(SamsungPayDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(SamsungPayDetails.class); @@ -1050,7 +1050,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(SepaDirectDebitDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(SepaDirectDebitDetails.class); @@ -1073,7 +1073,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(StoredPaymentMethodDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = @@ -1097,7 +1097,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(TwintDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(TwintDetails.class); @@ -1120,7 +1120,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(UpiCollectDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(UpiCollectDetails.class); @@ -1143,7 +1143,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(UpiIntentDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(UpiIntentDetails.class); @@ -1166,7 +1166,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(VippsDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(VippsDetails.class); @@ -1189,7 +1189,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(VisaCheckoutDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(VisaCheckoutDetails.class); @@ -1212,7 +1212,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(WeChatPayDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(WeChatPayDetails.class); @@ -1235,7 +1235,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(WeChatPayMiniProgramDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = @@ -1259,7 +1259,7 @@ public CheckoutPaymentMethod deserialize(JsonParser jp, DeserializationContext c // Checks if the unique type of the oneOf json matches any of the object TypeEnum values boolean typeMatch = Arrays.stream(ZipDetails.TypeEnum.values()) - .anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText())); + .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); if (typeMatch) { deserialized = tree.traverse(jp.getCodec()).readValueAs(ZipDetails.class); From e4bd6b647b43c7ccee13774d847ceab631048f89 Mon Sep 17 00:00:00 2001 From: gcatanese Date: Fri, 8 Aug 2025 16:42:03 +0200 Subject: [PATCH 2/7] Add tests --- src/test/java/com/adyen/CheckoutTest.java | 47 +++ .../java/com/adyen/serializer/ModelTest.java | 316 ++++++++++-------- 2 files changed, 230 insertions(+), 133 deletions(-) diff --git a/src/test/java/com/adyen/CheckoutTest.java b/src/test/java/com/adyen/CheckoutTest.java index 33e701a93..0d10ccb65 100644 --- a/src/test/java/com/adyen/CheckoutTest.java +++ b/src/test/java/com/adyen/CheckoutTest.java @@ -665,4 +665,51 @@ public void TestSessionsCheckDefaultValues() throws Exception { final JsonNode actual = mapper.readTree(captor.getValue()); assertEquals(expected, actual); } + + @Test + public void TestBccm() throws Exception { + Client client = createMockClientFromFile("mocks/checkout/paymentResponseBcmc.json"); + Amount amount = new Amount().currency("EUR").value(1000L); + PaymentRequest paymentRequest = new PaymentRequest(); + paymentRequest.setMerchantAccount("YOUR_MERCHANT_ACCOUNT"); + paymentRequest.setReference("YOUR_ORDER_NUMBER"); + paymentRequest.setAmount(new Amount() + .currency("EUR") + .value(1000L)); + paymentRequest.setPaymentMethod(new CheckoutPaymentMethod( + new CardDetails() + .type(CardDetails.TypeEnum.BCMC) + .holderName("Ms Smith") + .encryptedCardNumber("...") + .encryptedExpiryMonth("...") + .encryptedExpiryYear("...") + .brand("bcmc") + .checkoutAttemptId("...") + )); + PaymentsApi checkout = new PaymentsApi(client); + PaymentResponse paymentResponse = checkout.payments(paymentRequest); + assertEquals(PaymentResponse.ResultCodeEnum.REDIRECTSHOPPER, paymentResponse.getResultCode()); + assertNotNull(paymentResponse.getAction()); + } + + @Test + public void TestBccmMobile() throws Exception { + Client client = createMockClientFromFile("mocks/checkout/paymentResponseBcmcMobile.json"); + Amount amount = new Amount().currency("EUR").value(1000L); + PaymentRequest paymentRequest = new PaymentRequest(); + paymentRequest.setMerchantAccount("YOUR_MERCHANT_ACCOUNT"); + paymentRequest.setReference("YOUR_ORDER_NUMBER"); + paymentRequest.setAmount(new Amount() + .currency("EUR") + .value(1000L)); + paymentRequest.setPaymentMethod(new CheckoutPaymentMethod( + new StoredPaymentMethodDetails() + .type(StoredPaymentMethodDetails.TypeEnum.BCMC_MOBILE) + )); + PaymentsApi checkout = new PaymentsApi(client); + PaymentResponse paymentResponse = checkout.payments(paymentRequest); + assertEquals(PaymentResponse.ResultCodeEnum.PENDING, paymentResponse.getResultCode()); + assertNotNull(paymentResponse.getAction()); + } + } diff --git a/src/test/java/com/adyen/serializer/ModelTest.java b/src/test/java/com/adyen/serializer/ModelTest.java index 4214082bb..2128b338f 100644 --- a/src/test/java/com/adyen/serializer/ModelTest.java +++ b/src/test/java/com/adyen/serializer/ModelTest.java @@ -5,146 +5,196 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import com.adyen.model.checkout.CardDetails; +import com.adyen.model.checkout.CheckoutPaymentMethod; import com.adyen.model.checkout.CreateCheckoutSessionResponse; +import com.adyen.model.checkout.StoredPaymentMethodDetails; import com.adyen.model.legalentitymanagement.*; import com.fasterxml.jackson.core.JsonProcessingException; + import java.time.Month; import java.time.ZoneId; + import org.junit.Test; -/** Test model serialization (toJson) and deserialization (fromJson) */ +/** + * Test model serialization (toJson) and deserialization (fromJson) + */ public class ModelTest { - @Test - public void testFromJsonLegalEntity() throws JsonProcessingException { - String json = - "{\n" - + " \"id\": \"LE3227C223222B5BPCMFXD2XG\",\n" - + " \"reference\": \"YOUR_REFERENCE_12345\",\n" - + " \"type\": \"individual\",\n" - + " \"individual\": {\n" - + " \"name\": {\n" - + " \"firstName\": \"Jane\",\n" - + " \"lastName\": \"Doe\"\n" - + " },\n" - + " \"residentialAddress\": {\n" - + " \"country\": \"NL\",\n" - + " \"city\": \"Amsterdam\"\n" - + " }\n" - + " },\n" - + " \"capabilities\": {\n" - + " \"issueCard\": {\n" - + " \"allowed\": true,\n" - + " \"requested\": true\n" - + " }\n" - + " }\n" - + "}"; - - LegalEntity legalEntity = LegalEntity.fromJson(json); - - assertNotNull(legalEntity); - assertEquals("LE3227C223222B5BPCMFXD2XG", legalEntity.getId()); - assertEquals("YOUR_REFERENCE_12345", legalEntity.getReference()); - - assertEquals(LegalEntity.TypeEnum.INDIVIDUAL, legalEntity.getType()); - assertNotNull(legalEntity.getIndividual()); - - assertNotNull(legalEntity.getCapabilities()); - assertTrue(legalEntity.getCapabilities().containsKey("issueCard")); - assertNotNull(legalEntity.getCapabilities().get("issueCard")); - } - - @Test - public void testFromJsonLegalEntityWithInvalidEnum() throws JsonProcessingException { - String json = - "{\n" - + " \"id\": \"LE3227C223222B5BPCMFXD2XG\",\n" - + " \"reference\": \"YOUR_REFERENCE_12345\",\n" - + " \"type\": \"UNKNOWN\",\n" - + " \"individual\": {\n" - + " \"name\": {\n" - + " \"firstName\": \"Jane\",\n" - + " \"lastName\": \"Doe\"\n" - + " },\n" - + " \"residentialAddress\": {\n" - + " \"country\": \"NL\",\n" - + " \"city\": \"Amsterdam\"\n" - + " }\n" - + " },\n" - + " \"capabilities\": {\n" - + " \"issueCard\": {\n" - + " \"allowed\": true,\n" - + " \"requested\": true\n" - + " }\n" - + " }\n" - + "}"; - - LegalEntity legalEntity = LegalEntity.fromJson(json); - - assertNotNull(legalEntity); - assertEquals("LE3227C223222B5BPCMFXD2XG", legalEntity.getId()); - assertEquals("YOUR_REFERENCE_12345", legalEntity.getReference()); - // type is null since enum value is invalid - assertNull(legalEntity.getType()); - } - - @Test - public void testToJsonLegalEntity() throws JsonProcessingException { - LegalEntity legalEntity = - new LegalEntity() - .reference("YOUR_REFERENCE_12345") - .type(LegalEntity.TypeEnum.INDIVIDUAL) - .individual( - new Individual() - .name(new Name().firstName("Jane").lastName("Doe")) - .residentialAddress(new Address().country("NL").city("Amsterdam"))) - .putCapabilitiesItem( - "issueCard", - new LegalEntityCapability() - .allowedSettings( - new CapabilitySettings() - .addFundingSourceItem(CapabilitySettings.FundingSourceEnum.CREDIT))); - - String deserialized = legalEntity.toJson(); - - String expected = - "{\"capabilities\":{\"issueCard\":{\"allowedSettings\":{\"fundingSource\":[\"credit\"]}}},\"individual\":{\"name\":{\"firstName\":\"Jane\",\"lastName\":\"Doe\"},\"residentialAddress\":{\"city\":\"Amsterdam\",\"country\":\"NL\"}},\"reference\":\"YOUR_REFERENCE_12345\",\"type\":\"individual\"}"; - - assertEquals(expected, deserialized); - } - - @Test - public void testFromJsonCreateCheckoutSessionResponse() throws JsonProcessingException { - String json = - "{\n" - + " \"amount\": {\n" - + " \"currency\": \"EUR\",\n" - + " \"value\": 1000\n" - + " },\n" - + " \"countryCode\": \"NL\",\n" - + " \"expiresAt\": \"2022-01-11T13:53:18+01:00\",\n" - + " \"id\": \"CS451F2AB1ED897A94\",\n" - + " \"merchantAccount\": \"YOUR_MERCHANT_ACCOUNT\",\n" - + " \"reference\": \"YOUR_PAYMENT_REFERENCE\",\n" - + " \"url\": \"https://checkout-test.adyen.com/checkout/sessions/CS_1234567890ABCDEF\",\n" - + " \"sessionData\": \"Ab02b4c0!BQABAgBfYI29...\"\n" - + "}"; - - CreateCheckoutSessionResponse response = CreateCheckoutSessionResponse.fromJson(json); - - assertNotNull(response); - assertEquals("CS451F2AB1ED897A94", response.getId()); - assertEquals("YOUR_PAYMENT_REFERENCE", response.getReference()); - assertEquals( - "https://checkout-test.adyen.com/checkout/sessions/CS_1234567890ABCDEF", response.getUrl()); - - assertNotNull(response.getAmount()); - assertEquals("EUR", response.getAmount().getCurrency()); - assertEquals(1000L, response.getAmount().getValue().longValue()); - - assertEquals("2022-01-11T13:53:18+01:00", response.getExpiresAt().toString()); - assertEquals(2022, response.getExpiresAt().getYear()); - assertEquals(Month.JANUARY, response.getExpiresAt().getMonth()); - assertEquals(ZoneId.of("+01:00"), response.getExpiresAt().toZonedDateTime().getZone()); - } + @Test + public void testFromJsonLegalEntity() throws JsonProcessingException { + String json = + "{\n" + + " \"id\": \"LE3227C223222B5BPCMFXD2XG\",\n" + + " \"reference\": \"YOUR_REFERENCE_12345\",\n" + + " \"type\": \"individual\",\n" + + " \"individual\": {\n" + + " \"name\": {\n" + + " \"firstName\": \"Jane\",\n" + + " \"lastName\": \"Doe\"\n" + + " },\n" + + " \"residentialAddress\": {\n" + + " \"country\": \"NL\",\n" + + " \"city\": \"Amsterdam\"\n" + + " }\n" + + " },\n" + + " \"capabilities\": {\n" + + " \"issueCard\": {\n" + + " \"allowed\": true,\n" + + " \"requested\": true\n" + + " }\n" + + " }\n" + + "}"; + + LegalEntity legalEntity = LegalEntity.fromJson(json); + + assertNotNull(legalEntity); + assertEquals("LE3227C223222B5BPCMFXD2XG", legalEntity.getId()); + assertEquals("YOUR_REFERENCE_12345", legalEntity.getReference()); + + assertEquals(LegalEntity.TypeEnum.INDIVIDUAL, legalEntity.getType()); + assertNotNull(legalEntity.getIndividual()); + + assertNotNull(legalEntity.getCapabilities()); + assertTrue(legalEntity.getCapabilities().containsKey("issueCard")); + assertNotNull(legalEntity.getCapabilities().get("issueCard")); + } + + @Test + public void testFromJsonLegalEntityWithInvalidEnum() throws JsonProcessingException { + String json = + "{\n" + + " \"id\": \"LE3227C223222B5BPCMFXD2XG\",\n" + + " \"reference\": \"YOUR_REFERENCE_12345\",\n" + + " \"type\": \"UNKNOWN\",\n" + + " \"individual\": {\n" + + " \"name\": {\n" + + " \"firstName\": \"Jane\",\n" + + " \"lastName\": \"Doe\"\n" + + " },\n" + + " \"residentialAddress\": {\n" + + " \"country\": \"NL\",\n" + + " \"city\": \"Amsterdam\"\n" + + " }\n" + + " },\n" + + " \"capabilities\": {\n" + + " \"issueCard\": {\n" + + " \"allowed\": true,\n" + + " \"requested\": true\n" + + " }\n" + + " }\n" + + "}"; + + LegalEntity legalEntity = LegalEntity.fromJson(json); + + assertNotNull(legalEntity); + assertEquals("LE3227C223222B5BPCMFXD2XG", legalEntity.getId()); + assertEquals("YOUR_REFERENCE_12345", legalEntity.getReference()); + // type is null since enum value is invalid + assertNull(legalEntity.getType()); + } + + @Test + public void testToJsonLegalEntity() throws JsonProcessingException { + LegalEntity legalEntity = + new LegalEntity() + .reference("YOUR_REFERENCE_12345") + .type(LegalEntity.TypeEnum.INDIVIDUAL) + .individual( + new Individual() + .name(new Name().firstName("Jane").lastName("Doe")) + .residentialAddress(new Address().country("NL").city("Amsterdam"))) + .putCapabilitiesItem( + "issueCard", + new LegalEntityCapability() + .allowedSettings( + new CapabilitySettings() + .addFundingSourceItem(CapabilitySettings.FundingSourceEnum.CREDIT))); + + String deserialized = legalEntity.toJson(); + + String expected = + "{\"capabilities\":{\"issueCard\":{\"allowedSettings\":{\"fundingSource\":[\"credit\"]}}},\"individual\":{\"name\":{\"firstName\":\"Jane\",\"lastName\":\"Doe\"},\"residentialAddress\":{\"city\":\"Amsterdam\",\"country\":\"NL\"}},\"reference\":\"YOUR_REFERENCE_12345\",\"type\":\"individual\"}"; + + assertEquals(expected, deserialized); + } + + @Test + public void testFromJsonCreateCheckoutSessionResponse() throws JsonProcessingException { + String json = + "{\n" + + " \"amount\": {\n" + + " \"currency\": \"EUR\",\n" + + " \"value\": 1000\n" + + " },\n" + + " \"countryCode\": \"NL\",\n" + + " \"expiresAt\": \"2022-01-11T13:53:18+01:00\",\n" + + " \"id\": \"CS451F2AB1ED897A94\",\n" + + " \"merchantAccount\": \"YOUR_MERCHANT_ACCOUNT\",\n" + + " \"reference\": \"YOUR_PAYMENT_REFERENCE\",\n" + + " \"url\": \"https://checkout-test.adyen.com/checkout/sessions/CS_1234567890ABCDEF\",\n" + + " \"sessionData\": \"Ab02b4c0!BQABAgBfYI29...\"\n" + + "}"; + + CreateCheckoutSessionResponse response = CreateCheckoutSessionResponse.fromJson(json); + + assertNotNull(response); + assertEquals("CS451F2AB1ED897A94", response.getId()); + assertEquals("YOUR_PAYMENT_REFERENCE", response.getReference()); + assertEquals( + "https://checkout-test.adyen.com/checkout/sessions/CS_1234567890ABCDEF", response.getUrl()); + + assertNotNull(response.getAmount()); + assertEquals("EUR", response.getAmount().getCurrency()); + assertEquals(1000L, response.getAmount().getValue().longValue()); + + assertEquals("2022-01-11T13:53:18+01:00", response.getExpiresAt().toString()); + assertEquals(2022, response.getExpiresAt().getYear()); + assertEquals(Month.JANUARY, response.getExpiresAt().getMonth()); + assertEquals(ZoneId.of("+01:00"), response.getExpiresAt().toZonedDateTime().getZone()); + } + + @Test + public void testFromJsonCheckoutPaymentMethodBcmc() throws Exception { + String json = + "{\n" + + " \"type\": \"bcmc\",\n" + + " \"holderName\": \"Ms Smith\",\n" + + " \"encryptedCardNumber\": \"...\",\n" + + " \"encryptedExpiryMonth\": \"...\",\n" + + " \"encryptedExpiryYear\": \"...\",\n" + + " \"brand\": \"bcmc\",\n" + + " \"checkoutAttemptId\": \"...\"\n" + + "}"; + + CheckoutPaymentMethod paymentMethod = CheckoutPaymentMethod.fromJson(json); + + assertNotNull(paymentMethod); + + CardDetails cardDetails = paymentMethod.getCardDetails(); + assertNotNull(cardDetails); + + assertEquals(CardDetails.TypeEnum.BCMC, cardDetails.getType()); + assertEquals("bcmc", cardDetails.getBrand()); + assertEquals("Ms Smith", cardDetails.getHolderName()); + } + + @Test + public void testFromJsonCheckoutPaymentMethodBcmcMobile() throws Exception { + String json = + "{\n" + + " \"type\":\"bcmc_mobile\",\n" + + " \"storedPaymentMethodId\":\"7219687191761347\"\n" + + "}"; + + CheckoutPaymentMethod paymentMethod = CheckoutPaymentMethod.fromJson(json); + assertNotNull(paymentMethod); + + StoredPaymentMethodDetails storedPaymentMethodDetails = paymentMethod.getStoredPaymentMethodDetails(); + assertNotNull(storedPaymentMethodDetails); + + assertEquals(StoredPaymentMethodDetails.TypeEnum.BCMC_MOBILE, storedPaymentMethodDetails.getType()); + assertEquals("7219687191761347", storedPaymentMethodDetails.getStoredPaymentMethodId()); + } } From cd0a9e08745e540de8882fd518f1e6e1d7e63a02 Mon Sep 17 00:00:00 2001 From: gcatanese Date: Fri, 8 Aug 2025 16:42:38 +0200 Subject: [PATCH 3/7] Add test resources --- .../mocks/checkout/paymentResponseBcmc.json | 14 ++++++++++++++ .../mocks/checkout/paymentResponseBcmcMobile.json | 10 ++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/test/resources/mocks/checkout/paymentResponseBcmc.json create mode 100644 src/test/resources/mocks/checkout/paymentResponseBcmcMobile.json diff --git a/src/test/resources/mocks/checkout/paymentResponseBcmc.json b/src/test/resources/mocks/checkout/paymentResponseBcmc.json new file mode 100644 index 000000000..3b14a2cd2 --- /dev/null +++ b/src/test/resources/mocks/checkout/paymentResponseBcmc.json @@ -0,0 +1,14 @@ +{ + "resultCode": "RedirectShopper", + "action": { + "paymentMethodType": "bccm", + "url": "https://your-company.example.com/checkout?shopperOrder=12xy..", + "data": { + "MD": "OEVudmZVMUlkWjd0MDNwUWs2bmhSdz09...", + "PaReq": "eNpVUttygjAQ/RXbDyAXBYRZ00HpTH3wUosPfe...", + "TermUrl": "https://example.com/checkout?shopperOrder=12xy..." + }, + "method": "POST", + "type": "redirect" + } +} \ No newline at end of file diff --git a/src/test/resources/mocks/checkout/paymentResponseBcmcMobile.json b/src/test/resources/mocks/checkout/paymentResponseBcmcMobile.json new file mode 100644 index 000000000..cb92d1364 --- /dev/null +++ b/src/test/resources/mocks/checkout/paymentResponseBcmcMobile.json @@ -0,0 +1,10 @@ +{ + "resultCode": "Pending", + "action": { + "paymentData": "Ab02b4c0!BQABAgCpM2q6...==", + "paymentMethodType": "bcmc_mobile", + "url": "BEPGenApp://DoTx?TransId=1bcmc-test.adyen.com/pal/bep$P5FOT6N55HYZNXVPFDGIHEJC", + "qrCodeData": "BEP://1bcmc-test.adyen.com/pal/test", + "type": "qrCode" + } +} \ No newline at end of file From 5cc8329f4ba47964c3fdab644362fae5b891bcef Mon Sep 17 00:00:00 2001 From: gcatanese Date: Fri, 8 Aug 2025 16:43:05 +0200 Subject: [PATCH 4/7] Code formatting --- src/test/java/com/adyen/CheckoutTest.java | 33 +- .../java/com/adyen/serializer/ModelTest.java | 358 +++++++++--------- 2 files changed, 192 insertions(+), 199 deletions(-) diff --git a/src/test/java/com/adyen/CheckoutTest.java b/src/test/java/com/adyen/CheckoutTest.java index 0d10ccb65..c0cc356b2 100644 --- a/src/test/java/com/adyen/CheckoutTest.java +++ b/src/test/java/com/adyen/CheckoutTest.java @@ -673,19 +673,17 @@ public void TestBccm() throws Exception { PaymentRequest paymentRequest = new PaymentRequest(); paymentRequest.setMerchantAccount("YOUR_MERCHANT_ACCOUNT"); paymentRequest.setReference("YOUR_ORDER_NUMBER"); - paymentRequest.setAmount(new Amount() - .currency("EUR") - .value(1000L)); - paymentRequest.setPaymentMethod(new CheckoutPaymentMethod( + paymentRequest.setAmount(new Amount().currency("EUR").value(1000L)); + paymentRequest.setPaymentMethod( + new CheckoutPaymentMethod( new CardDetails() - .type(CardDetails.TypeEnum.BCMC) - .holderName("Ms Smith") - .encryptedCardNumber("...") - .encryptedExpiryMonth("...") - .encryptedExpiryYear("...") - .brand("bcmc") - .checkoutAttemptId("...") - )); + .type(CardDetails.TypeEnum.BCMC) + .holderName("Ms Smith") + .encryptedCardNumber("...") + .encryptedExpiryMonth("...") + .encryptedExpiryYear("...") + .brand("bcmc") + .checkoutAttemptId("..."))); PaymentsApi checkout = new PaymentsApi(client); PaymentResponse paymentResponse = checkout.payments(paymentRequest); assertEquals(PaymentResponse.ResultCodeEnum.REDIRECTSHOPPER, paymentResponse.getResultCode()); @@ -699,17 +697,14 @@ public void TestBccmMobile() throws Exception { PaymentRequest paymentRequest = new PaymentRequest(); paymentRequest.setMerchantAccount("YOUR_MERCHANT_ACCOUNT"); paymentRequest.setReference("YOUR_ORDER_NUMBER"); - paymentRequest.setAmount(new Amount() - .currency("EUR") - .value(1000L)); - paymentRequest.setPaymentMethod(new CheckoutPaymentMethod( + paymentRequest.setAmount(new Amount().currency("EUR").value(1000L)); + paymentRequest.setPaymentMethod( + new CheckoutPaymentMethod( new StoredPaymentMethodDetails() - .type(StoredPaymentMethodDetails.TypeEnum.BCMC_MOBILE) - )); + .type(StoredPaymentMethodDetails.TypeEnum.BCMC_MOBILE))); PaymentsApi checkout = new PaymentsApi(client); PaymentResponse paymentResponse = checkout.payments(paymentRequest); assertEquals(PaymentResponse.ResultCodeEnum.PENDING, paymentResponse.getResultCode()); assertNotNull(paymentResponse.getAction()); } - } diff --git a/src/test/java/com/adyen/serializer/ModelTest.java b/src/test/java/com/adyen/serializer/ModelTest.java index 2128b338f..d6b342fda 100644 --- a/src/test/java/com/adyen/serializer/ModelTest.java +++ b/src/test/java/com/adyen/serializer/ModelTest.java @@ -11,190 +11,188 @@ import com.adyen.model.checkout.StoredPaymentMethodDetails; import com.adyen.model.legalentitymanagement.*; import com.fasterxml.jackson.core.JsonProcessingException; - import java.time.Month; import java.time.ZoneId; - import org.junit.Test; -/** - * Test model serialization (toJson) and deserialization (fromJson) - */ +/** Test model serialization (toJson) and deserialization (fromJson) */ public class ModelTest { - @Test - public void testFromJsonLegalEntity() throws JsonProcessingException { - String json = - "{\n" - + " \"id\": \"LE3227C223222B5BPCMFXD2XG\",\n" - + " \"reference\": \"YOUR_REFERENCE_12345\",\n" - + " \"type\": \"individual\",\n" - + " \"individual\": {\n" - + " \"name\": {\n" - + " \"firstName\": \"Jane\",\n" - + " \"lastName\": \"Doe\"\n" - + " },\n" - + " \"residentialAddress\": {\n" - + " \"country\": \"NL\",\n" - + " \"city\": \"Amsterdam\"\n" - + " }\n" - + " },\n" - + " \"capabilities\": {\n" - + " \"issueCard\": {\n" - + " \"allowed\": true,\n" - + " \"requested\": true\n" - + " }\n" - + " }\n" - + "}"; - - LegalEntity legalEntity = LegalEntity.fromJson(json); - - assertNotNull(legalEntity); - assertEquals("LE3227C223222B5BPCMFXD2XG", legalEntity.getId()); - assertEquals("YOUR_REFERENCE_12345", legalEntity.getReference()); - - assertEquals(LegalEntity.TypeEnum.INDIVIDUAL, legalEntity.getType()); - assertNotNull(legalEntity.getIndividual()); - - assertNotNull(legalEntity.getCapabilities()); - assertTrue(legalEntity.getCapabilities().containsKey("issueCard")); - assertNotNull(legalEntity.getCapabilities().get("issueCard")); - } - - @Test - public void testFromJsonLegalEntityWithInvalidEnum() throws JsonProcessingException { - String json = - "{\n" - + " \"id\": \"LE3227C223222B5BPCMFXD2XG\",\n" - + " \"reference\": \"YOUR_REFERENCE_12345\",\n" - + " \"type\": \"UNKNOWN\",\n" - + " \"individual\": {\n" - + " \"name\": {\n" - + " \"firstName\": \"Jane\",\n" - + " \"lastName\": \"Doe\"\n" - + " },\n" - + " \"residentialAddress\": {\n" - + " \"country\": \"NL\",\n" - + " \"city\": \"Amsterdam\"\n" - + " }\n" - + " },\n" - + " \"capabilities\": {\n" - + " \"issueCard\": {\n" - + " \"allowed\": true,\n" - + " \"requested\": true\n" - + " }\n" - + " }\n" - + "}"; - - LegalEntity legalEntity = LegalEntity.fromJson(json); - - assertNotNull(legalEntity); - assertEquals("LE3227C223222B5BPCMFXD2XG", legalEntity.getId()); - assertEquals("YOUR_REFERENCE_12345", legalEntity.getReference()); - // type is null since enum value is invalid - assertNull(legalEntity.getType()); - } - - @Test - public void testToJsonLegalEntity() throws JsonProcessingException { - LegalEntity legalEntity = - new LegalEntity() - .reference("YOUR_REFERENCE_12345") - .type(LegalEntity.TypeEnum.INDIVIDUAL) - .individual( - new Individual() - .name(new Name().firstName("Jane").lastName("Doe")) - .residentialAddress(new Address().country("NL").city("Amsterdam"))) - .putCapabilitiesItem( - "issueCard", - new LegalEntityCapability() - .allowedSettings( - new CapabilitySettings() - .addFundingSourceItem(CapabilitySettings.FundingSourceEnum.CREDIT))); - - String deserialized = legalEntity.toJson(); - - String expected = - "{\"capabilities\":{\"issueCard\":{\"allowedSettings\":{\"fundingSource\":[\"credit\"]}}},\"individual\":{\"name\":{\"firstName\":\"Jane\",\"lastName\":\"Doe\"},\"residentialAddress\":{\"city\":\"Amsterdam\",\"country\":\"NL\"}},\"reference\":\"YOUR_REFERENCE_12345\",\"type\":\"individual\"}"; - - assertEquals(expected, deserialized); - } - - @Test - public void testFromJsonCreateCheckoutSessionResponse() throws JsonProcessingException { - String json = - "{\n" - + " \"amount\": {\n" - + " \"currency\": \"EUR\",\n" - + " \"value\": 1000\n" - + " },\n" - + " \"countryCode\": \"NL\",\n" - + " \"expiresAt\": \"2022-01-11T13:53:18+01:00\",\n" - + " \"id\": \"CS451F2AB1ED897A94\",\n" - + " \"merchantAccount\": \"YOUR_MERCHANT_ACCOUNT\",\n" - + " \"reference\": \"YOUR_PAYMENT_REFERENCE\",\n" - + " \"url\": \"https://checkout-test.adyen.com/checkout/sessions/CS_1234567890ABCDEF\",\n" - + " \"sessionData\": \"Ab02b4c0!BQABAgBfYI29...\"\n" - + "}"; - - CreateCheckoutSessionResponse response = CreateCheckoutSessionResponse.fromJson(json); - - assertNotNull(response); - assertEquals("CS451F2AB1ED897A94", response.getId()); - assertEquals("YOUR_PAYMENT_REFERENCE", response.getReference()); - assertEquals( - "https://checkout-test.adyen.com/checkout/sessions/CS_1234567890ABCDEF", response.getUrl()); - - assertNotNull(response.getAmount()); - assertEquals("EUR", response.getAmount().getCurrency()); - assertEquals(1000L, response.getAmount().getValue().longValue()); - - assertEquals("2022-01-11T13:53:18+01:00", response.getExpiresAt().toString()); - assertEquals(2022, response.getExpiresAt().getYear()); - assertEquals(Month.JANUARY, response.getExpiresAt().getMonth()); - assertEquals(ZoneId.of("+01:00"), response.getExpiresAt().toZonedDateTime().getZone()); - } - - @Test - public void testFromJsonCheckoutPaymentMethodBcmc() throws Exception { - String json = - "{\n" - + " \"type\": \"bcmc\",\n" - + " \"holderName\": \"Ms Smith\",\n" - + " \"encryptedCardNumber\": \"...\",\n" - + " \"encryptedExpiryMonth\": \"...\",\n" - + " \"encryptedExpiryYear\": \"...\",\n" - + " \"brand\": \"bcmc\",\n" - + " \"checkoutAttemptId\": \"...\"\n" - + "}"; - - CheckoutPaymentMethod paymentMethod = CheckoutPaymentMethod.fromJson(json); - - assertNotNull(paymentMethod); - - CardDetails cardDetails = paymentMethod.getCardDetails(); - assertNotNull(cardDetails); - - assertEquals(CardDetails.TypeEnum.BCMC, cardDetails.getType()); - assertEquals("bcmc", cardDetails.getBrand()); - assertEquals("Ms Smith", cardDetails.getHolderName()); - } - - @Test - public void testFromJsonCheckoutPaymentMethodBcmcMobile() throws Exception { - String json = - "{\n" + - " \"type\":\"bcmc_mobile\",\n" + - " \"storedPaymentMethodId\":\"7219687191761347\"\n" + - "}"; - - CheckoutPaymentMethod paymentMethod = CheckoutPaymentMethod.fromJson(json); - assertNotNull(paymentMethod); - - StoredPaymentMethodDetails storedPaymentMethodDetails = paymentMethod.getStoredPaymentMethodDetails(); - assertNotNull(storedPaymentMethodDetails); - - assertEquals(StoredPaymentMethodDetails.TypeEnum.BCMC_MOBILE, storedPaymentMethodDetails.getType()); - assertEquals("7219687191761347", storedPaymentMethodDetails.getStoredPaymentMethodId()); - } + @Test + public void testFromJsonLegalEntity() throws JsonProcessingException { + String json = + "{\n" + + " \"id\": \"LE3227C223222B5BPCMFXD2XG\",\n" + + " \"reference\": \"YOUR_REFERENCE_12345\",\n" + + " \"type\": \"individual\",\n" + + " \"individual\": {\n" + + " \"name\": {\n" + + " \"firstName\": \"Jane\",\n" + + " \"lastName\": \"Doe\"\n" + + " },\n" + + " \"residentialAddress\": {\n" + + " \"country\": \"NL\",\n" + + " \"city\": \"Amsterdam\"\n" + + " }\n" + + " },\n" + + " \"capabilities\": {\n" + + " \"issueCard\": {\n" + + " \"allowed\": true,\n" + + " \"requested\": true\n" + + " }\n" + + " }\n" + + "}"; + + LegalEntity legalEntity = LegalEntity.fromJson(json); + + assertNotNull(legalEntity); + assertEquals("LE3227C223222B5BPCMFXD2XG", legalEntity.getId()); + assertEquals("YOUR_REFERENCE_12345", legalEntity.getReference()); + + assertEquals(LegalEntity.TypeEnum.INDIVIDUAL, legalEntity.getType()); + assertNotNull(legalEntity.getIndividual()); + + assertNotNull(legalEntity.getCapabilities()); + assertTrue(legalEntity.getCapabilities().containsKey("issueCard")); + assertNotNull(legalEntity.getCapabilities().get("issueCard")); + } + + @Test + public void testFromJsonLegalEntityWithInvalidEnum() throws JsonProcessingException { + String json = + "{\n" + + " \"id\": \"LE3227C223222B5BPCMFXD2XG\",\n" + + " \"reference\": \"YOUR_REFERENCE_12345\",\n" + + " \"type\": \"UNKNOWN\",\n" + + " \"individual\": {\n" + + " \"name\": {\n" + + " \"firstName\": \"Jane\",\n" + + " \"lastName\": \"Doe\"\n" + + " },\n" + + " \"residentialAddress\": {\n" + + " \"country\": \"NL\",\n" + + " \"city\": \"Amsterdam\"\n" + + " }\n" + + " },\n" + + " \"capabilities\": {\n" + + " \"issueCard\": {\n" + + " \"allowed\": true,\n" + + " \"requested\": true\n" + + " }\n" + + " }\n" + + "}"; + + LegalEntity legalEntity = LegalEntity.fromJson(json); + + assertNotNull(legalEntity); + assertEquals("LE3227C223222B5BPCMFXD2XG", legalEntity.getId()); + assertEquals("YOUR_REFERENCE_12345", legalEntity.getReference()); + // type is null since enum value is invalid + assertNull(legalEntity.getType()); + } + + @Test + public void testToJsonLegalEntity() throws JsonProcessingException { + LegalEntity legalEntity = + new LegalEntity() + .reference("YOUR_REFERENCE_12345") + .type(LegalEntity.TypeEnum.INDIVIDUAL) + .individual( + new Individual() + .name(new Name().firstName("Jane").lastName("Doe")) + .residentialAddress(new Address().country("NL").city("Amsterdam"))) + .putCapabilitiesItem( + "issueCard", + new LegalEntityCapability() + .allowedSettings( + new CapabilitySettings() + .addFundingSourceItem(CapabilitySettings.FundingSourceEnum.CREDIT))); + + String deserialized = legalEntity.toJson(); + + String expected = + "{\"capabilities\":{\"issueCard\":{\"allowedSettings\":{\"fundingSource\":[\"credit\"]}}},\"individual\":{\"name\":{\"firstName\":\"Jane\",\"lastName\":\"Doe\"},\"residentialAddress\":{\"city\":\"Amsterdam\",\"country\":\"NL\"}},\"reference\":\"YOUR_REFERENCE_12345\",\"type\":\"individual\"}"; + + assertEquals(expected, deserialized); + } + + @Test + public void testFromJsonCreateCheckoutSessionResponse() throws JsonProcessingException { + String json = + "{\n" + + " \"amount\": {\n" + + " \"currency\": \"EUR\",\n" + + " \"value\": 1000\n" + + " },\n" + + " \"countryCode\": \"NL\",\n" + + " \"expiresAt\": \"2022-01-11T13:53:18+01:00\",\n" + + " \"id\": \"CS451F2AB1ED897A94\",\n" + + " \"merchantAccount\": \"YOUR_MERCHANT_ACCOUNT\",\n" + + " \"reference\": \"YOUR_PAYMENT_REFERENCE\",\n" + + " \"url\": \"https://checkout-test.adyen.com/checkout/sessions/CS_1234567890ABCDEF\",\n" + + " \"sessionData\": \"Ab02b4c0!BQABAgBfYI29...\"\n" + + "}"; + + CreateCheckoutSessionResponse response = CreateCheckoutSessionResponse.fromJson(json); + + assertNotNull(response); + assertEquals("CS451F2AB1ED897A94", response.getId()); + assertEquals("YOUR_PAYMENT_REFERENCE", response.getReference()); + assertEquals( + "https://checkout-test.adyen.com/checkout/sessions/CS_1234567890ABCDEF", response.getUrl()); + + assertNotNull(response.getAmount()); + assertEquals("EUR", response.getAmount().getCurrency()); + assertEquals(1000L, response.getAmount().getValue().longValue()); + + assertEquals("2022-01-11T13:53:18+01:00", response.getExpiresAt().toString()); + assertEquals(2022, response.getExpiresAt().getYear()); + assertEquals(Month.JANUARY, response.getExpiresAt().getMonth()); + assertEquals(ZoneId.of("+01:00"), response.getExpiresAt().toZonedDateTime().getZone()); + } + + @Test + public void testFromJsonCheckoutPaymentMethodBcmc() throws Exception { + String json = + "{\n" + + " \"type\": \"bcmc\",\n" + + " \"holderName\": \"Ms Smith\",\n" + + " \"encryptedCardNumber\": \"...\",\n" + + " \"encryptedExpiryMonth\": \"...\",\n" + + " \"encryptedExpiryYear\": \"...\",\n" + + " \"brand\": \"bcmc\",\n" + + " \"checkoutAttemptId\": \"...\"\n" + + "}"; + + CheckoutPaymentMethod paymentMethod = CheckoutPaymentMethod.fromJson(json); + + assertNotNull(paymentMethod); + + CardDetails cardDetails = paymentMethod.getCardDetails(); + assertNotNull(cardDetails); + + assertEquals(CardDetails.TypeEnum.BCMC, cardDetails.getType()); + assertEquals("bcmc", cardDetails.getBrand()); + assertEquals("Ms Smith", cardDetails.getHolderName()); + } + + @Test + public void testFromJsonCheckoutPaymentMethodBcmcMobile() throws Exception { + String json = + "{\n" + + " \"type\":\"bcmc_mobile\",\n" + + " \"storedPaymentMethodId\":\"7219687191761347\"\n" + + "}"; + + CheckoutPaymentMethod paymentMethod = CheckoutPaymentMethod.fromJson(json); + assertNotNull(paymentMethod); + + StoredPaymentMethodDetails storedPaymentMethodDetails = + paymentMethod.getStoredPaymentMethodDetails(); + assertNotNull(storedPaymentMethodDetails); + + assertEquals( + StoredPaymentMethodDetails.TypeEnum.BCMC_MOBILE, storedPaymentMethodDetails.getType()); + assertEquals("7219687191761347", storedPaymentMethodDetails.getStoredPaymentMethodId()); + } } From fe38cdde136b5eddfd80c4836981012dba2783d5 Mon Sep 17 00:00:00 2001 From: gcatanese Date: Mon, 11 Aug 2025 12:57:20 +0200 Subject: [PATCH 5/7] Remove unused variable --- src/test/java/com/adyen/CheckoutTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/com/adyen/CheckoutTest.java b/src/test/java/com/adyen/CheckoutTest.java index c0cc356b2..ad5902903 100644 --- a/src/test/java/com/adyen/CheckoutTest.java +++ b/src/test/java/com/adyen/CheckoutTest.java @@ -693,7 +693,6 @@ public void TestBccm() throws Exception { @Test public void TestBccmMobile() throws Exception { Client client = createMockClientFromFile("mocks/checkout/paymentResponseBcmcMobile.json"); - Amount amount = new Amount().currency("EUR").value(1000L); PaymentRequest paymentRequest = new PaymentRequest(); paymentRequest.setMerchantAccount("YOUR_MERCHANT_ACCOUNT"); paymentRequest.setReference("YOUR_ORDER_NUMBER"); From b222a680963937f4784163339f6d52a1546e721d Mon Sep 17 00:00:00 2001 From: gcatanese Date: Mon, 11 Aug 2025 12:57:51 +0200 Subject: [PATCH 6/7] Remove unused variable --- src/test/java/com/adyen/CheckoutTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/com/adyen/CheckoutTest.java b/src/test/java/com/adyen/CheckoutTest.java index ad5902903..504cde2cb 100644 --- a/src/test/java/com/adyen/CheckoutTest.java +++ b/src/test/java/com/adyen/CheckoutTest.java @@ -669,7 +669,6 @@ public void TestSessionsCheckDefaultValues() throws Exception { @Test public void TestBccm() throws Exception { Client client = createMockClientFromFile("mocks/checkout/paymentResponseBcmc.json"); - Amount amount = new Amount().currency("EUR").value(1000L); PaymentRequest paymentRequest = new PaymentRequest(); paymentRequest.setMerchantAccount("YOUR_MERCHANT_ACCOUNT"); paymentRequest.setReference("YOUR_ORDER_NUMBER"); From d5753f287a7bcd6bc694388d11913e4f09b21a38 Mon Sep 17 00:00:00 2001 From: Beppe Catanese <1771700+gcatanese@users.noreply.github.com> Date: Mon, 18 Aug 2025 16:50:52 +0200 Subject: [PATCH 7/7] Add missing bracket --- src/test/java/com/adyen/CheckoutTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/adyen/CheckoutTest.java b/src/test/java/com/adyen/CheckoutTest.java index 2fe0c15ce..a02dc9b1c 100644 --- a/src/test/java/com/adyen/CheckoutTest.java +++ b/src/test/java/com/adyen/CheckoutTest.java @@ -704,7 +704,8 @@ public void TestBccmMobile() throws Exception { PaymentResponse paymentResponse = checkout.payments(paymentRequest); assertEquals(PaymentResponse.ResultCodeEnum.PENDING, paymentResponse.getResultCode()); assertNotNull(paymentResponse.getAction()); - + } + @Test public void testPixActionQrCode() throws Exception { Client client = createMockClientFromFile("mocks/checkout/pixQrCodeResponse.json");