diff --git a/src/test/java/com/adyen/TransfersTest.java b/src/test/java/com/adyen/TransfersTest.java index b8a663163..f7280f8c7 100644 --- a/src/test/java/com/adyen/TransfersTest.java +++ b/src/test/java/com/adyen/TransfersTest.java @@ -118,6 +118,72 @@ public void getTransferTest() throws Exception { assertEquals(UKFpsTracingData.TypeEnum.UKFPS, eventTracing.getType()); } + /** + * Verifies that a transfer response for an issued card reversal is fully deserialized: the + * transfer status, the card category data (including the network variant), the network reason of + * the reversal, and the reversal event with its modification. + */ + @Test + public void getTransferReversalTest() throws Exception { + Client client = createMockClientFromFile("mocks/transfers/get-transfer-reversal.json"); + + TransfersApi transfers = new TransfersApi(client); + TransferData response = transfers.getTransfer("1W1UG35QQEBJLHZ8"); + + assertEquals(TransferData.StatusEnum.REVERSALRECEIVED, response.getStatus()); + assertEquals(TransferData.CategoryEnum.ISSUEDCARD, response.getCategory()); + + assertNotNull(response.getNetworkReason()); + assertEquals( + NetworkReason.NamespaceEnum.USACHCORRECTIONREASONCODE, + response.getNetworkReason().getNamespace()); + assertEquals("C01", response.getNetworkReason().getCode()); + + IssuedCard issuedCard = response.getCategoryData().getIssuedCard(); + assertEquals(IssuedCard.NetworkVariantEnum.MAESTRO_US, issuedCard.getNetworkVariant()); + + TransferEvent reversalEvent = + response.getEvents().stream() + .filter(event -> event.getStatus() == TransferEvent.StatusEnum.REVERSALRECEIVED) + .findFirst() + .orElseThrow(); + assertNotNull(reversalEvent.getModification()); + assertEquals( + Modification.StatusEnum.REVERSALRECEIVED, reversalEvent.getModification().getStatus()); + } + + /** + * Verifies the wire-value mapping of transfers enums and their forward compatibility: known + * values deserialize to the matching enum constant, while values not yet known to this library + * deserialize to null instead of throwing an exception. + */ + @Test + public void transfersEnumDeserializationTest() { + assertNull(IssuedCard.NetworkVariantEnum.fromValue("some_future_network")); + assertEquals("maestro_us", IssuedCard.NetworkVariantEnum.MAESTRO_US.getValue()); + assertEquals( + IssuedCard.NetworkVariantEnum.VISA, IssuedCard.NetworkVariantEnum.fromValue("visa")); + assertEquals( + NetworkReason.NamespaceEnum.USACHCORRECTIONREASONCODE, + NetworkReason.NamespaceEnum.fromValue("usAchCorrectionReasonCode")); + assertEquals( + TransferData.StatusEnum.REVERSALRECEIVED, + TransferData.StatusEnum.fromValue("reversalReceived")); + assertEquals( + TransferData.TypeEnum.BALANCEMIGRATION, + TransferData.TypeEnum.fromValue("balanceMigration")); + assertEquals(TransferData.TypeEnum.FXSELL, TransferData.TypeEnum.fromValue("fxSell")); + assertEquals(TransferData.TypeEnum.FXBUY, TransferData.TypeEnum.fromValue("fxBuy")); + assertEquals( + Transfer.StatusEnum.REVERSALRECEIVED, Transfer.StatusEnum.fromValue("reversalReceived")); + assertEquals( + TransferEvent.StatusEnum.REVERSALRECEIVED, + TransferEvent.StatusEnum.fromValue("reversalReceived")); + assertEquals( + Modification.StatusEnum.REVERSALRECEIVED, + Modification.StatusEnum.fromValue("reversalReceived")); + } + @Test public void transferTest() throws Exception { Client client = diff --git a/src/test/resources/mocks/transfers/get-transfer-reversal.json b/src/test/resources/mocks/transfers/get-transfer-reversal.json new file mode 100644 index 000000000..16f5ee5e3 --- /dev/null +++ b/src/test/resources/mocks/transfers/get-transfer-reversal.json @@ -0,0 +1,81 @@ +{ + "balancePlatform": "YOUR_BALANCE_PLATFORM", + "creationDate": "2021-05-03T15:20:06+02:00", + "id": "1W1UG35QQEBJLHZ8", + "accountHolder": { + "description": "S. Eller - Staff 123", + "id": "AH32272223222B5CZW6QZ2V34" + }, + "amount": { + "currency": "USD", + "value": 5400 + }, + "balanceAccount": { + "description": "My Balance Account", + "id": "BA3227C223222B5B9SCR82TMV" + }, + "category": "issuedCard", + "categoryData": { + "type": "issuedCard", + "authorisationType": "pos", + "networkVariant": "maestro_us", + "panEntryMode": "chip", + "processingType": "pos" + }, + "description": "Card authorisation reversal", + "direction": "outgoing", + "reason": "approved", + "reference": "312M2060T6S4UOIF", + "status": "reversalReceived", + "networkReason": { + "code": "C01", + "description": "Incorrect DFI account number", + "namespace": "usAchCorrectionReasonCode" + }, + "balances": [ + { + "balance": 0, + "currency": "USD", + "received": 0, + "reserved": 0 + } + ], + "events": [ + { + "bookingDate": "2021-05-03T14:53:39+01:00", + "id": "EVJN4233Q22322375JQ72V55G92ZXF", + "mutations": [ + { + "currency": "USD", + "received": -5400 + } + ], + "status": "received", + "type": "accounting", + "valueDate": "2021-05-03T14:53:39+01:00" + }, + { + "bookingDate": "2021-05-04T09:12:00+01:00", + "id": "EVJN4233Q22322375JQ72V55GB4TPV", + "modification": { + "id": "MOD1234567890", + "reference": "mock-modification-reference", + "status": "reversalReceived", + "type": "reversal", + "direction": "incoming" + }, + "mutations": [ + { + "currency": "USD", + "received": 5400, + "reserved": -5400 + } + ], + "status": "reversalReceived", + "type": "accounting", + "valueDate": "2021-05-04T09:12:00+01:00" + } + ], + "sequenceNumber": 3, + "type": "cardTransfer" +}