From cc66607a85985457657e353080c72447f37f5879 Mon Sep 17 00:00:00 2001 From: w112739 Date: Thu, 20 Jan 2022 17:09:21 +0100 Subject: [PATCH 01/15] [WIP] Add Wallet API and refactor common code - factorize common code in sdk-common - remove sdk-payment common No javadoc yet --- .../sips/util/SealCalculatorTest.java | 114 ---------- payment-sdk/build.gradle | 2 +- .../com/worldline/sips/api/PaypageClient.java | 194 ----------------- .../IncorrectProxyConfException.java | 8 - .../api/exception/IncorrectSealException.java | 8 - .../InvalidEnvironmentException.java | 8 - .../api/exception/InvalidKeyException.java | 8 - .../exception/InvalidMerchantException.java | 8 - .../PaymentEnvironment.java} | 8 +- .../PaymentInitializationException.java | 2 +- .../sips/helper/ResponseDataDeserializer.java | 0 .../helper/RuleResultListDeserializer.java | 0 .../sips/model/AcquirerResponseCode.java | 0 .../com/worldline/sips/model/Address.java | 0 .../com/worldline/sips/model/CaptureMode.java | 0 .../sips/model/CardCSCResultCode.java | 0 .../com/worldline/sips/model/Contact.java | 0 .../com/worldline/sips/model/Currency.java | 0 .../worldline/sips/model/CustomerAddress.java | 0 .../worldline/sips/model/CustomerContact.java | 0 .../sips/model/GuaranteeIndicator.java | 0 .../sips/model/HolderAuthentMethod.java | 0 .../sips/model/HolderAuthentProgram.java | 0 .../sips/model/HolderAuthentStatus.java | 0 .../com/worldline/sips/model/Language.java | 0 .../worldline/sips/model/OrderChannel.java | 0 .../worldline/sips/model/PanEntryMode.java | 0 .../worldline/sips/model/PaymentMeanType.java | 0 .../worldline/sips/model/PaymentPattern.java | 0 .../com/worldline/sips/model/PaypageData.java | 0 .../sips/model/RedirectionStatusCode.java | 0 .../worldline/sips/model/ResponseCode.java | 0 .../worldline/sips/model/ResponseData.java | 0 .../com/worldline/sips/model/RuleCode.java | 0 .../com/worldline/sips/model/RuleResult.java | 0 .../sips/model/RuleResultIndicator.java | 0 .../com/worldline/sips/model/RuleSetting.java | 0 .../com/worldline/sips/model/RuleType.java | 0 .../com/worldline/sips/model/ScoreColor.java | 0 .../com/worldline/sips/model/WalletType.java | 0 .../sips/model/request}/PaymentRequest.java | 36 ++-- .../response}/InitializationResponse.java | 21 +- .../sips/model/response}/PaypageResponse.java | 18 +- .../worldline/sips/api/PaypageClientTest.java | 28 +-- .../sips/api/SealCalculatorTest.java | 122 +++++++++++ .../build.gradle | 1 + .../java/com/worldline/sips/SIPS2Request.java | 68 ++++++ .../com/worldline/sips/SIPS2Response.java | 29 +++ .../java/com/worldline/sips/SipsClient.java | 201 ++++++++++++++++++ .../sips/configuration/Configuration.java | 0 .../IncorrectProxyConfException.java | 8 + .../exception/IncorrectSealException.java | 8 + .../InvalidEnvironmentException.java | 8 + .../sips/exception/InvalidKeyException.java | 8 + .../exception/InvalidMerchantException.java | 9 + .../exception/SealCalculationException.java | 0 .../sips/exception/SipsException.java | 8 + .../sips/exception/SipsRequestException.java | 8 + .../exception/UnknownStatusException.java | 0 .../UnsupportedCurrencyException.java | 0 .../UnsupportedLanguageException.java | 0 .../helper/AlphabeticalFieldComparator.java | 0 ...AlphabeticalReflectionToStringBuilder.java | 0 .../sips/helper/BooleanDeserializer.java | 0 .../sips/helper/SealStringStyle.java | 0 .../SortedReflectionToStringBuilder.java | 0 .../sips/model/PaymentMeanBrand.java | 0 .../worldline/sips/model/SipsEnvironment.java | 5 + .../sips/security}/SealCalculator.java | 28 +-- .../com/worldline/sips/security/Sealable.java | 7 + .../sips/util/ObjectMapperHolder.java | 0 settings.gradle | 3 + wallet-sdk/build.gradle | 6 + .../com/worldline/sips/api/WalletRequest.java | 10 + .../worldline/sips/api/WalletResponse.java | 8 + .../sips/api/WalletResponseCode.java | 61 ++++++ .../api/configuration/OfficeEnvironment.java | 26 +++ .../sips/api/model/data/PaymentMeanData.java | 29 +++ .../api/model/data/WalletPaymentMeanData.java | 16 ++ .../model/request/GetWalletDataRequest.java | 32 +++ .../model/response/GetWalletDataResponse.java | 16 ++ .../worldline/sips/utils/SipsClientTest.java | 24 +++ 82 files changed, 799 insertions(+), 413 deletions(-) delete mode 100644 payment-sdk-common/src/test/java/com/worldline/sips/util/SealCalculatorTest.java delete mode 100644 payment-sdk/src/main/java/com/worldline/sips/api/PaypageClient.java delete mode 100644 payment-sdk/src/main/java/com/worldline/sips/api/exception/IncorrectProxyConfException.java delete mode 100644 payment-sdk/src/main/java/com/worldline/sips/api/exception/IncorrectSealException.java delete mode 100644 payment-sdk/src/main/java/com/worldline/sips/api/exception/InvalidEnvironmentException.java delete mode 100644 payment-sdk/src/main/java/com/worldline/sips/api/exception/InvalidKeyException.java delete mode 100644 payment-sdk/src/main/java/com/worldline/sips/api/exception/InvalidMerchantException.java rename payment-sdk/src/main/java/com/worldline/sips/{api/configuration/Environment.java => configuration/PaymentEnvironment.java} (70%) rename payment-sdk/src/main/java/com/worldline/sips/{api => }/exception/PaymentInitializationException.java (81%) rename {payment-sdk-common => payment-sdk}/src/main/java/com/worldline/sips/helper/ResponseDataDeserializer.java (100%) rename {payment-sdk-common => payment-sdk}/src/main/java/com/worldline/sips/helper/RuleResultListDeserializer.java (100%) rename {payment-sdk-common => payment-sdk}/src/main/java/com/worldline/sips/model/AcquirerResponseCode.java (100%) rename {payment-sdk-common => payment-sdk}/src/main/java/com/worldline/sips/model/Address.java (100%) rename {payment-sdk-common => payment-sdk}/src/main/java/com/worldline/sips/model/CaptureMode.java (100%) rename {payment-sdk-common => payment-sdk}/src/main/java/com/worldline/sips/model/CardCSCResultCode.java (100%) rename {payment-sdk-common => payment-sdk}/src/main/java/com/worldline/sips/model/Contact.java (100%) rename {payment-sdk-common => payment-sdk}/src/main/java/com/worldline/sips/model/Currency.java (100%) rename {payment-sdk-common => payment-sdk}/src/main/java/com/worldline/sips/model/CustomerAddress.java (100%) rename {payment-sdk-common => payment-sdk}/src/main/java/com/worldline/sips/model/CustomerContact.java (100%) rename {payment-sdk-common => payment-sdk}/src/main/java/com/worldline/sips/model/GuaranteeIndicator.java (100%) rename {payment-sdk-common => payment-sdk}/src/main/java/com/worldline/sips/model/HolderAuthentMethod.java (100%) rename {payment-sdk-common => payment-sdk}/src/main/java/com/worldline/sips/model/HolderAuthentProgram.java (100%) rename {payment-sdk-common => payment-sdk}/src/main/java/com/worldline/sips/model/HolderAuthentStatus.java (100%) rename {payment-sdk-common => payment-sdk}/src/main/java/com/worldline/sips/model/Language.java (100%) rename {payment-sdk-common => payment-sdk}/src/main/java/com/worldline/sips/model/OrderChannel.java (100%) rename {payment-sdk-common => payment-sdk}/src/main/java/com/worldline/sips/model/PanEntryMode.java (100%) rename {payment-sdk-common => payment-sdk}/src/main/java/com/worldline/sips/model/PaymentMeanType.java (100%) rename {payment-sdk-common => payment-sdk}/src/main/java/com/worldline/sips/model/PaymentPattern.java (100%) rename {payment-sdk-common => payment-sdk}/src/main/java/com/worldline/sips/model/PaypageData.java (100%) rename {payment-sdk-common => payment-sdk}/src/main/java/com/worldline/sips/model/RedirectionStatusCode.java (100%) rename {payment-sdk-common => payment-sdk}/src/main/java/com/worldline/sips/model/ResponseCode.java (100%) rename {payment-sdk-common => payment-sdk}/src/main/java/com/worldline/sips/model/ResponseData.java (100%) rename {payment-sdk-common => payment-sdk}/src/main/java/com/worldline/sips/model/RuleCode.java (100%) rename {payment-sdk-common => payment-sdk}/src/main/java/com/worldline/sips/model/RuleResult.java (100%) rename {payment-sdk-common => payment-sdk}/src/main/java/com/worldline/sips/model/RuleResultIndicator.java (100%) rename {payment-sdk-common => payment-sdk}/src/main/java/com/worldline/sips/model/RuleSetting.java (100%) rename {payment-sdk-common => payment-sdk}/src/main/java/com/worldline/sips/model/RuleType.java (100%) rename {payment-sdk-common => payment-sdk}/src/main/java/com/worldline/sips/model/ScoreColor.java (100%) rename {payment-sdk-common => payment-sdk}/src/main/java/com/worldline/sips/model/WalletType.java (100%) rename {payment-sdk-common/src/main/java/com/worldline/sips/model => payment-sdk/src/main/java/com/worldline/sips/model/request}/PaymentRequest.java (90%) rename {payment-sdk-common/src/main/java/com/worldline/sips/model => payment-sdk/src/main/java/com/worldline/sips/model/response}/InitializationResponse.java (73%) rename {payment-sdk-common/src/main/java/com/worldline/sips/model => payment-sdk/src/main/java/com/worldline/sips/model/response}/PaypageResponse.java (82%) create mode 100644 payment-sdk/src/test/java/com/worldline/sips/api/SealCalculatorTest.java rename {payment-sdk-common => sdk-common}/build.gradle (79%) create mode 100644 sdk-common/src/main/java/com/worldline/sips/SIPS2Request.java create mode 100644 sdk-common/src/main/java/com/worldline/sips/SIPS2Response.java create mode 100644 sdk-common/src/main/java/com/worldline/sips/SipsClient.java rename {payment-sdk-common => sdk-common}/src/main/java/com/worldline/sips/configuration/Configuration.java (100%) create mode 100644 sdk-common/src/main/java/com/worldline/sips/exception/IncorrectProxyConfException.java create mode 100644 sdk-common/src/main/java/com/worldline/sips/exception/IncorrectSealException.java create mode 100644 sdk-common/src/main/java/com/worldline/sips/exception/InvalidEnvironmentException.java create mode 100644 sdk-common/src/main/java/com/worldline/sips/exception/InvalidKeyException.java create mode 100644 sdk-common/src/main/java/com/worldline/sips/exception/InvalidMerchantException.java rename {payment-sdk-common => sdk-common}/src/main/java/com/worldline/sips/exception/SealCalculationException.java (100%) create mode 100644 sdk-common/src/main/java/com/worldline/sips/exception/SipsException.java create mode 100644 sdk-common/src/main/java/com/worldline/sips/exception/SipsRequestException.java rename {payment-sdk-common => sdk-common}/src/main/java/com/worldline/sips/exception/UnknownStatusException.java (100%) rename {payment-sdk-common => sdk-common}/src/main/java/com/worldline/sips/exception/UnsupportedCurrencyException.java (100%) rename {payment-sdk-common => sdk-common}/src/main/java/com/worldline/sips/exception/UnsupportedLanguageException.java (100%) rename {payment-sdk-common => sdk-common}/src/main/java/com/worldline/sips/helper/AlphabeticalFieldComparator.java (100%) rename {payment-sdk-common => sdk-common}/src/main/java/com/worldline/sips/helper/AlphabeticalReflectionToStringBuilder.java (100%) rename {payment-sdk-common => sdk-common}/src/main/java/com/worldline/sips/helper/BooleanDeserializer.java (100%) rename {payment-sdk-common => sdk-common}/src/main/java/com/worldline/sips/helper/SealStringStyle.java (100%) rename {payment-sdk-common => sdk-common}/src/main/java/com/worldline/sips/helper/SortedReflectionToStringBuilder.java (100%) rename {payment-sdk-common => sdk-common}/src/main/java/com/worldline/sips/model/PaymentMeanBrand.java (100%) create mode 100644 sdk-common/src/main/java/com/worldline/sips/model/SipsEnvironment.java rename {payment-sdk-common/src/main/java/com/worldline/sips/util => sdk-common/src/main/java/com/worldline/sips/security}/SealCalculator.java (67%) create mode 100644 sdk-common/src/main/java/com/worldline/sips/security/Sealable.java rename {payment-sdk-common => sdk-common}/src/main/java/com/worldline/sips/util/ObjectMapperHolder.java (100%) create mode 100644 wallet-sdk/build.gradle create mode 100644 wallet-sdk/src/main/java/com/worldline/sips/api/WalletRequest.java create mode 100644 wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponse.java create mode 100644 wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponseCode.java create mode 100644 wallet-sdk/src/main/java/com/worldline/sips/api/configuration/OfficeEnvironment.java create mode 100644 wallet-sdk/src/main/java/com/worldline/sips/api/model/data/PaymentMeanData.java create mode 100644 wallet-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java create mode 100644 wallet-sdk/src/main/java/com/worldline/sips/api/model/request/GetWalletDataRequest.java create mode 100644 wallet-sdk/src/main/java/com/worldline/sips/api/model/response/GetWalletDataResponse.java create mode 100644 wallet-sdk/src/test/java/com/worldline/sips/utils/SipsClientTest.java diff --git a/payment-sdk-common/src/test/java/com/worldline/sips/util/SealCalculatorTest.java b/payment-sdk-common/src/test/java/com/worldline/sips/util/SealCalculatorTest.java deleted file mode 100644 index 8797290..0000000 --- a/payment-sdk-common/src/test/java/com/worldline/sips/util/SealCalculatorTest.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.worldline.sips.util; - -import com.worldline.sips.exception.SealCalculationException; -import com.worldline.sips.model.*; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.net.MalformedURLException; -import java.net.URL; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - -class SealCalculatorTest { - - private static final String ENCODED_REQUEST_SEAL = "198e5f278e3f8548e174e84492953c4871732278b7e2aa2cbf20bb1ab85914ea"; - private static final String ENCODED_RESPONSE_SEAL = "dd6eb8dd6c951b1ddc1af121007aaabe8ad4fda1d15ce386cfa455821d602025"; - private static final String DEMO_KEY = "superSafeSecretKey"; - private static final String RESPONSE_DEMO_KEY = "002001000000002_KEY1"; - private PaymentRequest paymentRequest; - - @BeforeEach - void setUp() throws Exception { - paymentRequest = new PaymentRequest(); - paymentRequest.setAmount(10); - paymentRequest.setCustomerId("customerId"); - paymentRequest.setAutomaticResponseUrl(new URL("http://test.com")); - paymentRequest.setTemplateName("customCSS.css"); - } - - @Test - void getSealString() { - String actual = SealCalculator.getSealString(paymentRequest); - String expected = "10http://test.comcustomerIdIR_WS_2.19customCSS.css"; - assertEquals(expected, actual, "Sealstring is incorrect!"); - } - - @Test - void getSealString_with_Currency() { - paymentRequest.setCurrencyCode(Currency.EUR); - String actual = SealCalculator.getSealString(paymentRequest); - String expected = "10http://test.com978customerIdIR_WS_2.19customCSS.css"; - assertEquals(expected, actual, "Sealstring is incorrect!"); - } - - @Test - void getSealString_with_list() { - paymentRequest.getPaymentMeanBrandList().add(PaymentMeanBrand.VISA); - paymentRequest.getPaymentMeanBrandList().add(PaymentMeanBrand.BCMC); - String actual = SealCalculator.getSealString(paymentRequest); - String expected = "10http://test.comcustomerIdIR_WS_2.19BCMCVISAcustomCSS.css"; - assertEquals(expected, actual, "Sealstring is incorrect!"); - } - - @Test - void getSealString_with_Container() { - Address deliveryAddress = new Address(); - deliveryAddress.setZipcode("deliveryZipcode"); - deliveryAddress.setCompany("deliveryCompany"); - paymentRequest.setDeliveryAddress(deliveryAddress); - - CustomerAddress customerAddress = new CustomerAddress(); - customerAddress.setCity("customerCity"); - customerAddress.setBusinessName("customerBusinessName"); - paymentRequest.setCustomerAddress(customerAddress); - - CustomerContact customerContact = new CustomerContact(); - customerContact.setFirstName("firstName"); - customerContact.setLastName("lastName"); - paymentRequest.setCustomerContact(customerContact); - - String actual = SealCalculator.getSealString(paymentRequest); - String expected = "10http://test.comcustomerBusinessNamecustomerCityfirstNamelastNamecustomerIddeliveryCompanydeliveryZipcodeIR_WS_2.19customCSS.css"; - assertEquals(expected, actual, "Sealstring is incorrect!"); - } - - @Test - void getSealString_with_ignoredField() { - paymentRequest.setKeyVersion(200); - String actual = SealCalculator.getSealString(paymentRequest); - String expected = "10http://test.comcustomerIdIR_WS_2.19customCSS.css"; - assertEquals(expected, actual, "Sealstring is incorrect!"); - } - - @Test - void calculate() throws SealCalculationException { - String actual = SealCalculator.calculate("This is a test!", DEMO_KEY); - assertEquals(ENCODED_REQUEST_SEAL, actual, "Encoded seal is incorrect!"); - } - - @Test - void calculate_with_null_string() { - assertThrows(NullPointerException.class, () -> SealCalculator.calculate(null, DEMO_KEY), "No exception is thrown when string to encode is null!"); - } - - @Test - void calculate_with_null_key() { - assertThrows(NullPointerException.class, () -> SealCalculator.calculate("This is a test!", null), "No exception is thrown when string to encode is null!"); - } - - @Test - void calculate_response_seal() throws MalformedURLException, SealCalculationException { - InitializationResponse initializationResponse = new InitializationResponse(); - initializationResponse.setRedirectionStatusCode(RedirectionStatusCode.TRANSACTION_INITIALIZED); - initializationResponse.setRedirectionStatusMessage("INITIALISATION REQUEST ACCEPTED"); - initializationResponse.setRedirectionVersion("IR_WS_2.0"); - initializationResponse.setRedirectionUrl(new URL("https://payment-web.simu.sips-services.com/payment")); - initializationResponse.setRedirectionData("FTEx33MrE9Nc0gvtIS0aydJngXH8uuirg3ZpFD_KRM22C9e3IFDdBdSZB3kdQwcyIjWhKpM9mHYTCaCCy7Vm0YWrLscP-TJ895c2GXsTKlwEkO_VEU-2j2VGVcbYAKE9kcoV6jnVU5OJE1AMXEXnm1AkMrm3riB35p7x-WUdnaU0oKIhsit2M4_mci3fWH9WNTqo-A07qPd9-5zRKCr2F91Z8R4HogmLYdx_xh6BOyXKp693Smrq-2H64A2BOC6n89JQT-e9GNBM_up1YMa-vvS3-b6bMoZ01ngO7n2-NttxvXn78XEDDDVQfYZGPrpjywvDhGTfhBun1mdbSfzGPOwd6dcLre4Nguht3JCsT27EyLOxGEjCDwMjKJ0Gb2toChEMRv7TtX2SlXGMuyUr24oToHGbdt6zOm3q1R7XnCqnVYT_YNnNPf6lppQCW81FVvdX5zfbW65tQzja0CFC2ss-kyT0v4owm8LLNMy2rEU2JYnQQrT2qhQYf8lGxL2qkC0S1TpPLRzK-ry3mkEcBgwxFKbB2DX4kRamx4n6v_Yke2PS1PUPoWbdruRkK1mDJAJhSorV4O3LeeM1B3LkuPNU2xZw__I55zaOyIy2sWz52Su6gapGcsw8qTNOhcOwQi1sYaSGviCfKF75zC-GCjbHGoyHfO5RBswwmqBMNbVc7l2FIAw8ZDwn18E07pDWNeMwaeWYrYhR_n1BfhaW03H5TojvjnEMMSfd11nab0PjFE5zWB3r--OadfE7m-NqHL70WKLPYNfvKdzXzoI3ejc3SmWycXMpJgENZAFVzy4MojbVby3prA4IXQ_xSEisoWoGJb1Kg2LxEUih9Jqpi9vinH_nqt29lHFKnWSIuhT8UdsBYvFRGYyrbxPOOz1eNBqvHO49eI2hpKeL280_eR4HmLPiiDASog3BgDFB2_Ed6upm_N1PUEdQ1xmwXkiL7fqnaFABXySxsTVhxyRgXGSAmA0gmeYwFf7bGIKUc-FPwqWewDxRnIfnz6Eh3qDG41xEr5URpc0LCzzo5XjFt5h7wmp3FftmSai4rCFIM6B4Jd9lljeXgAMayzfig77_S_JMtEDw6oqzbX6QpBsKnfnrAtxk26LL07qB5Yw9qj-NEbWf28GOPN9--xY5AeUbya5nyNQiT-3TyebxnjUysTrTuq1DptPflIrUuIwAewT6K1I-XRYDpgdTRwWFzTIi2kItzGcbozxMJi0S6eJnOQNb9zNSrUBysDlSGVct1UsHqYQO56_-uyAwZ7lv23WIZdgbUaGELoPsba8Jg9rzR-aZ0zEe9owORSbAh5qkk0ByvOQniLqGYn36AJbKiSrSjRG1n9vBjjzffvsWOQHlG_tPV6WPVaXvanjaHrg_v2tjtqWPCUCRFg6seM4KiZ3G5-WPkPX0LW19iu4ypazFsfgElIfF7--XuN2wnrbf5tvPxpk-EHACkcFUQ7ozBw5xjRG1n9vBjjzffvsWOQHlGzGBbU3BAx_KVN_SQuZCNZ66O6O6FdOnZF_dC9vfuhZx5livIUUGTQOiFt4JQv_tJ3gl32WWN5eAAxrLN-KDvv_z_69h-FQfvm0DChFKn5h9Jb54QR0qamngPqTNqRQxNcmK3onHxmG7IIS9Gsltfie7sc4Lt9p_hqLAC28DDefH03yQ0l15QSQSA7t8x3rtGuflj5D19C1tfYruMqWsxbF_OuasNvoqSnJcHI_HyMMnf7eGnYHEcQk4vutjrpZhcH1TRZ3nQYrrxzId10uYeGeB7NXgInfbYearASIu2_vnMuJj1F84sjXcMM29qxh5KvOAaCle_EK7_SCamPY6SzkmTCyJprTaIBkhUUjUDdem4rN_XaLIav0orq8E4IwU740RtZ_bwY483377FjkB5RsKKPYjzvh_RlAEOH7vo0AIf7eGnYHEcQk4vutjrpZhcI0RtZ_bwY483377FjkB5Rv07-b-FhxhFkrKQcO0J0LIaKn33u4Hp88PYNHX40sIyNK3sqPZPiYGDU7q6T76kxla1JZwz-5wSgABK-wV16UlA1v3M1KtQHKwOVIZVy3VSwephA7nr_67IDBnuW_bdYjqqqfJtu70VoEtZOvxckajWtSWcM_ucEoAASvsFdelJcaipDQGiSLyw4gWeiGVvJAJHG6sS8x21XuBIuCbQ8l9Orcf_-QEVEHjGdswxxpSUovuFIRWVkRniMqau0PF2uF2Vi5vBX5AQYvblDS0I-Nk5mOOxtF3rdTMKSdmHaylZGleYPX4zPU6HmEV4ipdMcHx_vB89SS_gwRtQ9PWLJh3HJwvIO2GJs6lrufoKpeHVk9jne_ybEoDL1qOawB6ESQK5q5UXSwdR3YaB8M0qw-UPPibFlDSsbVF-zNvfbA8IBQL83Jj6EwBHBwT0RHvrvQ9-0nLg03cckYVc3IJh-dMok6Z5Ga3fsi_953xGMoOX4_z-gTn5pXhDYgI-0g_CKeAtgLeNsxz-PlTwW_U_kfW6Q3V7HDgOi-QZxxNSTMSkQpAdC3JcbHIGuEHVGxs5zWWT5tmsYkXbS11VEduPVXb9NpuUzUB5GLL8W3y9w3hTgLI1bKcCSsF4b3mgLEwNNGbEzYudvCLn3MP8g5BKQ-GlMMZU93_ANjsgNXUNK3j0SHC1NaycxVaWqmVP9uWp1U"); - - String sealString = SealCalculator.getSealString(initializationResponse); - String actual = SealCalculator.calculate(sealString, RESPONSE_DEMO_KEY); - assertEquals(ENCODED_RESPONSE_SEAL, actual, "Encoded seal is incorrect!"); - } -} \ No newline at end of file diff --git a/payment-sdk/build.gradle b/payment-sdk/build.gradle index 20edc45..7491a6b 100644 --- a/payment-sdk/build.gradle +++ b/payment-sdk/build.gradle @@ -1,5 +1,5 @@ dependencies { - implementation project(':payment-sdk-common') + implementation project(':sdk-common') implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.0' implementation 'org.apache.commons:commons-lang3:3.12.0' implementation 'org.apache.httpcomponents.client5:httpclient5:5.1.2' diff --git a/payment-sdk/src/main/java/com/worldline/sips/api/PaypageClient.java b/payment-sdk/src/main/java/com/worldline/sips/api/PaypageClient.java deleted file mode 100644 index 6239ce6..0000000 --- a/payment-sdk/src/main/java/com/worldline/sips/api/PaypageClient.java +++ /dev/null @@ -1,194 +0,0 @@ -package com.worldline.sips.api; - -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.worldline.sips.api.configuration.Environment; -import com.worldline.sips.api.exception.*; -import com.worldline.sips.exception.SealCalculationException; -import com.worldline.sips.model.InitializationResponse; -import com.worldline.sips.model.PaymentRequest; -import com.worldline.sips.model.PaypageResponse; -import com.worldline.sips.util.ObjectMapperHolder; -import com.worldline.sips.util.SealCalculator; -import org.apache.commons.codec.digest.DigestUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.hc.client5.http.classic.methods.HttpPost; -import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; -import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; -import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; -import org.apache.hc.core5.http.ContentType; -import org.apache.hc.core5.http.HttpHost; -import org.apache.hc.core5.http.ParseException; -import org.apache.hc.core5.http.io.entity.EntityUtils; -import org.apache.hc.core5.http.io.entity.StringEntity; - -import java.io.IOException; -import java.net.URI; -import java.util.Map; - -/** - * Interact with the SIPS API in payment page mode. - */ -public class PaypageClient { - - private final Environment environment; - private final Integer keyVersion; - private final String merchantId; - private final String secretKey; - private final String proxyHost; - private final Integer proxyPort; - private final boolean proxyEnabled; - - /** - * Construct a new instance of the client for a given {@link Environment} - * - * @param environment the API environment to connect to. - * @param merchantId the merchant's ID. - * @param keyVersion the version of the secret key to use. - * @param secretKey the merchant's secret key. - * @throws IncorrectProxyConfException when the proxy configuration is incorrect - * @throws InvalidEnvironmentException when an unknown environment is specified - * @throws InvalidKeyException when the key version is null, or a key is blank, empty or null. - * @throws InvalidMerchantException when the key version is null, or a key is blank, empty or null. - */ - public PaypageClient(Environment environment, String merchantId, Integer keyVersion, String secretKey) - throws InvalidEnvironmentException, IncorrectProxyConfException, InvalidKeyException, InvalidMerchantException { - this(environment, merchantId, keyVersion, secretKey, false, null, null); - } - - public PaypageClient(Environment environment, String merchantId, Integer keyVersion, String secretKey, boolean proxyEnabled, String proxyHost, Integer proxyPort) - throws InvalidEnvironmentException, InvalidMerchantException, InvalidKeyException, IncorrectProxyConfException { - if (environment == null) { - throw new InvalidEnvironmentException("Invalid environment specified!"); - } - - if (StringUtils.isBlank(merchantId)) { - throw new InvalidMerchantException("Invalid merchant ID specified!"); - } - - if (keyVersion == null) { - throw new InvalidKeyException("Invalid key version specified!"); - } - - if (StringUtils.isBlank(secretKey)) { - throw new InvalidKeyException("Invalid key specified!"); - } - - if (proxyEnabled) { - if(StringUtils.isBlank(proxyHost) || proxyPort == null){ - throw new IncorrectProxyConfException("ProxyEnabled is true but proxyHost or proxyPort not filled"); - } - } - - this.environment = environment; - this.keyVersion = keyVersion; - this.merchantId = merchantId; - this.secretKey = secretKey; - this.proxyEnabled=proxyEnabled; - this.proxyHost=proxyHost; - this.proxyPort=proxyPort; - } - - /** - * Initialize a session with the SIPS API for given parameters. - * This is always the first step in a payment process. - * - * @param paymentRequest the parameters to use during the requested session. - * @return The API 's response for the preformed request. - * @throws IncorrectSealException when the response has been tampered with. - * @throws PaymentInitializationException when initialization fails due to processing exceptions, see inner exception for details. - * @throws SealCalculationException when seal calculation fails, see inner excpetion for details. - * @see PaymentRequest - * @see InitializationResponse - * @see #verifySeal(InitializationResponse) - */ - public InitializationResponse initialize(PaymentRequest paymentRequest) throws IncorrectSealException, PaymentInitializationException, SealCalculationException { - try { - HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); - if(this.proxyEnabled){ - HttpHost httpHost = new HttpHost(this.proxyHost, this.proxyPort); - httpClientBuilder.setProxy(httpHost); - } - CloseableHttpClient httpClient = httpClientBuilder.build(); - paymentRequest.setMerchantId(merchantId); - paymentRequest.setKeyVersion(keyVersion); - paymentRequest.setSeal(SealCalculator.calculate( - SealCalculator.getSealString(paymentRequest), secretKey)); - StringEntity requestEntity = new StringEntity( - ObjectMapperHolder.INSTANCE.get().writerFor(PaymentRequest.class) - .writeValueAsString(paymentRequest), - ContentType.APPLICATION_JSON); - - HttpPost postMethod = new HttpPost(getEnvironmentUrl()); - postMethod.setEntity(requestEntity); - - CloseableHttpResponse rawResponse = httpClient.execute(postMethod); - InitializationResponse initializationResponse = - ObjectMapperHolder.INSTANCE.get().readerFor(InitializationResponse.class) - .readValue(EntityUtils.toString(rawResponse.getEntity())); - - verifySeal(initializationResponse); - - return initializationResponse; - - } catch (JsonParseException | JsonMappingException e) { - throw new PaymentInitializationException("Exception while parsing PaymentRequest!", e); - } catch (IOException | ParseException e) { - throw new PaymentInitializationException("Exception while processing response from server!", e); - } - - } - - /** - * Decode a payment response for further processing. After the payment is made, the API will preform a - * POST request to the URL as defined in the {@link PaymentRequest}. - * - * @param parameters the content of the received request, mapped as key-value pairs. - * @return The API 's response for the preformed payment. - * @throws IncorrectSealException when the response has been tampered with. - * @see PaypageResponse - */ - public PaypageResponse decodeResponse(Map parameters) throws IncorrectSealException { - verifySeal(parameters.get("Data"), parameters.get("Seal")); - return ObjectMapperHolder.INSTANCE.get().copy() - .convertValue(parameters, PaypageResponse.class); - } - - private URI getEnvironmentUrl() { - return URI.create(environment.getUrl()); - } - - /** - * Verify the seal of an initialization response. To avoid tampered responses when a session is initialized, - * the seal for the received response should always be verified before returning the object to the user. - * - * @param initializationResponse the received response upon initialization - * @throws IncorrectSealException when the received seal is different from the one calculated - * @throws SealCalculationException when seal calculation fails, see inner excpetion for details. - */ - private void verifySeal(InitializationResponse initializationResponse) throws IncorrectSealException, SealCalculationException { - if (initializationResponse.getSeal() != null) { - String correctSeal = SealCalculator.calculate( - SealCalculator.getSealString(initializationResponse), secretKey); - if (!StringUtils.equals(correctSeal, initializationResponse.getSeal())) { - throw new IncorrectSealException("The initialization response has been tampered with!"); - } - } - } - - /** - * Verify the seal of a payment page response.To avoid tampered data for processed payments, - * the seal for the received response should always be verified before returning the object to the user. - * - * @param data the received response's Data attribute - * @param seal the received response's Seal attribute - * @throws IncorrectSealException when the received seal is different from the one calculated - */ - private void verifySeal(String data, String seal) throws IncorrectSealException { - String correctSeal = DigestUtils.sha256Hex(data + secretKey); - if (!StringUtils.equals(correctSeal, seal)) { - throw new IncorrectSealException("The payment page response has been tampered with!"); - } - } - -} diff --git a/payment-sdk/src/main/java/com/worldline/sips/api/exception/IncorrectProxyConfException.java b/payment-sdk/src/main/java/com/worldline/sips/api/exception/IncorrectProxyConfException.java deleted file mode 100644 index 80afc9e..0000000 --- a/payment-sdk/src/main/java/com/worldline/sips/api/exception/IncorrectProxyConfException.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.worldline.sips.api.exception; - -public class IncorrectProxyConfException extends Exception { - - public IncorrectProxyConfException(String message){ - super(message); - } -} diff --git a/payment-sdk/src/main/java/com/worldline/sips/api/exception/IncorrectSealException.java b/payment-sdk/src/main/java/com/worldline/sips/api/exception/IncorrectSealException.java deleted file mode 100644 index fdf5468..0000000 --- a/payment-sdk/src/main/java/com/worldline/sips/api/exception/IncorrectSealException.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.worldline.sips.api.exception; - -public class IncorrectSealException extends Exception { - - public IncorrectSealException(String message) { - super(message); - } -} diff --git a/payment-sdk/src/main/java/com/worldline/sips/api/exception/InvalidEnvironmentException.java b/payment-sdk/src/main/java/com/worldline/sips/api/exception/InvalidEnvironmentException.java deleted file mode 100644 index 9bf973e..0000000 --- a/payment-sdk/src/main/java/com/worldline/sips/api/exception/InvalidEnvironmentException.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.worldline.sips.api.exception; - -public class InvalidEnvironmentException extends Exception { - - public InvalidEnvironmentException(String message) { - super(message); - } -} diff --git a/payment-sdk/src/main/java/com/worldline/sips/api/exception/InvalidKeyException.java b/payment-sdk/src/main/java/com/worldline/sips/api/exception/InvalidKeyException.java deleted file mode 100644 index 62a1d03..0000000 --- a/payment-sdk/src/main/java/com/worldline/sips/api/exception/InvalidKeyException.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.worldline.sips.api.exception; - -public class InvalidKeyException extends Exception { - - public InvalidKeyException(String message) { - super(message); - } -} diff --git a/payment-sdk/src/main/java/com/worldline/sips/api/exception/InvalidMerchantException.java b/payment-sdk/src/main/java/com/worldline/sips/api/exception/InvalidMerchantException.java deleted file mode 100644 index 1d4bdf5..0000000 --- a/payment-sdk/src/main/java/com/worldline/sips/api/exception/InvalidMerchantException.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.worldline.sips.api.exception; - -public class InvalidMerchantException extends Exception { - - public InvalidMerchantException(String message) { - super(message); - } -} diff --git a/payment-sdk/src/main/java/com/worldline/sips/api/configuration/Environment.java b/payment-sdk/src/main/java/com/worldline/sips/configuration/PaymentEnvironment.java similarity index 70% rename from payment-sdk/src/main/java/com/worldline/sips/api/configuration/Environment.java rename to payment-sdk/src/main/java/com/worldline/sips/configuration/PaymentEnvironment.java index 774df0f..0f04f92 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/api/configuration/Environment.java +++ b/payment-sdk/src/main/java/com/worldline/sips/configuration/PaymentEnvironment.java @@ -1,16 +1,18 @@ -package com.worldline.sips.api.configuration; +package com.worldline.sips.configuration; + +import com.worldline.sips.model.SipsEnvironment; /** * The different environments available for the Worldline SIPS API. */ -public enum Environment { +public enum PaymentEnvironment implements SipsEnvironment { SIMU("https://payment-webinit.simu.sips-services.com/rs-services/v2/paymentInit"), TEST("https://payment-webinit.test.sips-services.com/rs-services/v2/paymentInit"), PROD("https://payment-webinit.sips-services.com/rs-services/v2/paymentInit"); private final String url; - Environment(String url) { + PaymentEnvironment(String url) { this.url = url; } diff --git a/payment-sdk/src/main/java/com/worldline/sips/api/exception/PaymentInitializationException.java b/payment-sdk/src/main/java/com/worldline/sips/exception/PaymentInitializationException.java similarity index 81% rename from payment-sdk/src/main/java/com/worldline/sips/api/exception/PaymentInitializationException.java rename to payment-sdk/src/main/java/com/worldline/sips/exception/PaymentInitializationException.java index 9a01bbe..e3027c3 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/api/exception/PaymentInitializationException.java +++ b/payment-sdk/src/main/java/com/worldline/sips/exception/PaymentInitializationException.java @@ -1,4 +1,4 @@ -package com.worldline.sips.api.exception; +package com.worldline.sips.exception; public class PaymentInitializationException extends Exception { public PaymentInitializationException(String message, Throwable cause) { diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/helper/ResponseDataDeserializer.java b/payment-sdk/src/main/java/com/worldline/sips/helper/ResponseDataDeserializer.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/helper/ResponseDataDeserializer.java rename to payment-sdk/src/main/java/com/worldline/sips/helper/ResponseDataDeserializer.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/helper/RuleResultListDeserializer.java b/payment-sdk/src/main/java/com/worldline/sips/helper/RuleResultListDeserializer.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/helper/RuleResultListDeserializer.java rename to payment-sdk/src/main/java/com/worldline/sips/helper/RuleResultListDeserializer.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/model/AcquirerResponseCode.java b/payment-sdk/src/main/java/com/worldline/sips/model/AcquirerResponseCode.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/model/AcquirerResponseCode.java rename to payment-sdk/src/main/java/com/worldline/sips/model/AcquirerResponseCode.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/model/Address.java b/payment-sdk/src/main/java/com/worldline/sips/model/Address.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/model/Address.java rename to payment-sdk/src/main/java/com/worldline/sips/model/Address.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/model/CaptureMode.java b/payment-sdk/src/main/java/com/worldline/sips/model/CaptureMode.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/model/CaptureMode.java rename to payment-sdk/src/main/java/com/worldline/sips/model/CaptureMode.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/model/CardCSCResultCode.java b/payment-sdk/src/main/java/com/worldline/sips/model/CardCSCResultCode.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/model/CardCSCResultCode.java rename to payment-sdk/src/main/java/com/worldline/sips/model/CardCSCResultCode.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/model/Contact.java b/payment-sdk/src/main/java/com/worldline/sips/model/Contact.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/model/Contact.java rename to payment-sdk/src/main/java/com/worldline/sips/model/Contact.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/model/Currency.java b/payment-sdk/src/main/java/com/worldline/sips/model/Currency.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/model/Currency.java rename to payment-sdk/src/main/java/com/worldline/sips/model/Currency.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/model/CustomerAddress.java b/payment-sdk/src/main/java/com/worldline/sips/model/CustomerAddress.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/model/CustomerAddress.java rename to payment-sdk/src/main/java/com/worldline/sips/model/CustomerAddress.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/model/CustomerContact.java b/payment-sdk/src/main/java/com/worldline/sips/model/CustomerContact.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/model/CustomerContact.java rename to payment-sdk/src/main/java/com/worldline/sips/model/CustomerContact.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/model/GuaranteeIndicator.java b/payment-sdk/src/main/java/com/worldline/sips/model/GuaranteeIndicator.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/model/GuaranteeIndicator.java rename to payment-sdk/src/main/java/com/worldline/sips/model/GuaranteeIndicator.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/model/HolderAuthentMethod.java b/payment-sdk/src/main/java/com/worldline/sips/model/HolderAuthentMethod.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/model/HolderAuthentMethod.java rename to payment-sdk/src/main/java/com/worldline/sips/model/HolderAuthentMethod.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/model/HolderAuthentProgram.java b/payment-sdk/src/main/java/com/worldline/sips/model/HolderAuthentProgram.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/model/HolderAuthentProgram.java rename to payment-sdk/src/main/java/com/worldline/sips/model/HolderAuthentProgram.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/model/HolderAuthentStatus.java b/payment-sdk/src/main/java/com/worldline/sips/model/HolderAuthentStatus.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/model/HolderAuthentStatus.java rename to payment-sdk/src/main/java/com/worldline/sips/model/HolderAuthentStatus.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/model/Language.java b/payment-sdk/src/main/java/com/worldline/sips/model/Language.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/model/Language.java rename to payment-sdk/src/main/java/com/worldline/sips/model/Language.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/model/OrderChannel.java b/payment-sdk/src/main/java/com/worldline/sips/model/OrderChannel.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/model/OrderChannel.java rename to payment-sdk/src/main/java/com/worldline/sips/model/OrderChannel.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/model/PanEntryMode.java b/payment-sdk/src/main/java/com/worldline/sips/model/PanEntryMode.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/model/PanEntryMode.java rename to payment-sdk/src/main/java/com/worldline/sips/model/PanEntryMode.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/model/PaymentMeanType.java b/payment-sdk/src/main/java/com/worldline/sips/model/PaymentMeanType.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/model/PaymentMeanType.java rename to payment-sdk/src/main/java/com/worldline/sips/model/PaymentMeanType.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/model/PaymentPattern.java b/payment-sdk/src/main/java/com/worldline/sips/model/PaymentPattern.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/model/PaymentPattern.java rename to payment-sdk/src/main/java/com/worldline/sips/model/PaymentPattern.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/model/PaypageData.java b/payment-sdk/src/main/java/com/worldline/sips/model/PaypageData.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/model/PaypageData.java rename to payment-sdk/src/main/java/com/worldline/sips/model/PaypageData.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/model/RedirectionStatusCode.java b/payment-sdk/src/main/java/com/worldline/sips/model/RedirectionStatusCode.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/model/RedirectionStatusCode.java rename to payment-sdk/src/main/java/com/worldline/sips/model/RedirectionStatusCode.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/model/ResponseCode.java b/payment-sdk/src/main/java/com/worldline/sips/model/ResponseCode.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/model/ResponseCode.java rename to payment-sdk/src/main/java/com/worldline/sips/model/ResponseCode.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/model/ResponseData.java b/payment-sdk/src/main/java/com/worldline/sips/model/ResponseData.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/model/ResponseData.java rename to payment-sdk/src/main/java/com/worldline/sips/model/ResponseData.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/model/RuleCode.java b/payment-sdk/src/main/java/com/worldline/sips/model/RuleCode.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/model/RuleCode.java rename to payment-sdk/src/main/java/com/worldline/sips/model/RuleCode.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/model/RuleResult.java b/payment-sdk/src/main/java/com/worldline/sips/model/RuleResult.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/model/RuleResult.java rename to payment-sdk/src/main/java/com/worldline/sips/model/RuleResult.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/model/RuleResultIndicator.java b/payment-sdk/src/main/java/com/worldline/sips/model/RuleResultIndicator.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/model/RuleResultIndicator.java rename to payment-sdk/src/main/java/com/worldline/sips/model/RuleResultIndicator.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/model/RuleSetting.java b/payment-sdk/src/main/java/com/worldline/sips/model/RuleSetting.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/model/RuleSetting.java rename to payment-sdk/src/main/java/com/worldline/sips/model/RuleSetting.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/model/RuleType.java b/payment-sdk/src/main/java/com/worldline/sips/model/RuleType.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/model/RuleType.java rename to payment-sdk/src/main/java/com/worldline/sips/model/RuleType.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/model/ScoreColor.java b/payment-sdk/src/main/java/com/worldline/sips/model/ScoreColor.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/model/ScoreColor.java rename to payment-sdk/src/main/java/com/worldline/sips/model/ScoreColor.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/model/WalletType.java b/payment-sdk/src/main/java/com/worldline/sips/model/WalletType.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/model/WalletType.java rename to payment-sdk/src/main/java/com/worldline/sips/model/WalletType.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/model/PaymentRequest.java b/payment-sdk/src/main/java/com/worldline/sips/model/request/PaymentRequest.java similarity index 90% rename from payment-sdk-common/src/main/java/com/worldline/sips/model/PaymentRequest.java rename to payment-sdk/src/main/java/com/worldline/sips/model/request/PaymentRequest.java index d0b5b17..2f79ea8 100644 --- a/payment-sdk-common/src/main/java/com/worldline/sips/model/PaymentRequest.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/request/PaymentRequest.java @@ -1,10 +1,22 @@ -package com.worldline.sips.model; +package com.worldline.sips.model.request; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.worldline.sips.SIPS2Request; import com.worldline.sips.configuration.Configuration; +import com.worldline.sips.model.Address; +import com.worldline.sips.model.CaptureMode; +import com.worldline.sips.model.Contact; +import com.worldline.sips.model.Currency; +import com.worldline.sips.model.CustomerAddress; +import com.worldline.sips.model.CustomerContact; +import com.worldline.sips.model.Language; +import com.worldline.sips.model.OrderChannel; +import com.worldline.sips.model.PaymentMeanBrand; +import com.worldline.sips.model.PaypageData; +import com.worldline.sips.model.response.InitializationResponse; import java.net.URL; import java.util.TreeSet; @@ -16,7 +28,7 @@ */ @JsonPropertyOrder(alphabetic = true) @JsonInclude(JsonInclude.Include.NON_EMPTY) -public class PaymentRequest { +public class PaymentRequest extends SIPS2Request { private static final String INTERFACE_VERSION = Configuration.INTERFACE_VERSION; private final TreeSet paymentMeanBrandList = new TreeSet<>(); @@ -49,12 +61,15 @@ public class PaymentRequest { private String returnContext; private String transactionOrigin; private String transactionReference; - private String seal; private String statementReference; private String templateName; private PaypageData paypageData; - public Integer getAmount() { + public PaymentRequest() { + super(""); + } + + public Integer getAmount() { return amount; } @@ -287,14 +302,6 @@ public void setTransactionReference(String transactionReference) { this.transactionReference = transactionReference; } - public String getSeal() { - return seal; - } - - public void setSeal(String seal) { - this.seal = seal; - } - public String getStatementReference() { return statementReference; } @@ -318,4 +325,9 @@ public PaypageData getPaypageData() { public void setPaypageData(PaypageData paypageData) { this.paypageData = paypageData; } + + @Override + public Class getResponseType() { + return InitializationResponse.class; + } } diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/model/InitializationResponse.java b/payment-sdk/src/main/java/com/worldline/sips/model/response/InitializationResponse.java similarity index 73% rename from payment-sdk-common/src/main/java/com/worldline/sips/model/InitializationResponse.java rename to payment-sdk/src/main/java/com/worldline/sips/model/response/InitializationResponse.java index 4d05df2..45dff92 100644 --- a/payment-sdk-common/src/main/java/com/worldline/sips/model/InitializationResponse.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/response/InitializationResponse.java @@ -1,11 +1,14 @@ -package com.worldline.sips.model; +package com.worldline.sips.model.response; +import com.worldline.sips.SIPS2Response; +import com.worldline.sips.model.RedirectionStatusCode; +import com.worldline.sips.model.ResponseCode; import java.net.URL; /** * The server's response to a session initialization request. */ -public class InitializationResponse { +public class InitializationResponse extends SIPS2Response { private String errorFieldName; private String redirectionData; private RedirectionStatusCode redirectionStatusCode; @@ -13,7 +16,6 @@ public class InitializationResponse { private URL redirectionUrl; private String redirectionVersion; private ResponseCode responseCode; - private String seal; public String getErrorFieldName() { return errorFieldName; @@ -71,11 +73,10 @@ public void setResponseCode(ResponseCode responseCode) { this.responseCode = responseCode; } - public String getSeal() { - return seal; - } - - public void setSeal(String seal) { - this.seal = seal; - } + @Override + public String toString() { + return String.format( + "InitializationResponse{errorFieldName='%s', redirectionData='%s', redirectionStatusCode=%s, redirectionStatusMessage='%s', redirectionUrl=%s, redirectionVersion='%s', responseCode=%s, seal='%s'}", + errorFieldName, redirectionData, redirectionStatusCode, redirectionStatusMessage, redirectionUrl, redirectionVersion, responseCode, getSeal()); + } } diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/model/PaypageResponse.java b/payment-sdk/src/main/java/com/worldline/sips/model/response/PaypageResponse.java similarity index 82% rename from payment-sdk-common/src/main/java/com/worldline/sips/model/PaypageResponse.java rename to payment-sdk/src/main/java/com/worldline/sips/model/response/PaypageResponse.java index f4d1da4..e5767e3 100644 --- a/payment-sdk-common/src/main/java/com/worldline/sips/model/PaypageResponse.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/response/PaypageResponse.java @@ -1,16 +1,18 @@ -package com.worldline.sips.model; +package com.worldline.sips.model.response; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonUnwrapped; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.worldline.sips.SIPS2Response; import com.worldline.sips.helper.ResponseDataDeserializer; +import com.worldline.sips.model.ResponseData; /** * The result of payment made via the SIPS payment page. */ @JsonIgnoreProperties(ignoreUnknown = true) -public class PaypageResponse { +public class PaypageResponse extends SIPS2Response { @JsonProperty("Data") @JsonUnwrapped @@ -20,8 +22,8 @@ public class PaypageResponse { private String encode; @JsonProperty("InterfaceVersion") private String interFaceVersion; - @JsonProperty("Seal") - private String seal; +// @JsonProperty("Seal") +// private String seal; public ResponseData getData() { return data; @@ -46,12 +48,4 @@ public String getInterFaceVersion() { public void setInterFaceVersion(String interFaceVersion) { this.interFaceVersion = interFaceVersion; } - - public String getSeal() { - return seal; - } - - public void setSeal(String seal) { - this.seal = seal; - } } diff --git a/payment-sdk/src/test/java/com/worldline/sips/api/PaypageClientTest.java b/payment-sdk/src/test/java/com/worldline/sips/api/PaypageClientTest.java index f3a6e73..b28cafb 100644 --- a/payment-sdk/src/test/java/com/worldline/sips/api/PaypageClientTest.java +++ b/payment-sdk/src/test/java/com/worldline/sips/api/PaypageClientTest.java @@ -1,8 +1,12 @@ package com.worldline.sips.api; -import com.worldline.sips.api.configuration.Environment; -import com.worldline.sips.api.exception.IncorrectProxyConfException; +import com.worldline.sips.SipsClient; +import com.worldline.sips.configuration.PaymentEnvironment; +import com.worldline.sips.exception.IncorrectProxyConfException; import com.worldline.sips.model.*; +import com.worldline.sips.model.request.PaymentRequest; +import com.worldline.sips.model.response.InitializationResponse; +import com.worldline.sips.model.response.PaypageResponse; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -16,13 +20,13 @@ import static org.junit.jupiter.api.Assertions.assertThrows; class PaypageClientTest { - private PaypageClient paypageClient; + private SipsClient paypageClient; private PaymentRequest paymentRequest; private Map responseParameters; @BeforeEach void setUp() throws Exception { - paypageClient = new PaypageClient(Environment.SIMU, "002001000000001", 1, "002001000000001_KEY1"); + paypageClient = new SipsClient(PaymentEnvironment.SIMU, "002001000000001", 1, "002001000000001_KEY1"); paymentRequest = new PaymentRequest(); paymentRequest.setAmount(2); @@ -38,16 +42,16 @@ void setUp() throws Exception { @Test void testClientProxyException(){ - assertThrows(IncorrectProxyConfException.class,()-> new PaypageClient(Environment.TEST, "002001000000001", 1, "002001000000001_KEY1", true, "monProxy", null)); + assertThrows(IncorrectProxyConfException.class,()-> new SipsClient(PaymentEnvironment.TEST, "002001000000001", 1, "002001000000001_KEY1", true, "monProxy", null)); - assertThrows(IncorrectProxyConfException.class,()-> new PaypageClient(Environment.TEST, "002001000000001", 1, "002001000000001_KEY1", true, "", 3128)); + assertThrows(IncorrectProxyConfException.class,()-> new SipsClient(PaymentEnvironment.TEST, "002001000000001", 1, "002001000000001_KEY1", true, "", 3128)); - assertThrows(IncorrectProxyConfException.class,()-> new PaypageClient(Environment.TEST, "002001000000001", 1, "002001000000001_KEY1", true, null, null)); + assertThrows(IncorrectProxyConfException.class,()-> new SipsClient(PaymentEnvironment.TEST, "002001000000001", 1, "002001000000001_KEY1", true, null, null)); } @Test void execute() throws Exception { - InitializationResponse initializationResponse = paypageClient.initialize(paymentRequest); + InitializationResponse initializationResponse = paypageClient.send(paymentRequest); assertEquals(RedirectionStatusCode.TRANSACTION_INITIALIZED, initializationResponse.getRedirectionStatusCode(), "Initialization failed!"); } @@ -55,7 +59,7 @@ void execute() throws Exception { void decodeResponse_with_succeeded_request() throws Exception { responseParameters.put("Data", "captureDay=0|captureMode=AUTHOR_CAPTURE|currencyCode=978|merchantId=002001000000001|orderChannel=INTERNET|responseCode=00|transactionDateTime=2018-02-06T07:54:23+01:00|transactionReference=b4fb98a9c2c|keyVersion=1|acquirerResponseCode=00|amount=2|authorisationId=12345|guaranteeIndicator=Y|cardCSCResultCode=4D|panExpiryDate=201902|paymentMeanBrand=VISA|paymentMeanType=CARD|customerIpAddress=194.78.195.168|maskedPan=4500#############01|holderAuthentRelegation=N|holderAuthentStatus=3D_SUCCESS|tokenPan=g011040a730424d1ba6|transactionOrigin=INTERNET|paymentPattern=ONE_SHOT"); responseParameters.put("Seal", "56bddfce68695b9b8a9de51c426aae31bb303fb15570f343975eaa3bd33c8c59"); - PaypageResponse paypageResponse = paypageClient.decodeResponse(responseParameters); + PaypageResponse paypageResponse = paypageClient.decodeResponse(PaypageResponse.class, responseParameters); assertNotNull(paypageResponse.getData(), "Data field is empty!"); assertNotNull(paypageResponse.getData().getResponseCode()); } @@ -64,7 +68,7 @@ void decodeResponse_with_succeeded_request() throws Exception { void decodeResponse_with_cancelled_request() throws Exception { responseParameters.put("Data", "captureDay=0|captureMode=AUTHOR_CAPTURE|currencyCode=978|merchantId=002001000000001|orderChannel=INTERNET|responseCode=17|transactionDateTime=2018-02-06T07:43:55+01:00|transactionReference=e1445438c15|keyVersion=1|amount=2|customerIpAddress=194.78.195.168|paymentPattern=ONE_SHOT"); responseParameters.put("Seal", "8f488030781e3196726ce0658dbc26f19781f7c7fbe212b39d63d3f4d1d77301"); - PaypageResponse paypageResponse = paypageClient.decodeResponse(responseParameters); + PaypageResponse paypageResponse = paypageClient.decodeResponse(PaypageResponse.class, responseParameters); assertNotNull(paypageResponse.getData(), "Data field is empty!"); assertNotNull(paypageResponse.getData().getResponseCode()); } @@ -73,8 +77,8 @@ void decodeResponse_with_cancelled_request() throws Exception { void decodeResponse_with_refused_request() throws Exception { responseParameters.put("Data", "captureDay=0|captureMode=AUTHOR_CAPTURE|currencyCode=978|merchantId=002001000000001|orderChannel=INTERNET|responseCode=05|transactionDateTime=2018-02-06T07:50:34+01:00|transactionReference=8bd59312ff4|keyVersion=1|amount=2|guaranteeIndicator=N|panExpiryDate=201803|paymentMeanBrand=VISA|paymentMeanType=CARD|customerIpAddress=194.78.195.168|maskedPan=4500#############01|holderAuthentRelegation=N|holderAuthentStatus=3D_FAILURE|tokenPan=g011040a730424d1ba6|transactionOrigin=INTERNET|paymentPattern=ONE_SHOT"); responseParameters.put("Seal", "e8c5bf4551ec60ce9b8ece6a98bdb1b5fde511539a391bc4ba314aaeac93b5be"); - PaypageResponse paypageResponse = paypageClient.decodeResponse(responseParameters); + PaypageResponse paypageResponse = paypageClient.decodeResponse(PaypageResponse.class, responseParameters); assertNotNull(paypageResponse.getData(), "Data field is empty!"); assertNotNull(paypageResponse.getData().getResponseCode()); } -} \ No newline at end of file +} diff --git a/payment-sdk/src/test/java/com/worldline/sips/api/SealCalculatorTest.java b/payment-sdk/src/test/java/com/worldline/sips/api/SealCalculatorTest.java new file mode 100644 index 0000000..38ca4c5 --- /dev/null +++ b/payment-sdk/src/test/java/com/worldline/sips/api/SealCalculatorTest.java @@ -0,0 +1,122 @@ +package com.worldline.sips.api; + +import com.worldline.sips.exception.SealCalculationException; +import com.worldline.sips.model.Address; +import com.worldline.sips.model.Currency; +import com.worldline.sips.model.CustomerAddress; +import com.worldline.sips.model.CustomerContact; +import com.worldline.sips.model.PaymentMeanBrand; +import com.worldline.sips.model.RedirectionStatusCode; +import com.worldline.sips.model.request.PaymentRequest; +import com.worldline.sips.model.response.InitializationResponse; +import com.worldline.sips.security.SealCalculator; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.net.MalformedURLException; +import java.net.URL; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +class SealCalculatorTest { + + private static final String ENCODED_REQUEST_SEAL = "198e5f278e3f8548e174e84492953c4871732278b7e2aa2cbf20bb1ab85914ea"; + private static final String ENCODED_RESPONSE_SEAL = "dd6eb8dd6c951b1ddc1af121007aaabe8ad4fda1d15ce386cfa455821d602025"; + private static final String DEMO_KEY = "superSafeSecretKey"; + private static final String RESPONSE_DEMO_KEY = "002001000000002_KEY1"; + private PaymentRequest paymentRequest; + + @BeforeEach + void setUp() throws Exception { + paymentRequest = new PaymentRequest(); + paymentRequest.setAmount(10); + paymentRequest.setCustomerId("customerId"); + paymentRequest.setAutomaticResponseUrl(new URL("http://test.com")); + paymentRequest.setTemplateName("customCSS.css"); + } + + @Test + void getSealString() { + String actual = SealCalculator.getSealString(paymentRequest); + String expected = "10http://test.comcustomerIdIR_WS_2.19customCSS.css"; + assertEquals(expected, actual, "Sealstring is incorrect!"); + } + + @Test + void getSealString_with_Currency() { + paymentRequest.setCurrencyCode(Currency.EUR); + String actual = SealCalculator.getSealString(paymentRequest); + String expected = "10http://test.com978customerIdIR_WS_2.19customCSS.css"; + assertEquals(expected, actual, "Sealstring is incorrect!"); + } + + @Test + void getSealString_with_list() { + paymentRequest.getPaymentMeanBrandList().add(PaymentMeanBrand.VISA); + paymentRequest.getPaymentMeanBrandList().add(PaymentMeanBrand.BCMC); + String actual = SealCalculator.getSealString(paymentRequest); + String expected = "10http://test.comcustomerIdIR_WS_2.19BCMCVISAcustomCSS.css"; + assertEquals(expected, actual, "Sealstring is incorrect!"); + } + + @Test + void getSealString_with_Container() { + Address deliveryAddress = new Address(); + deliveryAddress.setZipcode("deliveryZipcode"); + deliveryAddress.setCompany("deliveryCompany"); + paymentRequest.setDeliveryAddress(deliveryAddress); + + CustomerAddress customerAddress = new CustomerAddress(); + customerAddress.setCity("customerCity"); + customerAddress.setBusinessName("customerBusinessName"); + paymentRequest.setCustomerAddress(customerAddress); + + CustomerContact customerContact = new CustomerContact(); + customerContact.setFirstName("firstName"); + customerContact.setLastName("lastName"); + paymentRequest.setCustomerContact(customerContact); + + String actual = SealCalculator.getSealString(paymentRequest); + String expected = "10http://test.comcustomerBusinessNamecustomerCityfirstNamelastNamecustomerIddeliveryCompanydeliveryZipcodeIR_WS_2.19customCSS.css"; + assertEquals(expected, actual, "Sealstring is incorrect!"); + } + + @Test + void getSealString_with_ignoredField() { + paymentRequest.setKeyVersion(200); + String actual = SealCalculator.getSealString(paymentRequest); + String expected = "10http://test.comcustomerIdIR_WS_2.19customCSS.css"; + assertEquals(expected, actual, "Sealstring is incorrect!"); + } + + @Test + void calculate() throws SealCalculationException { + String actual = SealCalculator.calculate("This is a test!", DEMO_KEY); + assertEquals(ENCODED_REQUEST_SEAL, actual, "Encoded seal is incorrect!"); + } + + @Test + void calculate_with_null_string() { + assertThrows(NullPointerException.class, () -> SealCalculator.calculate(null, DEMO_KEY), "No exception is thrown when string to encode is null!"); + } + + @Test + void calculate_with_null_key() { + assertThrows(NullPointerException.class, () -> SealCalculator.calculate("This is a test!", null), "No exception is thrown when string to encode is null!"); + } + + @Test + void calculate_response_seal() throws MalformedURLException, SealCalculationException { + InitializationResponse initializationResponse = new InitializationResponse(); + initializationResponse.setRedirectionStatusCode(RedirectionStatusCode.TRANSACTION_INITIALIZED); + initializationResponse.setRedirectionStatusMessage("INITIALISATION REQUEST ACCEPTED"); + initializationResponse.setRedirectionVersion("IR_WS_2.0"); + initializationResponse.setRedirectionUrl(new URL("https://payment-web.simu.sips-services.com/payment")); + initializationResponse.setRedirectionData("FTEx33MrE9Nc0gvtIS0aydJngXH8uuirg3ZpFD_KRM22C9e3IFDdBdSZB3kdQwcyIjWhKpM9mHYTCaCCy7Vm0YWrLscP-TJ895c2GXsTKlwEkO_VEU-2j2VGVcbYAKE9kcoV6jnVU5OJE1AMXEXnm1AkMrm3riB35p7x-WUdnaU0oKIhsit2M4_mci3fWH9WNTqo-A07qPd9-5zRKCr2F91Z8R4HogmLYdx_xh6BOyXKp693Smrq-2H64A2BOC6n89JQT-e9GNBM_up1YMa-vvS3-b6bMoZ01ngO7n2-NttxvXn78XEDDDVQfYZGPrpjywvDhGTfhBun1mdbSfzGPOwd6dcLre4Nguht3JCsT27EyLOxGEjCDwMjKJ0Gb2toChEMRv7TtX2SlXGMuyUr24oToHGbdt6zOm3q1R7XnCqnVYT_YNnNPf6lppQCW81FVvdX5zfbW65tQzja0CFC2ss-kyT0v4owm8LLNMy2rEU2JYnQQrT2qhQYf8lGxL2qkC0S1TpPLRzK-ry3mkEcBgwxFKbB2DX4kRamx4n6v_Yke2PS1PUPoWbdruRkK1mDJAJhSorV4O3LeeM1B3LkuPNU2xZw__I55zaOyIy2sWz52Su6gapGcsw8qTNOhcOwQi1sYaSGviCfKF75zC-GCjbHGoyHfO5RBswwmqBMNbVc7l2FIAw8ZDwn18E07pDWNeMwaeWYrYhR_n1BfhaW03H5TojvjnEMMSfd11nab0PjFE5zWB3r--OadfE7m-NqHL70WKLPYNfvKdzXzoI3ejc3SmWycXMpJgENZAFVzy4MojbVby3prA4IXQ_xSEisoWoGJb1Kg2LxEUih9Jqpi9vinH_nqt29lHFKnWSIuhT8UdsBYvFRGYyrbxPOOz1eNBqvHO49eI2hpKeL280_eR4HmLPiiDASog3BgDFB2_Ed6upm_N1PUEdQ1xmwXkiL7fqnaFABXySxsTVhxyRgXGSAmA0gmeYwFf7bGIKUc-FPwqWewDxRnIfnz6Eh3qDG41xEr5URpc0LCzzo5XjFt5h7wmp3FftmSai4rCFIM6B4Jd9lljeXgAMayzfig77_S_JMtEDw6oqzbX6QpBsKnfnrAtxk26LL07qB5Yw9qj-NEbWf28GOPN9--xY5AeUbya5nyNQiT-3TyebxnjUysTrTuq1DptPflIrUuIwAewT6K1I-XRYDpgdTRwWFzTIi2kItzGcbozxMJi0S6eJnOQNb9zNSrUBysDlSGVct1UsHqYQO56_-uyAwZ7lv23WIZdgbUaGELoPsba8Jg9rzR-aZ0zEe9owORSbAh5qkk0ByvOQniLqGYn36AJbKiSrSjRG1n9vBjjzffvsWOQHlG_tPV6WPVaXvanjaHrg_v2tjtqWPCUCRFg6seM4KiZ3G5-WPkPX0LW19iu4ypazFsfgElIfF7--XuN2wnrbf5tvPxpk-EHACkcFUQ7ozBw5xjRG1n9vBjjzffvsWOQHlGzGBbU3BAx_KVN_SQuZCNZ66O6O6FdOnZF_dC9vfuhZx5livIUUGTQOiFt4JQv_tJ3gl32WWN5eAAxrLN-KDvv_z_69h-FQfvm0DChFKn5h9Jb54QR0qamngPqTNqRQxNcmK3onHxmG7IIS9Gsltfie7sc4Lt9p_hqLAC28DDefH03yQ0l15QSQSA7t8x3rtGuflj5D19C1tfYruMqWsxbF_OuasNvoqSnJcHI_HyMMnf7eGnYHEcQk4vutjrpZhcH1TRZ3nQYrrxzId10uYeGeB7NXgInfbYearASIu2_vnMuJj1F84sjXcMM29qxh5KvOAaCle_EK7_SCamPY6SzkmTCyJprTaIBkhUUjUDdem4rN_XaLIav0orq8E4IwU740RtZ_bwY483377FjkB5RsKKPYjzvh_RlAEOH7vo0AIf7eGnYHEcQk4vutjrpZhcI0RtZ_bwY483377FjkB5Rv07-b-FhxhFkrKQcO0J0LIaKn33u4Hp88PYNHX40sIyNK3sqPZPiYGDU7q6T76kxla1JZwz-5wSgABK-wV16UlA1v3M1KtQHKwOVIZVy3VSwephA7nr_67IDBnuW_bdYjqqqfJtu70VoEtZOvxckajWtSWcM_ucEoAASvsFdelJcaipDQGiSLyw4gWeiGVvJAJHG6sS8x21XuBIuCbQ8l9Orcf_-QEVEHjGdswxxpSUovuFIRWVkRniMqau0PF2uF2Vi5vBX5AQYvblDS0I-Nk5mOOxtF3rdTMKSdmHaylZGleYPX4zPU6HmEV4ipdMcHx_vB89SS_gwRtQ9PWLJh3HJwvIO2GJs6lrufoKpeHVk9jne_ybEoDL1qOawB6ESQK5q5UXSwdR3YaB8M0qw-UPPibFlDSsbVF-zNvfbA8IBQL83Jj6EwBHBwT0RHvrvQ9-0nLg03cckYVc3IJh-dMok6Z5Ga3fsi_953xGMoOX4_z-gTn5pXhDYgI-0g_CKeAtgLeNsxz-PlTwW_U_kfW6Q3V7HDgOi-QZxxNSTMSkQpAdC3JcbHIGuEHVGxs5zWWT5tmsYkXbS11VEduPVXb9NpuUzUB5GLL8W3y9w3hTgLI1bKcCSsF4b3mgLEwNNGbEzYudvCLn3MP8g5BKQ-GlMMZU93_ANjsgNXUNK3j0SHC1NaycxVaWqmVP9uWp1U"); + + String sealString = SealCalculator.getSealString(initializationResponse); + String actual = SealCalculator.calculate(sealString, RESPONSE_DEMO_KEY); + assertEquals(ENCODED_RESPONSE_SEAL, actual, "Encoded seal is incorrect!"); + } +} diff --git a/payment-sdk-common/build.gradle b/sdk-common/build.gradle similarity index 79% rename from payment-sdk-common/build.gradle rename to sdk-common/build.gradle index 61a49d4..e9e9ebb 100644 --- a/payment-sdk-common/build.gradle +++ b/sdk-common/build.gradle @@ -3,4 +3,5 @@ dependencies { implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.0' implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.0' implementation 'org.apache.commons:commons-lang3:3.12.0' + implementation 'org.apache.httpcomponents.client5:httpclient5:5.1.2' } diff --git a/sdk-common/src/main/java/com/worldline/sips/SIPS2Request.java b/sdk-common/src/main/java/com/worldline/sips/SIPS2Request.java new file mode 100644 index 0000000..44349cb --- /dev/null +++ b/sdk-common/src/main/java/com/worldline/sips/SIPS2Request.java @@ -0,0 +1,68 @@ +package com.worldline.sips; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.worldline.sips.exception.SealCalculationException; +import com.worldline.sips.security.SealCalculator; +import com.worldline.sips.security.Sealable; + +@JsonPropertyOrder(alphabetic = true) +@JsonInclude(JsonInclude.Include.NON_EMPTY) +public abstract class SIPS2Request implements Sealable { + private String seal; + private String merchantId; + private Integer keyVersion; + private String sealAlgorithm; + + private final String endpoint; + + public SIPS2Request(String endpoint) { + this.endpoint = endpoint; + } + + public String getMerchantId() { + return merchantId; + } + + public void setMerchantId(String merchantId) { + this.merchantId = merchantId; + } + + public Integer getKeyVersion() { + return keyVersion; + } + + public void setKeyVersion(Integer keyVersion) { + this.keyVersion = keyVersion; + } + + public String getSeal() { + return seal; + } + + public void calculateSeal(String secretKey) throws SealCalculationException { + this.seal = SealCalculator.calculate(SealCalculator.getSealString(this), secretKey); + //FIXME TODO + } + + @JsonIgnore + public abstract Class getResponseType(); + + @JsonIgnore + public final Class getRealType() { + return this.getClass(); + } + + public String getEndpoint() { + return endpoint; + } + + public String getSealAlgorithm() { + return sealAlgorithm; + } + + public void setSealAlgorithm(String sealAlgorithm) { + this.sealAlgorithm = sealAlgorithm; + } +} diff --git a/sdk-common/src/main/java/com/worldline/sips/SIPS2Response.java b/sdk-common/src/main/java/com/worldline/sips/SIPS2Response.java new file mode 100644 index 0000000..fb25342 --- /dev/null +++ b/sdk-common/src/main/java/com/worldline/sips/SIPS2Response.java @@ -0,0 +1,29 @@ +package com.worldline.sips; + +import com.worldline.sips.exception.IncorrectSealException; +import com.worldline.sips.exception.SealCalculationException; +import com.worldline.sips.security.SealCalculator; +import com.worldline.sips.security.Sealable; +import org.apache.commons.lang3.StringUtils; + +public class SIPS2Response implements Sealable { + private String seal; + + public void verifySeal(String secretKey) throws IncorrectSealException, SealCalculationException { + if (seal != null) { + String correctSeal = SealCalculator.calculate( + SealCalculator.getSealString(this), secretKey); + if (! StringUtils.equals(correctSeal, seal)) { + throw new IncorrectSealException("The initialization response has been tampered with!"); + } + } + } + + public String getSeal() { + return seal; + } + + public void setSeal(String seal) { + this.seal = seal; + } +} diff --git a/sdk-common/src/main/java/com/worldline/sips/SipsClient.java b/sdk-common/src/main/java/com/worldline/sips/SipsClient.java new file mode 100644 index 0000000..577d69d --- /dev/null +++ b/sdk-common/src/main/java/com/worldline/sips/SipsClient.java @@ -0,0 +1,201 @@ +package com.worldline.sips; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.worldline.sips.exception.IncorrectProxyConfException; +import com.worldline.sips.exception.IncorrectSealException; +import com.worldline.sips.exception.InvalidEnvironmentException; +import com.worldline.sips.exception.InvalidMerchantException; +import com.worldline.sips.exception.SealCalculationException; +import com.worldline.sips.exception.SipsException; +import com.worldline.sips.exception.SipsRequestException; +import com.worldline.sips.model.SipsEnvironment; +import com.worldline.sips.security.SealCalculator; +import com.worldline.sips.util.ObjectMapperHolder; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.security.InvalidKeyException; +import java.util.Map; +import org.apache.commons.codec.digest.DigestUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.hc.client5.http.classic.methods.HttpPost; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; +import org.apache.hc.core5.http.ContentType; +import org.apache.hc.core5.http.HttpHost; +import org.apache.hc.core5.http.ParseException; +import org.apache.hc.core5.http.io.entity.EntityUtils; +import org.apache.hc.core5.http.io.entity.StringEntity; + +/** + * Interact with SIPS APIs. + */ +public class SipsClient { + + private final SipsEnvironment environment; + private final boolean proxyEnabled; + private final String proxyHost; + private final Integer proxyPort; + private String merchantId; + private Integer keyVersion; + private String secretKey; + + /** FIXME javadoc + * Construct a new instance of the client for a given {@link SipsEnvironment} + * + * @param environment the API environment to connect to. + * @param merchantId the merchant's ID. + * @param keyVersion the version of the secret key to use. + * @param secretKey the merchant's secret key. + * @throws IncorrectProxyConfException when the proxy configuration is incorrect + * @throws InvalidEnvironmentException when an unknown environment is specified + * @throws com.worldline.sips.exception.InvalidKeyException when the key version is null, or a key is blank, empty or null. + * @throws InvalidMerchantException when the key version is null, or a key is blank, empty or null. + */ + public SipsClient(SipsEnvironment environment, String merchantId, Integer keyVersion, String secretKey) + throws InvalidEnvironmentException, IncorrectProxyConfException, InvalidMerchantException, InvalidKeyException { + this(environment, merchantId, keyVersion, secretKey, false, null, null); + } + + //FIXME javadoc + public SipsClient(SipsEnvironment environment, String merchantId, Integer keyVersion, String secretKey, + boolean proxyEnabled, String proxyHost, Integer proxyPort) + throws InvalidEnvironmentException, IncorrectProxyConfException, InvalidMerchantException, InvalidKeyException { + if (environment == null) { + throw new InvalidEnvironmentException("Invalid environment specified!"); + } + + if (proxyEnabled) { + if(StringUtils.isBlank(proxyHost) || proxyPort == null){ + throw new IncorrectProxyConfException("ProxyEnabled is true but proxyHost or proxyPort not filled"); + } + } + + if (StringUtils.isBlank(merchantId)) { + throw new InvalidMerchantException("Invalid merchant ID specified!"); + } + + if (keyVersion == null) { + throw new InvalidKeyException("Invalid key version specified!"); + } + + if (StringUtils.isBlank(secretKey)) { + throw new InvalidKeyException("Invalid key specified!"); + } + this.environment = environment; + this.proxyEnabled = proxyEnabled; + this.proxyHost = proxyHost; + this.proxyPort = proxyPort; + this.merchantId = merchantId; + this.keyVersion = keyVersion; + this.secretKey = secretKey; + } + + /** FIXME javadoc + * Initialize a session with the SIPS API for given parameters. + * This is always the first step in a payment process. + * + * @param paymentRequest the parameters to use during the requested session. + * @return The API 's response for the preformed request. + * @throws IncorrectSealException when the response has been tampered with. + * @throws PaymentInitializationException when initialization fails due to processing exceptions, see inner exception for details. + * @throws SealCalculationException when seal calculation fails, see inner excpetion for details. + * @see PaymentRequest + * @see InitializationResponse + * @see #verifySeal(InitializationResponse) + */ + public Response send(SIPS2Request request) + throws SipsRequestException, SipsException, SealCalculationException, IncorrectSealException { + String fullPath = environment.getUrl() + "/" + request.getEndpoint(); + try { + HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); + if (this.proxyEnabled){ + HttpHost httpHost = new HttpHost(this.proxyHost, this.proxyPort); + httpClientBuilder.setProxy(httpHost); + } + CloseableHttpClient httpClient = httpClientBuilder.build(); + request.setMerchantId(merchantId); + request.setKeyVersion(keyVersion); + request.calculateSeal(secretKey); + StringEntity requestEntity = new StringEntity( + ObjectMapperHolder.INSTANCE.get().writerFor(request.getRealType()) + .writeValueAsString(request), + ContentType.APPLICATION_JSON); + + HttpPost postMethod = new HttpPost(new URI(fullPath)); + postMethod.setEntity(requestEntity); + + CloseableHttpResponse rawResponse = httpClient.execute(postMethod); + Response response = + ObjectMapperHolder.INSTANCE.get().readerFor(request.getResponseType()) + .readValue(EntityUtils.toString(rawResponse.getEntity())); + + response.verifySeal(secretKey); + return response; + } catch (JsonParseException | JsonMappingException e) { + throw new SipsRequestException("Exception while parsing request!", e); + } catch (IOException | ParseException e) { + throw new SipsException("Exception while processing response from server!", e); + } catch (URISyntaxException e) { + throw new SipsRequestException("Invalid endpoint: '" + fullPath + "' !", e); + } + } + + /** FIXME javadoc + * Decode a payment response for further processing. After the payment is made, the API will preform a + * POST request to the URL as defined in the {@link PaymentRequest}. + * + * @param parameters the content of the received request, mapped as key-value pairs. + * @return The API 's response for the preformed payment. + * @throws IncorrectSealException when the response has been tampered with. + * @see PaypageResponse + */ + public Response decodeResponse(Class responseClass, Map parameters) throws IncorrectSealException { + verifySeal(parameters.get("Data"), parameters.get("Seal"), secretKey); + return ObjectMapperHolder.INSTANCE.get().copy() + .convertValue(parameters, responseClass); + } + + //FIXME javadoc + public static Response decodeResponse(Class responseClass, + Map parameters, String secretKey) throws IncorrectSealException { + verifySeal(parameters.get("Data"), parameters.get("Seal"), secretKey); + return ObjectMapperHolder.INSTANCE.get().copy() + .convertValue(parameters, responseClass); + } + + /** FIXME javadoc + * Verify the seal of an initialization response. To avoid tampered responses when a session is initialized, + * the seal for the received response should always be verified before returning the object to the user. + * + * @param response the received response upon initialization + * @throws IncorrectSealException when the received seal is different from the one calculated + * @throws SealCalculationException when seal calculation fails, see inner excpetion for details. + */ + private void verifySeal(SIPS2Response response) throws IncorrectSealException, SealCalculationException { + if (response.getSeal() != null) { + String correctSeal = SealCalculator.calculate( + SealCalculator.getSealString(response), secretKey); + if (!StringUtils.equals(correctSeal, response.getSeal())) { + throw new IncorrectSealException("The initialization response has been tampered with!"); + } + } + } + + /** + * Verify the seal of a payment page response.To avoid tampered data for processed payments, + * the seal for the received response should always be verified before returning the object to the user. + * + * @param data the received response's Data attribute + * @param seal the received response's Seal attribute + * @throws IncorrectSealException when the received seal is different from the one calculated + */ + private static void verifySeal(String data, String seal, String secretKey) throws IncorrectSealException { + String correctSeal = DigestUtils.sha256Hex(data + secretKey); + if (!StringUtils.equals(correctSeal, seal)) { + throw new IncorrectSealException("The payment page response has been tampered with!"); + } + } +} diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/configuration/Configuration.java b/sdk-common/src/main/java/com/worldline/sips/configuration/Configuration.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/configuration/Configuration.java rename to sdk-common/src/main/java/com/worldline/sips/configuration/Configuration.java diff --git a/sdk-common/src/main/java/com/worldline/sips/exception/IncorrectProxyConfException.java b/sdk-common/src/main/java/com/worldline/sips/exception/IncorrectProxyConfException.java new file mode 100644 index 0000000..7e87073 --- /dev/null +++ b/sdk-common/src/main/java/com/worldline/sips/exception/IncorrectProxyConfException.java @@ -0,0 +1,8 @@ +package com.worldline.sips.exception; + +public class IncorrectProxyConfException extends Exception { + + public IncorrectProxyConfException(String message){ + super(message); + } +} diff --git a/sdk-common/src/main/java/com/worldline/sips/exception/IncorrectSealException.java b/sdk-common/src/main/java/com/worldline/sips/exception/IncorrectSealException.java new file mode 100644 index 0000000..a466909 --- /dev/null +++ b/sdk-common/src/main/java/com/worldline/sips/exception/IncorrectSealException.java @@ -0,0 +1,8 @@ +package com.worldline.sips.exception; + +public class IncorrectSealException extends Exception { + + public IncorrectSealException(String message) { + super(message); + } +} diff --git a/sdk-common/src/main/java/com/worldline/sips/exception/InvalidEnvironmentException.java b/sdk-common/src/main/java/com/worldline/sips/exception/InvalidEnvironmentException.java new file mode 100644 index 0000000..c5f30c7 --- /dev/null +++ b/sdk-common/src/main/java/com/worldline/sips/exception/InvalidEnvironmentException.java @@ -0,0 +1,8 @@ +package com.worldline.sips.exception; + +public class InvalidEnvironmentException extends Exception { + + public InvalidEnvironmentException(String message) { + super(message); + } +} diff --git a/sdk-common/src/main/java/com/worldline/sips/exception/InvalidKeyException.java b/sdk-common/src/main/java/com/worldline/sips/exception/InvalidKeyException.java new file mode 100644 index 0000000..6d54406 --- /dev/null +++ b/sdk-common/src/main/java/com/worldline/sips/exception/InvalidKeyException.java @@ -0,0 +1,8 @@ +package com.worldline.sips.exception; + +public class InvalidKeyException extends Exception { + + public InvalidKeyException(String message) { + super(message); + } +} diff --git a/sdk-common/src/main/java/com/worldline/sips/exception/InvalidMerchantException.java b/sdk-common/src/main/java/com/worldline/sips/exception/InvalidMerchantException.java new file mode 100644 index 0000000..db1b2cd --- /dev/null +++ b/sdk-common/src/main/java/com/worldline/sips/exception/InvalidMerchantException.java @@ -0,0 +1,9 @@ +package com.worldline.sips.exception; + +public class InvalidMerchantException extends Exception { + + public InvalidMerchantException(String message) { + super(message); + } +} + diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/exception/SealCalculationException.java b/sdk-common/src/main/java/com/worldline/sips/exception/SealCalculationException.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/exception/SealCalculationException.java rename to sdk-common/src/main/java/com/worldline/sips/exception/SealCalculationException.java diff --git a/sdk-common/src/main/java/com/worldline/sips/exception/SipsException.java b/sdk-common/src/main/java/com/worldline/sips/exception/SipsException.java new file mode 100644 index 0000000..736bfe3 --- /dev/null +++ b/sdk-common/src/main/java/com/worldline/sips/exception/SipsException.java @@ -0,0 +1,8 @@ +package com.worldline.sips.exception; + +public class SipsException extends Exception { + + public SipsException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/sdk-common/src/main/java/com/worldline/sips/exception/SipsRequestException.java b/sdk-common/src/main/java/com/worldline/sips/exception/SipsRequestException.java new file mode 100644 index 0000000..75fda5f --- /dev/null +++ b/sdk-common/src/main/java/com/worldline/sips/exception/SipsRequestException.java @@ -0,0 +1,8 @@ +package com.worldline.sips.exception; + +public class SipsRequestException extends Exception { + + public SipsRequestException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/exception/UnknownStatusException.java b/sdk-common/src/main/java/com/worldline/sips/exception/UnknownStatusException.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/exception/UnknownStatusException.java rename to sdk-common/src/main/java/com/worldline/sips/exception/UnknownStatusException.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/exception/UnsupportedCurrencyException.java b/sdk-common/src/main/java/com/worldline/sips/exception/UnsupportedCurrencyException.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/exception/UnsupportedCurrencyException.java rename to sdk-common/src/main/java/com/worldline/sips/exception/UnsupportedCurrencyException.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/exception/UnsupportedLanguageException.java b/sdk-common/src/main/java/com/worldline/sips/exception/UnsupportedLanguageException.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/exception/UnsupportedLanguageException.java rename to sdk-common/src/main/java/com/worldline/sips/exception/UnsupportedLanguageException.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/helper/AlphabeticalFieldComparator.java b/sdk-common/src/main/java/com/worldline/sips/helper/AlphabeticalFieldComparator.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/helper/AlphabeticalFieldComparator.java rename to sdk-common/src/main/java/com/worldline/sips/helper/AlphabeticalFieldComparator.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/helper/AlphabeticalReflectionToStringBuilder.java b/sdk-common/src/main/java/com/worldline/sips/helper/AlphabeticalReflectionToStringBuilder.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/helper/AlphabeticalReflectionToStringBuilder.java rename to sdk-common/src/main/java/com/worldline/sips/helper/AlphabeticalReflectionToStringBuilder.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/helper/BooleanDeserializer.java b/sdk-common/src/main/java/com/worldline/sips/helper/BooleanDeserializer.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/helper/BooleanDeserializer.java rename to sdk-common/src/main/java/com/worldline/sips/helper/BooleanDeserializer.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/helper/SealStringStyle.java b/sdk-common/src/main/java/com/worldline/sips/helper/SealStringStyle.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/helper/SealStringStyle.java rename to sdk-common/src/main/java/com/worldline/sips/helper/SealStringStyle.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/helper/SortedReflectionToStringBuilder.java b/sdk-common/src/main/java/com/worldline/sips/helper/SortedReflectionToStringBuilder.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/helper/SortedReflectionToStringBuilder.java rename to sdk-common/src/main/java/com/worldline/sips/helper/SortedReflectionToStringBuilder.java diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/model/PaymentMeanBrand.java b/sdk-common/src/main/java/com/worldline/sips/model/PaymentMeanBrand.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/model/PaymentMeanBrand.java rename to sdk-common/src/main/java/com/worldline/sips/model/PaymentMeanBrand.java diff --git a/sdk-common/src/main/java/com/worldline/sips/model/SipsEnvironment.java b/sdk-common/src/main/java/com/worldline/sips/model/SipsEnvironment.java new file mode 100644 index 0000000..910e268 --- /dev/null +++ b/sdk-common/src/main/java/com/worldline/sips/model/SipsEnvironment.java @@ -0,0 +1,5 @@ +package com.worldline.sips.model; + +public interface SipsEnvironment { + String getUrl(); +} diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/util/SealCalculator.java b/sdk-common/src/main/java/com/worldline/sips/security/SealCalculator.java similarity index 67% rename from payment-sdk-common/src/main/java/com/worldline/sips/util/SealCalculator.java rename to sdk-common/src/main/java/com/worldline/sips/security/SealCalculator.java index 47e21b7..40e4b14 100644 --- a/payment-sdk-common/src/main/java/com/worldline/sips/util/SealCalculator.java +++ b/sdk-common/src/main/java/com/worldline/sips/security/SealCalculator.java @@ -1,10 +1,10 @@ -package com.worldline.sips.util; +package com.worldline.sips.security; +import com.worldline.sips.SIPS2Request; +import com.worldline.sips.SIPS2Response; import com.worldline.sips.exception.SealCalculationException; import com.worldline.sips.helper.AlphabeticalReflectionToStringBuilder; import com.worldline.sips.helper.SealStringStyle; -import com.worldline.sips.model.InitializationResponse; -import com.worldline.sips.model.PaymentRequest; import org.apache.commons.codec.binary.Hex; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; @@ -20,13 +20,13 @@ private SealCalculator() { } /** - * Calculate the encrypted seal for a {@link PaymentRequest} based on a given seal string. + * Calculate the encrypted seal for a {@link SIPS2Request} based on a given seal string. * - * @param sealString the seal string for the {@link PaymentRequest} that needs to be signed + * @param sealString the seal string for the {@link SIPS2Request} that needs to be signed * @param key the merchant's secret key * @return the encrypted seal for the request * @throws SealCalculationException when the encryption fails (e.g. algorithm missing, invalid key specified) - * @see #getSealString(PaymentRequest) + * @see #getSealString(SIPS2Request) */ public static String calculate(String sealString, String key) throws SealCalculationException { try { @@ -41,13 +41,13 @@ public static String calculate(String sealString, String key) throws SealCalcula } /** - * Sort & concatenate the fields of a given {@link PaymentRequest}, needed to correctly sign the request. + * Sort & concatenate the fields of a given {@link SIPS2Request}, needed to correctly sign the request. * - * @param paymentRequest the request that's needs to be signed + * @param request the request that's needs to be signed * @return a String, formatted as described in the API docs. */ - public static String getSealString(PaymentRequest paymentRequest) { - ReflectionToStringBuilder reflectionToStringBuilder = new AlphabeticalReflectionToStringBuilder(paymentRequest, new SealStringStyle()); + public static String getSealString(SIPS2Request request) { + ReflectionToStringBuilder reflectionToStringBuilder = new AlphabeticalReflectionToStringBuilder(request, new SealStringStyle()); reflectionToStringBuilder.setExcludeFieldNames("keyVersion"); reflectionToStringBuilder.setExcludeNullValues(true); reflectionToStringBuilder.setAppendStatics(true); @@ -55,13 +55,13 @@ public static String getSealString(PaymentRequest paymentRequest) { } /** - * Sort & concatenate the fields of a given {@link PaymentRequest}, needed to correctly verify a response. + * Sort & concatenate the fields of a given {@link SIPS2Response}, needed to correctly verify a response. * - * @param initializationResponse the response that's needs to be verified + * @param response the response that's needs to be verified * @return a String, formatted as described in the API docs. */ - public static String getSealString(InitializationResponse initializationResponse) { - ReflectionToStringBuilder reflectionToStringBuilder = new AlphabeticalReflectionToStringBuilder(initializationResponse, new SealStringStyle()); + public static String getSealString(SIPS2Response response) { + ReflectionToStringBuilder reflectionToStringBuilder = new AlphabeticalReflectionToStringBuilder(response, new SealStringStyle()); reflectionToStringBuilder.setExcludeFieldNames("seal"); reflectionToStringBuilder.setExcludeNullValues(true); diff --git a/sdk-common/src/main/java/com/worldline/sips/security/Sealable.java b/sdk-common/src/main/java/com/worldline/sips/security/Sealable.java new file mode 100644 index 0000000..2e506e0 --- /dev/null +++ b/sdk-common/src/main/java/com/worldline/sips/security/Sealable.java @@ -0,0 +1,7 @@ +package com.worldline.sips.security; + +public interface Sealable { + + String getSeal(); + +} diff --git a/payment-sdk-common/src/main/java/com/worldline/sips/util/ObjectMapperHolder.java b/sdk-common/src/main/java/com/worldline/sips/util/ObjectMapperHolder.java similarity index 100% rename from payment-sdk-common/src/main/java/com/worldline/sips/util/ObjectMapperHolder.java rename to sdk-common/src/main/java/com/worldline/sips/util/ObjectMapperHolder.java diff --git a/settings.gradle b/settings.gradle index 46f54d3..1da1695 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,5 @@ include(':payment-sdk-common') include(':payment-sdk') +include(':wallet-sdk') +include 'sdk-common' + diff --git a/wallet-sdk/build.gradle b/wallet-sdk/build.gradle new file mode 100644 index 0000000..7491a6b --- /dev/null +++ b/wallet-sdk/build.gradle @@ -0,0 +1,6 @@ +dependencies { + implementation project(':sdk-common') + implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.0' + implementation 'org.apache.commons:commons-lang3:3.12.0' + implementation 'org.apache.httpcomponents.client5:httpclient5:5.1.2' +} diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/WalletRequest.java b/wallet-sdk/src/main/java/com/worldline/sips/api/WalletRequest.java new file mode 100644 index 0000000..bc7eb1e --- /dev/null +++ b/wallet-sdk/src/main/java/com/worldline/sips/api/WalletRequest.java @@ -0,0 +1,10 @@ +package com.worldline.sips.api; + +import com.worldline.sips.SIPS2Request; + +public abstract class WalletRequest extends SIPS2Request { + + public WalletRequest(String endpoint) { + super("wallet/" + endpoint); + } +} diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponse.java b/wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponse.java new file mode 100644 index 0000000..176aee6 --- /dev/null +++ b/wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponse.java @@ -0,0 +1,8 @@ +package com.worldline.sips.api; + +import com.worldline.sips.SIPS2Response; + +public abstract class WalletResponse extends SIPS2Response { + private String errorFieldName; + +} diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponseCode.java b/wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponseCode.java new file mode 100644 index 0000000..85fe6cb --- /dev/null +++ b/wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponseCode.java @@ -0,0 +1,61 @@ +package com.worldline.sips.api; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; +import com.worldline.sips.exception.UnknownStatusException; + +public enum WalletResponseCode { + /** + * Successful operation + */ + SUCCESS("00"), + /** + * Invalid Merchant contract + */ + INVALID_MERCHANT("03"), + /** + * Invalid data, verify the request + */ + INVALID_DATA("12"), + /** + * Wallet / payment mean unknown by WL Sips + */ + UNKNOWN_WALLET("25"), + FORMAT_ERROR("30"), + /** + * MerchantId not allowed to access this wallet service + */ + NOT_ALLOWED("40"), + /** + * Duplicated wallet / payment mean + */ + ALREADY_PRESENT("94"), + /** + * Temporary problem at the WL Sips server level + */ + INTERNAL_TEMPORARY_PROBLEM("99") + ; + + private final String code; + + @JsonCreator + public static WalletResponseCode fromCode(String code) throws UnknownStatusException { + for (WalletResponseCode responseCode : WalletResponseCode.values()) { + if (responseCode.getCode().equals(code)) { + return responseCode; + } + } + + throw new UnknownStatusException(code + " is an unknown response code!"); + } + + @JsonValue + public String getCode() { + return code; + } + + + WalletResponseCode(String code) { + this.code = code; + } +} diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/configuration/OfficeEnvironment.java b/wallet-sdk/src/main/java/com/worldline/sips/api/configuration/OfficeEnvironment.java new file mode 100644 index 0000000..a11c7b4 --- /dev/null +++ b/wallet-sdk/src/main/java/com/worldline/sips/api/configuration/OfficeEnvironment.java @@ -0,0 +1,26 @@ +package com.worldline.sips.api.configuration; + +import com.worldline.sips.model.SipsEnvironment; +import java.net.URI; + +public enum OfficeEnvironment implements SipsEnvironment { + TEST("https://office-server.test.sips-services.com"), + PROD("https://office-server.sips-services.com"); + + private final String url; + private final URI uri; + + OfficeEnvironment(String url) { + this.url = url + "/rs-services/v2/"; + this.uri = URI.create(url); + } + + public String getUrl() { + return url; + } + + public URI getURI() { + return uri; + } + +} diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/model/data/PaymentMeanData.java b/wallet-sdk/src/main/java/com/worldline/sips/api/model/data/PaymentMeanData.java new file mode 100644 index 0000000..f7b2d09 --- /dev/null +++ b/wallet-sdk/src/main/java/com/worldline/sips/api/model/data/PaymentMeanData.java @@ -0,0 +1,29 @@ +package com.worldline.sips.api.model.data; + +public class PaymentMeanData { +/** + * accord + * accordkdo + * bancontact + * bcaCup + * bcacb3x + * bcacb4x + * bcmcMobile + * cetelem3x + * cetelem4x + * cofidis3x + * cofidis4x + * cofinoga + * cofinoga3xcb + * facilypay + * franfinance3xcb + * franfinance4xcb + * passbe + * paypal + * presto + * sdd + * unEuroCom + * visaCheckout + */ +} + diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java b/wallet-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java new file mode 100644 index 0000000..0d1064e --- /dev/null +++ b/wallet-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java @@ -0,0 +1,16 @@ +package com.worldline.sips.api.model.data; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.worldline.sips.model.PaymentMeanBrand; +import java.time.YearMonth; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class WalletPaymentMeanData { + String maskedPan; + YearMonth panExpiryDate; + String paymentMeanAlias; + PaymentMeanBrand paymentMeanBrand; + String paymentMeanBrandCobadgedList; + PaymentMeanData paymentMeanData; + String transactionActors; +} diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/model/request/GetWalletDataRequest.java b/wallet-sdk/src/main/java/com/worldline/sips/api/model/request/GetWalletDataRequest.java new file mode 100644 index 0000000..12003e5 --- /dev/null +++ b/wallet-sdk/src/main/java/com/worldline/sips/api/model/request/GetWalletDataRequest.java @@ -0,0 +1,32 @@ +package com.worldline.sips.api.model.request; + +import com.worldline.sips.api.WalletRequest; +import com.worldline.sips.api.model.response.GetWalletDataResponse; + +public class GetWalletDataRequest extends WalletRequest { + + private final String merchantWalletId; + private String intermediateServiceProviderId; + + public GetWalletDataRequest(String merchantWalletId) { + super("getWalletData"); + this.merchantWalletId = merchantWalletId; + } + + @Override + public Class getResponseType() { + return GetWalletDataResponse.class; + } + + public String getIntermediateServiceProviderId() { + return intermediateServiceProviderId; + } + + public void setIntermediateServiceProviderId(String intermediateServiceProviderId) { + this.intermediateServiceProviderId = intermediateServiceProviderId; + } + + public String getMerchantWalletId() { + return merchantWalletId; + } +} diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/model/response/GetWalletDataResponse.java b/wallet-sdk/src/main/java/com/worldline/sips/api/model/response/GetWalletDataResponse.java new file mode 100644 index 0000000..5202bc0 --- /dev/null +++ b/wallet-sdk/src/main/java/com/worldline/sips/api/model/response/GetWalletDataResponse.java @@ -0,0 +1,16 @@ +package com.worldline.sips.api.model.response; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.worldline.sips.api.WalletResponse; +import com.worldline.sips.api.WalletResponseCode; +import com.worldline.sips.api.model.data.WalletPaymentMeanData; +import java.time.LocalDateTime; +import java.util.List; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class GetWalletDataResponse extends WalletResponse { + private LocalDateTime walletCreationDateTime; + private LocalDateTime walletLastActionDateTime; + private WalletResponseCode walletResponseCode; + private List walletPaymentMeanDataList; +} diff --git a/wallet-sdk/src/test/java/com/worldline/sips/utils/SipsClientTest.java b/wallet-sdk/src/test/java/com/worldline/sips/utils/SipsClientTest.java new file mode 100644 index 0000000..96c4b5d --- /dev/null +++ b/wallet-sdk/src/test/java/com/worldline/sips/utils/SipsClientTest.java @@ -0,0 +1,24 @@ +package com.worldline.sips.utils; + +import com.worldline.sips.SipsClient; +import com.worldline.sips.api.configuration.OfficeEnvironment; +import com.worldline.sips.api.model.request.GetWalletDataRequest; +import com.worldline.sips.api.model.response.GetWalletDataResponse; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class SipsClientTest { + + private SipsClient sipsClient; + + @BeforeEach + public void setUp() throws Exception { + sipsClient = new SipsClient(OfficeEnvironment.TEST, "002001000000001", 1, "002001000000001_KEY1"); + } + + @Test + void testSendWalletRequest() throws Exception { + GetWalletDataResponse response = sipsClient.send(new GetWalletDataRequest("1")); + System.out.println(response); + } +} From c40789b700082a0d74a8264c2c7005ce45c849b2 Mon Sep 17 00:00:00 2001 From: w112739 Date: Thu, 20 Jan 2022 17:22:14 +0100 Subject: [PATCH 02/15] [WIP] rebased to 1.4.4-SNAPSHOT No javadoc yet --- .../sips/helper/ResponseDataDeserializer.java | 2 +- .../helper/RuleResultListDeserializer.java | 2 +- .../com/worldline/sips/model/RuleType.java | 5 ----- .../model/{ => data}/AcquirerResponseCode.java | 2 +- .../sips/model/{ => data}/Address.java | 2 +- .../sips/model/{ => data}/CaptureMode.java | 2 +- .../model/{ => data}/CardCSCResultCode.java | 2 +- .../sips/model/{ => data}/Contact.java | 2 +- .../sips/model/{ => data}/Currency.java | 2 +- .../sips/model/{ => data}/CustomerAddress.java | 2 +- .../sips/model/{ => data}/CustomerContact.java | 2 +- .../model/{ => data}/GuaranteeIndicator.java | 2 +- .../model/{ => data}/HolderAuthentMethod.java | 2 +- .../model/{ => data}/HolderAuthentProgram.java | 2 +- .../model/{ => data}/HolderAuthentStatus.java | 2 +- .../sips/model/{ => data}/Language.java | 2 +- .../sips/model/{ => data}/OrderChannel.java | 2 +- .../sips/model/{ => data}/PanEntryMode.java | 2 +- .../sips/model/{ => data}/PaymentMeanType.java | 2 +- .../sips/model/{ => data}/PaymentPattern.java | 2 +- .../sips/model/{ => data}/PaypageData.java | 2 +- .../{ => data}/RedirectionStatusCode.java | 2 +- .../sips/model/{ => data}/ResponseCode.java | 2 +- .../sips/model/{ => data}/ResponseData.java | 5 +++-- .../sips/model/{ => data}/RuleCode.java | 4 ++-- .../sips/model/{ => data}/RuleResult.java | 2 +- .../model/{ => data}/RuleResultIndicator.java | 2 +- .../sips/model/{ => data}/RuleSetting.java | 2 +- .../worldline/sips/model/data/RuleType.java | 5 +++++ .../sips/model/{ => data}/ScoreColor.java | 2 +- .../sips/model/{ => data}/WalletType.java | 2 +- .../sips/model/request/PaymentRequest.java | 18 +++++++++--------- .../model/response/InitializationResponse.java | 4 ++-- .../sips/model/response/PaypageResponse.java | 2 +- .../worldline/sips/api/PaypageClientTest.java | 4 +++- .../worldline/sips/api/SealCalculatorTest.java | 10 +++++----- 36 files changed, 57 insertions(+), 54 deletions(-) delete mode 100644 payment-sdk/src/main/java/com/worldline/sips/model/RuleType.java rename payment-sdk/src/main/java/com/worldline/sips/model/{ => data}/AcquirerResponseCode.java (98%) rename payment-sdk/src/main/java/com/worldline/sips/model/{ => data}/Address.java (98%) rename payment-sdk/src/main/java/com/worldline/sips/model/{ => data}/CaptureMode.java (64%) rename payment-sdk/src/main/java/com/worldline/sips/model/{ => data}/CardCSCResultCode.java (96%) rename payment-sdk/src/main/java/com/worldline/sips/model/{ => data}/Contact.java (97%) rename payment-sdk/src/main/java/com/worldline/sips/model/{ => data}/Currency.java (98%) rename payment-sdk/src/main/java/com/worldline/sips/model/{ => data}/CustomerAddress.java (92%) rename payment-sdk/src/main/java/com/worldline/sips/model/{ => data}/CustomerContact.java (95%) rename payment-sdk/src/main/java/com/worldline/sips/model/{ => data}/GuaranteeIndicator.java (90%) rename payment-sdk/src/main/java/com/worldline/sips/model/{ => data}/HolderAuthentMethod.java (92%) rename payment-sdk/src/main/java/com/worldline/sips/model/{ => data}/HolderAuthentProgram.java (94%) rename payment-sdk/src/main/java/com/worldline/sips/model/{ => data}/HolderAuthentStatus.java (95%) rename payment-sdk/src/main/java/com/worldline/sips/model/{ => data}/Language.java (97%) rename payment-sdk/src/main/java/com/worldline/sips/model/{ => data}/OrderChannel.java (58%) rename payment-sdk/src/main/java/com/worldline/sips/model/{ => data}/PanEntryMode.java (62%) rename payment-sdk/src/main/java/com/worldline/sips/model/{ => data}/PaymentMeanType.java (91%) rename payment-sdk/src/main/java/com/worldline/sips/model/{ => data}/PaymentPattern.java (68%) rename payment-sdk/src/main/java/com/worldline/sips/model/{ => data}/PaypageData.java (92%) rename payment-sdk/src/main/java/com/worldline/sips/model/{ => data}/RedirectionStatusCode.java (96%) rename payment-sdk/src/main/java/com/worldline/sips/model/{ => data}/ResponseCode.java (97%) rename payment-sdk/src/main/java/com/worldline/sips/model/{ => data}/ResponseData.java (98%) rename payment-sdk/src/main/java/com/worldline/sips/model/{ => data}/RuleCode.java (93%) rename payment-sdk/src/main/java/com/worldline/sips/model/{ => data}/RuleResult.java (94%) rename payment-sdk/src/main/java/com/worldline/sips/model/{ => data}/RuleResultIndicator.java (89%) rename payment-sdk/src/main/java/com/worldline/sips/model/{ => data}/RuleSetting.java (89%) create mode 100644 payment-sdk/src/main/java/com/worldline/sips/model/data/RuleType.java rename payment-sdk/src/main/java/com/worldline/sips/model/{ => data}/ScoreColor.java (91%) rename payment-sdk/src/main/java/com/worldline/sips/model/{ => data}/WalletType.java (70%) diff --git a/payment-sdk/src/main/java/com/worldline/sips/helper/ResponseDataDeserializer.java b/payment-sdk/src/main/java/com/worldline/sips/helper/ResponseDataDeserializer.java index d1544e8..93b2670 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/helper/ResponseDataDeserializer.java +++ b/payment-sdk/src/main/java/com/worldline/sips/helper/ResponseDataDeserializer.java @@ -3,7 +3,7 @@ import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; -import com.worldline.sips.model.ResponseData; +import com.worldline.sips.model.data.ResponseData; import com.worldline.sips.util.ObjectMapperHolder; import org.apache.commons.lang3.StringUtils; diff --git a/payment-sdk/src/main/java/com/worldline/sips/helper/RuleResultListDeserializer.java b/payment-sdk/src/main/java/com/worldline/sips/helper/RuleResultListDeserializer.java index 420c5b4..2e22578 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/helper/RuleResultListDeserializer.java +++ b/payment-sdk/src/main/java/com/worldline/sips/helper/RuleResultListDeserializer.java @@ -4,7 +4,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; -import com.worldline.sips.model.RuleResult; +import com.worldline.sips.model.data.RuleResult; import com.worldline.sips.util.ObjectMapperHolder; import java.io.IOException; diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/RuleType.java b/payment-sdk/src/main/java/com/worldline/sips/model/RuleType.java deleted file mode 100644 index 6d238f7..0000000 --- a/payment-sdk/src/main/java/com/worldline/sips/model/RuleType.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.worldline.sips.model; - -public enum RuleType { - G, N -} diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/AcquirerResponseCode.java b/payment-sdk/src/main/java/com/worldline/sips/model/data/AcquirerResponseCode.java similarity index 98% rename from payment-sdk/src/main/java/com/worldline/sips/model/AcquirerResponseCode.java rename to payment-sdk/src/main/java/com/worldline/sips/model/data/AcquirerResponseCode.java index bf05bb5..f3b56b4 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/AcquirerResponseCode.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/data/AcquirerResponseCode.java @@ -1,4 +1,4 @@ -package com.worldline.sips.model; +package com.worldline.sips.model.data; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/Address.java b/payment-sdk/src/main/java/com/worldline/sips/model/data/Address.java similarity index 98% rename from payment-sdk/src/main/java/com/worldline/sips/model/Address.java rename to payment-sdk/src/main/java/com/worldline/sips/model/data/Address.java index 4876900..ae6cc4e 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/Address.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/data/Address.java @@ -1,4 +1,4 @@ -package com.worldline.sips.model; +package com.worldline.sips.model.data; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonPropertyOrder; diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/CaptureMode.java b/payment-sdk/src/main/java/com/worldline/sips/model/data/CaptureMode.java similarity index 64% rename from payment-sdk/src/main/java/com/worldline/sips/model/CaptureMode.java rename to payment-sdk/src/main/java/com/worldline/sips/model/data/CaptureMode.java index fa61182..0d2a9cd 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/CaptureMode.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/data/CaptureMode.java @@ -1,4 +1,4 @@ -package com.worldline.sips.model; +package com.worldline.sips.model.data; public enum CaptureMode { AUTHOR_CAPTURE, IMMEDIATE, VALIDATION diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/CardCSCResultCode.java b/payment-sdk/src/main/java/com/worldline/sips/model/data/CardCSCResultCode.java similarity index 96% rename from payment-sdk/src/main/java/com/worldline/sips/model/CardCSCResultCode.java rename to payment-sdk/src/main/java/com/worldline/sips/model/data/CardCSCResultCode.java index fef6ab8..cfb8de1 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/CardCSCResultCode.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/data/CardCSCResultCode.java @@ -1,4 +1,4 @@ -package com.worldline.sips.model; +package com.worldline.sips.model.data; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/Contact.java b/payment-sdk/src/main/java/com/worldline/sips/model/data/Contact.java similarity index 97% rename from payment-sdk/src/main/java/com/worldline/sips/model/Contact.java rename to payment-sdk/src/main/java/com/worldline/sips/model/data/Contact.java index 9acf6c3..f545eb5 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/Contact.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/data/Contact.java @@ -1,4 +1,4 @@ -package com.worldline.sips.model; +package com.worldline.sips.model.data; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/Currency.java b/payment-sdk/src/main/java/com/worldline/sips/model/data/Currency.java similarity index 98% rename from payment-sdk/src/main/java/com/worldline/sips/model/Currency.java rename to payment-sdk/src/main/java/com/worldline/sips/model/data/Currency.java index 5b4888d..36e725c 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/Currency.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/data/Currency.java @@ -1,4 +1,4 @@ -package com.worldline.sips.model; +package com.worldline.sips.model.data; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/CustomerAddress.java b/payment-sdk/src/main/java/com/worldline/sips/model/data/CustomerAddress.java similarity index 92% rename from payment-sdk/src/main/java/com/worldline/sips/model/CustomerAddress.java rename to payment-sdk/src/main/java/com/worldline/sips/model/data/CustomerAddress.java index 7ad5542..105a668 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/CustomerAddress.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/data/CustomerAddress.java @@ -1,4 +1,4 @@ -package com.worldline.sips.model; +package com.worldline.sips.model.data; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonPropertyOrder; diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/CustomerContact.java b/payment-sdk/src/main/java/com/worldline/sips/model/data/CustomerContact.java similarity index 95% rename from payment-sdk/src/main/java/com/worldline/sips/model/CustomerContact.java rename to payment-sdk/src/main/java/com/worldline/sips/model/data/CustomerContact.java index 67745c7..b6d4615 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/CustomerContact.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/data/CustomerContact.java @@ -1,4 +1,4 @@ -package com.worldline.sips.model; +package com.worldline.sips.model.data; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonPropertyOrder; diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/GuaranteeIndicator.java b/payment-sdk/src/main/java/com/worldline/sips/model/data/GuaranteeIndicator.java similarity index 90% rename from payment-sdk/src/main/java/com/worldline/sips/model/GuaranteeIndicator.java rename to payment-sdk/src/main/java/com/worldline/sips/model/data/GuaranteeIndicator.java index e7a272f..9a4a54d 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/GuaranteeIndicator.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/data/GuaranteeIndicator.java @@ -1,4 +1,4 @@ -package com.worldline.sips.model; +package com.worldline.sips.model.data; import com.fasterxml.jackson.annotation.JsonCreator; import org.apache.commons.lang3.StringUtils; diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/HolderAuthentMethod.java b/payment-sdk/src/main/java/com/worldline/sips/model/data/HolderAuthentMethod.java similarity index 92% rename from payment-sdk/src/main/java/com/worldline/sips/model/HolderAuthentMethod.java rename to payment-sdk/src/main/java/com/worldline/sips/model/data/HolderAuthentMethod.java index b760b94..0c464ed 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/HolderAuthentMethod.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/data/HolderAuthentMethod.java @@ -1,4 +1,4 @@ -package com.worldline.sips.model; +package com.worldline.sips.model.data; import com.fasterxml.jackson.annotation.JsonCreator; import org.apache.commons.lang3.StringUtils; diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/HolderAuthentProgram.java b/payment-sdk/src/main/java/com/worldline/sips/model/data/HolderAuthentProgram.java similarity index 94% rename from payment-sdk/src/main/java/com/worldline/sips/model/HolderAuthentProgram.java rename to payment-sdk/src/main/java/com/worldline/sips/model/data/HolderAuthentProgram.java index 912fab3..c3b07c3 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/HolderAuthentProgram.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/data/HolderAuthentProgram.java @@ -1,4 +1,4 @@ -package com.worldline.sips.model; +package com.worldline.sips.model.data; import com.fasterxml.jackson.annotation.JsonCreator; import org.apache.commons.lang3.StringUtils; diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/HolderAuthentStatus.java b/payment-sdk/src/main/java/com/worldline/sips/model/data/HolderAuthentStatus.java similarity index 95% rename from payment-sdk/src/main/java/com/worldline/sips/model/HolderAuthentStatus.java rename to payment-sdk/src/main/java/com/worldline/sips/model/data/HolderAuthentStatus.java index a347920..9b4f005 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/HolderAuthentStatus.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/data/HolderAuthentStatus.java @@ -1,4 +1,4 @@ -package com.worldline.sips.model; +package com.worldline.sips.model.data; import com.fasterxml.jackson.annotation.JsonCreator; import org.apache.commons.lang3.StringUtils; diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/Language.java b/payment-sdk/src/main/java/com/worldline/sips/model/data/Language.java similarity index 97% rename from payment-sdk/src/main/java/com/worldline/sips/model/Language.java rename to payment-sdk/src/main/java/com/worldline/sips/model/data/Language.java index 9c3a1ce..6c1c2ec 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/Language.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/data/Language.java @@ -1,4 +1,4 @@ -package com.worldline.sips.model; +package com.worldline.sips.model.data; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/OrderChannel.java b/payment-sdk/src/main/java/com/worldline/sips/model/data/OrderChannel.java similarity index 58% rename from payment-sdk/src/main/java/com/worldline/sips/model/OrderChannel.java rename to payment-sdk/src/main/java/com/worldline/sips/model/data/OrderChannel.java index 3e42adc..abe8bc4 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/OrderChannel.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/data/OrderChannel.java @@ -1,4 +1,4 @@ -package com.worldline.sips.model; +package com.worldline.sips.model.data; public enum OrderChannel { INAPP, INTERNET, MOTO diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/PanEntryMode.java b/payment-sdk/src/main/java/com/worldline/sips/model/data/PanEntryMode.java similarity index 62% rename from payment-sdk/src/main/java/com/worldline/sips/model/PanEntryMode.java rename to payment-sdk/src/main/java/com/worldline/sips/model/data/PanEntryMode.java index 6f365e8..726f071 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/PanEntryMode.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/data/PanEntryMode.java @@ -1,4 +1,4 @@ -package com.worldline.sips.model; +package com.worldline.sips.model.data; public enum PanEntryMode { MANUAL, OEMPAY, VIRTUAL, WALLET diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/PaymentMeanType.java b/payment-sdk/src/main/java/com/worldline/sips/model/data/PaymentMeanType.java similarity index 91% rename from payment-sdk/src/main/java/com/worldline/sips/model/PaymentMeanType.java rename to payment-sdk/src/main/java/com/worldline/sips/model/data/PaymentMeanType.java index 48a41ec..341de7f 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/PaymentMeanType.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/data/PaymentMeanType.java @@ -1,4 +1,4 @@ -package com.worldline.sips.model; +package com.worldline.sips.model.data; import com.fasterxml.jackson.annotation.JsonCreator; import org.apache.commons.lang3.StringUtils; diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/PaymentPattern.java b/payment-sdk/src/main/java/com/worldline/sips/model/data/PaymentPattern.java similarity index 68% rename from payment-sdk/src/main/java/com/worldline/sips/model/PaymentPattern.java rename to payment-sdk/src/main/java/com/worldline/sips/model/data/PaymentPattern.java index 10bd71d..29e88f7 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/PaymentPattern.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/data/PaymentPattern.java @@ -1,4 +1,4 @@ -package com.worldline.sips.model; +package com.worldline.sips.model.data; public enum PaymentPattern { ONE_SHOT, RECURRING_1, RECURRING_N, INSTALMENT diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/PaypageData.java b/payment-sdk/src/main/java/com/worldline/sips/model/data/PaypageData.java similarity index 92% rename from payment-sdk/src/main/java/com/worldline/sips/model/PaypageData.java rename to payment-sdk/src/main/java/com/worldline/sips/model/data/PaypageData.java index eb33d29..36ad861 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/PaypageData.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/data/PaypageData.java @@ -1,4 +1,4 @@ -package com.worldline.sips.model; +package com.worldline.sips.model.data; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonPropertyOrder; diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/RedirectionStatusCode.java b/payment-sdk/src/main/java/com/worldline/sips/model/data/RedirectionStatusCode.java similarity index 96% rename from payment-sdk/src/main/java/com/worldline/sips/model/RedirectionStatusCode.java rename to payment-sdk/src/main/java/com/worldline/sips/model/data/RedirectionStatusCode.java index ade3891..6d2ab1c 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/RedirectionStatusCode.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/data/RedirectionStatusCode.java @@ -1,4 +1,4 @@ -package com.worldline.sips.model; +package com.worldline.sips.model.data; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/ResponseCode.java b/payment-sdk/src/main/java/com/worldline/sips/model/data/ResponseCode.java similarity index 97% rename from payment-sdk/src/main/java/com/worldline/sips/model/ResponseCode.java rename to payment-sdk/src/main/java/com/worldline/sips/model/data/ResponseCode.java index 6be7acb..3adcaf6 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/ResponseCode.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/data/ResponseCode.java @@ -1,4 +1,4 @@ -package com.worldline.sips.model; +package com.worldline.sips.model.data; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/ResponseData.java b/payment-sdk/src/main/java/com/worldline/sips/model/data/ResponseData.java similarity index 98% rename from payment-sdk/src/main/java/com/worldline/sips/model/ResponseData.java rename to payment-sdk/src/main/java/com/worldline/sips/model/data/ResponseData.java index b1f276b..19cb610 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/ResponseData.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/data/ResponseData.java @@ -1,10 +1,11 @@ -package com.worldline.sips.model; +package com.worldline.sips.model.data; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.worldline.sips.helper.BooleanDeserializer; import com.worldline.sips.helper.RuleResultListDeserializer; +import com.worldline.sips.model.PaymentMeanBrand; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.YearMonth; @@ -277,4 +278,4 @@ public String getOrderId() { public String getReturnContext() { return returnContext; } -} \ No newline at end of file +} diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/RuleCode.java b/payment-sdk/src/main/java/com/worldline/sips/model/data/RuleCode.java similarity index 93% rename from payment-sdk/src/main/java/com/worldline/sips/model/RuleCode.java rename to payment-sdk/src/main/java/com/worldline/sips/model/data/RuleCode.java index ef570ac..411c732 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/RuleCode.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/data/RuleCode.java @@ -1,4 +1,4 @@ -package com.worldline.sips.model; +package com.worldline.sips.model.data; public enum RuleCode { @@ -76,4 +76,4 @@ public enum RuleCode { PQ, PR, QP -} \ No newline at end of file +} diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/RuleResult.java b/payment-sdk/src/main/java/com/worldline/sips/model/data/RuleResult.java similarity index 94% rename from payment-sdk/src/main/java/com/worldline/sips/model/RuleResult.java rename to payment-sdk/src/main/java/com/worldline/sips/model/data/RuleResult.java index 0e2532a..29c6725 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/RuleResult.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/data/RuleResult.java @@ -1,4 +1,4 @@ -package com.worldline.sips.model; +package com.worldline.sips.model.data; public class RuleResult { private RuleCode ruleCode; diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/RuleResultIndicator.java b/payment-sdk/src/main/java/com/worldline/sips/model/data/RuleResultIndicator.java similarity index 89% rename from payment-sdk/src/main/java/com/worldline/sips/model/RuleResultIndicator.java rename to payment-sdk/src/main/java/com/worldline/sips/model/data/RuleResultIndicator.java index 1bb5803..af41528 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/RuleResultIndicator.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/data/RuleResultIndicator.java @@ -1,4 +1,4 @@ -package com.worldline.sips.model; +package com.worldline.sips.model.data; import com.fasterxml.jackson.annotation.JsonCreator; diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/RuleSetting.java b/payment-sdk/src/main/java/com/worldline/sips/model/data/RuleSetting.java similarity index 89% rename from payment-sdk/src/main/java/com/worldline/sips/model/RuleSetting.java rename to payment-sdk/src/main/java/com/worldline/sips/model/data/RuleSetting.java index 46e9a81..cb6c1c8 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/RuleSetting.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/data/RuleSetting.java @@ -1,4 +1,4 @@ -package com.worldline.sips.model; +package com.worldline.sips.model.data; import com.fasterxml.jackson.annotation.JsonCreator; import org.apache.commons.lang3.StringUtils; diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/data/RuleType.java b/payment-sdk/src/main/java/com/worldline/sips/model/data/RuleType.java new file mode 100644 index 0000000..dc408b7 --- /dev/null +++ b/payment-sdk/src/main/java/com/worldline/sips/model/data/RuleType.java @@ -0,0 +1,5 @@ +package com.worldline.sips.model.data; + +public enum RuleType { + G, N +} diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/ScoreColor.java b/payment-sdk/src/main/java/com/worldline/sips/model/data/ScoreColor.java similarity index 91% rename from payment-sdk/src/main/java/com/worldline/sips/model/ScoreColor.java rename to payment-sdk/src/main/java/com/worldline/sips/model/data/ScoreColor.java index a6abf98..d321907 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/ScoreColor.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/data/ScoreColor.java @@ -1,4 +1,4 @@ -package com.worldline.sips.model; +package com.worldline.sips.model.data; import com.fasterxml.jackson.annotation.JsonCreator; import org.apache.commons.lang3.StringUtils; diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/WalletType.java b/payment-sdk/src/main/java/com/worldline/sips/model/data/WalletType.java similarity index 70% rename from payment-sdk/src/main/java/com/worldline/sips/model/WalletType.java rename to payment-sdk/src/main/java/com/worldline/sips/model/data/WalletType.java index ee31dd6..2fa6582 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/WalletType.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/data/WalletType.java @@ -1,4 +1,4 @@ -package com.worldline.sips.model; +package com.worldline.sips.model.data; public enum WalletType { BCMCMOBILE, MASTERPASS, MERCHANT_WALLET, PAYLIB, VISACHECKOUT diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/request/PaymentRequest.java b/payment-sdk/src/main/java/com/worldline/sips/model/request/PaymentRequest.java index 2f79ea8..492b4f4 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/request/PaymentRequest.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/request/PaymentRequest.java @@ -6,16 +6,16 @@ import com.worldline.sips.SIPS2Request; import com.worldline.sips.configuration.Configuration; -import com.worldline.sips.model.Address; -import com.worldline.sips.model.CaptureMode; -import com.worldline.sips.model.Contact; -import com.worldline.sips.model.Currency; -import com.worldline.sips.model.CustomerAddress; -import com.worldline.sips.model.CustomerContact; -import com.worldline.sips.model.Language; -import com.worldline.sips.model.OrderChannel; +import com.worldline.sips.model.data.Address; +import com.worldline.sips.model.data.CaptureMode; +import com.worldline.sips.model.data.Contact; +import com.worldline.sips.model.data.Currency; +import com.worldline.sips.model.data.CustomerAddress; +import com.worldline.sips.model.data.CustomerContact; +import com.worldline.sips.model.data.Language; +import com.worldline.sips.model.data.OrderChannel; import com.worldline.sips.model.PaymentMeanBrand; -import com.worldline.sips.model.PaypageData; +import com.worldline.sips.model.data.PaypageData; import com.worldline.sips.model.response.InitializationResponse; import java.net.URL; import java.util.TreeSet; diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/response/InitializationResponse.java b/payment-sdk/src/main/java/com/worldline/sips/model/response/InitializationResponse.java index 45dff92..0e9bb9d 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/response/InitializationResponse.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/response/InitializationResponse.java @@ -1,8 +1,8 @@ package com.worldline.sips.model.response; import com.worldline.sips.SIPS2Response; -import com.worldline.sips.model.RedirectionStatusCode; -import com.worldline.sips.model.ResponseCode; +import com.worldline.sips.model.data.RedirectionStatusCode; +import com.worldline.sips.model.data.ResponseCode; import java.net.URL; /** diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/response/PaypageResponse.java b/payment-sdk/src/main/java/com/worldline/sips/model/response/PaypageResponse.java index e5767e3..b502c97 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/response/PaypageResponse.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/response/PaypageResponse.java @@ -6,7 +6,7 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.worldline.sips.SIPS2Response; import com.worldline.sips.helper.ResponseDataDeserializer; -import com.worldline.sips.model.ResponseData; +import com.worldline.sips.model.data.ResponseData; /** * The result of payment made via the SIPS payment page. diff --git a/payment-sdk/src/test/java/com/worldline/sips/api/PaypageClientTest.java b/payment-sdk/src/test/java/com/worldline/sips/api/PaypageClientTest.java index b28cafb..bcc8265 100644 --- a/payment-sdk/src/test/java/com/worldline/sips/api/PaypageClientTest.java +++ b/payment-sdk/src/test/java/com/worldline/sips/api/PaypageClientTest.java @@ -3,7 +3,9 @@ import com.worldline.sips.SipsClient; import com.worldline.sips.configuration.PaymentEnvironment; import com.worldline.sips.exception.IncorrectProxyConfException; -import com.worldline.sips.model.*; +import com.worldline.sips.model.data.Currency; +import com.worldline.sips.model.data.OrderChannel; +import com.worldline.sips.model.data.RedirectionStatusCode; import com.worldline.sips.model.request.PaymentRequest; import com.worldline.sips.model.response.InitializationResponse; import com.worldline.sips.model.response.PaypageResponse; diff --git a/payment-sdk/src/test/java/com/worldline/sips/api/SealCalculatorTest.java b/payment-sdk/src/test/java/com/worldline/sips/api/SealCalculatorTest.java index 38ca4c5..512275f 100644 --- a/payment-sdk/src/test/java/com/worldline/sips/api/SealCalculatorTest.java +++ b/payment-sdk/src/test/java/com/worldline/sips/api/SealCalculatorTest.java @@ -1,12 +1,12 @@ package com.worldline.sips.api; import com.worldline.sips.exception.SealCalculationException; -import com.worldline.sips.model.Address; -import com.worldline.sips.model.Currency; -import com.worldline.sips.model.CustomerAddress; -import com.worldline.sips.model.CustomerContact; +import com.worldline.sips.model.data.Address; +import com.worldline.sips.model.data.Currency; +import com.worldline.sips.model.data.CustomerAddress; +import com.worldline.sips.model.data.CustomerContact; import com.worldline.sips.model.PaymentMeanBrand; -import com.worldline.sips.model.RedirectionStatusCode; +import com.worldline.sips.model.data.RedirectionStatusCode; import com.worldline.sips.model.request.PaymentRequest; import com.worldline.sips.model.response.InitializationResponse; import com.worldline.sips.security.SealCalculator; From b817b12dd77a71c96dc82989cf76238ae36a5542 Mon Sep 17 00:00:00 2001 From: w112739 Date: Fri, 21 Jan 2022 12:17:03 +0100 Subject: [PATCH 03/15] [WIP] Fix serialisation & seal computation - Seal computation now sort all fields of a class hierarchy instead of sorting on each class - Fix broken seal calculator tests --- .../sips/api/SealCalculatorTest.java | 12 +-- .../java/com/worldline/sips/SIPS2Request.java | 2 +- .../com/worldline/sips/SIPS2Response.java | 2 +- .../SortedReflectionToStringBuilder.java | 83 +++++++++++-------- .../sips/security/SealCalculator.java | 2 +- .../com/worldline/sips/api/WalletRequest.java | 8 ++ .../worldline/sips/api/WalletResponse.java | 8 ++ .../sips/api/WalletResponseCode.java | 14 +++- .../api/configuration/OfficeEnvironment.java | 2 +- .../api/model/data/WalletPaymentMeanData.java | 2 +- .../model/response/GetWalletDataResponse.java | 13 ++- .../worldline/sips/utils/SipsClientTest.java | 24 ------ .../worldline/sips/utils/WalletSipsTest.java | 40 +++++++++ 13 files changed, 138 insertions(+), 74 deletions(-) delete mode 100644 wallet-sdk/src/test/java/com/worldline/sips/utils/SipsClientTest.java create mode 100644 wallet-sdk/src/test/java/com/worldline/sips/utils/WalletSipsTest.java diff --git a/payment-sdk/src/test/java/com/worldline/sips/api/SealCalculatorTest.java b/payment-sdk/src/test/java/com/worldline/sips/api/SealCalculatorTest.java index 512275f..ae89d97 100644 --- a/payment-sdk/src/test/java/com/worldline/sips/api/SealCalculatorTest.java +++ b/payment-sdk/src/test/java/com/worldline/sips/api/SealCalculatorTest.java @@ -1,5 +1,6 @@ package com.worldline.sips.api; +import com.worldline.sips.configuration.Configuration; import com.worldline.sips.exception.SealCalculationException; import com.worldline.sips.model.data.Address; import com.worldline.sips.model.data.Currency; @@ -25,6 +26,7 @@ class SealCalculatorTest { private static final String ENCODED_RESPONSE_SEAL = "dd6eb8dd6c951b1ddc1af121007aaabe8ad4fda1d15ce386cfa455821d602025"; private static final String DEMO_KEY = "superSafeSecretKey"; private static final String RESPONSE_DEMO_KEY = "002001000000002_KEY1"; + private PaymentRequest paymentRequest; @BeforeEach @@ -39,7 +41,7 @@ void setUp() throws Exception { @Test void getSealString() { String actual = SealCalculator.getSealString(paymentRequest); - String expected = "10http://test.comcustomerIdIR_WS_2.19customCSS.css"; + String expected = "10http://test.comcustomerIdIR_WS_2.35customCSS.css"; assertEquals(expected, actual, "Sealstring is incorrect!"); } @@ -47,7 +49,7 @@ void getSealString() { void getSealString_with_Currency() { paymentRequest.setCurrencyCode(Currency.EUR); String actual = SealCalculator.getSealString(paymentRequest); - String expected = "10http://test.com978customerIdIR_WS_2.19customCSS.css"; + String expected = "10http://test.com978customerIdIR_WS_2.35customCSS.css"; assertEquals(expected, actual, "Sealstring is incorrect!"); } @@ -56,7 +58,7 @@ void getSealString_with_list() { paymentRequest.getPaymentMeanBrandList().add(PaymentMeanBrand.VISA); paymentRequest.getPaymentMeanBrandList().add(PaymentMeanBrand.BCMC); String actual = SealCalculator.getSealString(paymentRequest); - String expected = "10http://test.comcustomerIdIR_WS_2.19BCMCVISAcustomCSS.css"; + String expected = "10http://test.comcustomerIdIR_WS_2.35BCMCVISAcustomCSS.css"; assertEquals(expected, actual, "Sealstring is incorrect!"); } @@ -78,7 +80,7 @@ void getSealString_with_Container() { paymentRequest.setCustomerContact(customerContact); String actual = SealCalculator.getSealString(paymentRequest); - String expected = "10http://test.comcustomerBusinessNamecustomerCityfirstNamelastNamecustomerIddeliveryCompanydeliveryZipcodeIR_WS_2.19customCSS.css"; + String expected = "10http://test.comcustomerBusinessNamecustomerCityfirstNamelastNamecustomerIddeliveryCompanydeliveryZipcodeIR_WS_2.35customCSS.css"; assertEquals(expected, actual, "Sealstring is incorrect!"); } @@ -86,7 +88,7 @@ void getSealString_with_Container() { void getSealString_with_ignoredField() { paymentRequest.setKeyVersion(200); String actual = SealCalculator.getSealString(paymentRequest); - String expected = "10http://test.comcustomerIdIR_WS_2.19customCSS.css"; + String expected = "10http://test.comcustomerIdIR_WS_2.35customCSS.css"; assertEquals(expected, actual, "Sealstring is incorrect!"); } diff --git a/sdk-common/src/main/java/com/worldline/sips/SIPS2Request.java b/sdk-common/src/main/java/com/worldline/sips/SIPS2Request.java index 44349cb..e848502 100644 --- a/sdk-common/src/main/java/com/worldline/sips/SIPS2Request.java +++ b/sdk-common/src/main/java/com/worldline/sips/SIPS2Request.java @@ -43,7 +43,6 @@ public String getSeal() { public void calculateSeal(String secretKey) throws SealCalculationException { this.seal = SealCalculator.calculate(SealCalculator.getSealString(this), secretKey); - //FIXME TODO } @JsonIgnore @@ -54,6 +53,7 @@ public final Class getRealType() { return this.getClass(); } + @JsonIgnore public String getEndpoint() { return endpoint; } diff --git a/sdk-common/src/main/java/com/worldline/sips/SIPS2Response.java b/sdk-common/src/main/java/com/worldline/sips/SIPS2Response.java index fb25342..1a97ca6 100644 --- a/sdk-common/src/main/java/com/worldline/sips/SIPS2Response.java +++ b/sdk-common/src/main/java/com/worldline/sips/SIPS2Response.java @@ -14,7 +14,7 @@ public void verifySeal(String secretKey) throws IncorrectSealException, SealCalc String correctSeal = SealCalculator.calculate( SealCalculator.getSealString(this), secretKey); if (! StringUtils.equals(correctSeal, seal)) { - throw new IncorrectSealException("The initialization response has been tampered with!"); + throw new IncorrectSealException("The response has been tampered with!"); } } } diff --git a/sdk-common/src/main/java/com/worldline/sips/helper/SortedReflectionToStringBuilder.java b/sdk-common/src/main/java/com/worldline/sips/helper/SortedReflectionToStringBuilder.java index b5a1f5c..6cbc08d 100644 --- a/sdk-common/src/main/java/com/worldline/sips/helper/SortedReflectionToStringBuilder.java +++ b/sdk-common/src/main/java/com/worldline/sips/helper/SortedReflectionToStringBuilder.java @@ -1,12 +1,13 @@ package com.worldline.sips.helper; -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; - -import java.lang.reflect.AccessibleObject; import java.lang.reflect.Field; +import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; +import java.util.List; +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import org.apache.commons.lang3.builder.ToStringSummary; public class SortedReflectionToStringBuilder extends ReflectionToStringBuilder { @@ -16,45 +17,55 @@ public SortedReflectionToStringBuilder(Object object, ToStringStyle style) { super(object, style); } - public void setComparator(Comparator comparator) { this.comparator = comparator; } - @Override - protected void appendFieldsIn(Class clazz) { - if (clazz.isArray()) { - this.reflectionAppendArray(this.getObject()); - return; - } - - Field[] fields = clazz.getDeclaredFields(); - - if (comparator != null) { - Arrays.sort(fields, comparator); - } - AccessibleObject.setAccessible(fields, true); - for (final Field field : fields) { - final String fieldName = field.getName(); - if (this.accept(field)) { - try { - // Warning: Field.get(Object) creates wrappers objects - // for primitive types. - final Object fieldValue = this.getValue(field); - if (!isExcludeNullValues() || fieldValue != null) { - this.append(fieldName, fieldValue); - } - } catch (final IllegalAccessException ex) { - //this can't happen. Would get a Security exception - // instead - //throw a runtime exception in case the impossible - // happens. - throw new InternalError("Unexpected IllegalAccessException: " + ex.getMessage()); - } - } + @Override + public String toString() { + if (this.getObject() == null) { + return super.toString(); + } + Class clazz = this.getObject().getClass(); + List allFields = getAllFields(clazz); + if (comparator != null) { + allFields.sort(comparator); + } + for (final Field field : allFields) { + final String fieldName = field.getName(); + if (this.accept(field)) { + try { + field.setAccessible(true); + // Warning: Field.get(Object) creates wrappers objects + // for primitive types. + final Object fieldValue = this.getValue(field); + if (!isExcludeNullValues() || fieldValue != null) { + this.append(fieldName, fieldValue, !field.isAnnotationPresent(ToStringSummary.class)); + } + } catch (final IllegalAccessException ex) { + //this can't happen. Would get a Security exception + // instead + //throw a runtime exception in case the impossible + // happens. + throw new InternalError("Unexpected IllegalAccessException: " + ex.getMessage()); } + } } + getStyle().appendEnd(this.getStringBuffer(), this.getObject()); + return this.getStringBuffer().toString(); + } + public static List getAllFields(Class type) { + List fields = new ArrayList<>(); + List> temp = new ArrayList<>(); + for (Class c = type; c != null; c = c.getSuperclass()) { + temp.add(Arrays.asList(c.getDeclaredFields())); + } + for (int i = temp.size() - 1; i >= 0; i--) { + fields.addAll(temp.get(i)); + } + return fields; + } } diff --git a/sdk-common/src/main/java/com/worldline/sips/security/SealCalculator.java b/sdk-common/src/main/java/com/worldline/sips/security/SealCalculator.java index 40e4b14..c74aec9 100644 --- a/sdk-common/src/main/java/com/worldline/sips/security/SealCalculator.java +++ b/sdk-common/src/main/java/com/worldline/sips/security/SealCalculator.java @@ -48,7 +48,7 @@ public static String calculate(String sealString, String key) throws SealCalcula */ public static String getSealString(SIPS2Request request) { ReflectionToStringBuilder reflectionToStringBuilder = new AlphabeticalReflectionToStringBuilder(request, new SealStringStyle()); - reflectionToStringBuilder.setExcludeFieldNames("keyVersion"); + reflectionToStringBuilder.setExcludeFieldNames("keyVersion", "endpoint"); reflectionToStringBuilder.setExcludeNullValues(true); reflectionToStringBuilder.setAppendStatics(true); return reflectionToStringBuilder.toString(); diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/WalletRequest.java b/wallet-sdk/src/main/java/com/worldline/sips/api/WalletRequest.java index bc7eb1e..41358b5 100644 --- a/wallet-sdk/src/main/java/com/worldline/sips/api/WalletRequest.java +++ b/wallet-sdk/src/main/java/com/worldline/sips/api/WalletRequest.java @@ -1,10 +1,18 @@ package com.worldline.sips.api; +import com.fasterxml.jackson.annotation.JsonInclude; import com.worldline.sips.SIPS2Request; public abstract class WalletRequest extends SIPS2Request { + private final String interfaceVersion = "WR_WS_2.39"; + public WalletRequest(String endpoint) { super("wallet/" + endpoint); } + + @JsonInclude + public String getInterfaceVersion() { + return interfaceVersion; + } } diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponse.java b/wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponse.java index 176aee6..e9bf714 100644 --- a/wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponse.java +++ b/wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponse.java @@ -4,5 +4,13 @@ public abstract class WalletResponse extends SIPS2Response { private String errorFieldName; + private WalletResponseCode walletResponseCode; + public String getErrorFieldName() { + return errorFieldName; + } + + public WalletResponseCode getWalletResponseCode() { + return walletResponseCode; + } } diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponseCode.java b/wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponseCode.java index 85fe6cb..6a130d6 100644 --- a/wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponseCode.java +++ b/wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponseCode.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonValue; import com.worldline.sips.exception.UnknownStatusException; +//FIXME add data type https://documentation.sips.worldline.com/en/WLSIPS.001-GD-Data-dictionary.html#Sips.001_DD_en-Value-responseCode_ public enum WalletResponseCode { /** * Successful operation @@ -22,6 +23,8 @@ public enum WalletResponseCode { */ UNKNOWN_WALLET("25"), FORMAT_ERROR("30"), + + FRAUD_SUSPECTED("34"), /** * MerchantId not allowed to access this wallet service */ @@ -38,6 +41,10 @@ public enum WalletResponseCode { private final String code; + WalletResponseCode(String code) { + this.code = code; + } + @JsonCreator public static WalletResponseCode fromCode(String code) throws UnknownStatusException { for (WalletResponseCode responseCode : WalletResponseCode.values()) { @@ -54,8 +61,9 @@ public String getCode() { return code; } - - WalletResponseCode(String code) { - this.code = code; + @Override + public String toString() { + return code; } + } diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/configuration/OfficeEnvironment.java b/wallet-sdk/src/main/java/com/worldline/sips/api/configuration/OfficeEnvironment.java index a11c7b4..7e9f984 100644 --- a/wallet-sdk/src/main/java/com/worldline/sips/api/configuration/OfficeEnvironment.java +++ b/wallet-sdk/src/main/java/com/worldline/sips/api/configuration/OfficeEnvironment.java @@ -11,7 +11,7 @@ public enum OfficeEnvironment implements SipsEnvironment { private final URI uri; OfficeEnvironment(String url) { - this.url = url + "/rs-services/v2/"; + this.url = url + "/rs-services/v2"; this.uri = URI.create(url); } diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java b/wallet-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java index 0d1064e..8ef161d 100644 --- a/wallet-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java +++ b/wallet-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java @@ -11,6 +11,6 @@ public class WalletPaymentMeanData { String paymentMeanAlias; PaymentMeanBrand paymentMeanBrand; String paymentMeanBrandCobadgedList; - PaymentMeanData paymentMeanData; + /*PaymentMeanData*/ String paymentMeanData; String transactionActors; } diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/model/response/GetWalletDataResponse.java b/wallet-sdk/src/main/java/com/worldline/sips/api/model/response/GetWalletDataResponse.java index 5202bc0..c234743 100644 --- a/wallet-sdk/src/main/java/com/worldline/sips/api/model/response/GetWalletDataResponse.java +++ b/wallet-sdk/src/main/java/com/worldline/sips/api/model/response/GetWalletDataResponse.java @@ -11,6 +11,17 @@ public class GetWalletDataResponse extends WalletResponse { private LocalDateTime walletCreationDateTime; private LocalDateTime walletLastActionDateTime; - private WalletResponseCode walletResponseCode; private List walletPaymentMeanDataList; + + public LocalDateTime getWalletCreationDateTime() { + return walletCreationDateTime; + } + + public LocalDateTime getWalletLastActionDateTime() { + return walletLastActionDateTime; + } + + public List getWalletPaymentMeanDataList() { + return walletPaymentMeanDataList; + } } diff --git a/wallet-sdk/src/test/java/com/worldline/sips/utils/SipsClientTest.java b/wallet-sdk/src/test/java/com/worldline/sips/utils/SipsClientTest.java deleted file mode 100644 index 96c4b5d..0000000 --- a/wallet-sdk/src/test/java/com/worldline/sips/utils/SipsClientTest.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.worldline.sips.utils; - -import com.worldline.sips.SipsClient; -import com.worldline.sips.api.configuration.OfficeEnvironment; -import com.worldline.sips.api.model.request.GetWalletDataRequest; -import com.worldline.sips.api.model.response.GetWalletDataResponse; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -public class SipsClientTest { - - private SipsClient sipsClient; - - @BeforeEach - public void setUp() throws Exception { - sipsClient = new SipsClient(OfficeEnvironment.TEST, "002001000000001", 1, "002001000000001_KEY1"); - } - - @Test - void testSendWalletRequest() throws Exception { - GetWalletDataResponse response = sipsClient.send(new GetWalletDataRequest("1")); - System.out.println(response); - } -} diff --git a/wallet-sdk/src/test/java/com/worldline/sips/utils/WalletSipsTest.java b/wallet-sdk/src/test/java/com/worldline/sips/utils/WalletSipsTest.java new file mode 100644 index 0000000..52cb019 --- /dev/null +++ b/wallet-sdk/src/test/java/com/worldline/sips/utils/WalletSipsTest.java @@ -0,0 +1,40 @@ +package com.worldline.sips.utils; + +import com.worldline.sips.SipsClient; +import com.worldline.sips.api.WalletResponseCode; +import com.worldline.sips.api.configuration.OfficeEnvironment; +import com.worldline.sips.api.model.request.GetWalletDataRequest; +import com.worldline.sips.api.model.response.GetWalletDataResponse; +import com.worldline.sips.util.ObjectMapperHolder; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class WalletSipsTest { + + private SipsClient sipsClient; + + @BeforeEach + public void setUp() throws Exception { + sipsClient = new SipsClient(OfficeEnvironment.TEST, "201040040170001", 1, "rxSP61eeP_oNi5TxCD7Ngy9YcwC8MLw6OlmFGGcsY54"); + } + + @Test + void testSendWalletRequest() throws Exception { + GetWalletDataResponse response = sipsClient.send(new GetWalletDataRequest("1")); + System.out.println(response); + } + + @Test + void testResponseDeserialization() throws Exception { + GetWalletDataResponse response = ObjectMapperHolder.INSTANCE.get().readerFor(GetWalletDataResponse.class) + .readValue("{\"seal\":\"1\"}"); + Assertions.assertEquals("1", response.getSeal()); + + + response = ObjectMapperHolder.INSTANCE.get().readerFor(GetWalletDataResponse.class) + .readValue("{\"walletResponseCode\":\"00\"}"); + Assertions.assertEquals(WalletResponseCode.SUCCESS, response.getWalletResponseCode()); + + } +} From f19a2e19fe623f21075140c8583878d192c447ee Mon Sep 17 00:00:00 2001 From: w112739 Date: Fri, 21 Jan 2022 13:22:41 +0100 Subject: [PATCH 04/15] [WIP] Add all payment mean brand --- .../sips/model/PaymentMeanBrand.java | 97 ++++++++++++++++++- .../sips/model}/PaymentMeanType.java | 5 +- 2 files changed, 99 insertions(+), 3 deletions(-) rename {payment-sdk/src/main/java/com/worldline/sips/model/data => sdk-common/src/main/java/com/worldline/sips/model}/PaymentMeanType.java (74%) diff --git a/sdk-common/src/main/java/com/worldline/sips/model/PaymentMeanBrand.java b/sdk-common/src/main/java/com/worldline/sips/model/PaymentMeanBrand.java index 1cb4fa4..f196ec0 100644 --- a/sdk-common/src/main/java/com/worldline/sips/model/PaymentMeanBrand.java +++ b/sdk-common/src/main/java/com/worldline/sips/model/PaymentMeanBrand.java @@ -1,5 +1,100 @@ package com.worldline.sips.model; +import static com.worldline.sips.model.PaymentMeanType.*; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonValue; +import com.worldline.sips.exception.UnknownStatusException; + public enum PaymentMeanBrand { - AMEX, BCMC, CB, CBCONLINE, ELV, IDEAL, IGNHOMEPAY, KBCONLINE, MAESTRO, MASTERCARD, MASTERPASS, PAYPAL, PAYTRAIL, SOFORTUBERWEISUNG, VISA, VPAY + _1EUROCOM(ONLINE_CREDIT), + _3XCBCOFINOGA(CARD), + ACCEPTGIRO(CREDIT_TRANSFER), + ACCORD(CARD), + ACCORD_KDO(CARD), + ACCORD_3X(ONLINE_CREDIT), + ACCORD_4X(ONLINE_CREDIT), + AMEX(CARD), + AURORE(CARD), + BCACB_3X(ONLINE_CREDIT), + BCACB_4X(ONLINE_CREDIT), + BCACUP(CARD), + BCMC(CARD), + CACF_3X(ONLINE_CREDIT), + CACF_4X(ONLINE_CREDIT), + CADHOC(CARD), + CADOCARTE(CARD), + CB(CARD), + CBCONLINE(CREDIT_TRANSFER), + CETELEM_3X(ONLINE_CREDIT), + CETELEM_4X(ONLINE_CREDIT), + COFIDIS_3X(ONLINE_CREDIT), + COFIDIS_4X(ONLINE_CREDIT), + CONECS(VOUCHER), + CUP(CARD), + CVA(CARD), + CVCO(VOUCHER), + DINNERS(CARD), + ECV(VOUCHER), + ELV(DIRECT_DEBIT), + FIVORY(WALLET), + FRANFINANCE_3X(ONLINE_CREDIT), + FRANFINANCE_4X(ONLINE_CREDIT), + GIROPAY(CREDIT_TRANSFER), + IDEAL(CREDIT_TRANSFER), + ILLICADO(CARD), + INCASSO(DIRECT_DEBIT), + IGNHOMEPAY(CREDIT_TRANSFER), + JCB(CARD), + KBCONLINE(CREDIT_TRANSFER), + LEPOTCOMMUN(CARD), + LYDIA(PROVIDER), + MAESTRO(CARD), + MASTERCARD(CARD), + MASTERPASS(EMPTY), + PASSCADO(CARD), + PAY_BY_BANK(CREDIT_TRANSFER), + PAYLIB(EMPTY), + PAYPAL(WALLET), + PAYTRAIL(CREDIT_TRANSFER), + POSTFINANCE(CARD), + PRESTO(ONLINE_CREDIT), + SEPA_DIRECT_DEBIT(DIRECT_DEBIT), + SOFINCO(CARD), + SOFORTUBERWEISUNG(CREDIT_TRANSFER), + SPIRITOFCADEAU(CARD), + VISA(CARD), + VISA_ELECTRON(CARD), + VPAY(CARD); + + final String realName; + final PaymentMeanType paymentMeanType; + + PaymentMeanBrand(PaymentMeanType paymentMeanType) { + String name = name(); + this.paymentMeanType = paymentMeanType; + this.realName = name.charAt(0) == '_' ? name.substring(1) : name; + } + + @JsonValue + public String getRealName() { + return this.realName; + } + + @JsonCreator + public static PaymentMeanBrand fromRealName(String string) throws UnknownStatusException { + for (PaymentMeanBrand responseCode : PaymentMeanBrand.values()) { + if (responseCode.getRealName().equals(string)) { + return responseCode; + } + } + + throw new UnknownStatusException(string + " is an unknown payment mean brand!"); + } + + @JsonIgnore + public PaymentMeanType getPaymentMeanType() { + return paymentMeanType; + } } diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/data/PaymentMeanType.java b/sdk-common/src/main/java/com/worldline/sips/model/PaymentMeanType.java similarity index 74% rename from payment-sdk/src/main/java/com/worldline/sips/model/data/PaymentMeanType.java rename to sdk-common/src/main/java/com/worldline/sips/model/PaymentMeanType.java index 341de7f..308338d 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/data/PaymentMeanType.java +++ b/sdk-common/src/main/java/com/worldline/sips/model/PaymentMeanType.java @@ -1,10 +1,11 @@ -package com.worldline.sips.model.data; +package com.worldline.sips.model; import com.fasterxml.jackson.annotation.JsonCreator; import org.apache.commons.lang3.StringUtils; public enum PaymentMeanType { - CARD, CREDIT_TRANSFER, DIRECT_DEBIT, EMPTY; + CARD, CREDIT_TRANSFER, DIRECT_DEBIT, + VOUCHER, WALLET, ONLINE_CREDIT, EMPTY, PROVIDER; @JsonCreator public static PaymentMeanType fromValue(String value) { From 7202f3235d023d3b4d8780afc18c55df6681e8b0 Mon Sep 17 00:00:00 2001 From: w112739 Date: Fri, 21 Jan 2022 13:31:58 +0100 Subject: [PATCH 05/15] [WIP] Add Delete Payment Mean Request --- .../sips/model/data/ResponseData.java | 1 + .../api/model/data/WalletPaymentMeanData.java | 46 ++++++++++++++++--- .../request/DeletePaymentMeanRequest.java | 38 +++++++++++++++ .../model/request/GetWalletDataRequest.java | 10 ++-- .../response/DeletePaymentMeanResponse.java | 14 ++++++ .../worldline/sips/utils/WalletSipsTest.java | 26 +++++++++++ 6 files changed, 124 insertions(+), 11 deletions(-) create mode 100644 wallet-sdk/src/main/java/com/worldline/sips/api/model/request/DeletePaymentMeanRequest.java create mode 100644 wallet-sdk/src/main/java/com/worldline/sips/api/model/response/DeletePaymentMeanResponse.java diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/data/ResponseData.java b/payment-sdk/src/main/java/com/worldline/sips/model/data/ResponseData.java index 19cb610..212aadb 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/data/ResponseData.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/data/ResponseData.java @@ -6,6 +6,7 @@ import com.worldline.sips.helper.RuleResultListDeserializer; import com.worldline.sips.model.PaymentMeanBrand; +import com.worldline.sips.model.PaymentMeanType; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.YearMonth; diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java b/wallet-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java index 8ef161d..9117a5c 100644 --- a/wallet-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java +++ b/wallet-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java @@ -6,11 +6,45 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class WalletPaymentMeanData { - String maskedPan; - YearMonth panExpiryDate; - String paymentMeanAlias; - PaymentMeanBrand paymentMeanBrand; - String paymentMeanBrandCobadgedList; + private String paymentMeanId; + //FIXME wtf ? + private String maskedPan; + private YearMonth panExpiryDate; + private String paymentMeanAlias; + private PaymentMeanBrand paymentMeanBrand; + private String paymentMeanBrandCobadgedList; /*PaymentMeanData*/ String paymentMeanData; - String transactionActors; + private String transactionActors; + + public String getPaymentMeanId() { + return paymentMeanId; + } + + public String getMaskedPan() { + return maskedPan; + } + + public YearMonth getPanExpiryDate() { + return panExpiryDate; + } + + public String getPaymentMeanAlias() { + return paymentMeanAlias; + } + + public PaymentMeanBrand getPaymentMeanBrand() { + return paymentMeanBrand; + } + + public String getPaymentMeanBrandCobadgedList() { + return paymentMeanBrandCobadgedList; + } + + public String getPaymentMeanData() { + return paymentMeanData; + } + + public String getTransactionActors() { + return transactionActors; + } } diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/model/request/DeletePaymentMeanRequest.java b/wallet-sdk/src/main/java/com/worldline/sips/api/model/request/DeletePaymentMeanRequest.java new file mode 100644 index 0000000..3f0ae51 --- /dev/null +++ b/wallet-sdk/src/main/java/com/worldline/sips/api/model/request/DeletePaymentMeanRequest.java @@ -0,0 +1,38 @@ +package com.worldline.sips.api.model.request; + +import com.worldline.sips.api.WalletRequest; +import com.worldline.sips.api.model.response.DeletePaymentMeanResponse; + +public class DeletePaymentMeanRequest extends WalletRequest { + + private final String merchantWalletId; + private final String paymentMeanId; + private String intermediateServiceProviderId; + + public DeletePaymentMeanRequest(String merchantWalletId, String paymentMeanId) { + super("deletePaymentMean"); + this.merchantWalletId = merchantWalletId; + this.paymentMeanId = paymentMeanId; + } + + public String getMerchantWalletId() { + return merchantWalletId; + } + + public String getPaymentMeanId() { + return paymentMeanId; + } + + public String getIntermediateServiceProviderId() { + return intermediateServiceProviderId; + } + + public void setIntermediateServiceProviderId(String intermediateServiceProviderId) { + this.intermediateServiceProviderId = intermediateServiceProviderId; + } + + @Override + public Class getResponseType() { + return DeletePaymentMeanResponse.class; + } +} diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/model/request/GetWalletDataRequest.java b/wallet-sdk/src/main/java/com/worldline/sips/api/model/request/GetWalletDataRequest.java index 12003e5..4e8a02c 100644 --- a/wallet-sdk/src/main/java/com/worldline/sips/api/model/request/GetWalletDataRequest.java +++ b/wallet-sdk/src/main/java/com/worldline/sips/api/model/request/GetWalletDataRequest.java @@ -13,11 +13,6 @@ public GetWalletDataRequest(String merchantWalletId) { this.merchantWalletId = merchantWalletId; } - @Override - public Class getResponseType() { - return GetWalletDataResponse.class; - } - public String getIntermediateServiceProviderId() { return intermediateServiceProviderId; } @@ -29,4 +24,9 @@ public void setIntermediateServiceProviderId(String intermediateServiceProviderI public String getMerchantWalletId() { return merchantWalletId; } + + @Override + public Class getResponseType() { + return GetWalletDataResponse.class; + } } diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/model/response/DeletePaymentMeanResponse.java b/wallet-sdk/src/main/java/com/worldline/sips/api/model/response/DeletePaymentMeanResponse.java new file mode 100644 index 0000000..cf644fe --- /dev/null +++ b/wallet-sdk/src/main/java/com/worldline/sips/api/model/response/DeletePaymentMeanResponse.java @@ -0,0 +1,14 @@ +package com.worldline.sips.api.model.response; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.worldline.sips.api.WalletResponse; +import java.time.LocalDateTime; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class DeletePaymentMeanResponse extends WalletResponse { + private LocalDateTime walletActionDateTime; + + public LocalDateTime getWalletActionDateTime() { + return walletActionDateTime; + } +} diff --git a/wallet-sdk/src/test/java/com/worldline/sips/utils/WalletSipsTest.java b/wallet-sdk/src/test/java/com/worldline/sips/utils/WalletSipsTest.java index 52cb019..03fb1e7 100644 --- a/wallet-sdk/src/test/java/com/worldline/sips/utils/WalletSipsTest.java +++ b/wallet-sdk/src/test/java/com/worldline/sips/utils/WalletSipsTest.java @@ -36,5 +36,31 @@ void testResponseDeserialization() throws Exception { .readValue("{\"walletResponseCode\":\"00\"}"); Assertions.assertEquals(WalletResponseCode.SUCCESS, response.getWalletResponseCode()); + + response = ObjectMapperHolder.INSTANCE.get().readerFor(GetWalletDataResponse.class) + .readValue("{\n" + + " \"walletCreationDateTime\": \"2013-12-23T05:17:26-12:00\",\n" + + " \"walletLastActionDateTime\": \"2014-01-19T23:16:00-12:00\",\n" + + " \"walletResponseCode\": \"00\",\n" + + " \"walletPaymentMeanDataList\": [\n" + + " {\n" + + " \"paymentMeanId\": \"14\",\n" + + " \"maskedPan\": \"4977##########02\",\n" + + " \"paymentMeanBrand\": \"SEPA_DIRECT_DEBIT\"\n" + + " },\n" + + " {\n" + + " \"paymentMeanId\": \"13\",\n" + + " \"maskedPan\": \"4977##########55\",\n" + + " \"paymentMeanAlias\": \"MySDD\",\n" + + " \"panExpiryDate\": \"201501\",\n" + + " \"paymentMeanBrand\": \"CB\"\n" + + " }\n" + + " ],\n" + + " \"seal\": \"4579cfc4044c29550327f9cba0be400129e95cb5b2639c6e301484930b4f9f94\"\n" + + "}"); + Assertions.assertEquals(WalletResponseCode.SUCCESS, response.getWalletResponseCode()); + + + } } From 542b41b110cfcd40ff16988d343a577f8f5a35df Mon Sep 17 00:00:00 2001 From: Jydet Date: Fri, 21 Jan 2022 17:50:35 +0100 Subject: [PATCH 06/15] [WIP] javadoc & formatting --- build.gradle | 18 +-- .../configuration/PaymentConfiguration.java | 7 +- .../configuration/PaymentEnvironment.java | 2 +- .../sips/model/request/PaymentRequest.java | 6 +- .../sips/api/SealCalculatorTest.java | 1 - .../java/com/worldline/sips/SIPS2Request.java | 63 +++++++---- .../com/worldline/sips/SIPS2Response.java | 23 +++- .../java/com/worldline/sips/SipsClient.java | 103 +++++++++--------- .../IncorrectProxyConfException.java | 1 + .../exception/IncorrectSealException.java | 1 + .../InvalidEnvironmentException.java | 1 + .../sips/exception/InvalidKeyException.java | 1 + .../exception/InvalidMerchantException.java | 1 + .../exception/SealCalculationException.java | 2 + .../sips/exception/SipsException.java | 1 + .../sips/exception/SipsRequestException.java | 1 + .../exception/UnknownStatusException.java | 2 + .../UnsupportedCurrencyException.java | 2 + .../UnsupportedLanguageException.java | 2 + ...AlphabeticalReflectionToStringBuilder.java | 1 - .../sips/helper/SealStringStyle.java | 7 +- .../SortedReflectionToStringBuilder.java | 7 +- .../worldline/sips/model/PaymentMeanType.java | 3 +- .../worldline/sips/model/SipsEnvironment.java | 3 + .../sips/security/SealCalculator.java | 5 +- .../com/worldline/sips/security/Sealable.java | 3 + .../sips/util/ObjectMapperHolder.java | 5 +- .../com/worldline/sips/api/WalletRequest.java | 5 +- .../configuration/OfficeConfiguration.java | 15 +++ 29 files changed, 193 insertions(+), 99 deletions(-) rename sdk-common/src/main/java/com/worldline/sips/configuration/Configuration.java => payment-sdk/src/main/java/com/worldline/sips/configuration/PaymentConfiguration.java (61%) create mode 100644 wallet-sdk/src/main/java/com/worldline/sips/api/configuration/OfficeConfiguration.java diff --git a/build.gradle b/build.gradle index d047c1d..7d2b4a6 100644 --- a/build.gradle +++ b/build.gradle @@ -57,15 +57,15 @@ allprojects { } } } - repositories { - maven { - url "https://oss.sonatype.org/service/local/staging/deploy/maven2" - credentials { - username sonatypeUsername - password sonatypePassword - } - } - } +// repositories { +// maven { +// url "https://oss.sonatype.org/service/local/staging/deploy/maven2" +// credentials { +// username sonatypeUsername +// password sonatypePassword +// } +// } +// } } signing { diff --git a/sdk-common/src/main/java/com/worldline/sips/configuration/Configuration.java b/payment-sdk/src/main/java/com/worldline/sips/configuration/PaymentConfiguration.java similarity index 61% rename from sdk-common/src/main/java/com/worldline/sips/configuration/Configuration.java rename to payment-sdk/src/main/java/com/worldline/sips/configuration/PaymentConfiguration.java index 70d1bda..0885b1b 100644 --- a/sdk-common/src/main/java/com/worldline/sips/configuration/Configuration.java +++ b/payment-sdk/src/main/java/com/worldline/sips/configuration/PaymentConfiguration.java @@ -1,12 +1,15 @@ package com.worldline.sips.configuration; -public class Configuration { +/** + * Container for global configuration values + */ +public class PaymentConfiguration { /** * The targeted version of the API */ public static final String INTERFACE_VERSION = "IR_WS_2.35"; - private Configuration() { + private PaymentConfiguration() { // Nothing to see here } } diff --git a/payment-sdk/src/main/java/com/worldline/sips/configuration/PaymentEnvironment.java b/payment-sdk/src/main/java/com/worldline/sips/configuration/PaymentEnvironment.java index 0f04f92..21473d2 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/configuration/PaymentEnvironment.java +++ b/payment-sdk/src/main/java/com/worldline/sips/configuration/PaymentEnvironment.java @@ -3,7 +3,7 @@ import com.worldline.sips.model.SipsEnvironment; /** - * The different environments available for the Worldline SIPS API. + * The different environments available for the Worldline SIPS payment API. */ public enum PaymentEnvironment implements SipsEnvironment { SIMU("https://payment-webinit.simu.sips-services.com/rs-services/v2/paymentInit"), diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/request/PaymentRequest.java b/payment-sdk/src/main/java/com/worldline/sips/model/request/PaymentRequest.java index 492b4f4..199d5c6 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/request/PaymentRequest.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/request/PaymentRequest.java @@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.worldline.sips.SIPS2Request; -import com.worldline.sips.configuration.Configuration; +import com.worldline.sips.configuration.PaymentConfiguration; import com.worldline.sips.model.data.Address; import com.worldline.sips.model.data.CaptureMode; @@ -24,12 +24,12 @@ * Request to initialize a session with the Worldline SIPS API. * The possible values of each field are described in the API doc. * - * @see Configuration + * @see PaymentConfiguration */ @JsonPropertyOrder(alphabetic = true) @JsonInclude(JsonInclude.Include.NON_EMPTY) public class PaymentRequest extends SIPS2Request { - private static final String INTERFACE_VERSION = Configuration.INTERFACE_VERSION; + private static final String INTERFACE_VERSION = PaymentConfiguration.INTERFACE_VERSION; private final TreeSet paymentMeanBrandList = new TreeSet<>(); diff --git a/payment-sdk/src/test/java/com/worldline/sips/api/SealCalculatorTest.java b/payment-sdk/src/test/java/com/worldline/sips/api/SealCalculatorTest.java index ae89d97..b620b71 100644 --- a/payment-sdk/src/test/java/com/worldline/sips/api/SealCalculatorTest.java +++ b/payment-sdk/src/test/java/com/worldline/sips/api/SealCalculatorTest.java @@ -1,6 +1,5 @@ package com.worldline.sips.api; -import com.worldline.sips.configuration.Configuration; import com.worldline.sips.exception.SealCalculationException; import com.worldline.sips.model.data.Address; import com.worldline.sips.model.data.Currency; diff --git a/sdk-common/src/main/java/com/worldline/sips/SIPS2Request.java b/sdk-common/src/main/java/com/worldline/sips/SIPS2Request.java index e848502..ec0c512 100644 --- a/sdk-common/src/main/java/com/worldline/sips/SIPS2Request.java +++ b/sdk-common/src/main/java/com/worldline/sips/SIPS2Request.java @@ -7,6 +7,13 @@ import com.worldline.sips.security.SealCalculator; import com.worldline.sips.security.Sealable; +/** + * An abstract object containing the basis of every SIPS requests + * @param the type of the response that should be returned by sending this request to SIPS + * + * @see Sealable + * @see SIPS2Response + */ @JsonPropertyOrder(alphabetic = true) @JsonInclude(JsonInclude.Include.NON_EMPTY) public abstract class SIPS2Request implements Sealable { @@ -14,42 +21,33 @@ public abstract class SIPS2Request implements Se private String merchantId; private Integer keyVersion; private String sealAlgorithm; - private final String endpoint; + /** + * @param endpoint the http endpoint targeted by this request + */ public SIPS2Request(String endpoint) { this.endpoint = endpoint; } - public String getMerchantId() { - return merchantId; - } - - public void setMerchantId(String merchantId) { - this.merchantId = merchantId; - } - - public Integer getKeyVersion() { - return keyVersion; - } - - public void setKeyVersion(Integer keyVersion) { - this.keyVersion = keyVersion; - } - - public String getSeal() { - return seal; - } - + /** + * Compute the seal of this request. + * + * @throws SealCalculationException when seal calculation fails, see inner exception for details. + */ public void calculateSeal(String secretKey) throws SealCalculationException { this.seal = SealCalculator.calculate(SealCalculator.getSealString(this), secretKey); } + /** + * Should be provided by subclasses to permit the deserialization of the response + * @return the response's type + */ @JsonIgnore public abstract Class getResponseType(); @JsonIgnore - public final Class getRealType() { + final Class getRealType() { return this.getClass(); } @@ -65,4 +63,25 @@ public String getSealAlgorithm() { public void setSealAlgorithm(String sealAlgorithm) { this.sealAlgorithm = sealAlgorithm; } + + public String getMerchantId() { + return merchantId; + } + + public void setMerchantId(String merchantId) { + this.merchantId = merchantId; + } + + public Integer getKeyVersion() { + return keyVersion; + } + + public void setKeyVersion(Integer keyVersion) { + this.keyVersion = keyVersion; + } + + public String getSeal() { + return seal; + } + } diff --git a/sdk-common/src/main/java/com/worldline/sips/SIPS2Response.java b/sdk-common/src/main/java/com/worldline/sips/SIPS2Response.java index 1a97ca6..f490a71 100644 --- a/sdk-common/src/main/java/com/worldline/sips/SIPS2Response.java +++ b/sdk-common/src/main/java/com/worldline/sips/SIPS2Response.java @@ -6,9 +6,19 @@ import com.worldline.sips.security.Sealable; import org.apache.commons.lang3.StringUtils; -public class SIPS2Response implements Sealable { +/** + * An abstract response from SIPS2 that contains the seal mechanism logic + */ +public abstract class SIPS2Response implements Sealable { private String seal; + /** + * Check that this object's data has not been tempered and is conformed to its {@link #seal} + * @param secretKey the secret key used to create this response (it is the same as the one use to create the request + * that induced this response + * @throws SealCalculationException if a seal calculation failed + * @throws IncorrectSealException if the response's seal is incorrect + */ public void verifySeal(String secretKey) throws IncorrectSealException, SealCalculationException { if (seal != null) { String correctSeal = SealCalculator.calculate( @@ -19,10 +29,21 @@ public void verifySeal(String secretKey) throws IncorrectSealException, SealCalc } } + /** + * @see Sealable + * @return this response's seal + */ public String getSeal() { return seal; } + /** + * Set the seal of this response + * @param seal the new seal + * @deprecated /!\ Using this method is discouraged and could lead to security false positives; + * do not use it if you are not sure of what you're doing + */ + @Deprecated public void setSeal(String seal) { this.seal = seal; } diff --git a/sdk-common/src/main/java/com/worldline/sips/SipsClient.java b/sdk-common/src/main/java/com/worldline/sips/SipsClient.java index 577d69d..c77207d 100644 --- a/sdk-common/src/main/java/com/worldline/sips/SipsClient.java +++ b/sdk-common/src/main/java/com/worldline/sips/SipsClient.java @@ -38,20 +38,20 @@ public class SipsClient { private final boolean proxyEnabled; private final String proxyHost; private final Integer proxyPort; - private String merchantId; - private Integer keyVersion; - private String secretKey; + private final String merchantId; + private final Integer keyVersion; + private final String secretKey; - /** FIXME javadoc - * Construct a new instance of the client for a given {@link SipsEnvironment} + /** + * Construct a new instance of the client for a given {@link SipsEnvironment}. * * @param environment the API environment to connect to. * @param merchantId the merchant's ID. * @param keyVersion the version of the secret key to use. * @param secretKey the merchant's secret key. - * @throws IncorrectProxyConfException when the proxy configuration is incorrect - * @throws InvalidEnvironmentException when an unknown environment is specified - * @throws com.worldline.sips.exception.InvalidKeyException when the key version is null, or a key is blank, empty or null. + * @throws IncorrectProxyConfException when the proxy configuration is incorrect. + * @throws InvalidEnvironmentException when an unknown environment is specified. + * @throws InvalidKeyException when the key version is null, or a key is blank, empty or null. * @throws InvalidMerchantException when the key version is null, or a key is blank, empty or null. */ public SipsClient(SipsEnvironment environment, String merchantId, Integer keyVersion, String secretKey) @@ -59,7 +59,22 @@ public SipsClient(SipsEnvironment environment, String merchantId, Integer keyVer this(environment, merchantId, keyVersion, secretKey, false, null, null); } - //FIXME javadoc + /** + * Construct a new instance of the client for a given {@link SipsEnvironment} with a defined proxy. + * + * @param environment the API environment to connect to. + * @param merchantId the merchant's ID. + * @param keyVersion the version of the secret key to use. + * @param secretKey the merchant's secret key. + * @param proxyEnabled true if a proxy configuration is provided. + * @param proxyHost the host of the proxy; if proxyEnabled is true this should net be blank, empty or null otherwise it should be null. + * @param proxyPort the port of the proxy; if proxyEnabled is true this should net be blank, empty or null otherwise it should be null. + * + * @throws IncorrectProxyConfException when the proxy configuration is incorrect. + * @throws InvalidEnvironmentException when an unknown environment is specified. + * @throws InvalidKeyException when the key version is null, or a key is blank, empty or null. + * @throws InvalidMerchantException when the key version is null, or a key is blank, empty or null. + */ public SipsClient(SipsEnvironment environment, String merchantId, Integer keyVersion, String secretKey, boolean proxyEnabled, String proxyHost, Integer proxyPort) throws InvalidEnvironmentException, IncorrectProxyConfException, InvalidMerchantException, InvalidKeyException { @@ -68,7 +83,7 @@ public SipsClient(SipsEnvironment environment, String merchantId, Integer keyVer } if (proxyEnabled) { - if(StringUtils.isBlank(proxyHost) || proxyPort == null){ + if (StringUtils.isBlank(proxyHost) || proxyPort == null){ throw new IncorrectProxyConfException("ProxyEnabled is true but proxyHost or proxyPort not filled"); } } @@ -93,25 +108,23 @@ public SipsClient(SipsEnvironment environment, String merchantId, Integer keyVer this.secretKey = secretKey; } - /** FIXME javadoc - * Initialize a session with the SIPS API for given parameters. - * This is always the first step in a payment process. + /** + * Send a request to sips and get the response synchronously. + * + * The seal of the request is calculated, the request is send, the response is received and its seal is checked. * - * @param paymentRequest the parameters to use during the requested session. - * @return The API 's response for the preformed request. - * @throws IncorrectSealException when the response has been tampered with. - * @throws PaymentInitializationException when initialization fails due to processing exceptions, see inner exception for details. - * @throws SealCalculationException when seal calculation fails, see inner excpetion for details. - * @see PaymentRequest - * @see InitializationResponse - * @see #verifySeal(InitializationResponse) + * @param request the request that will be sent to SIPS + * @throws SipsRequestException if an error occurred while serializing or sending the request + * @throws SipsException if an error occurred while receiving or deserializing the response + * @throws SealCalculationException if a seal calculation failed + * @throws IncorrectSealException if the response's seal is incorrect */ public Response send(SIPS2Request request) throws SipsRequestException, SipsException, SealCalculationException, IncorrectSealException { String fullPath = environment.getUrl() + "/" + request.getEndpoint(); try { HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); - if (this.proxyEnabled){ + if (this.proxyEnabled) { HttpHost httpHost = new HttpHost(this.proxyHost, this.proxyPort); httpClientBuilder.setProxy(httpHost); } @@ -143,49 +156,41 @@ public Response send(SIPS2Request req } } - /** FIXME javadoc - * Decode a payment response for further processing. After the payment is made, the API will preform a - * POST request to the URL as defined in the {@link PaymentRequest}. - * - * @param parameters the content of the received request, mapped as key-value pairs. - * @return The API 's response for the preformed payment. - * @throws IncorrectSealException when the response has been tampered with. - * @see PaypageResponse + /** + * Decode a SIPS response object from a map of parameters. + * + * @param responseClass the type of the response to construct + * @param parameters the content of the received request, mapped as key-value pairs. + * @param secretKey the secret key used to create the request that induced this response + * @return The constructed response. + * @throws IncorrectSealException - If the response has been tampered with. + * @throws IllegalArgumentException – If conversion fails due to incompatible type; if so, root cause will contain underlying + * checked exception data binding functionality threw */ - public Response decodeResponse(Class responseClass, Map parameters) throws IncorrectSealException { - verifySeal(parameters.get("Data"), parameters.get("Seal"), secretKey); - return ObjectMapperHolder.INSTANCE.get().copy() - .convertValue(parameters, responseClass); - } - //FIXME javadoc public static Response decodeResponse(Class responseClass, - Map parameters, String secretKey) throws IncorrectSealException { + Map parameters, String secretKey) throws IncorrectSealException, IllegalArgumentException { verifySeal(parameters.get("Data"), parameters.get("Seal"), secretKey); return ObjectMapperHolder.INSTANCE.get().copy() .convertValue(parameters, responseClass); } - /** FIXME javadoc - * Verify the seal of an initialization response. To avoid tampered responses when a session is initialized, + /** + * Verify the seal of an sips response. To avoid tampered responses, * the seal for the received response should always be verified before returning the object to the user. * * @param response the received response upon initialization * @throws IncorrectSealException when the received seal is different from the one calculated - * @throws SealCalculationException when seal calculation fails, see inner excpetion for details. + * @throws SealCalculationException when seal calculation fails, see inner exception for details. + * + * @see SIPS2Response#verifySeal(String) = identical */ private void verifySeal(SIPS2Response response) throws IncorrectSealException, SealCalculationException { - if (response.getSeal() != null) { - String correctSeal = SealCalculator.calculate( - SealCalculator.getSealString(response), secretKey); - if (!StringUtils.equals(correctSeal, response.getSeal())) { - throw new IncorrectSealException("The initialization response has been tampered with!"); - } - } + response.verifySeal(secretKey); } /** - * Verify the seal of a payment page response.To avoid tampered data for processed payments, + * Verify the seal of a sips response. To avoid tampered data, * the seal for the received response should always be verified before returning the object to the user. * * @param data the received response's Data attribute @@ -194,7 +199,7 @@ private void verifySeal(SIPS2Response response) throws IncorrectSealException, S */ private static void verifySeal(String data, String seal, String secretKey) throws IncorrectSealException { String correctSeal = DigestUtils.sha256Hex(data + secretKey); - if (!StringUtils.equals(correctSeal, seal)) { + if (! StringUtils.equals(correctSeal, seal)) { throw new IncorrectSealException("The payment page response has been tampered with!"); } } diff --git a/sdk-common/src/main/java/com/worldline/sips/exception/IncorrectProxyConfException.java b/sdk-common/src/main/java/com/worldline/sips/exception/IncorrectProxyConfException.java index 7e87073..96ac0bd 100644 --- a/sdk-common/src/main/java/com/worldline/sips/exception/IncorrectProxyConfException.java +++ b/sdk-common/src/main/java/com/worldline/sips/exception/IncorrectProxyConfException.java @@ -5,4 +5,5 @@ public class IncorrectProxyConfException extends Exception { public IncorrectProxyConfException(String message){ super(message); } + } diff --git a/sdk-common/src/main/java/com/worldline/sips/exception/IncorrectSealException.java b/sdk-common/src/main/java/com/worldline/sips/exception/IncorrectSealException.java index a466909..48cf107 100644 --- a/sdk-common/src/main/java/com/worldline/sips/exception/IncorrectSealException.java +++ b/sdk-common/src/main/java/com/worldline/sips/exception/IncorrectSealException.java @@ -5,4 +5,5 @@ public class IncorrectSealException extends Exception { public IncorrectSealException(String message) { super(message); } + } diff --git a/sdk-common/src/main/java/com/worldline/sips/exception/InvalidEnvironmentException.java b/sdk-common/src/main/java/com/worldline/sips/exception/InvalidEnvironmentException.java index c5f30c7..3f526de 100644 --- a/sdk-common/src/main/java/com/worldline/sips/exception/InvalidEnvironmentException.java +++ b/sdk-common/src/main/java/com/worldline/sips/exception/InvalidEnvironmentException.java @@ -5,4 +5,5 @@ public class InvalidEnvironmentException extends Exception { public InvalidEnvironmentException(String message) { super(message); } + } diff --git a/sdk-common/src/main/java/com/worldline/sips/exception/InvalidKeyException.java b/sdk-common/src/main/java/com/worldline/sips/exception/InvalidKeyException.java index 6d54406..d9c0f16 100644 --- a/sdk-common/src/main/java/com/worldline/sips/exception/InvalidKeyException.java +++ b/sdk-common/src/main/java/com/worldline/sips/exception/InvalidKeyException.java @@ -5,4 +5,5 @@ public class InvalidKeyException extends Exception { public InvalidKeyException(String message) { super(message); } + } diff --git a/sdk-common/src/main/java/com/worldline/sips/exception/InvalidMerchantException.java b/sdk-common/src/main/java/com/worldline/sips/exception/InvalidMerchantException.java index db1b2cd..16600d5 100644 --- a/sdk-common/src/main/java/com/worldline/sips/exception/InvalidMerchantException.java +++ b/sdk-common/src/main/java/com/worldline/sips/exception/InvalidMerchantException.java @@ -5,5 +5,6 @@ public class InvalidMerchantException extends Exception { public InvalidMerchantException(String message) { super(message); } + } diff --git a/sdk-common/src/main/java/com/worldline/sips/exception/SealCalculationException.java b/sdk-common/src/main/java/com/worldline/sips/exception/SealCalculationException.java index 5b33148..98d15ef 100644 --- a/sdk-common/src/main/java/com/worldline/sips/exception/SealCalculationException.java +++ b/sdk-common/src/main/java/com/worldline/sips/exception/SealCalculationException.java @@ -1,7 +1,9 @@ package com.worldline.sips.exception; public class SealCalculationException extends Exception { + public SealCalculationException(String message, Throwable cause) { super(message, cause); } + } diff --git a/sdk-common/src/main/java/com/worldline/sips/exception/SipsException.java b/sdk-common/src/main/java/com/worldline/sips/exception/SipsException.java index 736bfe3..8fcc8f1 100644 --- a/sdk-common/src/main/java/com/worldline/sips/exception/SipsException.java +++ b/sdk-common/src/main/java/com/worldline/sips/exception/SipsException.java @@ -5,4 +5,5 @@ public class SipsException extends Exception { public SipsException(String message, Throwable cause) { super(message, cause); } + } diff --git a/sdk-common/src/main/java/com/worldline/sips/exception/SipsRequestException.java b/sdk-common/src/main/java/com/worldline/sips/exception/SipsRequestException.java index 75fda5f..03b8854 100644 --- a/sdk-common/src/main/java/com/worldline/sips/exception/SipsRequestException.java +++ b/sdk-common/src/main/java/com/worldline/sips/exception/SipsRequestException.java @@ -5,4 +5,5 @@ public class SipsRequestException extends Exception { public SipsRequestException(String message, Throwable cause) { super(message, cause); } + } diff --git a/sdk-common/src/main/java/com/worldline/sips/exception/UnknownStatusException.java b/sdk-common/src/main/java/com/worldline/sips/exception/UnknownStatusException.java index eb16a1b..41c56bf 100644 --- a/sdk-common/src/main/java/com/worldline/sips/exception/UnknownStatusException.java +++ b/sdk-common/src/main/java/com/worldline/sips/exception/UnknownStatusException.java @@ -1,7 +1,9 @@ package com.worldline.sips.exception; public class UnknownStatusException extends Exception { + public UnknownStatusException(String message) { super(message); } + } diff --git a/sdk-common/src/main/java/com/worldline/sips/exception/UnsupportedCurrencyException.java b/sdk-common/src/main/java/com/worldline/sips/exception/UnsupportedCurrencyException.java index 1706e03..0cee7ed 100644 --- a/sdk-common/src/main/java/com/worldline/sips/exception/UnsupportedCurrencyException.java +++ b/sdk-common/src/main/java/com/worldline/sips/exception/UnsupportedCurrencyException.java @@ -1,7 +1,9 @@ package com.worldline.sips.exception; public class UnsupportedCurrencyException extends Exception { + public UnsupportedCurrencyException(String message) { super(message); } + } diff --git a/sdk-common/src/main/java/com/worldline/sips/exception/UnsupportedLanguageException.java b/sdk-common/src/main/java/com/worldline/sips/exception/UnsupportedLanguageException.java index 499e908..a2c31f8 100644 --- a/sdk-common/src/main/java/com/worldline/sips/exception/UnsupportedLanguageException.java +++ b/sdk-common/src/main/java/com/worldline/sips/exception/UnsupportedLanguageException.java @@ -1,7 +1,9 @@ package com.worldline.sips.exception; public class UnsupportedLanguageException extends Exception { + public UnsupportedLanguageException(String message) { super(message); } + } diff --git a/sdk-common/src/main/java/com/worldline/sips/helper/AlphabeticalReflectionToStringBuilder.java b/sdk-common/src/main/java/com/worldline/sips/helper/AlphabeticalReflectionToStringBuilder.java index 3d7b4d6..4e0e37f 100644 --- a/sdk-common/src/main/java/com/worldline/sips/helper/AlphabeticalReflectionToStringBuilder.java +++ b/sdk-common/src/main/java/com/worldline/sips/helper/AlphabeticalReflectionToStringBuilder.java @@ -9,5 +9,4 @@ public AlphabeticalReflectionToStringBuilder(Object object, ToStringStyle style) setComparator(new AlphabeticalFieldComparator()); } - } diff --git a/sdk-common/src/main/java/com/worldline/sips/helper/SealStringStyle.java b/sdk-common/src/main/java/com/worldline/sips/helper/SealStringStyle.java index a389c03..54d731b 100644 --- a/sdk-common/src/main/java/com/worldline/sips/helper/SealStringStyle.java +++ b/sdk-common/src/main/java/com/worldline/sips/helper/SealStringStyle.java @@ -6,7 +6,10 @@ import java.util.Arrays; - +/** + * A {@link RecursiveToStringStyle} parametrized to the seal format + * @see com.worldline.sips.security.Sealable + */ public final class SealStringStyle extends RecursiveToStringStyle { public SealStringStyle() { super(); @@ -41,6 +44,6 @@ protected void appendDetail(StringBuffer buffer, String fieldName, Object[] arra @Override protected boolean accept(Class clazz) { - return !clazz.isEnum() && clazz.getPackage().getName().startsWith("com.worldline"); + return ! clazz.isEnum() && clazz.getPackage().getName().startsWith("com.worldline"); } } diff --git a/sdk-common/src/main/java/com/worldline/sips/helper/SortedReflectionToStringBuilder.java b/sdk-common/src/main/java/com/worldline/sips/helper/SortedReflectionToStringBuilder.java index 6cbc08d..35587fa 100644 --- a/sdk-common/src/main/java/com/worldline/sips/helper/SortedReflectionToStringBuilder.java +++ b/sdk-common/src/main/java/com/worldline/sips/helper/SortedReflectionToStringBuilder.java @@ -55,7 +55,12 @@ public String toString() { return this.getStringBuffer().toString(); } - public static List getAllFields(Class type) { + /** + * Get all the fields of a given type (include private and inherited fields from the class hierarchy) + * @param type + * @return a list containing all the fields of the given type + */ + private static List getAllFields(Class type) { List fields = new ArrayList<>(); List> temp = new ArrayList<>(); for (Class c = type; c != null; c = c.getSuperclass()) { diff --git a/sdk-common/src/main/java/com/worldline/sips/model/PaymentMeanType.java b/sdk-common/src/main/java/com/worldline/sips/model/PaymentMeanType.java index 308338d..27ef74a 100644 --- a/sdk-common/src/main/java/com/worldline/sips/model/PaymentMeanType.java +++ b/sdk-common/src/main/java/com/worldline/sips/model/PaymentMeanType.java @@ -5,14 +5,13 @@ public enum PaymentMeanType { CARD, CREDIT_TRANSFER, DIRECT_DEBIT, - VOUCHER, WALLET, ONLINE_CREDIT, EMPTY, PROVIDER; + VOUCHER, WALLET, ONLINE_CREDIT, EMPTY, PROVIDER; @JsonCreator public static PaymentMeanType fromValue(String value) { if (StringUtils.isBlank(value)) { return PaymentMeanType.EMPTY; } - return PaymentMeanType.valueOf(value); } diff --git a/sdk-common/src/main/java/com/worldline/sips/model/SipsEnvironment.java b/sdk-common/src/main/java/com/worldline/sips/model/SipsEnvironment.java index 910e268..537872c 100644 --- a/sdk-common/src/main/java/com/worldline/sips/model/SipsEnvironment.java +++ b/sdk-common/src/main/java/com/worldline/sips/model/SipsEnvironment.java @@ -1,5 +1,8 @@ package com.worldline.sips.model; +/** + * Contains the target URL for a SIPS Environment + */ public interface SipsEnvironment { String getUrl(); } diff --git a/sdk-common/src/main/java/com/worldline/sips/security/SealCalculator.java b/sdk-common/src/main/java/com/worldline/sips/security/SealCalculator.java index c74aec9..d327c00 100644 --- a/sdk-common/src/main/java/com/worldline/sips/security/SealCalculator.java +++ b/sdk-common/src/main/java/com/worldline/sips/security/SealCalculator.java @@ -14,6 +14,10 @@ import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; +/** + * Utility class to compute seals. + * @see Sealable + */ public class SealCalculator { private SealCalculator() { // Nothing to see here @@ -37,7 +41,6 @@ public static String calculate(String sealString, String key) throws SealCalcula } catch (NoSuchAlgorithmException | InvalidKeyException e) { throw new SealCalculationException("Seal could not be calculated!", e); } - } /** diff --git a/sdk-common/src/main/java/com/worldline/sips/security/Sealable.java b/sdk-common/src/main/java/com/worldline/sips/security/Sealable.java index 2e506e0..fde4cda 100644 --- a/sdk-common/src/main/java/com/worldline/sips/security/Sealable.java +++ b/sdk-common/src/main/java/com/worldline/sips/security/Sealable.java @@ -1,5 +1,8 @@ package com.worldline.sips.security; +/** + * Something that contains a seal that validates its integrity + */ public interface Sealable { String getSeal(); diff --git a/sdk-common/src/main/java/com/worldline/sips/util/ObjectMapperHolder.java b/sdk-common/src/main/java/com/worldline/sips/util/ObjectMapperHolder.java index 193c44a..4d8b505 100644 --- a/sdk-common/src/main/java/com/worldline/sips/util/ObjectMapperHolder.java +++ b/sdk-common/src/main/java/com/worldline/sips/util/ObjectMapperHolder.java @@ -11,7 +11,10 @@ import java.time.YearMonth; import java.time.format.DateTimeFormatter; - +/** + * Container for the global mapper object instance + * @see ObjectMapper + */ public enum ObjectMapperHolder { INSTANCE; diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/WalletRequest.java b/wallet-sdk/src/main/java/com/worldline/sips/api/WalletRequest.java index 41358b5..bebf5d8 100644 --- a/wallet-sdk/src/main/java/com/worldline/sips/api/WalletRequest.java +++ b/wallet-sdk/src/main/java/com/worldline/sips/api/WalletRequest.java @@ -2,17 +2,16 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.worldline.sips.SIPS2Request; +import com.worldline.sips.api.configuration.OfficeConfiguration; public abstract class WalletRequest extends SIPS2Request { - private final String interfaceVersion = "WR_WS_2.39"; - public WalletRequest(String endpoint) { super("wallet/" + endpoint); } @JsonInclude public String getInterfaceVersion() { - return interfaceVersion; + return OfficeConfiguration.INTERFACE_VERSION; } } diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/configuration/OfficeConfiguration.java b/wallet-sdk/src/main/java/com/worldline/sips/api/configuration/OfficeConfiguration.java new file mode 100644 index 0000000..1314e71 --- /dev/null +++ b/wallet-sdk/src/main/java/com/worldline/sips/api/configuration/OfficeConfiguration.java @@ -0,0 +1,15 @@ +package com.worldline.sips.api.configuration; + +/** + * Container for global configuration values + */ +public class OfficeConfiguration { + /** + * The targeted version of the API + */ + public static final String INTERFACE_VERSION = "WR_WS_2.39"; + + private OfficeConfiguration() { + // Nothing to see here + } +} From 0b0a56bec28638a924df683dc7a8eb870b3d6862 Mon Sep 17 00:00:00 2001 From: Jydet Date: Fri, 21 Jan 2022 18:01:57 +0100 Subject: [PATCH 07/15] [WIP] formatting --- .../sips/helper/ResponseDataDeserializer.java | 10 +- .../sips/model/data/ResponseData.java | 3 +- .../sips/model/request/PaymentRequest.java | 22 +- .../response/InitializationResponse.java | 13 +- .../sips/model/response/PaypageResponse.java | 2 - .../worldline/sips/api/PaypageClientTest.java | 8 +- .../sips/api/SealCalculatorTest.java | 200 +++++------ .../java/com/worldline/sips/SIPS2Request.java | 111 +++--- .../com/worldline/sips/SIPS2Response.java | 68 ++-- .../java/com/worldline/sips/SipsClient.java | 340 +++++++++--------- .../IncorrectProxyConfException.java | 6 +- .../exception/IncorrectSealException.java | 6 +- .../InvalidEnvironmentException.java | 6 +- .../sips/exception/InvalidKeyException.java | 6 +- .../exception/InvalidMerchantException.java | 6 +- .../sips/exception/SipsException.java | 6 +- .../sips/exception/SipsRequestException.java | 6 +- .../sips/helper/SealStringStyle.java | 7 +- .../SortedReflectionToStringBuilder.java | 104 +++--- .../sips/model/PaymentMeanBrand.java | 175 ++++----- .../worldline/sips/model/SipsEnvironment.java | 2 +- .../sips/security/SealCalculator.java | 1 + .../com/worldline/sips/security/Sealable.java | 2 +- .../sips/util/ObjectMapperHolder.java | 3 +- .../com/worldline/sips/api/WalletRequest.java | 14 +- .../worldline/sips/api/WalletResponse.java | 16 +- .../sips/api/WalletResponseCode.java | 103 +++--- .../api/configuration/OfficeEnvironment.java | 29 +- .../api/model/data/WalletPaymentMeanData.java | 83 ++--- .../request/DeletePaymentMeanRequest.java | 60 ++-- .../model/request/GetWalletDataRequest.java | 48 +-- .../response/DeletePaymentMeanResponse.java | 9 +- .../model/response/GetWalletDataResponse.java | 26 +- .../worldline/sips/utils/WalletSipsTest.java | 83 +++-- 34 files changed, 805 insertions(+), 779 deletions(-) diff --git a/payment-sdk/src/main/java/com/worldline/sips/helper/ResponseDataDeserializer.java b/payment-sdk/src/main/java/com/worldline/sips/helper/ResponseDataDeserializer.java index 93b2670..1726049 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/helper/ResponseDataDeserializer.java +++ b/payment-sdk/src/main/java/com/worldline/sips/helper/ResponseDataDeserializer.java @@ -21,18 +21,18 @@ public ResponseData deserialize(JsonParser jsonParser, DeserializationContext de } final String value = jsonParser.getText().trim(); final Map mapped = Arrays.stream(value.split("\\|")) - .map(element -> element.split("=", 2)) - .filter(pair -> isNotNullOrEmpty(pair[1])) - .collect(Collectors.toMap(pair -> pair[0], pair -> pair[1])); + .map(element -> element.split("=", 2)) + .filter(pair -> isNotNullOrEmpty(pair[1])) + .collect(Collectors.toMap(pair -> pair[0], pair -> pair[1])); return ObjectMapperHolder.INSTANCE.get().copy() - .convertValue(mapped, ResponseData.class); + .convertValue(mapped, ResponseData.class); } private boolean isNotNullOrEmpty(final CharSequence cs) { - return !StringUtils.isBlank(cs) && !StringUtils.equals(cs, "null"); + return ! StringUtils.isBlank(cs) && ! StringUtils.equals(cs, "null"); } } diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/data/ResponseData.java b/payment-sdk/src/main/java/com/worldline/sips/model/data/ResponseData.java index 212aadb..46c30a5 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/data/ResponseData.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/data/ResponseData.java @@ -4,9 +4,9 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.worldline.sips.helper.BooleanDeserializer; import com.worldline.sips.helper.RuleResultListDeserializer; - import com.worldline.sips.model.PaymentMeanBrand; import com.worldline.sips.model.PaymentMeanType; + import java.time.LocalDate; import java.time.LocalDateTime; import java.time.YearMonth; @@ -75,7 +75,6 @@ public class ResponseData { private String returnContext; - public int getAmount() { return amount; } diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/request/PaymentRequest.java b/payment-sdk/src/main/java/com/worldline/sips/model/request/PaymentRequest.java index 199d5c6..6680a85 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/request/PaymentRequest.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/request/PaymentRequest.java @@ -5,7 +5,7 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.worldline.sips.SIPS2Request; import com.worldline.sips.configuration.PaymentConfiguration; - +import com.worldline.sips.model.PaymentMeanBrand; import com.worldline.sips.model.data.Address; import com.worldline.sips.model.data.CaptureMode; import com.worldline.sips.model.data.Contact; @@ -14,9 +14,9 @@ import com.worldline.sips.model.data.CustomerContact; import com.worldline.sips.model.data.Language; import com.worldline.sips.model.data.OrderChannel; -import com.worldline.sips.model.PaymentMeanBrand; import com.worldline.sips.model.data.PaypageData; import com.worldline.sips.model.response.InitializationResponse; + import java.net.URL; import java.util.TreeSet; @@ -65,11 +65,11 @@ public class PaymentRequest extends SIPS2Request { private String templateName; private PaypageData paypageData; - public PaymentRequest() { - super(""); - } + public PaymentRequest() { + super(""); + } - public Integer getAmount() { + public Integer getAmount() { return amount; } @@ -270,6 +270,10 @@ public String getOrderId() { return orderId; } + public void setOrderId(String orderId) { + this.orderId = orderId; + } + public String getReturnContext() { return returnContext; } @@ -286,10 +290,6 @@ public void setTransactionOrigin(String transactionOrigin) { this.transactionOrigin = transactionOrigin; } - public void setOrderId(String orderId) { - this.orderId = orderId; - } - public TreeSet getPaymentMeanBrandList() { return paymentMeanBrandList; } @@ -328,6 +328,6 @@ public void setPaypageData(PaypageData paypageData) { @Override public Class getResponseType() { - return InitializationResponse.class; + return InitializationResponse.class; } } diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/response/InitializationResponse.java b/payment-sdk/src/main/java/com/worldline/sips/model/response/InitializationResponse.java index 0e9bb9d..6f3f2c6 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/response/InitializationResponse.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/response/InitializationResponse.java @@ -3,6 +3,7 @@ import com.worldline.sips.SIPS2Response; import com.worldline.sips.model.data.RedirectionStatusCode; import com.worldline.sips.model.data.ResponseCode; + import java.net.URL; /** @@ -73,10 +74,10 @@ public void setResponseCode(ResponseCode responseCode) { this.responseCode = responseCode; } - @Override - public String toString() { - return String.format( - "InitializationResponse{errorFieldName='%s', redirectionData='%s', redirectionStatusCode=%s, redirectionStatusMessage='%s', redirectionUrl=%s, redirectionVersion='%s', responseCode=%s, seal='%s'}", - errorFieldName, redirectionData, redirectionStatusCode, redirectionStatusMessage, redirectionUrl, redirectionVersion, responseCode, getSeal()); - } + @Override + public String toString() { + return String.format( + "InitializationResponse{errorFieldName='%s', redirectionData='%s', redirectionStatusCode=%s, redirectionStatusMessage='%s', redirectionUrl=%s, redirectionVersion='%s', responseCode=%s, seal='%s'}", + errorFieldName, redirectionData, redirectionStatusCode, redirectionStatusMessage, redirectionUrl, redirectionVersion, responseCode, getSeal()); + } } diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/response/PaypageResponse.java b/payment-sdk/src/main/java/com/worldline/sips/model/response/PaypageResponse.java index b502c97..faaf4cc 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/response/PaypageResponse.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/response/PaypageResponse.java @@ -22,8 +22,6 @@ public class PaypageResponse extends SIPS2Response { private String encode; @JsonProperty("InterfaceVersion") private String interFaceVersion; -// @JsonProperty("Seal") -// private String seal; public ResponseData getData() { return data; diff --git a/payment-sdk/src/test/java/com/worldline/sips/api/PaypageClientTest.java b/payment-sdk/src/test/java/com/worldline/sips/api/PaypageClientTest.java index bcc8265..1d1a0b9 100644 --- a/payment-sdk/src/test/java/com/worldline/sips/api/PaypageClientTest.java +++ b/payment-sdk/src/test/java/com/worldline/sips/api/PaypageClientTest.java @@ -43,12 +43,12 @@ void setUp() throws Exception { } @Test - void testClientProxyException(){ - assertThrows(IncorrectProxyConfException.class,()-> new SipsClient(PaymentEnvironment.TEST, "002001000000001", 1, "002001000000001_KEY1", true, "monProxy", null)); + void testClientProxyException() { + assertThrows(IncorrectProxyConfException.class, () -> new SipsClient(PaymentEnvironment.TEST, "002001000000001", 1, "002001000000001_KEY1", true, "monProxy", null)); - assertThrows(IncorrectProxyConfException.class,()-> new SipsClient(PaymentEnvironment.TEST, "002001000000001", 1, "002001000000001_KEY1", true, "", 3128)); + assertThrows(IncorrectProxyConfException.class, () -> new SipsClient(PaymentEnvironment.TEST, "002001000000001", 1, "002001000000001_KEY1", true, "", 3128)); - assertThrows(IncorrectProxyConfException.class,()-> new SipsClient(PaymentEnvironment.TEST, "002001000000001", 1, "002001000000001_KEY1", true, null, null)); + assertThrows(IncorrectProxyConfException.class, () -> new SipsClient(PaymentEnvironment.TEST, "002001000000001", 1, "002001000000001_KEY1", true, null, null)); } @Test diff --git a/payment-sdk/src/test/java/com/worldline/sips/api/SealCalculatorTest.java b/payment-sdk/src/test/java/com/worldline/sips/api/SealCalculatorTest.java index b620b71..401f02b 100644 --- a/payment-sdk/src/test/java/com/worldline/sips/api/SealCalculatorTest.java +++ b/payment-sdk/src/test/java/com/worldline/sips/api/SealCalculatorTest.java @@ -1,11 +1,11 @@ package com.worldline.sips.api; import com.worldline.sips.exception.SealCalculationException; +import com.worldline.sips.model.PaymentMeanBrand; import com.worldline.sips.model.data.Address; import com.worldline.sips.model.data.Currency; import com.worldline.sips.model.data.CustomerAddress; import com.worldline.sips.model.data.CustomerContact; -import com.worldline.sips.model.PaymentMeanBrand; import com.worldline.sips.model.data.RedirectionStatusCode; import com.worldline.sips.model.request.PaymentRequest; import com.worldline.sips.model.response.InitializationResponse; @@ -21,103 +21,103 @@ class SealCalculatorTest { - private static final String ENCODED_REQUEST_SEAL = "198e5f278e3f8548e174e84492953c4871732278b7e2aa2cbf20bb1ab85914ea"; - private static final String ENCODED_RESPONSE_SEAL = "dd6eb8dd6c951b1ddc1af121007aaabe8ad4fda1d15ce386cfa455821d602025"; - private static final String DEMO_KEY = "superSafeSecretKey"; - private static final String RESPONSE_DEMO_KEY = "002001000000002_KEY1"; - - private PaymentRequest paymentRequest; - - @BeforeEach - void setUp() throws Exception { - paymentRequest = new PaymentRequest(); - paymentRequest.setAmount(10); - paymentRequest.setCustomerId("customerId"); - paymentRequest.setAutomaticResponseUrl(new URL("http://test.com")); - paymentRequest.setTemplateName("customCSS.css"); - } - - @Test - void getSealString() { - String actual = SealCalculator.getSealString(paymentRequest); - String expected = "10http://test.comcustomerIdIR_WS_2.35customCSS.css"; - assertEquals(expected, actual, "Sealstring is incorrect!"); - } - - @Test - void getSealString_with_Currency() { - paymentRequest.setCurrencyCode(Currency.EUR); - String actual = SealCalculator.getSealString(paymentRequest); - String expected = "10http://test.com978customerIdIR_WS_2.35customCSS.css"; - assertEquals(expected, actual, "Sealstring is incorrect!"); - } - - @Test - void getSealString_with_list() { - paymentRequest.getPaymentMeanBrandList().add(PaymentMeanBrand.VISA); - paymentRequest.getPaymentMeanBrandList().add(PaymentMeanBrand.BCMC); - String actual = SealCalculator.getSealString(paymentRequest); - String expected = "10http://test.comcustomerIdIR_WS_2.35BCMCVISAcustomCSS.css"; - assertEquals(expected, actual, "Sealstring is incorrect!"); - } - - @Test - void getSealString_with_Container() { - Address deliveryAddress = new Address(); - deliveryAddress.setZipcode("deliveryZipcode"); - deliveryAddress.setCompany("deliveryCompany"); - paymentRequest.setDeliveryAddress(deliveryAddress); - - CustomerAddress customerAddress = new CustomerAddress(); - customerAddress.setCity("customerCity"); - customerAddress.setBusinessName("customerBusinessName"); - paymentRequest.setCustomerAddress(customerAddress); - - CustomerContact customerContact = new CustomerContact(); - customerContact.setFirstName("firstName"); - customerContact.setLastName("lastName"); - paymentRequest.setCustomerContact(customerContact); - - String actual = SealCalculator.getSealString(paymentRequest); - String expected = "10http://test.comcustomerBusinessNamecustomerCityfirstNamelastNamecustomerIddeliveryCompanydeliveryZipcodeIR_WS_2.35customCSS.css"; - assertEquals(expected, actual, "Sealstring is incorrect!"); - } - - @Test - void getSealString_with_ignoredField() { - paymentRequest.setKeyVersion(200); - String actual = SealCalculator.getSealString(paymentRequest); - String expected = "10http://test.comcustomerIdIR_WS_2.35customCSS.css"; - assertEquals(expected, actual, "Sealstring is incorrect!"); - } - - @Test - void calculate() throws SealCalculationException { - String actual = SealCalculator.calculate("This is a test!", DEMO_KEY); - assertEquals(ENCODED_REQUEST_SEAL, actual, "Encoded seal is incorrect!"); - } - - @Test - void calculate_with_null_string() { - assertThrows(NullPointerException.class, () -> SealCalculator.calculate(null, DEMO_KEY), "No exception is thrown when string to encode is null!"); - } - - @Test - void calculate_with_null_key() { - assertThrows(NullPointerException.class, () -> SealCalculator.calculate("This is a test!", null), "No exception is thrown when string to encode is null!"); - } - - @Test - void calculate_response_seal() throws MalformedURLException, SealCalculationException { - InitializationResponse initializationResponse = new InitializationResponse(); - initializationResponse.setRedirectionStatusCode(RedirectionStatusCode.TRANSACTION_INITIALIZED); - initializationResponse.setRedirectionStatusMessage("INITIALISATION REQUEST ACCEPTED"); - initializationResponse.setRedirectionVersion("IR_WS_2.0"); - initializationResponse.setRedirectionUrl(new URL("https://payment-web.simu.sips-services.com/payment")); - initializationResponse.setRedirectionData("FTEx33MrE9Nc0gvtIS0aydJngXH8uuirg3ZpFD_KRM22C9e3IFDdBdSZB3kdQwcyIjWhKpM9mHYTCaCCy7Vm0YWrLscP-TJ895c2GXsTKlwEkO_VEU-2j2VGVcbYAKE9kcoV6jnVU5OJE1AMXEXnm1AkMrm3riB35p7x-WUdnaU0oKIhsit2M4_mci3fWH9WNTqo-A07qPd9-5zRKCr2F91Z8R4HogmLYdx_xh6BOyXKp693Smrq-2H64A2BOC6n89JQT-e9GNBM_up1YMa-vvS3-b6bMoZ01ngO7n2-NttxvXn78XEDDDVQfYZGPrpjywvDhGTfhBun1mdbSfzGPOwd6dcLre4Nguht3JCsT27EyLOxGEjCDwMjKJ0Gb2toChEMRv7TtX2SlXGMuyUr24oToHGbdt6zOm3q1R7XnCqnVYT_YNnNPf6lppQCW81FVvdX5zfbW65tQzja0CFC2ss-kyT0v4owm8LLNMy2rEU2JYnQQrT2qhQYf8lGxL2qkC0S1TpPLRzK-ry3mkEcBgwxFKbB2DX4kRamx4n6v_Yke2PS1PUPoWbdruRkK1mDJAJhSorV4O3LeeM1B3LkuPNU2xZw__I55zaOyIy2sWz52Su6gapGcsw8qTNOhcOwQi1sYaSGviCfKF75zC-GCjbHGoyHfO5RBswwmqBMNbVc7l2FIAw8ZDwn18E07pDWNeMwaeWYrYhR_n1BfhaW03H5TojvjnEMMSfd11nab0PjFE5zWB3r--OadfE7m-NqHL70WKLPYNfvKdzXzoI3ejc3SmWycXMpJgENZAFVzy4MojbVby3prA4IXQ_xSEisoWoGJb1Kg2LxEUih9Jqpi9vinH_nqt29lHFKnWSIuhT8UdsBYvFRGYyrbxPOOz1eNBqvHO49eI2hpKeL280_eR4HmLPiiDASog3BgDFB2_Ed6upm_N1PUEdQ1xmwXkiL7fqnaFABXySxsTVhxyRgXGSAmA0gmeYwFf7bGIKUc-FPwqWewDxRnIfnz6Eh3qDG41xEr5URpc0LCzzo5XjFt5h7wmp3FftmSai4rCFIM6B4Jd9lljeXgAMayzfig77_S_JMtEDw6oqzbX6QpBsKnfnrAtxk26LL07qB5Yw9qj-NEbWf28GOPN9--xY5AeUbya5nyNQiT-3TyebxnjUysTrTuq1DptPflIrUuIwAewT6K1I-XRYDpgdTRwWFzTIi2kItzGcbozxMJi0S6eJnOQNb9zNSrUBysDlSGVct1UsHqYQO56_-uyAwZ7lv23WIZdgbUaGELoPsba8Jg9rzR-aZ0zEe9owORSbAh5qkk0ByvOQniLqGYn36AJbKiSrSjRG1n9vBjjzffvsWOQHlG_tPV6WPVaXvanjaHrg_v2tjtqWPCUCRFg6seM4KiZ3G5-WPkPX0LW19iu4ypazFsfgElIfF7--XuN2wnrbf5tvPxpk-EHACkcFUQ7ozBw5xjRG1n9vBjjzffvsWOQHlGzGBbU3BAx_KVN_SQuZCNZ66O6O6FdOnZF_dC9vfuhZx5livIUUGTQOiFt4JQv_tJ3gl32WWN5eAAxrLN-KDvv_z_69h-FQfvm0DChFKn5h9Jb54QR0qamngPqTNqRQxNcmK3onHxmG7IIS9Gsltfie7sc4Lt9p_hqLAC28DDefH03yQ0l15QSQSA7t8x3rtGuflj5D19C1tfYruMqWsxbF_OuasNvoqSnJcHI_HyMMnf7eGnYHEcQk4vutjrpZhcH1TRZ3nQYrrxzId10uYeGeB7NXgInfbYearASIu2_vnMuJj1F84sjXcMM29qxh5KvOAaCle_EK7_SCamPY6SzkmTCyJprTaIBkhUUjUDdem4rN_XaLIav0orq8E4IwU740RtZ_bwY483377FjkB5RsKKPYjzvh_RlAEOH7vo0AIf7eGnYHEcQk4vutjrpZhcI0RtZ_bwY483377FjkB5Rv07-b-FhxhFkrKQcO0J0LIaKn33u4Hp88PYNHX40sIyNK3sqPZPiYGDU7q6T76kxla1JZwz-5wSgABK-wV16UlA1v3M1KtQHKwOVIZVy3VSwephA7nr_67IDBnuW_bdYjqqqfJtu70VoEtZOvxckajWtSWcM_ucEoAASvsFdelJcaipDQGiSLyw4gWeiGVvJAJHG6sS8x21XuBIuCbQ8l9Orcf_-QEVEHjGdswxxpSUovuFIRWVkRniMqau0PF2uF2Vi5vBX5AQYvblDS0I-Nk5mOOxtF3rdTMKSdmHaylZGleYPX4zPU6HmEV4ipdMcHx_vB89SS_gwRtQ9PWLJh3HJwvIO2GJs6lrufoKpeHVk9jne_ybEoDL1qOawB6ESQK5q5UXSwdR3YaB8M0qw-UPPibFlDSsbVF-zNvfbA8IBQL83Jj6EwBHBwT0RHvrvQ9-0nLg03cckYVc3IJh-dMok6Z5Ga3fsi_953xGMoOX4_z-gTn5pXhDYgI-0g_CKeAtgLeNsxz-PlTwW_U_kfW6Q3V7HDgOi-QZxxNSTMSkQpAdC3JcbHIGuEHVGxs5zWWT5tmsYkXbS11VEduPVXb9NpuUzUB5GLL8W3y9w3hTgLI1bKcCSsF4b3mgLEwNNGbEzYudvCLn3MP8g5BKQ-GlMMZU93_ANjsgNXUNK3j0SHC1NaycxVaWqmVP9uWp1U"); - - String sealString = SealCalculator.getSealString(initializationResponse); - String actual = SealCalculator.calculate(sealString, RESPONSE_DEMO_KEY); - assertEquals(ENCODED_RESPONSE_SEAL, actual, "Encoded seal is incorrect!"); - } + private static final String ENCODED_REQUEST_SEAL = "198e5f278e3f8548e174e84492953c4871732278b7e2aa2cbf20bb1ab85914ea"; + private static final String ENCODED_RESPONSE_SEAL = "dd6eb8dd6c951b1ddc1af121007aaabe8ad4fda1d15ce386cfa455821d602025"; + private static final String DEMO_KEY = "superSafeSecretKey"; + private static final String RESPONSE_DEMO_KEY = "002001000000002_KEY1"; + + private PaymentRequest paymentRequest; + + @BeforeEach + void setUp() throws Exception { + paymentRequest = new PaymentRequest(); + paymentRequest.setAmount(10); + paymentRequest.setCustomerId("customerId"); + paymentRequest.setAutomaticResponseUrl(new URL("http://test.com")); + paymentRequest.setTemplateName("customCSS.css"); + } + + @Test + void getSealString() { + String actual = SealCalculator.getSealString(paymentRequest); + String expected = "10http://test.comcustomerIdIR_WS_2.35customCSS.css"; + assertEquals(expected, actual, "Sealstring is incorrect!"); + } + + @Test + void getSealString_with_Currency() { + paymentRequest.setCurrencyCode(Currency.EUR); + String actual = SealCalculator.getSealString(paymentRequest); + String expected = "10http://test.com978customerIdIR_WS_2.35customCSS.css"; + assertEquals(expected, actual, "Sealstring is incorrect!"); + } + + @Test + void getSealString_with_list() { + paymentRequest.getPaymentMeanBrandList().add(PaymentMeanBrand.VISA); + paymentRequest.getPaymentMeanBrandList().add(PaymentMeanBrand.BCMC); + String actual = SealCalculator.getSealString(paymentRequest); + String expected = "10http://test.comcustomerIdIR_WS_2.35BCMCVISAcustomCSS.css"; + assertEquals(expected, actual, "Sealstring is incorrect!"); + } + + @Test + void getSealString_with_Container() { + Address deliveryAddress = new Address(); + deliveryAddress.setZipcode("deliveryZipcode"); + deliveryAddress.setCompany("deliveryCompany"); + paymentRequest.setDeliveryAddress(deliveryAddress); + + CustomerAddress customerAddress = new CustomerAddress(); + customerAddress.setCity("customerCity"); + customerAddress.setBusinessName("customerBusinessName"); + paymentRequest.setCustomerAddress(customerAddress); + + CustomerContact customerContact = new CustomerContact(); + customerContact.setFirstName("firstName"); + customerContact.setLastName("lastName"); + paymentRequest.setCustomerContact(customerContact); + + String actual = SealCalculator.getSealString(paymentRequest); + String expected = "10http://test.comcustomerBusinessNamecustomerCityfirstNamelastNamecustomerIddeliveryCompanydeliveryZipcodeIR_WS_2.35customCSS.css"; + assertEquals(expected, actual, "Sealstring is incorrect!"); + } + + @Test + void getSealString_with_ignoredField() { + paymentRequest.setKeyVersion(200); + String actual = SealCalculator.getSealString(paymentRequest); + String expected = "10http://test.comcustomerIdIR_WS_2.35customCSS.css"; + assertEquals(expected, actual, "Sealstring is incorrect!"); + } + + @Test + void calculate() throws SealCalculationException { + String actual = SealCalculator.calculate("This is a test!", DEMO_KEY); + assertEquals(ENCODED_REQUEST_SEAL, actual, "Encoded seal is incorrect!"); + } + + @Test + void calculate_with_null_string() { + assertThrows(NullPointerException.class, () -> SealCalculator.calculate(null, DEMO_KEY), "No exception is thrown when string to encode is null!"); + } + + @Test + void calculate_with_null_key() { + assertThrows(NullPointerException.class, () -> SealCalculator.calculate("This is a test!", null), "No exception is thrown when string to encode is null!"); + } + + @Test + void calculate_response_seal() throws MalformedURLException, SealCalculationException { + InitializationResponse initializationResponse = new InitializationResponse(); + initializationResponse.setRedirectionStatusCode(RedirectionStatusCode.TRANSACTION_INITIALIZED); + initializationResponse.setRedirectionStatusMessage("INITIALISATION REQUEST ACCEPTED"); + initializationResponse.setRedirectionVersion("IR_WS_2.0"); + initializationResponse.setRedirectionUrl(new URL("https://payment-web.simu.sips-services.com/payment")); + initializationResponse.setRedirectionData("FTEx33MrE9Nc0gvtIS0aydJngXH8uuirg3ZpFD_KRM22C9e3IFDdBdSZB3kdQwcyIjWhKpM9mHYTCaCCy7Vm0YWrLscP-TJ895c2GXsTKlwEkO_VEU-2j2VGVcbYAKE9kcoV6jnVU5OJE1AMXEXnm1AkMrm3riB35p7x-WUdnaU0oKIhsit2M4_mci3fWH9WNTqo-A07qPd9-5zRKCr2F91Z8R4HogmLYdx_xh6BOyXKp693Smrq-2H64A2BOC6n89JQT-e9GNBM_up1YMa-vvS3-b6bMoZ01ngO7n2-NttxvXn78XEDDDVQfYZGPrpjywvDhGTfhBun1mdbSfzGPOwd6dcLre4Nguht3JCsT27EyLOxGEjCDwMjKJ0Gb2toChEMRv7TtX2SlXGMuyUr24oToHGbdt6zOm3q1R7XnCqnVYT_YNnNPf6lppQCW81FVvdX5zfbW65tQzja0CFC2ss-kyT0v4owm8LLNMy2rEU2JYnQQrT2qhQYf8lGxL2qkC0S1TpPLRzK-ry3mkEcBgwxFKbB2DX4kRamx4n6v_Yke2PS1PUPoWbdruRkK1mDJAJhSorV4O3LeeM1B3LkuPNU2xZw__I55zaOyIy2sWz52Su6gapGcsw8qTNOhcOwQi1sYaSGviCfKF75zC-GCjbHGoyHfO5RBswwmqBMNbVc7l2FIAw8ZDwn18E07pDWNeMwaeWYrYhR_n1BfhaW03H5TojvjnEMMSfd11nab0PjFE5zWB3r--OadfE7m-NqHL70WKLPYNfvKdzXzoI3ejc3SmWycXMpJgENZAFVzy4MojbVby3prA4IXQ_xSEisoWoGJb1Kg2LxEUih9Jqpi9vinH_nqt29lHFKnWSIuhT8UdsBYvFRGYyrbxPOOz1eNBqvHO49eI2hpKeL280_eR4HmLPiiDASog3BgDFB2_Ed6upm_N1PUEdQ1xmwXkiL7fqnaFABXySxsTVhxyRgXGSAmA0gmeYwFf7bGIKUc-FPwqWewDxRnIfnz6Eh3qDG41xEr5URpc0LCzzo5XjFt5h7wmp3FftmSai4rCFIM6B4Jd9lljeXgAMayzfig77_S_JMtEDw6oqzbX6QpBsKnfnrAtxk26LL07qB5Yw9qj-NEbWf28GOPN9--xY5AeUbya5nyNQiT-3TyebxnjUysTrTuq1DptPflIrUuIwAewT6K1I-XRYDpgdTRwWFzTIi2kItzGcbozxMJi0S6eJnOQNb9zNSrUBysDlSGVct1UsHqYQO56_-uyAwZ7lv23WIZdgbUaGELoPsba8Jg9rzR-aZ0zEe9owORSbAh5qkk0ByvOQniLqGYn36AJbKiSrSjRG1n9vBjjzffvsWOQHlG_tPV6WPVaXvanjaHrg_v2tjtqWPCUCRFg6seM4KiZ3G5-WPkPX0LW19iu4ypazFsfgElIfF7--XuN2wnrbf5tvPxpk-EHACkcFUQ7ozBw5xjRG1n9vBjjzffvsWOQHlGzGBbU3BAx_KVN_SQuZCNZ66O6O6FdOnZF_dC9vfuhZx5livIUUGTQOiFt4JQv_tJ3gl32WWN5eAAxrLN-KDvv_z_69h-FQfvm0DChFKn5h9Jb54QR0qamngPqTNqRQxNcmK3onHxmG7IIS9Gsltfie7sc4Lt9p_hqLAC28DDefH03yQ0l15QSQSA7t8x3rtGuflj5D19C1tfYruMqWsxbF_OuasNvoqSnJcHI_HyMMnf7eGnYHEcQk4vutjrpZhcH1TRZ3nQYrrxzId10uYeGeB7NXgInfbYearASIu2_vnMuJj1F84sjXcMM29qxh5KvOAaCle_EK7_SCamPY6SzkmTCyJprTaIBkhUUjUDdem4rN_XaLIav0orq8E4IwU740RtZ_bwY483377FjkB5RsKKPYjzvh_RlAEOH7vo0AIf7eGnYHEcQk4vutjrpZhcI0RtZ_bwY483377FjkB5Rv07-b-FhxhFkrKQcO0J0LIaKn33u4Hp88PYNHX40sIyNK3sqPZPiYGDU7q6T76kxla1JZwz-5wSgABK-wV16UlA1v3M1KtQHKwOVIZVy3VSwephA7nr_67IDBnuW_bdYjqqqfJtu70VoEtZOvxckajWtSWcM_ucEoAASvsFdelJcaipDQGiSLyw4gWeiGVvJAJHG6sS8x21XuBIuCbQ8l9Orcf_-QEVEHjGdswxxpSUovuFIRWVkRniMqau0PF2uF2Vi5vBX5AQYvblDS0I-Nk5mOOxtF3rdTMKSdmHaylZGleYPX4zPU6HmEV4ipdMcHx_vB89SS_gwRtQ9PWLJh3HJwvIO2GJs6lrufoKpeHVk9jne_ybEoDL1qOawB6ESQK5q5UXSwdR3YaB8M0qw-UPPibFlDSsbVF-zNvfbA8IBQL83Jj6EwBHBwT0RHvrvQ9-0nLg03cckYVc3IJh-dMok6Z5Ga3fsi_953xGMoOX4_z-gTn5pXhDYgI-0g_CKeAtgLeNsxz-PlTwW_U_kfW6Q3V7HDgOi-QZxxNSTMSkQpAdC3JcbHIGuEHVGxs5zWWT5tmsYkXbS11VEduPVXb9NpuUzUB5GLL8W3y9w3hTgLI1bKcCSsF4b3mgLEwNNGbEzYudvCLn3MP8g5BKQ-GlMMZU93_ANjsgNXUNK3j0SHC1NaycxVaWqmVP9uWp1U"); + + String sealString = SealCalculator.getSealString(initializationResponse); + String actual = SealCalculator.calculate(sealString, RESPONSE_DEMO_KEY); + assertEquals(ENCODED_RESPONSE_SEAL, actual, "Encoded seal is incorrect!"); + } } diff --git a/sdk-common/src/main/java/com/worldline/sips/SIPS2Request.java b/sdk-common/src/main/java/com/worldline/sips/SIPS2Request.java index ec0c512..97951d1 100644 --- a/sdk-common/src/main/java/com/worldline/sips/SIPS2Request.java +++ b/sdk-common/src/main/java/com/worldline/sips/SIPS2Request.java @@ -9,79 +9,80 @@ /** * An abstract object containing the basis of every SIPS requests - * @param the type of the response that should be returned by sending this request to SIPS * + * @param the type of the response that should be returned by sending this request to SIPS * @see Sealable * @see SIPS2Response */ @JsonPropertyOrder(alphabetic = true) @JsonInclude(JsonInclude.Include.NON_EMPTY) public abstract class SIPS2Request implements Sealable { - private String seal; - private String merchantId; - private Integer keyVersion; - private String sealAlgorithm; - private final String endpoint; + private final String endpoint; + private String seal; + private String merchantId; + private Integer keyVersion; + private String sealAlgorithm; - /** - * @param endpoint the http endpoint targeted by this request - */ - public SIPS2Request(String endpoint) { - this.endpoint = endpoint; - } + /** + * @param endpoint the http endpoint targeted by this request + */ + public SIPS2Request(String endpoint) { + this.endpoint = endpoint; + } - /** - * Compute the seal of this request. - * - * @throws SealCalculationException when seal calculation fails, see inner exception for details. - */ - public void calculateSeal(String secretKey) throws SealCalculationException { - this.seal = SealCalculator.calculate(SealCalculator.getSealString(this), secretKey); - } + /** + * Compute the seal of this request. + * + * @throws SealCalculationException when seal calculation fails, see inner exception for details. + */ + public void calculateSeal(String secretKey) throws SealCalculationException { + this.seal = SealCalculator.calculate(SealCalculator.getSealString(this), secretKey); + } - /** - * Should be provided by subclasses to permit the deserialization of the response - * @return the response's type - */ - @JsonIgnore - public abstract Class getResponseType(); + /** + * Should be provided by subclasses to permit the deserialization of the response + * + * @return the response's type + */ + @JsonIgnore + public abstract Class getResponseType(); - @JsonIgnore - final Class getRealType() { - return this.getClass(); - } + @JsonIgnore + final Class getRealType() { + return this.getClass(); + } - @JsonIgnore - public String getEndpoint() { - return endpoint; - } + @JsonIgnore + public String getEndpoint() { + return endpoint; + } - public String getSealAlgorithm() { - return sealAlgorithm; - } + public String getSealAlgorithm() { + return sealAlgorithm; + } - public void setSealAlgorithm(String sealAlgorithm) { - this.sealAlgorithm = sealAlgorithm; - } + public void setSealAlgorithm(String sealAlgorithm) { + this.sealAlgorithm = sealAlgorithm; + } - public String getMerchantId() { - return merchantId; - } + public String getMerchantId() { + return merchantId; + } - public void setMerchantId(String merchantId) { - this.merchantId = merchantId; - } + public void setMerchantId(String merchantId) { + this.merchantId = merchantId; + } - public Integer getKeyVersion() { - return keyVersion; - } + public Integer getKeyVersion() { + return keyVersion; + } - public void setKeyVersion(Integer keyVersion) { - this.keyVersion = keyVersion; - } + public void setKeyVersion(Integer keyVersion) { + this.keyVersion = keyVersion; + } - public String getSeal() { - return seal; - } + public String getSeal() { + return seal; + } } diff --git a/sdk-common/src/main/java/com/worldline/sips/SIPS2Response.java b/sdk-common/src/main/java/com/worldline/sips/SIPS2Response.java index f490a71..262c038 100644 --- a/sdk-common/src/main/java/com/worldline/sips/SIPS2Response.java +++ b/sdk-common/src/main/java/com/worldline/sips/SIPS2Response.java @@ -10,41 +10,43 @@ * An abstract response from SIPS2 that contains the seal mechanism logic */ public abstract class SIPS2Response implements Sealable { - private String seal; + private String seal; - /** - * Check that this object's data has not been tempered and is conformed to its {@link #seal} - * @param secretKey the secret key used to create this response (it is the same as the one use to create the request - * that induced this response - * @throws SealCalculationException if a seal calculation failed - * @throws IncorrectSealException if the response's seal is incorrect - */ - public void verifySeal(String secretKey) throws IncorrectSealException, SealCalculationException { - if (seal != null) { - String correctSeal = SealCalculator.calculate( - SealCalculator.getSealString(this), secretKey); - if (! StringUtils.equals(correctSeal, seal)) { - throw new IncorrectSealException("The response has been tampered with!"); - } + /** + * Check that this object's data has not been tempered and is conformed to its {@link #seal} + * + * @param secretKey the secret key used to create this response (it is the same as the one use to create the request + * that induced this response + * @throws SealCalculationException if a seal calculation failed + * @throws IncorrectSealException if the response's seal is incorrect + */ + public void verifySeal(String secretKey) throws IncorrectSealException, SealCalculationException { + if (seal != null) { + String correctSeal = SealCalculator.calculate( + SealCalculator.getSealString(this), secretKey); + if (! StringUtils.equals(correctSeal, seal)) { + throw new IncorrectSealException("The response has been tampered with!"); + } + } } - } - /** - * @see Sealable - * @return this response's seal - */ - public String getSeal() { - return seal; - } + /** + * @return this response's seal + * @see Sealable + */ + public String getSeal() { + return seal; + } - /** - * Set the seal of this response - * @param seal the new seal - * @deprecated /!\ Using this method is discouraged and could lead to security false positives; - * do not use it if you are not sure of what you're doing - */ - @Deprecated - public void setSeal(String seal) { - this.seal = seal; - } + /** + * Set the seal of this response + * + * @param seal the new seal + * @deprecated /!\ Using this method is discouraged and could lead to security false positives; + * do not use it if you are not sure of what you're doing + */ + @Deprecated + public void setSeal(String seal) { + this.seal = seal; + } } diff --git a/sdk-common/src/main/java/com/worldline/sips/SipsClient.java b/sdk-common/src/main/java/com/worldline/sips/SipsClient.java index c77207d..e2cb8df 100644 --- a/sdk-common/src/main/java/com/worldline/sips/SipsClient.java +++ b/sdk-common/src/main/java/com/worldline/sips/SipsClient.java @@ -10,13 +10,7 @@ import com.worldline.sips.exception.SipsException; import com.worldline.sips.exception.SipsRequestException; import com.worldline.sips.model.SipsEnvironment; -import com.worldline.sips.security.SealCalculator; import com.worldline.sips.util.ObjectMapperHolder; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.security.InvalidKeyException; -import java.util.Map; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang3.StringUtils; import org.apache.hc.client5.http.classic.methods.HttpPost; @@ -29,178 +23,196 @@ import org.apache.hc.core5.http.io.entity.EntityUtils; import org.apache.hc.core5.http.io.entity.StringEntity; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.security.InvalidKeyException; +import java.util.Map; + /** * Interact with SIPS APIs. */ public class SipsClient { - private final SipsEnvironment environment; - private final boolean proxyEnabled; - private final String proxyHost; - private final Integer proxyPort; - private final String merchantId; - private final Integer keyVersion; - private final String secretKey; - - /** - * Construct a new instance of the client for a given {@link SipsEnvironment}. - * - * @param environment the API environment to connect to. - * @param merchantId the merchant's ID. - * @param keyVersion the version of the secret key to use. - * @param secretKey the merchant's secret key. - * @throws IncorrectProxyConfException when the proxy configuration is incorrect. - * @throws InvalidEnvironmentException when an unknown environment is specified. - * @throws InvalidKeyException when the key version is null, or a key is blank, empty or null. - * @throws InvalidMerchantException when the key version is null, or a key is blank, empty or null. - */ - public SipsClient(SipsEnvironment environment, String merchantId, Integer keyVersion, String secretKey) - throws InvalidEnvironmentException, IncorrectProxyConfException, InvalidMerchantException, InvalidKeyException { - this(environment, merchantId, keyVersion, secretKey, false, null, null); - } - - /** - * Construct a new instance of the client for a given {@link SipsEnvironment} with a defined proxy. - * - * @param environment the API environment to connect to. - * @param merchantId the merchant's ID. - * @param keyVersion the version of the secret key to use. - * @param secretKey the merchant's secret key. - * @param proxyEnabled true if a proxy configuration is provided. - * @param proxyHost the host of the proxy; if proxyEnabled is true this should net be blank, empty or null otherwise it should be null. - * @param proxyPort the port of the proxy; if proxyEnabled is true this should net be blank, empty or null otherwise it should be null. - * - * @throws IncorrectProxyConfException when the proxy configuration is incorrect. - * @throws InvalidEnvironmentException when an unknown environment is specified. - * @throws InvalidKeyException when the key version is null, or a key is blank, empty or null. - * @throws InvalidMerchantException when the key version is null, or a key is blank, empty or null. - */ - public SipsClient(SipsEnvironment environment, String merchantId, Integer keyVersion, String secretKey, - boolean proxyEnabled, String proxyHost, Integer proxyPort) - throws InvalidEnvironmentException, IncorrectProxyConfException, InvalidMerchantException, InvalidKeyException { - if (environment == null) { - throw new InvalidEnvironmentException("Invalid environment specified!"); + private final SipsEnvironment environment; + private final boolean proxyEnabled; + private final String proxyHost; + private final Integer proxyPort; + private final String merchantId; + private final Integer keyVersion; + private final String secretKey; + + /** + * Construct a new instance of the client for a given {@link SipsEnvironment}. + * + * @param environment the API environment to connect to. + * @param merchantId the merchant's ID. + * @param keyVersion the version of the secret key to use. + * @param secretKey the merchant's secret key. + * @throws IncorrectProxyConfException when the proxy configuration is incorrect. + * @throws InvalidEnvironmentException when an unknown environment is specified. + * @throws InvalidKeyException when the key version is null, or a key is blank, empty or null. + * @throws InvalidMerchantException when the key version is null, or a key is blank, empty or null. + */ + public SipsClient(SipsEnvironment environment, String merchantId, Integer keyVersion, String secretKey) + throws InvalidEnvironmentException, IncorrectProxyConfException, InvalidMerchantException, InvalidKeyException { + this(environment, merchantId, keyVersion, secretKey, false, null, null); } - if (proxyEnabled) { - if (StringUtils.isBlank(proxyHost) || proxyPort == null){ - throw new IncorrectProxyConfException("ProxyEnabled is true but proxyHost or proxyPort not filled"); - } + /** + * Construct a new instance of the client for a given {@link SipsEnvironment} with a defined proxy. + * + * @param environment the API environment to connect to. + * @param merchantId the merchant's ID. + * @param keyVersion the version of the secret key to use. + * @param secretKey the merchant's secret key. + * @param proxyEnabled true if a proxy configuration is provided. + * @param proxyHost the host of the proxy; if proxyEnabled is true this should net be blank, empty or null otherwise it should be null. + * @param proxyPort the port of the proxy; if proxyEnabled is true this should net be blank, empty or null otherwise it should be null. + * @throws IncorrectProxyConfException when the proxy configuration is incorrect. + * @throws InvalidEnvironmentException when an unknown environment is specified. + * @throws InvalidKeyException when the key version is null, or a key is blank, empty or null. + * @throws InvalidMerchantException when the key version is null, or a key is blank, empty or null. + */ + public SipsClient(SipsEnvironment environment, String merchantId, Integer keyVersion, String secretKey, + boolean proxyEnabled, String proxyHost, Integer proxyPort) + throws InvalidEnvironmentException, IncorrectProxyConfException, InvalidMerchantException, InvalidKeyException { + if (environment == null) { + throw new InvalidEnvironmentException("Invalid environment specified!"); + } + + if (proxyEnabled) { + if (StringUtils.isBlank(proxyHost) || proxyPort == null) { + throw new IncorrectProxyConfException("ProxyEnabled is true but proxyHost or proxyPort not filled"); + } + } + + if (StringUtils.isBlank(merchantId)) { + throw new InvalidMerchantException("Invalid merchant ID specified!"); + } + + if (keyVersion == null) { + throw new InvalidKeyException("Invalid key version specified!"); + } + + if (StringUtils.isBlank(secretKey)) { + throw new InvalidKeyException("Invalid key specified!"); + } + this.environment = environment; + this.proxyEnabled = proxyEnabled; + this.proxyHost = proxyHost; + this.proxyPort = proxyPort; + this.merchantId = merchantId; + this.keyVersion = keyVersion; + this.secretKey = secretKey; } - if (StringUtils.isBlank(merchantId)) { - throw new InvalidMerchantException("Invalid merchant ID specified!"); + /** + * Decode a SIPS response object from a map of parameters. + * + * @param responseClass the type of the response to construct + * @param parameters the content of the received request, mapped as key-value pairs. + * @param secretKey the secret key used to create the request that induced this response + * @return The constructed response. + * @throws IncorrectSealException - If the response has been tampered with. + * @throws IllegalArgumentException – If conversion fails due to incompatible type; if so, root cause will contain underlying + * checked exception data binding functionality threw + */ + public static Response decodeResponse(Class responseClass, + Map parameters, String secretKey) throws IncorrectSealException, IllegalArgumentException { + verifySeal(parameters.get("Data"), parameters.get("Seal"), secretKey); + return ObjectMapperHolder.INSTANCE.get().copy() + .convertValue(parameters, responseClass); } - if (keyVersion == null) { - throw new InvalidKeyException("Invalid key version specified!"); + /** + * Verify the seal of a sips response. To avoid tampered data, + * the seal for the received response should always be verified before returning the object to the user. + * + * @param data the received response's Data attribute + * @param seal the received response's Seal attribute + * @throws IncorrectSealException when the received seal is different from the one calculated + */ + private static void verifySeal(String data, String seal, String secretKey) throws IncorrectSealException { + String correctSeal = DigestUtils.sha256Hex(data + secretKey); + if (! StringUtils.equals(correctSeal, seal)) { + throw new IncorrectSealException("The payment page response has been tampered with!"); + } } - if (StringUtils.isBlank(secretKey)) { - throw new InvalidKeyException("Invalid key specified!"); + /** + * Send a request to sips and get the response synchronously. + *

+ * The seal of the request is calculated, the request is send, the response is received and its seal is checked. + * + * @param request the request that will be sent to SIPS + * @throws SipsRequestException if an error occurred while serializing or sending the request + * @throws SipsException if an error occurred while receiving or deserializing the response + * @throws SealCalculationException if a seal calculation failed + * @throws IncorrectSealException if the response's seal is incorrect + */ + public Response send(SIPS2Request request) + throws SipsRequestException, SipsException, SealCalculationException, IncorrectSealException { + String fullPath = environment.getUrl() + "/" + request.getEndpoint(); + try { + HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); + if (this.proxyEnabled) { + HttpHost httpHost = new HttpHost(this.proxyHost, this.proxyPort); + httpClientBuilder.setProxy(httpHost); + } + CloseableHttpClient httpClient = httpClientBuilder.build(); + request.setMerchantId(merchantId); + request.setKeyVersion(keyVersion); + request.calculateSeal(secretKey); + StringEntity requestEntity = new StringEntity( + ObjectMapperHolder.INSTANCE.get().writerFor(request.getRealType()) + .writeValueAsString(request), + ContentType.APPLICATION_JSON); + + HttpPost postMethod = new HttpPost(new URI(fullPath)); + postMethod.setEntity(requestEntity); + + CloseableHttpResponse rawResponse = httpClient.execute(postMethod); + Response response = + ObjectMapperHolder.INSTANCE.get().readerFor(request.getResponseType()) + .readValue(EntityUtils.toString(rawResponse.getEntity())); + + response.verifySeal(secretKey); + return response; + } catch (JsonParseException | JsonMappingException e) { + throw new SipsRequestException("Exception while parsing request!", e); + } catch (IOException | ParseException e) { + throw new SipsException("Exception while processing response from server!", e); + } catch (URISyntaxException e) { + throw new SipsRequestException("Invalid endpoint: '" + fullPath + "' !", e); + } } - this.environment = environment; - this.proxyEnabled = proxyEnabled; - this.proxyHost = proxyHost; - this.proxyPort = proxyPort; - this.merchantId = merchantId; - this.keyVersion = keyVersion; - this.secretKey = secretKey; - } - - /** - * Send a request to sips and get the response synchronously. - * - * The seal of the request is calculated, the request is send, the response is received and its seal is checked. - * - * @param request the request that will be sent to SIPS - * @throws SipsRequestException if an error occurred while serializing or sending the request - * @throws SipsException if an error occurred while receiving or deserializing the response - * @throws SealCalculationException if a seal calculation failed - * @throws IncorrectSealException if the response's seal is incorrect - */ - public Response send(SIPS2Request request) - throws SipsRequestException, SipsException, SealCalculationException, IncorrectSealException { - String fullPath = environment.getUrl() + "/" + request.getEndpoint(); - try { - HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); - if (this.proxyEnabled) { - HttpHost httpHost = new HttpHost(this.proxyHost, this.proxyPort); - httpClientBuilder.setProxy(httpHost); - } - CloseableHttpClient httpClient = httpClientBuilder.build(); - request.setMerchantId(merchantId); - request.setKeyVersion(keyVersion); - request.calculateSeal(secretKey); - StringEntity requestEntity = new StringEntity( - ObjectMapperHolder.INSTANCE.get().writerFor(request.getRealType()) - .writeValueAsString(request), - ContentType.APPLICATION_JSON); - - HttpPost postMethod = new HttpPost(new URI(fullPath)); - postMethod.setEntity(requestEntity); - - CloseableHttpResponse rawResponse = httpClient.execute(postMethod); - Response response = - ObjectMapperHolder.INSTANCE.get().readerFor(request.getResponseType()) - .readValue(EntityUtils.toString(rawResponse.getEntity())); - - response.verifySeal(secretKey); - return response; - } catch (JsonParseException | JsonMappingException e) { - throw new SipsRequestException("Exception while parsing request!", e); - } catch (IOException | ParseException e) { - throw new SipsException("Exception while processing response from server!", e); - } catch (URISyntaxException e) { - throw new SipsRequestException("Invalid endpoint: '" + fullPath + "' !", e); + + /** + * Decode a SIPS response object from a map of parameters. + * + * @param responseClass the type of the response to construct + * @param parameters the content of the received request, mapped as key-value pairs. + * @return The constructed response. + * @throws IncorrectSealException - If the response has been tampered with. + * @throws IllegalArgumentException – If conversion fails due to incompatible type; if so, root cause will contain underlying + * checked exception data binding functionality threw + */ + public Response decodeResponse(Class responseClass, Map parameters) + throws IncorrectSealException, IllegalArgumentException { + return decodeResponse(responseClass, parameters, secretKey); } - } - - /** - * Decode a SIPS response object from a map of parameters. - * - * @param responseClass the type of the response to construct - * @param parameters the content of the received request, mapped as key-value pairs. - * @param secretKey the secret key used to create the request that induced this response - * @return The constructed response. - * @throws IncorrectSealException - If the response has been tampered with. - * @throws IllegalArgumentException – If conversion fails due to incompatible type; if so, root cause will contain underlying - * checked exception data binding functionality threw - */ - //FIXME javadoc - public static Response decodeResponse(Class responseClass, - Map parameters, String secretKey) throws IncorrectSealException, IllegalArgumentException { - verifySeal(parameters.get("Data"), parameters.get("Seal"), secretKey); - return ObjectMapperHolder.INSTANCE.get().copy() - .convertValue(parameters, responseClass); - } - - /** - * Verify the seal of an sips response. To avoid tampered responses, - * the seal for the received response should always be verified before returning the object to the user. - * - * @param response the received response upon initialization - * @throws IncorrectSealException when the received seal is different from the one calculated - * @throws SealCalculationException when seal calculation fails, see inner exception for details. - * - * @see SIPS2Response#verifySeal(String) = identical - */ - private void verifySeal(SIPS2Response response) throws IncorrectSealException, SealCalculationException { - response.verifySeal(secretKey); - } - - /** - * Verify the seal of a sips response. To avoid tampered data, - * the seal for the received response should always be verified before returning the object to the user. - * - * @param data the received response's Data attribute - * @param seal the received response's Seal attribute - * @throws IncorrectSealException when the received seal is different from the one calculated - */ - private static void verifySeal(String data, String seal, String secretKey) throws IncorrectSealException { - String correctSeal = DigestUtils.sha256Hex(data + secretKey); - if (! StringUtils.equals(correctSeal, seal)) { - throw new IncorrectSealException("The payment page response has been tampered with!"); + + /** + * Verify the seal of a sips response. To avoid tampered responses, + * the seal for the received response should always be verified before returning the object to the user. + * + * @param response the received response upon initialization + * @throws IncorrectSealException when the received seal is different from the one calculated + * @throws SealCalculationException when seal calculation fails, see inner exception for details. + * @see SIPS2Response#verifySeal(String) = identical + */ + private void verifySeal(SIPS2Response response) throws IncorrectSealException, SealCalculationException { + response.verifySeal(secretKey); } - } } diff --git a/sdk-common/src/main/java/com/worldline/sips/exception/IncorrectProxyConfException.java b/sdk-common/src/main/java/com/worldline/sips/exception/IncorrectProxyConfException.java index 96ac0bd..b577412 100644 --- a/sdk-common/src/main/java/com/worldline/sips/exception/IncorrectProxyConfException.java +++ b/sdk-common/src/main/java/com/worldline/sips/exception/IncorrectProxyConfException.java @@ -2,8 +2,8 @@ public class IncorrectProxyConfException extends Exception { - public IncorrectProxyConfException(String message){ - super(message); - } + public IncorrectProxyConfException(String message) { + super(message); + } } diff --git a/sdk-common/src/main/java/com/worldline/sips/exception/IncorrectSealException.java b/sdk-common/src/main/java/com/worldline/sips/exception/IncorrectSealException.java index 48cf107..7a95910 100644 --- a/sdk-common/src/main/java/com/worldline/sips/exception/IncorrectSealException.java +++ b/sdk-common/src/main/java/com/worldline/sips/exception/IncorrectSealException.java @@ -2,8 +2,8 @@ public class IncorrectSealException extends Exception { - public IncorrectSealException(String message) { - super(message); - } + public IncorrectSealException(String message) { + super(message); + } } diff --git a/sdk-common/src/main/java/com/worldline/sips/exception/InvalidEnvironmentException.java b/sdk-common/src/main/java/com/worldline/sips/exception/InvalidEnvironmentException.java index 3f526de..1072375 100644 --- a/sdk-common/src/main/java/com/worldline/sips/exception/InvalidEnvironmentException.java +++ b/sdk-common/src/main/java/com/worldline/sips/exception/InvalidEnvironmentException.java @@ -2,8 +2,8 @@ public class InvalidEnvironmentException extends Exception { - public InvalidEnvironmentException(String message) { - super(message); - } + public InvalidEnvironmentException(String message) { + super(message); + } } diff --git a/sdk-common/src/main/java/com/worldline/sips/exception/InvalidKeyException.java b/sdk-common/src/main/java/com/worldline/sips/exception/InvalidKeyException.java index d9c0f16..820afb0 100644 --- a/sdk-common/src/main/java/com/worldline/sips/exception/InvalidKeyException.java +++ b/sdk-common/src/main/java/com/worldline/sips/exception/InvalidKeyException.java @@ -2,8 +2,8 @@ public class InvalidKeyException extends Exception { - public InvalidKeyException(String message) { - super(message); - } + public InvalidKeyException(String message) { + super(message); + } } diff --git a/sdk-common/src/main/java/com/worldline/sips/exception/InvalidMerchantException.java b/sdk-common/src/main/java/com/worldline/sips/exception/InvalidMerchantException.java index 16600d5..58fe480 100644 --- a/sdk-common/src/main/java/com/worldline/sips/exception/InvalidMerchantException.java +++ b/sdk-common/src/main/java/com/worldline/sips/exception/InvalidMerchantException.java @@ -2,9 +2,9 @@ public class InvalidMerchantException extends Exception { - public InvalidMerchantException(String message) { - super(message); - } + public InvalidMerchantException(String message) { + super(message); + } } diff --git a/sdk-common/src/main/java/com/worldline/sips/exception/SipsException.java b/sdk-common/src/main/java/com/worldline/sips/exception/SipsException.java index 8fcc8f1..1686678 100644 --- a/sdk-common/src/main/java/com/worldline/sips/exception/SipsException.java +++ b/sdk-common/src/main/java/com/worldline/sips/exception/SipsException.java @@ -2,8 +2,8 @@ public class SipsException extends Exception { - public SipsException(String message, Throwable cause) { - super(message, cause); - } + public SipsException(String message, Throwable cause) { + super(message, cause); + } } diff --git a/sdk-common/src/main/java/com/worldline/sips/exception/SipsRequestException.java b/sdk-common/src/main/java/com/worldline/sips/exception/SipsRequestException.java index 03b8854..12e9b87 100644 --- a/sdk-common/src/main/java/com/worldline/sips/exception/SipsRequestException.java +++ b/sdk-common/src/main/java/com/worldline/sips/exception/SipsRequestException.java @@ -2,8 +2,8 @@ public class SipsRequestException extends Exception { - public SipsRequestException(String message, Throwable cause) { - super(message, cause); - } + public SipsRequestException(String message, Throwable cause) { + super(message, cause); + } } diff --git a/sdk-common/src/main/java/com/worldline/sips/helper/SealStringStyle.java b/sdk-common/src/main/java/com/worldline/sips/helper/SealStringStyle.java index 54d731b..4208def 100644 --- a/sdk-common/src/main/java/com/worldline/sips/helper/SealStringStyle.java +++ b/sdk-common/src/main/java/com/worldline/sips/helper/SealStringStyle.java @@ -8,6 +8,7 @@ /** * A {@link RecursiveToStringStyle} parametrized to the seal format + * * @see com.worldline.sips.security.Sealable */ public final class SealStringStyle extends RecursiveToStringStyle { @@ -27,9 +28,9 @@ public SealStringStyle() { @Override public void appendDetail(StringBuffer buffer, String fieldName, Object value) { - if (!ClassUtils.isPrimitiveWrapper(value.getClass()) && - !String.class.equals(value.getClass()) && - accept(value.getClass())) { + if (! ClassUtils.isPrimitiveWrapper(value.getClass()) && + ! String.class.equals(value.getClass()) && + accept(value.getClass())) { buffer.append(AlphabeticalReflectionToStringBuilder.toString(value, this)); } else { super.appendDetail(buffer, fieldName, value); diff --git a/sdk-common/src/main/java/com/worldline/sips/helper/SortedReflectionToStringBuilder.java b/sdk-common/src/main/java/com/worldline/sips/helper/SortedReflectionToStringBuilder.java index 35587fa..dd3b7b0 100644 --- a/sdk-common/src/main/java/com/worldline/sips/helper/SortedReflectionToStringBuilder.java +++ b/sdk-common/src/main/java/com/worldline/sips/helper/SortedReflectionToStringBuilder.java @@ -1,13 +1,14 @@ package com.worldline.sips.helper; +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import org.apache.commons.lang3.builder.ToStringSummary; + import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.List; -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; -import org.apache.commons.lang3.builder.ToStringSummary; public class SortedReflectionToStringBuilder extends ReflectionToStringBuilder { @@ -17,60 +18,61 @@ public SortedReflectionToStringBuilder(Object object, ToStringStyle style) { super(object, style); } + /** + * Get all the fields of a given type (include private and inherited fields from the class hierarchy) + * + * @param type + * @return a list containing all the fields of the given type + */ + private static List getAllFields(Class type) { + List fields = new ArrayList<>(); + List> temp = new ArrayList<>(); + for (Class c = type; c != null; c = c.getSuperclass()) { + temp.add(Arrays.asList(c.getDeclaredFields())); + } + for (int i = temp.size() - 1; i >= 0; i--) { + fields.addAll(temp.get(i)); + } + return fields; + } + public void setComparator(Comparator comparator) { this.comparator = comparator; } - @Override - public String toString() { - if (this.getObject() == null) { - return super.toString(); - } - Class clazz = this.getObject().getClass(); - List allFields = getAllFields(clazz); - if (comparator != null) { - allFields.sort(comparator); - } - for (final Field field : allFields) { - final String fieldName = field.getName(); - if (this.accept(field)) { - try { - field.setAccessible(true); - // Warning: Field.get(Object) creates wrappers objects - // for primitive types. - final Object fieldValue = this.getValue(field); - if (!isExcludeNullValues() || fieldValue != null) { - this.append(fieldName, fieldValue, !field.isAnnotationPresent(ToStringSummary.class)); - } - } catch (final IllegalAccessException ex) { - //this can't happen. Would get a Security exception - // instead - //throw a runtime exception in case the impossible - // happens. - throw new InternalError("Unexpected IllegalAccessException: " + ex.getMessage()); + @Override + public String toString() { + if (this.getObject() == null) { + return super.toString(); } - } - } - getStyle().appendEnd(this.getStringBuffer(), this.getObject()); - return this.getStringBuffer().toString(); - } - - /** - * Get all the fields of a given type (include private and inherited fields from the class hierarchy) - * @param type - * @return a list containing all the fields of the given type - */ - private static List getAllFields(Class type) { - List fields = new ArrayList<>(); - List> temp = new ArrayList<>(); - for (Class c = type; c != null; c = c.getSuperclass()) { - temp.add(Arrays.asList(c.getDeclaredFields())); - } - for (int i = temp.size() - 1; i >= 0; i--) { - fields.addAll(temp.get(i)); + Class clazz = this.getObject().getClass(); + List allFields = getAllFields(clazz); + if (comparator != null) { + allFields.sort(comparator); + } + for (final Field field : allFields) { + final String fieldName = field.getName(); + if (this.accept(field)) { + try { + field.setAccessible(true); + // Warning: Field.get(Object) creates wrappers objects + // for primitive types. + final Object fieldValue = this.getValue(field); + if (! isExcludeNullValues() || fieldValue != null) { + this.append(fieldName, fieldValue, ! field.isAnnotationPresent(ToStringSummary.class)); + } + } catch (final IllegalAccessException ex) { + //this can't happen. Would get a Security exception + // instead + //throw a runtime exception in case the impossible + // happens. + throw new InternalError("Unexpected IllegalAccessException: " + ex.getMessage()); + } + } + } + getStyle().appendEnd(this.getStringBuffer(), this.getObject()); + return this.getStringBuffer().toString(); } - return fields; - } } diff --git a/sdk-common/src/main/java/com/worldline/sips/model/PaymentMeanBrand.java b/sdk-common/src/main/java/com/worldline/sips/model/PaymentMeanBrand.java index f196ec0..6580d8b 100644 --- a/sdk-common/src/main/java/com/worldline/sips/model/PaymentMeanBrand.java +++ b/sdk-common/src/main/java/com/worldline/sips/model/PaymentMeanBrand.java @@ -1,100 +1,107 @@ package com.worldline.sips.model; -import static com.worldline.sips.model.PaymentMeanType.*; - import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonValue; import com.worldline.sips.exception.UnknownStatusException; +import static com.worldline.sips.model.PaymentMeanType.CARD; +import static com.worldline.sips.model.PaymentMeanType.CREDIT_TRANSFER; +import static com.worldline.sips.model.PaymentMeanType.DIRECT_DEBIT; +import static com.worldline.sips.model.PaymentMeanType.EMPTY; +import static com.worldline.sips.model.PaymentMeanType.ONLINE_CREDIT; +import static com.worldline.sips.model.PaymentMeanType.PROVIDER; +import static com.worldline.sips.model.PaymentMeanType.VOUCHER; +import static com.worldline.sips.model.PaymentMeanType.WALLET; + public enum PaymentMeanBrand { - _1EUROCOM(ONLINE_CREDIT), - _3XCBCOFINOGA(CARD), - ACCEPTGIRO(CREDIT_TRANSFER), - ACCORD(CARD), - ACCORD_KDO(CARD), - ACCORD_3X(ONLINE_CREDIT), - ACCORD_4X(ONLINE_CREDIT), - AMEX(CARD), - AURORE(CARD), - BCACB_3X(ONLINE_CREDIT), - BCACB_4X(ONLINE_CREDIT), - BCACUP(CARD), - BCMC(CARD), - CACF_3X(ONLINE_CREDIT), - CACF_4X(ONLINE_CREDIT), - CADHOC(CARD), - CADOCARTE(CARD), - CB(CARD), - CBCONLINE(CREDIT_TRANSFER), - CETELEM_3X(ONLINE_CREDIT), - CETELEM_4X(ONLINE_CREDIT), - COFIDIS_3X(ONLINE_CREDIT), - COFIDIS_4X(ONLINE_CREDIT), - CONECS(VOUCHER), - CUP(CARD), - CVA(CARD), - CVCO(VOUCHER), - DINNERS(CARD), - ECV(VOUCHER), - ELV(DIRECT_DEBIT), - FIVORY(WALLET), - FRANFINANCE_3X(ONLINE_CREDIT), - FRANFINANCE_4X(ONLINE_CREDIT), - GIROPAY(CREDIT_TRANSFER), - IDEAL(CREDIT_TRANSFER), - ILLICADO(CARD), - INCASSO(DIRECT_DEBIT), - IGNHOMEPAY(CREDIT_TRANSFER), - JCB(CARD), - KBCONLINE(CREDIT_TRANSFER), - LEPOTCOMMUN(CARD), - LYDIA(PROVIDER), - MAESTRO(CARD), - MASTERCARD(CARD), - MASTERPASS(EMPTY), - PASSCADO(CARD), - PAY_BY_BANK(CREDIT_TRANSFER), - PAYLIB(EMPTY), - PAYPAL(WALLET), - PAYTRAIL(CREDIT_TRANSFER), - POSTFINANCE(CARD), - PRESTO(ONLINE_CREDIT), - SEPA_DIRECT_DEBIT(DIRECT_DEBIT), - SOFINCO(CARD), - SOFORTUBERWEISUNG(CREDIT_TRANSFER), - SPIRITOFCADEAU(CARD), - VISA(CARD), - VISA_ELECTRON(CARD), - VPAY(CARD); + _1EUROCOM(ONLINE_CREDIT), + _3XCBCOFINOGA(CARD), + ACCEPTGIRO(CREDIT_TRANSFER), + ACCORD(CARD), + ACCORD_KDO(CARD), + ACCORD_3X(ONLINE_CREDIT), + ACCORD_4X(ONLINE_CREDIT), + AMEX(CARD), + AURORE(CARD), + BCACB_3X(ONLINE_CREDIT), + BCACB_4X(ONLINE_CREDIT), + BCACUP(CARD), + BCMC(CARD), + CACF_3X(ONLINE_CREDIT), + CACF_4X(ONLINE_CREDIT), + CADHOC(CARD), + CADOCARTE(CARD), + CB(CARD), + CBCONLINE(CREDIT_TRANSFER), + CETELEM_3X(ONLINE_CREDIT), + CETELEM_4X(ONLINE_CREDIT), + COFIDIS_3X(ONLINE_CREDIT), + COFIDIS_4X(ONLINE_CREDIT), + CONECS(VOUCHER), + CUP(CARD), + CVA(CARD), + CVCO(VOUCHER), + DINNERS(CARD), + ECV(VOUCHER), + ELV(DIRECT_DEBIT), + FIVORY(WALLET), + FRANFINANCE_3X(ONLINE_CREDIT), + FRANFINANCE_4X(ONLINE_CREDIT), + GIROPAY(CREDIT_TRANSFER), + IDEAL(CREDIT_TRANSFER), + ILLICADO(CARD), + INCASSO(DIRECT_DEBIT), + IGNHOMEPAY(CREDIT_TRANSFER), + JCB(CARD), + KBCONLINE(CREDIT_TRANSFER), + LEPOTCOMMUN(CARD), + LYDIA(PROVIDER), + MAESTRO(CARD), + MASTERCARD(CARD), + MASTERPASS(EMPTY), + PASSCADO(CARD), + PAY_BY_BANK(CREDIT_TRANSFER), + PAYLIB(EMPTY), + PAYPAL(WALLET), + PAYTRAIL(CREDIT_TRANSFER), + POSTFINANCE(CARD), + PRESTO(ONLINE_CREDIT), + SEPA_DIRECT_DEBIT(DIRECT_DEBIT), + SOFINCO(CARD), + SOFORTUBERWEISUNG(CREDIT_TRANSFER), + SPIRITOFCADEAU(CARD), + VISA(CARD), + VISA_ELECTRON(CARD), + VPAY(CARD); - final String realName; - final PaymentMeanType paymentMeanType; + final String realName; + final PaymentMeanType paymentMeanType; - PaymentMeanBrand(PaymentMeanType paymentMeanType) { - String name = name(); - this.paymentMeanType = paymentMeanType; - this.realName = name.charAt(0) == '_' ? name.substring(1) : name; - } + PaymentMeanBrand(PaymentMeanType paymentMeanType) { + String name = name(); + this.paymentMeanType = paymentMeanType; + this.realName = name.charAt(0) == '_' ? name.substring(1) : name; + } - @JsonValue - public String getRealName() { - return this.realName; - } + @JsonCreator + public static PaymentMeanBrand fromRealName(String string) throws UnknownStatusException { + for (PaymentMeanBrand responseCode : PaymentMeanBrand.values()) { + if (responseCode.getRealName().equals(string)) { + return responseCode; + } + } - @JsonCreator - public static PaymentMeanBrand fromRealName(String string) throws UnknownStatusException { - for (PaymentMeanBrand responseCode : PaymentMeanBrand.values()) { - if (responseCode.getRealName().equals(string)) { - return responseCode; - } + throw new UnknownStatusException(string + " is an unknown payment mean brand!"); } - throw new UnknownStatusException(string + " is an unknown payment mean brand!"); - } + @JsonValue + public String getRealName() { + return this.realName; + } - @JsonIgnore - public PaymentMeanType getPaymentMeanType() { - return paymentMeanType; - } + @JsonIgnore + public PaymentMeanType getPaymentMeanType() { + return paymentMeanType; + } } diff --git a/sdk-common/src/main/java/com/worldline/sips/model/SipsEnvironment.java b/sdk-common/src/main/java/com/worldline/sips/model/SipsEnvironment.java index 537872c..2a4de17 100644 --- a/sdk-common/src/main/java/com/worldline/sips/model/SipsEnvironment.java +++ b/sdk-common/src/main/java/com/worldline/sips/model/SipsEnvironment.java @@ -4,5 +4,5 @@ * Contains the target URL for a SIPS Environment */ public interface SipsEnvironment { - String getUrl(); + String getUrl(); } diff --git a/sdk-common/src/main/java/com/worldline/sips/security/SealCalculator.java b/sdk-common/src/main/java/com/worldline/sips/security/SealCalculator.java index d327c00..27762f9 100644 --- a/sdk-common/src/main/java/com/worldline/sips/security/SealCalculator.java +++ b/sdk-common/src/main/java/com/worldline/sips/security/SealCalculator.java @@ -16,6 +16,7 @@ /** * Utility class to compute seals. + * * @see Sealable */ public class SealCalculator { diff --git a/sdk-common/src/main/java/com/worldline/sips/security/Sealable.java b/sdk-common/src/main/java/com/worldline/sips/security/Sealable.java index fde4cda..3fe390c 100644 --- a/sdk-common/src/main/java/com/worldline/sips/security/Sealable.java +++ b/sdk-common/src/main/java/com/worldline/sips/security/Sealable.java @@ -5,6 +5,6 @@ */ public interface Sealable { - String getSeal(); + String getSeal(); } diff --git a/sdk-common/src/main/java/com/worldline/sips/util/ObjectMapperHolder.java b/sdk-common/src/main/java/com/worldline/sips/util/ObjectMapperHolder.java index 4d8b505..fbd2213 100644 --- a/sdk-common/src/main/java/com/worldline/sips/util/ObjectMapperHolder.java +++ b/sdk-common/src/main/java/com/worldline/sips/util/ObjectMapperHolder.java @@ -13,6 +13,7 @@ /** * Container for the global mapper object instance + * * @see ObjectMapper */ public enum ObjectMapperHolder { @@ -26,7 +27,7 @@ public enum ObjectMapperHolder { private static ObjectMapper create() { return new ObjectMapper() - .registerModule(new JavaTimeModule() + .registerModule(new JavaTimeModule() .addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ISO_OFFSET_DATE_TIME)) .addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.BASIC_ISO_DATE)) .addDeserializer(YearMonth.class, new YearMonthDeserializer(DateTimeFormatter.ofPattern("yyyyMM")))); diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/WalletRequest.java b/wallet-sdk/src/main/java/com/worldline/sips/api/WalletRequest.java index bebf5d8..76f6df7 100644 --- a/wallet-sdk/src/main/java/com/worldline/sips/api/WalletRequest.java +++ b/wallet-sdk/src/main/java/com/worldline/sips/api/WalletRequest.java @@ -6,12 +6,12 @@ public abstract class WalletRequest extends SIPS2Request { - public WalletRequest(String endpoint) { - super("wallet/" + endpoint); - } + public WalletRequest(String endpoint) { + super("wallet/" + endpoint); + } - @JsonInclude - public String getInterfaceVersion() { - return OfficeConfiguration.INTERFACE_VERSION; - } + @JsonInclude + public String getInterfaceVersion() { + return OfficeConfiguration.INTERFACE_VERSION; + } } diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponse.java b/wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponse.java index e9bf714..f320784 100644 --- a/wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponse.java +++ b/wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponse.java @@ -3,14 +3,14 @@ import com.worldline.sips.SIPS2Response; public abstract class WalletResponse extends SIPS2Response { - private String errorFieldName; - private WalletResponseCode walletResponseCode; + private String errorFieldName; + private WalletResponseCode walletResponseCode; - public String getErrorFieldName() { - return errorFieldName; - } + public String getErrorFieldName() { + return errorFieldName; + } - public WalletResponseCode getWalletResponseCode() { - return walletResponseCode; - } + public WalletResponseCode getWalletResponseCode() { + return walletResponseCode; + } } diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponseCode.java b/wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponseCode.java index 6a130d6..e195263 100644 --- a/wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponseCode.java +++ b/wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponseCode.java @@ -6,64 +6,63 @@ //FIXME add data type https://documentation.sips.worldline.com/en/WLSIPS.001-GD-Data-dictionary.html#Sips.001_DD_en-Value-responseCode_ public enum WalletResponseCode { - /** - * Successful operation - */ - SUCCESS("00"), - /** - * Invalid Merchant contract - */ - INVALID_MERCHANT("03"), - /** - * Invalid data, verify the request - */ - INVALID_DATA("12"), - /** - * Wallet / payment mean unknown by WL Sips - */ - UNKNOWN_WALLET("25"), - FORMAT_ERROR("30"), + /** + * Successful operation + */ + SUCCESS("00"), + /** + * Invalid Merchant contract + */ + INVALID_MERCHANT("03"), + /** + * Invalid data, verify the request + */ + INVALID_DATA("12"), + /** + * Wallet / payment mean unknown by WL Sips + */ + UNKNOWN_WALLET("25"), + FORMAT_ERROR("30"), - FRAUD_SUSPECTED("34"), - /** - * MerchantId not allowed to access this wallet service - */ - NOT_ALLOWED("40"), - /** - * Duplicated wallet / payment mean - */ - ALREADY_PRESENT("94"), - /** - * Temporary problem at the WL Sips server level - */ - INTERNAL_TEMPORARY_PROBLEM("99") - ; + FRAUD_SUSPECTED("34"), + /** + * MerchantId not allowed to access this wallet service + */ + NOT_ALLOWED("40"), + /** + * Duplicated wallet / payment mean + */ + ALREADY_PRESENT("94"), + /** + * Temporary problem at the WL Sips server level + */ + INTERNAL_TEMPORARY_PROBLEM("99"); - private final String code; + private final String code; - WalletResponseCode(String code) { - this.code = code; - } - - @JsonCreator - public static WalletResponseCode fromCode(String code) throws UnknownStatusException { - for (WalletResponseCode responseCode : WalletResponseCode.values()) { - if (responseCode.getCode().equals(code)) { - return responseCode; - } + WalletResponseCode(String code) { + this.code = code; } - throw new UnknownStatusException(code + " is an unknown response code!"); - } + @JsonCreator + public static WalletResponseCode fromCode(String code) throws UnknownStatusException { + for (WalletResponseCode responseCode : WalletResponseCode.values()) { + if (responseCode.getCode().equals(code)) { + return responseCode; + } + } - @JsonValue - public String getCode() { - return code; - } + throw new UnknownStatusException(code + " is an unknown response code!"); + } - @Override - public String toString() { - return code; - } + @JsonValue + public String getCode() { + return code; + } + + @Override + public String toString() { + return code; + } } diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/configuration/OfficeEnvironment.java b/wallet-sdk/src/main/java/com/worldline/sips/api/configuration/OfficeEnvironment.java index 7e9f984..2f9f849 100644 --- a/wallet-sdk/src/main/java/com/worldline/sips/api/configuration/OfficeEnvironment.java +++ b/wallet-sdk/src/main/java/com/worldline/sips/api/configuration/OfficeEnvironment.java @@ -1,26 +1,27 @@ package com.worldline.sips.api.configuration; import com.worldline.sips.model.SipsEnvironment; + import java.net.URI; public enum OfficeEnvironment implements SipsEnvironment { - TEST("https://office-server.test.sips-services.com"), - PROD("https://office-server.sips-services.com"); + TEST("https://office-server.test.sips-services.com"), + PROD("https://office-server.sips-services.com"); - private final String url; - private final URI uri; + private final String url; + private final URI uri; - OfficeEnvironment(String url) { - this.url = url + "/rs-services/v2"; - this.uri = URI.create(url); - } + OfficeEnvironment(String url) { + this.url = url + "/rs-services/v2"; + this.uri = URI.create(url); + } - public String getUrl() { - return url; - } + public String getUrl() { + return url; + } - public URI getURI() { - return uri; - } + public URI getURI() { + return uri; + } } diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java b/wallet-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java index 9117a5c..9ab86e8 100644 --- a/wallet-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java +++ b/wallet-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java @@ -2,49 +2,50 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.worldline.sips.model.PaymentMeanBrand; + import java.time.YearMonth; @JsonIgnoreProperties(ignoreUnknown = true) public class WalletPaymentMeanData { - private String paymentMeanId; - //FIXME wtf ? - private String maskedPan; - private YearMonth panExpiryDate; - private String paymentMeanAlias; - private PaymentMeanBrand paymentMeanBrand; - private String paymentMeanBrandCobadgedList; - /*PaymentMeanData*/ String paymentMeanData; - private String transactionActors; - - public String getPaymentMeanId() { - return paymentMeanId; - } - - public String getMaskedPan() { - return maskedPan; - } - - public YearMonth getPanExpiryDate() { - return panExpiryDate; - } - - public String getPaymentMeanAlias() { - return paymentMeanAlias; - } - - public PaymentMeanBrand getPaymentMeanBrand() { - return paymentMeanBrand; - } - - public String getPaymentMeanBrandCobadgedList() { - return paymentMeanBrandCobadgedList; - } - - public String getPaymentMeanData() { - return paymentMeanData; - } - - public String getTransactionActors() { - return transactionActors; - } + /*PaymentMeanData*/ String paymentMeanData; + private String paymentMeanId; + //FIXME wtf ? + private String maskedPan; + private YearMonth panExpiryDate; + private String paymentMeanAlias; + private PaymentMeanBrand paymentMeanBrand; + private String paymentMeanBrandCobadgedList; + private String transactionActors; + + public String getPaymentMeanId() { + return paymentMeanId; + } + + public String getMaskedPan() { + return maskedPan; + } + + public YearMonth getPanExpiryDate() { + return panExpiryDate; + } + + public String getPaymentMeanAlias() { + return paymentMeanAlias; + } + + public PaymentMeanBrand getPaymentMeanBrand() { + return paymentMeanBrand; + } + + public String getPaymentMeanBrandCobadgedList() { + return paymentMeanBrandCobadgedList; + } + + public String getPaymentMeanData() { + return paymentMeanData; + } + + public String getTransactionActors() { + return transactionActors; + } } diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/model/request/DeletePaymentMeanRequest.java b/wallet-sdk/src/main/java/com/worldline/sips/api/model/request/DeletePaymentMeanRequest.java index 3f0ae51..102f2ea 100644 --- a/wallet-sdk/src/main/java/com/worldline/sips/api/model/request/DeletePaymentMeanRequest.java +++ b/wallet-sdk/src/main/java/com/worldline/sips/api/model/request/DeletePaymentMeanRequest.java @@ -5,34 +5,34 @@ public class DeletePaymentMeanRequest extends WalletRequest { - private final String merchantWalletId; - private final String paymentMeanId; - private String intermediateServiceProviderId; - - public DeletePaymentMeanRequest(String merchantWalletId, String paymentMeanId) { - super("deletePaymentMean"); - this.merchantWalletId = merchantWalletId; - this.paymentMeanId = paymentMeanId; - } - - public String getMerchantWalletId() { - return merchantWalletId; - } - - public String getPaymentMeanId() { - return paymentMeanId; - } - - public String getIntermediateServiceProviderId() { - return intermediateServiceProviderId; - } - - public void setIntermediateServiceProviderId(String intermediateServiceProviderId) { - this.intermediateServiceProviderId = intermediateServiceProviderId; - } - - @Override - public Class getResponseType() { - return DeletePaymentMeanResponse.class; - } + private final String merchantWalletId; + private final String paymentMeanId; + private String intermediateServiceProviderId; + + public DeletePaymentMeanRequest(String merchantWalletId, String paymentMeanId) { + super("deletePaymentMean"); + this.merchantWalletId = merchantWalletId; + this.paymentMeanId = paymentMeanId; + } + + public String getMerchantWalletId() { + return merchantWalletId; + } + + public String getPaymentMeanId() { + return paymentMeanId; + } + + public String getIntermediateServiceProviderId() { + return intermediateServiceProviderId; + } + + public void setIntermediateServiceProviderId(String intermediateServiceProviderId) { + this.intermediateServiceProviderId = intermediateServiceProviderId; + } + + @Override + public Class getResponseType() { + return DeletePaymentMeanResponse.class; + } } diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/model/request/GetWalletDataRequest.java b/wallet-sdk/src/main/java/com/worldline/sips/api/model/request/GetWalletDataRequest.java index 4e8a02c..5c98aa6 100644 --- a/wallet-sdk/src/main/java/com/worldline/sips/api/model/request/GetWalletDataRequest.java +++ b/wallet-sdk/src/main/java/com/worldline/sips/api/model/request/GetWalletDataRequest.java @@ -5,28 +5,28 @@ public class GetWalletDataRequest extends WalletRequest { - private final String merchantWalletId; - private String intermediateServiceProviderId; - - public GetWalletDataRequest(String merchantWalletId) { - super("getWalletData"); - this.merchantWalletId = merchantWalletId; - } - - public String getIntermediateServiceProviderId() { - return intermediateServiceProviderId; - } - - public void setIntermediateServiceProviderId(String intermediateServiceProviderId) { - this.intermediateServiceProviderId = intermediateServiceProviderId; - } - - public String getMerchantWalletId() { - return merchantWalletId; - } - - @Override - public Class getResponseType() { - return GetWalletDataResponse.class; - } + private final String merchantWalletId; + private String intermediateServiceProviderId; + + public GetWalletDataRequest(String merchantWalletId) { + super("getWalletData"); + this.merchantWalletId = merchantWalletId; + } + + public String getIntermediateServiceProviderId() { + return intermediateServiceProviderId; + } + + public void setIntermediateServiceProviderId(String intermediateServiceProviderId) { + this.intermediateServiceProviderId = intermediateServiceProviderId; + } + + public String getMerchantWalletId() { + return merchantWalletId; + } + + @Override + public Class getResponseType() { + return GetWalletDataResponse.class; + } } diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/model/response/DeletePaymentMeanResponse.java b/wallet-sdk/src/main/java/com/worldline/sips/api/model/response/DeletePaymentMeanResponse.java index cf644fe..473a072 100644 --- a/wallet-sdk/src/main/java/com/worldline/sips/api/model/response/DeletePaymentMeanResponse.java +++ b/wallet-sdk/src/main/java/com/worldline/sips/api/model/response/DeletePaymentMeanResponse.java @@ -2,13 +2,14 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.worldline.sips.api.WalletResponse; + import java.time.LocalDateTime; @JsonIgnoreProperties(ignoreUnknown = true) public class DeletePaymentMeanResponse extends WalletResponse { - private LocalDateTime walletActionDateTime; + private LocalDateTime walletActionDateTime; - public LocalDateTime getWalletActionDateTime() { - return walletActionDateTime; - } + public LocalDateTime getWalletActionDateTime() { + return walletActionDateTime; + } } diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/model/response/GetWalletDataResponse.java b/wallet-sdk/src/main/java/com/worldline/sips/api/model/response/GetWalletDataResponse.java index c234743..e0362d1 100644 --- a/wallet-sdk/src/main/java/com/worldline/sips/api/model/response/GetWalletDataResponse.java +++ b/wallet-sdk/src/main/java/com/worldline/sips/api/model/response/GetWalletDataResponse.java @@ -2,26 +2,26 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.worldline.sips.api.WalletResponse; -import com.worldline.sips.api.WalletResponseCode; import com.worldline.sips.api.model.data.WalletPaymentMeanData; + import java.time.LocalDateTime; import java.util.List; @JsonIgnoreProperties(ignoreUnknown = true) public class GetWalletDataResponse extends WalletResponse { - private LocalDateTime walletCreationDateTime; - private LocalDateTime walletLastActionDateTime; - private List walletPaymentMeanDataList; + private LocalDateTime walletCreationDateTime; + private LocalDateTime walletLastActionDateTime; + private List walletPaymentMeanDataList; - public LocalDateTime getWalletCreationDateTime() { - return walletCreationDateTime; - } + public LocalDateTime getWalletCreationDateTime() { + return walletCreationDateTime; + } - public LocalDateTime getWalletLastActionDateTime() { - return walletLastActionDateTime; - } + public LocalDateTime getWalletLastActionDateTime() { + return walletLastActionDateTime; + } - public List getWalletPaymentMeanDataList() { - return walletPaymentMeanDataList; - } + public List getWalletPaymentMeanDataList() { + return walletPaymentMeanDataList; + } } diff --git a/wallet-sdk/src/test/java/com/worldline/sips/utils/WalletSipsTest.java b/wallet-sdk/src/test/java/com/worldline/sips/utils/WalletSipsTest.java index 03fb1e7..cfc61ae 100644 --- a/wallet-sdk/src/test/java/com/worldline/sips/utils/WalletSipsTest.java +++ b/wallet-sdk/src/test/java/com/worldline/sips/utils/WalletSipsTest.java @@ -12,55 +12,54 @@ public class WalletSipsTest { - private SipsClient sipsClient; + private SipsClient sipsClient; - @BeforeEach - public void setUp() throws Exception { - sipsClient = new SipsClient(OfficeEnvironment.TEST, "201040040170001", 1, "rxSP61eeP_oNi5TxCD7Ngy9YcwC8MLw6OlmFGGcsY54"); - } + @BeforeEach + public void setUp() throws Exception { + sipsClient = new SipsClient(OfficeEnvironment.TEST, "201040040170001", 1, "rxSP61eeP_oNi5TxCD7Ngy9YcwC8MLw6OlmFGGcsY54"); + } - @Test - void testSendWalletRequest() throws Exception { - GetWalletDataResponse response = sipsClient.send(new GetWalletDataRequest("1")); - System.out.println(response); - } + @Test + void testSendWalletRequest() throws Exception { + GetWalletDataResponse response = sipsClient.send(new GetWalletDataRequest("1")); + System.out.println(response); + } - @Test - void testResponseDeserialization() throws Exception { - GetWalletDataResponse response = ObjectMapperHolder.INSTANCE.get().readerFor(GetWalletDataResponse.class) - .readValue("{\"seal\":\"1\"}"); - Assertions.assertEquals("1", response.getSeal()); + @Test + void testResponseDeserialization() throws Exception { + GetWalletDataResponse response = ObjectMapperHolder.INSTANCE.get().readerFor(GetWalletDataResponse.class) + .readValue("{\"seal\":\"1\"}"); + Assertions.assertEquals("1", response.getSeal()); - response = ObjectMapperHolder.INSTANCE.get().readerFor(GetWalletDataResponse.class) - .readValue("{\"walletResponseCode\":\"00\"}"); - Assertions.assertEquals(WalletResponseCode.SUCCESS, response.getWalletResponseCode()); + response = ObjectMapperHolder.INSTANCE.get().readerFor(GetWalletDataResponse.class) + .readValue("{\"walletResponseCode\":\"00\"}"); + Assertions.assertEquals(WalletResponseCode.SUCCESS, response.getWalletResponseCode()); - response = ObjectMapperHolder.INSTANCE.get().readerFor(GetWalletDataResponse.class) - .readValue("{\n" - + " \"walletCreationDateTime\": \"2013-12-23T05:17:26-12:00\",\n" - + " \"walletLastActionDateTime\": \"2014-01-19T23:16:00-12:00\",\n" - + " \"walletResponseCode\": \"00\",\n" - + " \"walletPaymentMeanDataList\": [\n" - + " {\n" - + " \"paymentMeanId\": \"14\",\n" - + " \"maskedPan\": \"4977##########02\",\n" - + " \"paymentMeanBrand\": \"SEPA_DIRECT_DEBIT\"\n" - + " },\n" - + " {\n" - + " \"paymentMeanId\": \"13\",\n" - + " \"maskedPan\": \"4977##########55\",\n" - + " \"paymentMeanAlias\": \"MySDD\",\n" - + " \"panExpiryDate\": \"201501\",\n" - + " \"paymentMeanBrand\": \"CB\"\n" - + " }\n" - + " ],\n" - + " \"seal\": \"4579cfc4044c29550327f9cba0be400129e95cb5b2639c6e301484930b4f9f94\"\n" - + "}"); - Assertions.assertEquals(WalletResponseCode.SUCCESS, response.getWalletResponseCode()); + response = ObjectMapperHolder.INSTANCE.get().readerFor(GetWalletDataResponse.class) + .readValue("{\n" + + " \"walletCreationDateTime\": \"2013-12-23T05:17:26-12:00\",\n" + + " \"walletLastActionDateTime\": \"2014-01-19T23:16:00-12:00\",\n" + + " \"walletResponseCode\": \"00\",\n" + + " \"walletPaymentMeanDataList\": [\n" + + " {\n" + + " \"paymentMeanId\": \"14\",\n" + + " \"maskedPan\": \"4977##########02\",\n" + + " \"paymentMeanBrand\": \"SEPA_DIRECT_DEBIT\"\n" + + " },\n" + + " {\n" + + " \"paymentMeanId\": \"13\",\n" + + " \"maskedPan\": \"4977##########55\",\n" + + " \"paymentMeanAlias\": \"MySDD\",\n" + + " \"panExpiryDate\": \"201501\",\n" + + " \"paymentMeanBrand\": \"CB\"\n" + + " }\n" + + " ],\n" + + " \"seal\": \"4579cfc4044c29550327f9cba0be400129e95cb5b2639c6e301484930b4f9f94\"\n" + + "}"); + Assertions.assertEquals(WalletResponseCode.SUCCESS, response.getWalletResponseCode()); - - } + } } From 789eb00c47c8ebe8d38fbdf2fdc8198e5f024f15 Mon Sep 17 00:00:00 2001 From: Jydet Date: Sat, 22 Jan 2022 17:37:37 +0100 Subject: [PATCH 08/15] [WIP] Delete ING' HOMEPAY & remove ref to sips 2 --- .../sips/model/request/PaymentRequest.java | 4 ++-- .../model/response/InitializationResponse.java | 4 ++-- .../sips/model/response/PaypageResponse.java | 4 ++-- .../{SIPS2Request.java => SIPSRequest.java} | 8 ++++---- .../{SIPS2Response.java => SIPSResponse.java} | 4 ++-- .../java/com/worldline/sips/SipsClient.java | 12 ++++++------ .../worldline/sips/model/PaymentMeanBrand.java | 1 - .../sips/security/SealCalculator.java | 18 +++++++++--------- .../com/worldline/sips/api/WalletRequest.java | 4 ++-- .../com/worldline/sips/api/WalletResponse.java | 4 ++-- 10 files changed, 31 insertions(+), 32 deletions(-) rename sdk-common/src/main/java/com/worldline/sips/{SIPS2Request.java => SIPSRequest.java} (91%) rename sdk-common/src/main/java/com/worldline/sips/{SIPS2Response.java => SIPSResponse.java} (92%) diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/request/PaymentRequest.java b/payment-sdk/src/main/java/com/worldline/sips/model/request/PaymentRequest.java index 6680a85..a504b3a 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/request/PaymentRequest.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/request/PaymentRequest.java @@ -3,7 +3,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import com.worldline.sips.SIPS2Request; +import com.worldline.sips.SIPSRequest; import com.worldline.sips.configuration.PaymentConfiguration; import com.worldline.sips.model.PaymentMeanBrand; import com.worldline.sips.model.data.Address; @@ -28,7 +28,7 @@ */ @JsonPropertyOrder(alphabetic = true) @JsonInclude(JsonInclude.Include.NON_EMPTY) -public class PaymentRequest extends SIPS2Request { +public class PaymentRequest extends SIPSRequest { private static final String INTERFACE_VERSION = PaymentConfiguration.INTERFACE_VERSION; private final TreeSet paymentMeanBrandList = new TreeSet<>(); diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/response/InitializationResponse.java b/payment-sdk/src/main/java/com/worldline/sips/model/response/InitializationResponse.java index 6f3f2c6..6092de0 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/response/InitializationResponse.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/response/InitializationResponse.java @@ -1,6 +1,6 @@ package com.worldline.sips.model.response; -import com.worldline.sips.SIPS2Response; +import com.worldline.sips.SIPSResponse; import com.worldline.sips.model.data.RedirectionStatusCode; import com.worldline.sips.model.data.ResponseCode; @@ -9,7 +9,7 @@ /** * The server's response to a session initialization request. */ -public class InitializationResponse extends SIPS2Response { +public class InitializationResponse extends SIPSResponse { private String errorFieldName; private String redirectionData; private RedirectionStatusCode redirectionStatusCode; diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/response/PaypageResponse.java b/payment-sdk/src/main/java/com/worldline/sips/model/response/PaypageResponse.java index faaf4cc..0e2c87e 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/response/PaypageResponse.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/response/PaypageResponse.java @@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonUnwrapped; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.worldline.sips.SIPS2Response; +import com.worldline.sips.SIPSResponse; import com.worldline.sips.helper.ResponseDataDeserializer; import com.worldline.sips.model.data.ResponseData; @@ -12,7 +12,7 @@ * The result of payment made via the SIPS payment page. */ @JsonIgnoreProperties(ignoreUnknown = true) -public class PaypageResponse extends SIPS2Response { +public class PaypageResponse extends SIPSResponse { @JsonProperty("Data") @JsonUnwrapped diff --git a/sdk-common/src/main/java/com/worldline/sips/SIPS2Request.java b/sdk-common/src/main/java/com/worldline/sips/SIPSRequest.java similarity index 91% rename from sdk-common/src/main/java/com/worldline/sips/SIPS2Request.java rename to sdk-common/src/main/java/com/worldline/sips/SIPSRequest.java index 97951d1..fe23608 100644 --- a/sdk-common/src/main/java/com/worldline/sips/SIPS2Request.java +++ b/sdk-common/src/main/java/com/worldline/sips/SIPSRequest.java @@ -12,11 +12,11 @@ * * @param the type of the response that should be returned by sending this request to SIPS * @see Sealable - * @see SIPS2Response + * @see SIPSResponse */ @JsonPropertyOrder(alphabetic = true) @JsonInclude(JsonInclude.Include.NON_EMPTY) -public abstract class SIPS2Request implements Sealable { +public abstract class SIPSRequest implements Sealable { private final String endpoint; private String seal; private String merchantId; @@ -26,7 +26,7 @@ public abstract class SIPS2Request implements Se /** * @param endpoint the http endpoint targeted by this request */ - public SIPS2Request(String endpoint) { + public SIPSRequest(String endpoint) { this.endpoint = endpoint; } @@ -48,7 +48,7 @@ public void calculateSeal(String secretKey) throws SealCalculationException { public abstract Class getResponseType(); @JsonIgnore - final Class getRealType() { + final Class getRealType() { return this.getClass(); } diff --git a/sdk-common/src/main/java/com/worldline/sips/SIPS2Response.java b/sdk-common/src/main/java/com/worldline/sips/SIPSResponse.java similarity index 92% rename from sdk-common/src/main/java/com/worldline/sips/SIPS2Response.java rename to sdk-common/src/main/java/com/worldline/sips/SIPSResponse.java index 262c038..98b8fbc 100644 --- a/sdk-common/src/main/java/com/worldline/sips/SIPS2Response.java +++ b/sdk-common/src/main/java/com/worldline/sips/SIPSResponse.java @@ -7,9 +7,9 @@ import org.apache.commons.lang3.StringUtils; /** - * An abstract response from SIPS2 that contains the seal mechanism logic + * An abstract response from SIPS that contains the seal mechanism logic */ -public abstract class SIPS2Response implements Sealable { +public abstract class SIPSResponse implements Sealable { private String seal; /** diff --git a/sdk-common/src/main/java/com/worldline/sips/SipsClient.java b/sdk-common/src/main/java/com/worldline/sips/SipsClient.java index e2cb8df..c1916b3 100644 --- a/sdk-common/src/main/java/com/worldline/sips/SipsClient.java +++ b/sdk-common/src/main/java/com/worldline/sips/SipsClient.java @@ -118,8 +118,8 @@ public SipsClient(SipsEnvironment environment, String merchantId, Integer keyVer * @throws IllegalArgumentException – If conversion fails due to incompatible type; if so, root cause will contain underlying * checked exception data binding functionality threw */ - public static Response decodeResponse(Class responseClass, - Map parameters, String secretKey) throws IncorrectSealException, IllegalArgumentException { + public static Response decodeResponse(Class responseClass, + Map parameters, String secretKey) throws IncorrectSealException, IllegalArgumentException { verifySeal(parameters.get("Data"), parameters.get("Seal"), secretKey); return ObjectMapperHolder.INSTANCE.get().copy() .convertValue(parameters, responseClass); @@ -151,7 +151,7 @@ private static void verifySeal(String data, String seal, String secretKey) throw * @throws SealCalculationException if a seal calculation failed * @throws IncorrectSealException if the response's seal is incorrect */ - public Response send(SIPS2Request request) + public Response send(SIPSRequest request) throws SipsRequestException, SipsException, SealCalculationException, IncorrectSealException { String fullPath = environment.getUrl() + "/" + request.getEndpoint(); try { @@ -198,7 +198,7 @@ public Response send(SIPS2Request req * @throws IllegalArgumentException – If conversion fails due to incompatible type; if so, root cause will contain underlying * checked exception data binding functionality threw */ - public Response decodeResponse(Class responseClass, Map parameters) + public Response decodeResponse(Class responseClass, Map parameters) throws IncorrectSealException, IllegalArgumentException { return decodeResponse(responseClass, parameters, secretKey); } @@ -210,9 +210,9 @@ public Response decodeResponse(Class * @param response the received response upon initialization * @throws IncorrectSealException when the received seal is different from the one calculated * @throws SealCalculationException when seal calculation fails, see inner exception for details. - * @see SIPS2Response#verifySeal(String) = identical + * @see SIPSResponse#verifySeal(String) = identical */ - private void verifySeal(SIPS2Response response) throws IncorrectSealException, SealCalculationException { + private void verifySeal(SIPSResponse response) throws IncorrectSealException, SealCalculationException { response.verifySeal(secretKey); } } diff --git a/sdk-common/src/main/java/com/worldline/sips/model/PaymentMeanBrand.java b/sdk-common/src/main/java/com/worldline/sips/model/PaymentMeanBrand.java index 6580d8b..7a22b51 100644 --- a/sdk-common/src/main/java/com/worldline/sips/model/PaymentMeanBrand.java +++ b/sdk-common/src/main/java/com/worldline/sips/model/PaymentMeanBrand.java @@ -52,7 +52,6 @@ public enum PaymentMeanBrand { IDEAL(CREDIT_TRANSFER), ILLICADO(CARD), INCASSO(DIRECT_DEBIT), - IGNHOMEPAY(CREDIT_TRANSFER), JCB(CARD), KBCONLINE(CREDIT_TRANSFER), LEPOTCOMMUN(CARD), diff --git a/sdk-common/src/main/java/com/worldline/sips/security/SealCalculator.java b/sdk-common/src/main/java/com/worldline/sips/security/SealCalculator.java index 27762f9..0c5148f 100644 --- a/sdk-common/src/main/java/com/worldline/sips/security/SealCalculator.java +++ b/sdk-common/src/main/java/com/worldline/sips/security/SealCalculator.java @@ -1,7 +1,7 @@ package com.worldline.sips.security; -import com.worldline.sips.SIPS2Request; -import com.worldline.sips.SIPS2Response; +import com.worldline.sips.SIPSRequest; +import com.worldline.sips.SIPSResponse; import com.worldline.sips.exception.SealCalculationException; import com.worldline.sips.helper.AlphabeticalReflectionToStringBuilder; import com.worldline.sips.helper.SealStringStyle; @@ -25,13 +25,13 @@ private SealCalculator() { } /** - * Calculate the encrypted seal for a {@link SIPS2Request} based on a given seal string. + * Calculate the encrypted seal for a {@link SIPSRequest} based on a given seal string. * - * @param sealString the seal string for the {@link SIPS2Request} that needs to be signed + * @param sealString the seal string for the {@link SIPSRequest} that needs to be signed * @param key the merchant's secret key * @return the encrypted seal for the request * @throws SealCalculationException when the encryption fails (e.g. algorithm missing, invalid key specified) - * @see #getSealString(SIPS2Request) + * @see #getSealString(SIPSRequest) */ public static String calculate(String sealString, String key) throws SealCalculationException { try { @@ -45,12 +45,12 @@ public static String calculate(String sealString, String key) throws SealCalcula } /** - * Sort & concatenate the fields of a given {@link SIPS2Request}, needed to correctly sign the request. + * Sort & concatenate the fields of a given {@link SIPSRequest}, needed to correctly sign the request. * * @param request the request that's needs to be signed * @return a String, formatted as described in the API docs. */ - public static String getSealString(SIPS2Request request) { + public static String getSealString(SIPSRequest request) { ReflectionToStringBuilder reflectionToStringBuilder = new AlphabeticalReflectionToStringBuilder(request, new SealStringStyle()); reflectionToStringBuilder.setExcludeFieldNames("keyVersion", "endpoint"); reflectionToStringBuilder.setExcludeNullValues(true); @@ -59,12 +59,12 @@ public static String getSealString(SIPS2Request request) { } /** - * Sort & concatenate the fields of a given {@link SIPS2Response}, needed to correctly verify a response. + * Sort & concatenate the fields of a given {@link SIPSResponse}, needed to correctly verify a response. * * @param response the response that's needs to be verified * @return a String, formatted as described in the API docs. */ - public static String getSealString(SIPS2Response response) { + public static String getSealString(SIPSResponse response) { ReflectionToStringBuilder reflectionToStringBuilder = new AlphabeticalReflectionToStringBuilder(response, new SealStringStyle()); reflectionToStringBuilder.setExcludeFieldNames("seal"); reflectionToStringBuilder.setExcludeNullValues(true); diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/WalletRequest.java b/wallet-sdk/src/main/java/com/worldline/sips/api/WalletRequest.java index 76f6df7..936d13c 100644 --- a/wallet-sdk/src/main/java/com/worldline/sips/api/WalletRequest.java +++ b/wallet-sdk/src/main/java/com/worldline/sips/api/WalletRequest.java @@ -1,10 +1,10 @@ package com.worldline.sips.api; import com.fasterxml.jackson.annotation.JsonInclude; -import com.worldline.sips.SIPS2Request; +import com.worldline.sips.SIPSRequest; import com.worldline.sips.api.configuration.OfficeConfiguration; -public abstract class WalletRequest extends SIPS2Request { +public abstract class WalletRequest extends SIPSRequest { public WalletRequest(String endpoint) { super("wallet/" + endpoint); diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponse.java b/wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponse.java index f320784..0bb3939 100644 --- a/wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponse.java +++ b/wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponse.java @@ -1,8 +1,8 @@ package com.worldline.sips.api; -import com.worldline.sips.SIPS2Response; +import com.worldline.sips.SIPSResponse; -public abstract class WalletResponse extends SIPS2Response { +public abstract class WalletResponse extends SIPSResponse { private String errorFieldName; private WalletResponseCode walletResponseCode; From af604f2da876ed6050e6e03d64845f44b4c3512f Mon Sep 17 00:00:00 2001 From: w112739 Date: Mon, 24 Jan 2022 15:25:39 +0100 Subject: [PATCH 09/15] [WIP] Rename common sdk - fix javadoc - fix exception bad imports - remove unused code - add few tests - accept unknown response code --- build.gradle | 27 +++++++++-------- {wallet-sdk => office-sdk}/build.gradle | 0 .../com/worldline/sips/api/WalletRequest.java | 0 .../worldline/sips/api/WalletResponse.java | 9 ++++++ .../configuration/OfficeConfiguration.java | 0 .../api/configuration/OfficeEnvironment.java | 4 --- .../model/data/NamedWalletResponseCode.java | 18 +++--------- .../api/model/data/UnknownResponseCode.java | 23 +++++++++++++++ .../api/model/data/WalletPaymentMeanData.java | 1 + .../api/model/data/WalletResponseCode.java | 19 ++++++++++++ .../request/DeletePaymentMeanRequest.java | 0 .../model/request/GetWalletDataRequest.java | 0 .../response/DeletePaymentMeanResponse.java | 0 .../model/response/GetWalletDataResponse.java | 0 .../WalletResponseDeserializeCodeTest.java | 22 ++++++++++++++ .../worldline/sips/utils/WalletSipsTest.java | 21 ++++++++++---- .../PaymentInitializationException.java | 7 ----- .../response/InitializationResponse.java | 7 ----- .../java/com/worldline/sips/SIPSRequest.java | 1 + .../java/com/worldline/sips/SipsClient.java | 10 +++++-- settings.gradle | 3 +- .../sips/api/model/data/PaymentMeanData.java | 29 ------------------- 22 files changed, 118 insertions(+), 83 deletions(-) rename {wallet-sdk => office-sdk}/build.gradle (100%) rename {wallet-sdk => office-sdk}/src/main/java/com/worldline/sips/api/WalletRequest.java (100%) rename {wallet-sdk => office-sdk}/src/main/java/com/worldline/sips/api/WalletResponse.java (56%) rename {wallet-sdk => office-sdk}/src/main/java/com/worldline/sips/api/configuration/OfficeConfiguration.java (100%) rename {wallet-sdk => office-sdk}/src/main/java/com/worldline/sips/api/configuration/OfficeEnvironment.java (90%) rename wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponseCode.java => office-sdk/src/main/java/com/worldline/sips/api/model/data/NamedWalletResponseCode.java (70%) create mode 100644 office-sdk/src/main/java/com/worldline/sips/api/model/data/UnknownResponseCode.java rename {wallet-sdk => office-sdk}/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java (99%) create mode 100644 office-sdk/src/main/java/com/worldline/sips/api/model/data/WalletResponseCode.java rename {wallet-sdk => office-sdk}/src/main/java/com/worldline/sips/api/model/request/DeletePaymentMeanRequest.java (100%) rename {wallet-sdk => office-sdk}/src/main/java/com/worldline/sips/api/model/request/GetWalletDataRequest.java (100%) rename {wallet-sdk => office-sdk}/src/main/java/com/worldline/sips/api/model/response/DeletePaymentMeanResponse.java (100%) rename {wallet-sdk => office-sdk}/src/main/java/com/worldline/sips/api/model/response/GetWalletDataResponse.java (100%) create mode 100644 office-sdk/src/test/java/com/worldline/sips/api/model/data/WalletResponseDeserializeCodeTest.java rename {wallet-sdk => office-sdk}/src/test/java/com/worldline/sips/utils/WalletSipsTest.java (69%) delete mode 100644 payment-sdk/src/main/java/com/worldline/sips/exception/PaymentInitializationException.java delete mode 100644 wallet-sdk/src/main/java/com/worldline/sips/api/model/data/PaymentMeanData.java diff --git a/build.gradle b/build.gradle index 7d2b4a6..2237078 100644 --- a/build.gradle +++ b/build.gradle @@ -57,20 +57,23 @@ allprojects { } } } -// repositories { -// maven { -// url "https://oss.sonatype.org/service/local/staging/deploy/maven2" -// credentials { -// username sonatypeUsername -// password sonatypePassword -// } -// } -// } - } + repositories { + maven { + def releasesRepoUrl = "https://nexus.kazan.myworldline.com/repository/rcs-store-releases" + def snapshotsRepoUrl = "https://nexus.kazan.myworldline.com/repository/rcs-store-snapshots" - signing { - sign publishing.publications.maven + url = project.hasProperty('release') ? releasesRepoUrl : snapshotsRepoUrl + credentials { + username= findProperty('nexusRepoUser') + password= findProperty('nexusRepoPass') + } + } + } } +// +// signing { +// sign publishing.publications.maven +// } javadoc { if (JavaVersion.current().isJava9Compatible()) { diff --git a/wallet-sdk/build.gradle b/office-sdk/build.gradle similarity index 100% rename from wallet-sdk/build.gradle rename to office-sdk/build.gradle diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/WalletRequest.java b/office-sdk/src/main/java/com/worldline/sips/api/WalletRequest.java similarity index 100% rename from wallet-sdk/src/main/java/com/worldline/sips/api/WalletRequest.java rename to office-sdk/src/main/java/com/worldline/sips/api/WalletRequest.java diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponse.java b/office-sdk/src/main/java/com/worldline/sips/api/WalletResponse.java similarity index 56% rename from wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponse.java rename to office-sdk/src/main/java/com/worldline/sips/api/WalletResponse.java index 0bb3939..b3254eb 100644 --- a/wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponse.java +++ b/office-sdk/src/main/java/com/worldline/sips/api/WalletResponse.java @@ -1,11 +1,20 @@ package com.worldline.sips.api; import com.worldline.sips.SIPSResponse; +import com.worldline.sips.api.model.data.NamedWalletResponseCode; +import com.worldline.sips.api.model.data.WalletResponseCode; + public abstract class WalletResponse extends SIPSResponse { + private String errorFieldName; private WalletResponseCode walletResponseCode; + /** + * Available if walletResponseCode is {@link NamedWalletResponseCode#FORMAT_ERROR} or + * {@link NamedWalletResponseCode#INVALID_DATA} + * @return the error + */ public String getErrorFieldName() { return errorFieldName; } diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/configuration/OfficeConfiguration.java b/office-sdk/src/main/java/com/worldline/sips/api/configuration/OfficeConfiguration.java similarity index 100% rename from wallet-sdk/src/main/java/com/worldline/sips/api/configuration/OfficeConfiguration.java rename to office-sdk/src/main/java/com/worldline/sips/api/configuration/OfficeConfiguration.java diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/configuration/OfficeEnvironment.java b/office-sdk/src/main/java/com/worldline/sips/api/configuration/OfficeEnvironment.java similarity index 90% rename from wallet-sdk/src/main/java/com/worldline/sips/api/configuration/OfficeEnvironment.java rename to office-sdk/src/main/java/com/worldline/sips/api/configuration/OfficeEnvironment.java index 2f9f849..935de0c 100644 --- a/wallet-sdk/src/main/java/com/worldline/sips/api/configuration/OfficeEnvironment.java +++ b/office-sdk/src/main/java/com/worldline/sips/api/configuration/OfficeEnvironment.java @@ -20,8 +20,4 @@ public String getUrl() { return url; } - public URI getURI() { - return uri; - } - } diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponseCode.java b/office-sdk/src/main/java/com/worldline/sips/api/model/data/NamedWalletResponseCode.java similarity index 70% rename from wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponseCode.java rename to office-sdk/src/main/java/com/worldline/sips/api/model/data/NamedWalletResponseCode.java index e195263..84e5f54 100644 --- a/wallet-sdk/src/main/java/com/worldline/sips/api/WalletResponseCode.java +++ b/office-sdk/src/main/java/com/worldline/sips/api/model/data/NamedWalletResponseCode.java @@ -1,11 +1,11 @@ -package com.worldline.sips.api; +package com.worldline.sips.api.model.data; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; import com.worldline.sips.exception.UnknownStatusException; //FIXME add data type https://documentation.sips.worldline.com/en/WLSIPS.001-GD-Data-dictionary.html#Sips.001_DD_en-Value-responseCode_ -public enum WalletResponseCode { +public enum NamedWalletResponseCode implements WalletResponseCode { /** * Successful operation */ @@ -40,21 +40,11 @@ public enum WalletResponseCode { private final String code; - WalletResponseCode(String code) { + NamedWalletResponseCode(String code) { this.code = code; } - @JsonCreator - public static WalletResponseCode fromCode(String code) throws UnknownStatusException { - for (WalletResponseCode responseCode : WalletResponseCode.values()) { - if (responseCode.getCode().equals(code)) { - return responseCode; - } - } - - throw new UnknownStatusException(code + " is an unknown response code!"); - } - + @Override @JsonValue public String getCode() { return code; diff --git a/office-sdk/src/main/java/com/worldline/sips/api/model/data/UnknownResponseCode.java b/office-sdk/src/main/java/com/worldline/sips/api/model/data/UnknownResponseCode.java new file mode 100644 index 0000000..8a5065b --- /dev/null +++ b/office-sdk/src/main/java/com/worldline/sips/api/model/data/UnknownResponseCode.java @@ -0,0 +1,23 @@ +package com.worldline.sips.api.model.data; + +import com.fasterxml.jackson.annotation.JsonValue; + +public class UnknownResponseCode implements WalletResponseCode { + + private final String responseCode; + + public UnknownResponseCode(String responseCode) { + this.responseCode = responseCode; + } + + @Override + @JsonValue + public String getCode() { + return responseCode; + } + + @Override + public String toString() { + return responseCode; + } +} diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java b/office-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java similarity index 99% rename from wallet-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java rename to office-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java index 9ab86e8..590bfee 100644 --- a/wallet-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java +++ b/office-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java @@ -48,4 +48,5 @@ public String getPaymentMeanData() { public String getTransactionActors() { return transactionActors; } + } diff --git a/office-sdk/src/main/java/com/worldline/sips/api/model/data/WalletResponseCode.java b/office-sdk/src/main/java/com/worldline/sips/api/model/data/WalletResponseCode.java new file mode 100644 index 0000000..932caa3 --- /dev/null +++ b/office-sdk/src/main/java/com/worldline/sips/api/model/data/WalletResponseCode.java @@ -0,0 +1,19 @@ +package com.worldline.sips.api.model.data; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +public interface WalletResponseCode { + @JsonValue + String getCode(); + + @JsonCreator + static WalletResponseCode fromCode(String code) { + for (NamedWalletResponseCode responseCode : NamedWalletResponseCode.values()) { + if (responseCode.getCode().equals(code)) { + return responseCode; + } + } + return new UnknownResponseCode(code); + } +} diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/model/request/DeletePaymentMeanRequest.java b/office-sdk/src/main/java/com/worldline/sips/api/model/request/DeletePaymentMeanRequest.java similarity index 100% rename from wallet-sdk/src/main/java/com/worldline/sips/api/model/request/DeletePaymentMeanRequest.java rename to office-sdk/src/main/java/com/worldline/sips/api/model/request/DeletePaymentMeanRequest.java diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/model/request/GetWalletDataRequest.java b/office-sdk/src/main/java/com/worldline/sips/api/model/request/GetWalletDataRequest.java similarity index 100% rename from wallet-sdk/src/main/java/com/worldline/sips/api/model/request/GetWalletDataRequest.java rename to office-sdk/src/main/java/com/worldline/sips/api/model/request/GetWalletDataRequest.java diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/model/response/DeletePaymentMeanResponse.java b/office-sdk/src/main/java/com/worldline/sips/api/model/response/DeletePaymentMeanResponse.java similarity index 100% rename from wallet-sdk/src/main/java/com/worldline/sips/api/model/response/DeletePaymentMeanResponse.java rename to office-sdk/src/main/java/com/worldline/sips/api/model/response/DeletePaymentMeanResponse.java diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/model/response/GetWalletDataResponse.java b/office-sdk/src/main/java/com/worldline/sips/api/model/response/GetWalletDataResponse.java similarity index 100% rename from wallet-sdk/src/main/java/com/worldline/sips/api/model/response/GetWalletDataResponse.java rename to office-sdk/src/main/java/com/worldline/sips/api/model/response/GetWalletDataResponse.java diff --git a/office-sdk/src/test/java/com/worldline/sips/api/model/data/WalletResponseDeserializeCodeTest.java b/office-sdk/src/test/java/com/worldline/sips/api/model/data/WalletResponseDeserializeCodeTest.java new file mode 100644 index 0000000..307fc65 --- /dev/null +++ b/office-sdk/src/test/java/com/worldline/sips/api/model/data/WalletResponseDeserializeCodeTest.java @@ -0,0 +1,22 @@ +package com.worldline.sips.api.model.data; + +import com.worldline.sips.util.ObjectMapperHolder; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +class WalletResponseDeserializeCodeTest { + + @Test + public void deserializeKnownCode() throws Exception { + WalletResponseCode red = ObjectMapperHolder.INSTANCE.get().readerFor(WalletResponseCode.class).readValue("\"00\""); + Assertions.assertEquals("00", red.getCode()); + Assertions.assertEquals(NamedWalletResponseCode.SUCCESS, red); + } + + @Test + public void deserializeUnknownCode() throws Exception { + WalletResponseCode red = ObjectMapperHolder.INSTANCE.get().readerFor(WalletResponseCode.class).readValue("\"01\""); + Assertions.assertEquals("01", red.getCode()); + Assertions.assertEquals(UnknownResponseCode.class, red.getClass()); + } +} diff --git a/wallet-sdk/src/test/java/com/worldline/sips/utils/WalletSipsTest.java b/office-sdk/src/test/java/com/worldline/sips/utils/WalletSipsTest.java similarity index 69% rename from wallet-sdk/src/test/java/com/worldline/sips/utils/WalletSipsTest.java rename to office-sdk/src/test/java/com/worldline/sips/utils/WalletSipsTest.java index cfc61ae..021f535 100644 --- a/wallet-sdk/src/test/java/com/worldline/sips/utils/WalletSipsTest.java +++ b/office-sdk/src/test/java/com/worldline/sips/utils/WalletSipsTest.java @@ -1,11 +1,14 @@ package com.worldline.sips.utils; import com.worldline.sips.SipsClient; -import com.worldline.sips.api.WalletResponseCode; import com.worldline.sips.api.configuration.OfficeEnvironment; +import com.worldline.sips.api.model.data.NamedWalletResponseCode; +import com.worldline.sips.api.model.data.WalletPaymentMeanData; import com.worldline.sips.api.model.request.GetWalletDataRequest; import com.worldline.sips.api.model.response.GetWalletDataResponse; +import com.worldline.sips.model.PaymentMeanBrand; import com.worldline.sips.util.ObjectMapperHolder; +import java.util.List; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -34,7 +37,7 @@ void testResponseDeserialization() throws Exception { response = ObjectMapperHolder.INSTANCE.get().readerFor(GetWalletDataResponse.class) .readValue("{\"walletResponseCode\":\"00\"}"); - Assertions.assertEquals(WalletResponseCode.SUCCESS, response.getWalletResponseCode()); + Assertions.assertEquals(NamedWalletResponseCode.SUCCESS, response.getWalletResponseCode()); response = ObjectMapperHolder.INSTANCE.get().readerFor(GetWalletDataResponse.class) @@ -58,8 +61,16 @@ void testResponseDeserialization() throws Exception { + " ],\n" + " \"seal\": \"4579cfc4044c29550327f9cba0be400129e95cb5b2639c6e301484930b4f9f94\"\n" + "}"); - Assertions.assertEquals(WalletResponseCode.SUCCESS, response.getWalletResponseCode()); - - + Assertions.assertEquals(NamedWalletResponseCode.SUCCESS, response.getWalletResponseCode()); + List list = response.getWalletPaymentMeanDataList(); + Assertions.assertNotNull(list); + Assertions.assertEquals(2, list.size()); + WalletPaymentMeanData walletPaymentMeanData = list.get(0); + Assertions.assertNull(walletPaymentMeanData.getPaymentMeanAlias()); + Assertions.assertNull(walletPaymentMeanData.getPanExpiryDate()); + Assertions.assertEquals("14", walletPaymentMeanData.getPaymentMeanId()); + Assertions.assertEquals("4977##########02", walletPaymentMeanData.getMaskedPan()); + Assertions.assertEquals(PaymentMeanBrand.SEPA_DIRECT_DEBIT, walletPaymentMeanData.getPaymentMeanBrand()); + Assertions.assertNull(response.getErrorFieldName()); } } diff --git a/payment-sdk/src/main/java/com/worldline/sips/exception/PaymentInitializationException.java b/payment-sdk/src/main/java/com/worldline/sips/exception/PaymentInitializationException.java deleted file mode 100644 index e3027c3..0000000 --- a/payment-sdk/src/main/java/com/worldline/sips/exception/PaymentInitializationException.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.worldline.sips.exception; - -public class PaymentInitializationException extends Exception { - public PaymentInitializationException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/response/InitializationResponse.java b/payment-sdk/src/main/java/com/worldline/sips/model/response/InitializationResponse.java index 6092de0..e52ba5f 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/response/InitializationResponse.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/response/InitializationResponse.java @@ -73,11 +73,4 @@ public ResponseCode getResponseCode() { public void setResponseCode(ResponseCode responseCode) { this.responseCode = responseCode; } - - @Override - public String toString() { - return String.format( - "InitializationResponse{errorFieldName='%s', redirectionData='%s', redirectionStatusCode=%s, redirectionStatusMessage='%s', redirectionUrl=%s, redirectionVersion='%s', responseCode=%s, seal='%s'}", - errorFieldName, redirectionData, redirectionStatusCode, redirectionStatusMessage, redirectionUrl, redirectionVersion, responseCode, getSeal()); - } } diff --git a/sdk-common/src/main/java/com/worldline/sips/SIPSRequest.java b/sdk-common/src/main/java/com/worldline/sips/SIPSRequest.java index fe23608..1c6a72a 100644 --- a/sdk-common/src/main/java/com/worldline/sips/SIPSRequest.java +++ b/sdk-common/src/main/java/com/worldline/sips/SIPSRequest.java @@ -33,6 +33,7 @@ public SIPSRequest(String endpoint) { /** * Compute the seal of this request. * + * @param secretKey the secret key that will be used to generate this request's seal * @throws SealCalculationException when seal calculation fails, see inner exception for details. */ public void calculateSeal(String secretKey) throws SealCalculationException { diff --git a/sdk-common/src/main/java/com/worldline/sips/SipsClient.java b/sdk-common/src/main/java/com/worldline/sips/SipsClient.java index c1916b3..3073a6d 100644 --- a/sdk-common/src/main/java/com/worldline/sips/SipsClient.java +++ b/sdk-common/src/main/java/com/worldline/sips/SipsClient.java @@ -5,6 +5,7 @@ import com.worldline.sips.exception.IncorrectProxyConfException; import com.worldline.sips.exception.IncorrectSealException; import com.worldline.sips.exception.InvalidEnvironmentException; +import com.worldline.sips.exception.InvalidKeyException; import com.worldline.sips.exception.InvalidMerchantException; import com.worldline.sips.exception.SealCalculationException; import com.worldline.sips.exception.SipsException; @@ -26,7 +27,6 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; -import java.security.InvalidKeyException; import java.util.Map; /** @@ -113,6 +113,7 @@ public SipsClient(SipsEnvironment environment, String merchantId, Integer keyVer * @param responseClass the type of the response to construct * @param parameters the content of the received request, mapped as key-value pairs. * @param secretKey the secret key used to create the request that induced this response + * @param the type of the response * @return The constructed response. * @throws IncorrectSealException - If the response has been tampered with. * @throws IllegalArgumentException – If conversion fails due to incompatible type; if so, root cause will contain underlying @@ -143,9 +144,11 @@ private static void verifySeal(String data, String seal, String secretKey) throw /** * Send a request to sips and get the response synchronously. *

- * The seal of the request is calculated, the request is send, the response is received and its seal is checked. + * The seal of the request is calculated, the request is sent, the response is received and its seal is checked. * - * @param request the request that will be sent to SIPS + * @param request the request that will be sent to SIPS + * @param the type of the response + * @return a response object mapping the response sent by Sips * @throws SipsRequestException if an error occurred while serializing or sending the request * @throws SipsException if an error occurred while receiving or deserializing the response * @throws SealCalculationException if a seal calculation failed @@ -193,6 +196,7 @@ public Response send(SIPSRequest reque * * @param responseClass the type of the response to construct * @param parameters the content of the received request, mapped as key-value pairs. + * @param the type of the response * @return The constructed response. * @throws IncorrectSealException - If the response has been tampered with. * @throws IllegalArgumentException – If conversion fails due to incompatible type; if so, root cause will contain underlying diff --git a/settings.gradle b/settings.gradle index 1da1695..683f005 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,5 +1,4 @@ -include(':payment-sdk-common') include(':payment-sdk') -include(':wallet-sdk') +include(':office-sdk') include 'sdk-common' diff --git a/wallet-sdk/src/main/java/com/worldline/sips/api/model/data/PaymentMeanData.java b/wallet-sdk/src/main/java/com/worldline/sips/api/model/data/PaymentMeanData.java deleted file mode 100644 index f7b2d09..0000000 --- a/wallet-sdk/src/main/java/com/worldline/sips/api/model/data/PaymentMeanData.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.worldline.sips.api.model.data; - -public class PaymentMeanData { -/** - * accord - * accordkdo - * bancontact - * bcaCup - * bcacb3x - * bcacb4x - * bcmcMobile - * cetelem3x - * cetelem4x - * cofidis3x - * cofidis4x - * cofinoga - * cofinoga3xcb - * facilypay - * franfinance3xcb - * franfinance4xcb - * passbe - * paypal - * presto - * sdd - * unEuroCom - * visaCheckout - */ -} - From f003d620caaeccc46f35c28cccce603bcb8f13a9 Mon Sep 17 00:00:00 2001 From: w112739 Date: Mon, 24 Jan 2022 15:56:53 +0100 Subject: [PATCH 10/15] [WIP] Rename common sdk - fix javadoc - fix exception bad imports - remove unused code - add few tests - accept unknown response code --- .../sips/api/model/data/NamedWalletResponseCode.java | 3 --- .../worldline/sips/api/model/data/WalletPaymentMeanData.java | 4 +--- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/office-sdk/src/main/java/com/worldline/sips/api/model/data/NamedWalletResponseCode.java b/office-sdk/src/main/java/com/worldline/sips/api/model/data/NamedWalletResponseCode.java index 84e5f54..68942f8 100644 --- a/office-sdk/src/main/java/com/worldline/sips/api/model/data/NamedWalletResponseCode.java +++ b/office-sdk/src/main/java/com/worldline/sips/api/model/data/NamedWalletResponseCode.java @@ -1,10 +1,7 @@ package com.worldline.sips.api.model.data; -import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; -import com.worldline.sips.exception.UnknownStatusException; -//FIXME add data type https://documentation.sips.worldline.com/en/WLSIPS.001-GD-Data-dictionary.html#Sips.001_DD_en-Value-responseCode_ public enum NamedWalletResponseCode implements WalletResponseCode { /** * Successful operation diff --git a/office-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java b/office-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java index 590bfee..ab05639 100644 --- a/office-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java +++ b/office-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java @@ -2,14 +2,12 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.worldline.sips.model.PaymentMeanBrand; - import java.time.YearMonth; @JsonIgnoreProperties(ignoreUnknown = true) public class WalletPaymentMeanData { - /*PaymentMeanData*/ String paymentMeanData; + private String paymentMeanData; private String paymentMeanId; - //FIXME wtf ? private String maskedPan; private YearMonth panExpiryDate; private String paymentMeanAlias; From 70f56eece414852d2fc1177123c3165f41c97354 Mon Sep 17 00:00:00 2001 From: w112739 Date: Mon, 24 Jan 2022 15:56:53 +0100 Subject: [PATCH 11/15] [WIP] Remove todos --- .../sips/api/model/data/NamedWalletResponseCode.java | 3 --- .../worldline/sips/api/model/data/WalletPaymentMeanData.java | 4 +--- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/office-sdk/src/main/java/com/worldline/sips/api/model/data/NamedWalletResponseCode.java b/office-sdk/src/main/java/com/worldline/sips/api/model/data/NamedWalletResponseCode.java index 84e5f54..68942f8 100644 --- a/office-sdk/src/main/java/com/worldline/sips/api/model/data/NamedWalletResponseCode.java +++ b/office-sdk/src/main/java/com/worldline/sips/api/model/data/NamedWalletResponseCode.java @@ -1,10 +1,7 @@ package com.worldline.sips.api.model.data; -import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; -import com.worldline.sips.exception.UnknownStatusException; -//FIXME add data type https://documentation.sips.worldline.com/en/WLSIPS.001-GD-Data-dictionary.html#Sips.001_DD_en-Value-responseCode_ public enum NamedWalletResponseCode implements WalletResponseCode { /** * Successful operation diff --git a/office-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java b/office-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java index 590bfee..ab05639 100644 --- a/office-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java +++ b/office-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java @@ -2,14 +2,12 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.worldline.sips.model.PaymentMeanBrand; - import java.time.YearMonth; @JsonIgnoreProperties(ignoreUnknown = true) public class WalletPaymentMeanData { - /*PaymentMeanData*/ String paymentMeanData; + private String paymentMeanData; private String paymentMeanId; - //FIXME wtf ? private String maskedPan; private YearMonth panExpiryDate; private String paymentMeanAlias; From f570fcd63d394509a1ef513cdc1439578dd87eae Mon Sep 17 00:00:00 2001 From: w112739 Date: Mon, 24 Jan 2022 16:21:18 +0100 Subject: [PATCH 12/15] Update README.md --- README.md | 63 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 59a6d9f..3782573 100644 --- a/README.md +++ b/README.md @@ -4,14 +4,16 @@ This package provides a JAVA implementation for SIPS, a Worldline e-payments gat > :warning: This library was written for SIPS 2.0 and is not compatible with SIPS 1.0 ## Before you begin -This package contains a basic connector for SIPS, based on the **SIPS Paypage JSON API**. +This package contains a basic connector for SIPS, based on the **SIPS Paypage JSON API** and a very basic but extendable connector to the **SIPS Office JSON API**. Please refer to the [documentation](https://documentation.sips.worldline.com) for a better understanding. If you find field or functionality is missing, feel free to submit a PR or create an issue. -## Installing +## Payage API -### using Gradle +### Installing + +#### using Gradle ```groovy dependencies { @@ -20,7 +22,7 @@ dependencies { ``` -### using Maven +#### using Maven ```xml com.worldline.sips @@ -29,14 +31,14 @@ dependencies { ``` -## Usage +### Usage > :bulb: Currently this library only supports SIPS in pay page mode. -### Initialization +#### Initialization First, create a client for the desired environment using your merchant ID, key version & secret key: ```java -PaypageClient paypageClient = new PaypageClient( - Environment.TEST, +SipsClient paypageClient = new SipsClient( + PaymentEnvironment.TEST, "002001000000002", 1, // This shouldn't be hardcoded here... "002001000000002_KEY1"); // ...and neither should this. @@ -59,14 +61,14 @@ paymentRequest.setTransactionReference("My awesome transaction reference"); And initialize your session on the server: ```java -InitalizationResponse initializationResponse = paypageClient.initialize(paymentRequest); +InitalizationResponse initializationResponse = paypageClient.send(paymentRequest); ``` The `initializationResponse` you'll receive from the server contains all information needed to continue handling your transaction. If your initialization was successful, your response will contain a `RedirectionStatusCode.TRANSACTION_INITIALIZED`. -### Making the payment +#### Making the payment In case your initialization was successful, you have to use the `redirectionUrl` received to perform a POST request with both the `redirectionData` and `seal` as parameters. Since this should redirect the customer the SIPS payment page, the cleanest example is a simple HTML form: @@ -79,16 +81,53 @@ payment page, the cleanest example is a simple HTML form: ``` -### Verifying the payment +#### Verifying the payment When your customer is done, he will be able to return to your application. This is done via a form, making a POST request to the `normalReturnUrl` provided during the initialization of your payment. This POST request contains details on the payment. You can simply decode these responses, providing a `Map` of the parameters included in the received request to your `PaypageClient`: ```java -PaypageResponse paypageResponse = paypageClient.decodeResponse(mappedRequestParameters); +PaypageResponse paypageResponse = paypageClient.decodeResponse(PaypageResponse.class, mappedRequestParameters); +``` + +Alternatively if you don't have a client object when you need to verify the response, you can use the static method +of the SipsClient class (in this case you will have to provide your secret key): + +```java +PaypageResponse paypageResponse = SipsClient.decodeResponse(PaypageResponse.class, mappedRequestParameters, sipsSecretKey) ``` > :warning: Since the customer is not always redirecting back (e.g. he closes the confirmation page), it's a good practice to include an `automaticResponseUrl`. SIPS will always POST details on the transaction on this URL, even if a customer doesn't redirect back to your application. + +## Office API + +### Installing + +#### using Gradle +```groovy + +dependencies { + implementation 'com.worldline.sips:office-sdk:1.4.3' +} + +``` + +#### using Maven +```xml + + com.worldline.sips + office-sdk + 1.4.3 + +``` +### Usage + +The usage for sips office is the same as the payment API : create a SipsClient and send requests. + +Example with the getWalletData call : +````java +GetWalletDataResponse response = sipsClient.send(new GetWalletDataRequest(merchantWalletId)); +```` From f51f420f4122ea581d89758deb962d8f935f6e07 Mon Sep 17 00:00:00 2001 From: w112739 Date: Fri, 25 Feb 2022 18:36:16 +0100 Subject: [PATCH 13/15] Fix seal computation for response requests - YearMonth is correctly parsed in seal computation - Add s10TransactionReference for Sips1 retro-compatibility - Fix payment response parameters type - Offesetted type zone are now correctly parsed --- .../com/worldline/sips/api/WalletRequest.java | 3 +- .../configuration/OfficeConfiguration.java | 2 +- .../api/model/data/WalletPaymentMeanData.java | 10 ++-- .../model/response/GetWalletDataResponse.java | 12 ++--- .../sips/model/data/ResponseData.java | 10 +++- .../model/data/S10TransactionReference.java | 35 +++++++++++++ .../sips/model/request/PaymentRequest.java | 13 ++++- .../java/com/worldline/sips/SIPSResponse.java | 6 ++- .../java/com/worldline/sips/SipsClient.java | 51 +++++++++++++++++-- .../sips/helper/SealStringStyle.java | 9 ++-- .../sips/util/ObjectMapperHolder.java | 3 +- 11 files changed, 127 insertions(+), 27 deletions(-) create mode 100644 payment-sdk/src/main/java/com/worldline/sips/model/data/S10TransactionReference.java diff --git a/office-sdk/src/main/java/com/worldline/sips/api/WalletRequest.java b/office-sdk/src/main/java/com/worldline/sips/api/WalletRequest.java index 936d13c..24d82bb 100644 --- a/office-sdk/src/main/java/com/worldline/sips/api/WalletRequest.java +++ b/office-sdk/src/main/java/com/worldline/sips/api/WalletRequest.java @@ -5,6 +5,7 @@ import com.worldline.sips.api.configuration.OfficeConfiguration; public abstract class WalletRequest extends SIPSRequest { + private static final String INTERFACE_VERSION = OfficeConfiguration.INTERFACE_VERSION; public WalletRequest(String endpoint) { super("wallet/" + endpoint); @@ -12,6 +13,6 @@ public WalletRequest(String endpoint) { @JsonInclude public String getInterfaceVersion() { - return OfficeConfiguration.INTERFACE_VERSION; + return INTERFACE_VERSION; } } diff --git a/office-sdk/src/main/java/com/worldline/sips/api/configuration/OfficeConfiguration.java b/office-sdk/src/main/java/com/worldline/sips/api/configuration/OfficeConfiguration.java index 1314e71..7073c96 100644 --- a/office-sdk/src/main/java/com/worldline/sips/api/configuration/OfficeConfiguration.java +++ b/office-sdk/src/main/java/com/worldline/sips/api/configuration/OfficeConfiguration.java @@ -7,7 +7,7 @@ public class OfficeConfiguration { /** * The targeted version of the API */ - public static final String INTERFACE_VERSION = "WR_WS_2.39"; + public static final String INTERFACE_VERSION = "WR_WS_2.42"; private OfficeConfiguration() { // Nothing to see here diff --git a/office-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java b/office-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java index ab05639..b9778e7 100644 --- a/office-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java +++ b/office-sdk/src/main/java/com/worldline/sips/api/model/data/WalletPaymentMeanData.java @@ -12,8 +12,8 @@ public class WalletPaymentMeanData { private YearMonth panExpiryDate; private String paymentMeanAlias; private PaymentMeanBrand paymentMeanBrand; - private String paymentMeanBrandCobadgedList; - private String transactionActors; + private String[] paymentMeanCoBadgingBrandList; + private String[] transactionActors; public String getPaymentMeanId() { return paymentMeanId; @@ -35,15 +35,15 @@ public PaymentMeanBrand getPaymentMeanBrand() { return paymentMeanBrand; } - public String getPaymentMeanBrandCobadgedList() { - return paymentMeanBrandCobadgedList; + public String[] getPaymentMeanCoBadgingBrandList() { + return paymentMeanCoBadgingBrandList; } public String getPaymentMeanData() { return paymentMeanData; } - public String getTransactionActors() { + public String[] getTransactionActors() { return transactionActors; } diff --git a/office-sdk/src/main/java/com/worldline/sips/api/model/response/GetWalletDataResponse.java b/office-sdk/src/main/java/com/worldline/sips/api/model/response/GetWalletDataResponse.java index e0362d1..3673cf7 100644 --- a/office-sdk/src/main/java/com/worldline/sips/api/model/response/GetWalletDataResponse.java +++ b/office-sdk/src/main/java/com/worldline/sips/api/model/response/GetWalletDataResponse.java @@ -3,21 +3,21 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.worldline.sips.api.WalletResponse; import com.worldline.sips.api.model.data.WalletPaymentMeanData; - -import java.time.LocalDateTime; +import java.time.OffsetDateTime; import java.util.List; @JsonIgnoreProperties(ignoreUnknown = true) public class GetWalletDataResponse extends WalletResponse { - private LocalDateTime walletCreationDateTime; - private LocalDateTime walletLastActionDateTime; + private OffsetDateTime walletCreationDateTime; + private OffsetDateTime walletLastActionDateTime; + private List walletPaymentMeanDataList; - public LocalDateTime getWalletCreationDateTime() { + public OffsetDateTime getWalletCreationDateTime() { return walletCreationDateTime; } - public LocalDateTime getWalletLastActionDateTime() { + public OffsetDateTime getWalletLastActionDateTime() { return walletLastActionDateTime; } diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/data/ResponseData.java b/payment-sdk/src/main/java/com/worldline/sips/model/data/ResponseData.java index 46c30a5..5bf94e5 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/data/ResponseData.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/data/ResponseData.java @@ -6,7 +6,6 @@ import com.worldline.sips.helper.RuleResultListDeserializer; import com.worldline.sips.model.PaymentMeanBrand; import com.worldline.sips.model.PaymentMeanType; - import java.time.LocalDate; import java.time.LocalDateTime; import java.time.YearMonth; @@ -73,7 +72,16 @@ public class ResponseData { private String orderId; private String returnContext; + private int s10TransactionId; + private LocalDate s10TransactionIdDate; + + public int getS10TransactionId() { + return s10TransactionId; + } + public LocalDate getS10TransactionIdDate() { + return s10TransactionIdDate; + } public int getAmount() { return amount; diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/data/S10TransactionReference.java b/payment-sdk/src/main/java/com/worldline/sips/model/data/S10TransactionReference.java new file mode 100644 index 0000000..76fd3e3 --- /dev/null +++ b/payment-sdk/src/main/java/com/worldline/sips/model/data/S10TransactionReference.java @@ -0,0 +1,35 @@ +package com.worldline.sips.model.data; + +import com.fasterxml.jackson.annotation.JsonInclude; +import java.time.LocalDate; + + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +public class S10TransactionReference { + private int s10TransactionId; + private LocalDate s10TransactionIdDate; + + public S10TransactionReference() { + + } + + public S10TransactionReference(int s10TransactionId) { + this.s10TransactionId = s10TransactionId; + } + + public int getS10TransactionId() { + return s10TransactionId; + } + + public void setS10TransactionId(int s10TransactionId) { + this.s10TransactionId = s10TransactionId; + } + + public LocalDate getS10TransactionIdDate() { + return s10TransactionIdDate; + } + + public void setS10TransactionIdDate(LocalDate s10TransactionIdDate) { + this.s10TransactionIdDate = s10TransactionIdDate; + } +} diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/request/PaymentRequest.java b/payment-sdk/src/main/java/com/worldline/sips/model/request/PaymentRequest.java index a504b3a..b92a642 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/request/PaymentRequest.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/request/PaymentRequest.java @@ -15,8 +15,8 @@ import com.worldline.sips.model.data.Language; import com.worldline.sips.model.data.OrderChannel; import com.worldline.sips.model.data.PaypageData; +import com.worldline.sips.model.data.S10TransactionReference; import com.worldline.sips.model.response.InitializationResponse; - import java.net.URL; import java.util.TreeSet; @@ -64,6 +64,7 @@ public class PaymentRequest extends SIPSRequest { private String statementReference; private String templateName; private PaypageData paypageData; + private S10TransactionReference s10TransactionReference; public PaymentRequest() { super(""); @@ -326,7 +327,15 @@ public void setPaypageData(PaypageData paypageData) { this.paypageData = paypageData; } - @Override + public S10TransactionReference getS10TransactionReference() { + return s10TransactionReference; + } + + public void setS10TransactionReference(S10TransactionReference s10TransactionReference) { + this.s10TransactionReference = s10TransactionReference; + } + + @Override public Class getResponseType() { return InitializationResponse.class; } diff --git a/sdk-common/src/main/java/com/worldline/sips/SIPSResponse.java b/sdk-common/src/main/java/com/worldline/sips/SIPSResponse.java index 98b8fbc..1fabeec 100644 --- a/sdk-common/src/main/java/com/worldline/sips/SIPSResponse.java +++ b/sdk-common/src/main/java/com/worldline/sips/SIPSResponse.java @@ -22,8 +22,10 @@ public abstract class SIPSResponse implements Sealable { */ public void verifySeal(String secretKey) throws IncorrectSealException, SealCalculationException { if (seal != null) { - String correctSeal = SealCalculator.calculate( - SealCalculator.getSealString(this), secretKey); + String sealString = SealCalculator.getSealString(this); + System.out.println(sealString); + String correctSeal = SealCalculator.calculate( + sealString, secretKey); if (! StringUtils.equals(correctSeal, seal)) { throw new IncorrectSealException("The response has been tampered with!"); } diff --git a/sdk-common/src/main/java/com/worldline/sips/SipsClient.java b/sdk-common/src/main/java/com/worldline/sips/SipsClient.java index 3073a6d..165f3bf 100644 --- a/sdk-common/src/main/java/com/worldline/sips/SipsClient.java +++ b/sdk-common/src/main/java/com/worldline/sips/SipsClient.java @@ -2,6 +2,8 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import com.worldline.sips.exception.IncorrectProxyConfException; import com.worldline.sips.exception.IncorrectSealException; import com.worldline.sips.exception.InvalidEnvironmentException; @@ -12,6 +14,10 @@ import com.worldline.sips.exception.SipsRequestException; import com.worldline.sips.model.SipsEnvironment; import com.worldline.sips.util.ObjectMapperHolder; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Map; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang3.StringUtils; import org.apache.hc.client5.http.classic.methods.HttpPost; @@ -24,11 +30,6 @@ import org.apache.hc.core5.http.io.entity.EntityUtils; import org.apache.hc.core5.http.io.entity.StringEntity; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Map; - /** * Interact with SIPS APIs. */ @@ -126,6 +127,46 @@ public static Response decodeResponse(Class the type of the response + * @return The constructed response. + * @throws IncorrectSealException - If the response has been tampered with. + * @throws IllegalArgumentException – If conversion fails due to incompatible type; if so, root cause will contain underlying + * checked exception data binding functionality threw + */ + public Response decodeResponse(Class responseClass, + String rawJson) throws IncorrectSealException, IllegalArgumentException { + return decodeResponse(responseClass, rawJson, secretKey); + } + /** + * Decode a SIPS response object from a json string. + * + * @param responseClass the type of the response to construct + * @param rawJson the content of the received request as raw JSON. + * @param secretKey the secret key used to create the request that induced this response + * @param the type of the response + * @return The constructed response. + * @throws IncorrectSealException - If the response has been tampered with. + * @throws IllegalArgumentException – If conversion fails due to incompatible type; if so, root cause will contain underlying + * checked exception data binding functionality threw + */ + public static Response decodeResponse(Class responseClass, + String rawJson, String secretKey) throws IncorrectSealException, IllegalArgumentException { + ObjectMapper copy = ObjectMapperHolder.INSTANCE.get().copy(); + JsonNode jsonObj; + try { + jsonObj = copy.readTree(rawJson); + } catch (Exception e) { + throw new IllegalArgumentException(e); + } + verifySeal(jsonObj.get("Data").textValue(), jsonObj.get("Seal").textValue(), secretKey); + return copy.convertValue(jsonObj, responseClass); + } + /** * Verify the seal of a sips response. To avoid tampered data, * the seal for the received response should always be verified before returning the object to the user. diff --git a/sdk-common/src/main/java/com/worldline/sips/helper/SealStringStyle.java b/sdk-common/src/main/java/com/worldline/sips/helper/SealStringStyle.java index 4208def..69cbce6 100644 --- a/sdk-common/src/main/java/com/worldline/sips/helper/SealStringStyle.java +++ b/sdk-common/src/main/java/com/worldline/sips/helper/SealStringStyle.java @@ -1,11 +1,11 @@ package com.worldline.sips.helper; +import java.time.YearMonth; +import java.util.Arrays; import org.apache.commons.lang3.ClassUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.builder.RecursiveToStringStyle; -import java.util.Arrays; - /** * A {@link RecursiveToStringStyle} parametrized to the seal format * @@ -33,7 +33,10 @@ public void appendDetail(StringBuffer buffer, String fieldName, Object value) { accept(value.getClass())) { buffer.append(AlphabeticalReflectionToStringBuilder.toString(value, this)); } else { - super.appendDetail(buffer, fieldName, value); + if (value instanceof YearMonth) { + value = ((YearMonth) value).toString().replace("-", ""); + } + super.appendDetail(buffer, fieldName, value); } } diff --git a/sdk-common/src/main/java/com/worldline/sips/util/ObjectMapperHolder.java b/sdk-common/src/main/java/com/worldline/sips/util/ObjectMapperHolder.java index fbd2213..493162c 100644 --- a/sdk-common/src/main/java/com/worldline/sips/util/ObjectMapperHolder.java +++ b/sdk-common/src/main/java/com/worldline/sips/util/ObjectMapperHolder.java @@ -1,11 +1,11 @@ package com.worldline.sips.util; +import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer; import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer; import com.fasterxml.jackson.datatype.jsr310.deser.YearMonthDeserializer; - import java.time.LocalDate; import java.time.LocalDateTime; import java.time.YearMonth; @@ -27,6 +27,7 @@ public enum ObjectMapperHolder { private static ObjectMapper create() { return new ObjectMapper() + .configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, false) .registerModule(new JavaTimeModule() .addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ISO_OFFSET_DATE_TIME)) .addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.BASIC_ISO_DATE)) From bfaa8edbab3cae1797a6696775d612166084c12d Mon Sep 17 00:00:00 2001 From: Arthur PELLOUX-PRAYER Date: Mon, 21 Nov 2022 14:06:28 +0100 Subject: [PATCH 14/15] Add support for unknown payement brand and mean --- CHANGELOG.md | 2 +- build.gradle | 2 +- .../response/DeletePaymentMeanResponse.java | 7 +- .../worldline/sips/utils/WalletSipsTest.java | 15 ++- .../configuration/PaymentConfiguration.java | 2 +- .../worldline/sips/api/PaypageClientTest.java | 9 ++ .../sips/api/SealCalculatorTest.java | 27 +++-- .../sips/helper/SealStringStyle.java | 6 +- .../sips/model/NamedPaymentMeanBrand.java | 96 +++++++++++++++++ .../sips/model/NamedPaymentMeanType.java | 11 ++ .../sips/model/PaymentMeanBrand.java | 102 ++---------------- .../worldline/sips/model/PaymentMeanType.java | 19 ++-- .../sips/model/UnknownPaymentMeanBrand.java | 14 +++ .../sips/model/UnknownPaymentMeanType.java | 14 +++ 14 files changed, 201 insertions(+), 125 deletions(-) create mode 100644 sdk-common/src/main/java/com/worldline/sips/model/NamedPaymentMeanBrand.java create mode 100644 sdk-common/src/main/java/com/worldline/sips/model/NamedPaymentMeanType.java create mode 100644 sdk-common/src/main/java/com/worldline/sips/model/UnknownPaymentMeanBrand.java create mode 100644 sdk-common/src/main/java/com/worldline/sips/model/UnknownPaymentMeanType.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 56d714d..7e895b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,7 +27,7 @@ All notable changes to this project will be documented in this file. :warning: **BREAKING:** Changed SIPS platform URLs ### Changed -- Bumped interface version to 21R1 (IR_WS_2.35) +- Bumped interface version to 21R1 (IR_WS_2.46) ### Upgraded - Update fasterxml/jackson to 2.12.1 diff --git a/build.gradle b/build.gradle index 2237078..fac5306 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ allprojects { sourceCompatibility = 1.8 group 'com.worldline.sips' - version '1.4.4-SNAPSHOT' + version '1.4.5-SNAPSHOT' task sourcesJar(type: Jar, dependsOn: classes) { archiveClassifier.set("sources") diff --git a/office-sdk/src/main/java/com/worldline/sips/api/model/response/DeletePaymentMeanResponse.java b/office-sdk/src/main/java/com/worldline/sips/api/model/response/DeletePaymentMeanResponse.java index 473a072..a7d6960 100644 --- a/office-sdk/src/main/java/com/worldline/sips/api/model/response/DeletePaymentMeanResponse.java +++ b/office-sdk/src/main/java/com/worldline/sips/api/model/response/DeletePaymentMeanResponse.java @@ -2,14 +2,13 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.worldline.sips.api.WalletResponse; - -import java.time.LocalDateTime; +import java.time.OffsetDateTime; @JsonIgnoreProperties(ignoreUnknown = true) public class DeletePaymentMeanResponse extends WalletResponse { - private LocalDateTime walletActionDateTime; + private OffsetDateTime walletActionDateTime; - public LocalDateTime getWalletActionDateTime() { + public OffsetDateTime getWalletActionDateTime() { return walletActionDateTime; } } diff --git a/office-sdk/src/test/java/com/worldline/sips/utils/WalletSipsTest.java b/office-sdk/src/test/java/com/worldline/sips/utils/WalletSipsTest.java index 021f535..370532d 100644 --- a/office-sdk/src/test/java/com/worldline/sips/utils/WalletSipsTest.java +++ b/office-sdk/src/test/java/com/worldline/sips/utils/WalletSipsTest.java @@ -4,9 +4,11 @@ import com.worldline.sips.api.configuration.OfficeEnvironment; import com.worldline.sips.api.model.data.NamedWalletResponseCode; import com.worldline.sips.api.model.data.WalletPaymentMeanData; +import com.worldline.sips.api.model.request.DeletePaymentMeanRequest; import com.worldline.sips.api.model.request.GetWalletDataRequest; +import com.worldline.sips.api.model.response.DeletePaymentMeanResponse; import com.worldline.sips.api.model.response.GetWalletDataResponse; -import com.worldline.sips.model.PaymentMeanBrand; +import com.worldline.sips.model.NamedPaymentMeanBrand; import com.worldline.sips.util.ObjectMapperHolder; import java.util.List; import org.junit.jupiter.api.Assertions; @@ -22,6 +24,15 @@ public void setUp() throws Exception { sipsClient = new SipsClient(OfficeEnvironment.TEST, "201040040170001", 1, "rxSP61eeP_oNi5TxCD7Ngy9YcwC8MLw6OlmFGGcsY54"); } + @Test + void testDeleteWalletMean() throws Exception { + DeletePaymentMeanRequest req = new DeletePaymentMeanRequest("ATCTR59_3884977603", "2"); + System.out.println(ObjectMapperHolder.INSTANCE.get().writerFor(DeletePaymentMeanRequest.class).writeValueAsString(req)); + DeletePaymentMeanResponse response = sipsClient.send(req); + System.out.println("Response"); + System.out.println(ObjectMapperHolder.INSTANCE.get().writerFor(DeletePaymentMeanResponse.class).writeValueAsString(response)); + } + @Test void testSendWalletRequest() throws Exception { GetWalletDataResponse response = sipsClient.send(new GetWalletDataRequest("1")); @@ -70,7 +81,7 @@ void testResponseDeserialization() throws Exception { Assertions.assertNull(walletPaymentMeanData.getPanExpiryDate()); Assertions.assertEquals("14", walletPaymentMeanData.getPaymentMeanId()); Assertions.assertEquals("4977##########02", walletPaymentMeanData.getMaskedPan()); - Assertions.assertEquals(PaymentMeanBrand.SEPA_DIRECT_DEBIT, walletPaymentMeanData.getPaymentMeanBrand()); + Assertions.assertEquals(NamedPaymentMeanBrand.SEPA_DIRECT_DEBIT, walletPaymentMeanData.getPaymentMeanBrand()); Assertions.assertNull(response.getErrorFieldName()); } } diff --git a/payment-sdk/src/main/java/com/worldline/sips/configuration/PaymentConfiguration.java b/payment-sdk/src/main/java/com/worldline/sips/configuration/PaymentConfiguration.java index 0885b1b..1a90191 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/configuration/PaymentConfiguration.java +++ b/payment-sdk/src/main/java/com/worldline/sips/configuration/PaymentConfiguration.java @@ -7,7 +7,7 @@ public class PaymentConfiguration { /** * The targeted version of the API */ - public static final String INTERFACE_VERSION = "IR_WS_2.35"; + public static final String INTERFACE_VERSION = "IR_WS_2.46"; private PaymentConfiguration() { // Nothing to see here diff --git a/payment-sdk/src/test/java/com/worldline/sips/api/PaypageClientTest.java b/payment-sdk/src/test/java/com/worldline/sips/api/PaypageClientTest.java index 1d1a0b9..0949472 100644 --- a/payment-sdk/src/test/java/com/worldline/sips/api/PaypageClientTest.java +++ b/payment-sdk/src/test/java/com/worldline/sips/api/PaypageClientTest.java @@ -75,6 +75,15 @@ void decodeResponse_with_cancelled_request() throws Exception { assertNotNull(paypageResponse.getData().getResponseCode()); } + @Test + void decodeResponse_with_cancelled_request_unknown() throws Exception { + responseParameters.put("Data", "captureDay=0|captureMode=AUTHOR_CAPTURE|currencyCode=978|merchantId=011122211100002|orderChannel=INTERNET|responseCode=17|transactionDateTime=2022-11-21T10:58:26+01:00|transactionReference=20221121896|keyVersion=1|amount=99|paymentMeanBrand=UNKNOWN|paymentMeanType=CARD|customerEmail=dl-fr-rcs-store@worldline.com|customerId=ATCBE606_196784528|customerIpAddress=160.92.8.86|merchantWalletId=ATCBE606_196784528|orderId=ATCBE0007452752|returnContext=b2261cc1c58baa7bc95ed414d48c9282cdf008094d56457bc3c3bbafdd82e168#SHOP_BE_REF#1626#WEB#false#false#false#true#FR#147.161.183.78#null#null#false#null#null#null#0#FR#fr|paymentPattern=ONE_SHOT|customerMobilePhone=null|mandateAuthentMethod=null|mandateUsage=null|transactionActors=null|mandateId=null|captureLimitDate=null|dccStatus=null|dccResponseCode=null|dccAmount=null|dccCurrencyCode=null|dccExchangeRate=null|dccExchangeRateValidity=null|dccProvider=null|statementReference=null|panEntryMode=null|walletType=null|holderAuthentMethod=null|holderAuthentProgram=null|paymentMeanId=null|instalmentNumber=null|instalmentDatesList=null|instalmentTransactionReferencesList=null|instalmentAmountsList=null|settlementMode=null|mandateCertificationType=null|valueDate=null|creditorId=null|acquirerResponseIdentifier=null|acquirerResponseMessage=null|paymentMeanTradingName=null|additionalAuthorisationNumber=null|issuerWalletInformation=null|s10TransactionId=896|s10TransactionIdDate=20221121|preAuthenticationColor=null|preAuthenticationInfo=null|preAuthenticationProfile=null|preAuthenticationThreshold=null|preAuthenticationValue=null|invoiceReference=null|s10transactionIdsList=null|cardProductCode=null|cardProductName=null|cardProductProfile=null|issuerCode=null|issuerCountryCode=null|acquirerNativeResponseCode=null|settlementModeComplement=null|preAuthorisationProfile=null|preAuthorisationProfileValue=null|preAuthorisationRuleResultList=null|preAuthenticationProfileValue=null|preAuthenticationRuleResultList=null|paymentMeanBrandSelectionStatus=null|transactionPlatform=PROD|avsAddressResponseCode=null|avsPostcodeResponseCode=null|customerCompanyName=null|customerBusinessName=null|customerLegalId=null|customerPositionOccupied=null|paymentAttemptNumber=1|holderContactEmail=null|installmentIntermediateServiceProviderOperationIdsList=null|holderAuthentType=null|acquirerContractNumber=null|secureReference=null|authentExemptionReasonList=null|paymentAccountReference=null|schemeTransactionIdentifier=null|guaranteeLimitDateTime=null|paymentMeanDataProvider=null"); + responseParameters.put("Seal", "abcdfb8ee60361aa29856f0c4d1f2947cebbc89189227dda1c32a4bf8d852413"); + PaypageResponse paypageResponse = paypageClient.decodeResponse(PaypageResponse.class, responseParameters); + assertNotNull(paypageResponse.getData(), "Data field is empty!"); + assertNotNull(paypageResponse.getData().getResponseCode()); + } + @Test void decodeResponse_with_refused_request() throws Exception { responseParameters.put("Data", "captureDay=0|captureMode=AUTHOR_CAPTURE|currencyCode=978|merchantId=002001000000001|orderChannel=INTERNET|responseCode=05|transactionDateTime=2018-02-06T07:50:34+01:00|transactionReference=8bd59312ff4|keyVersion=1|amount=2|guaranteeIndicator=N|panExpiryDate=201803|paymentMeanBrand=VISA|paymentMeanType=CARD|customerIpAddress=194.78.195.168|maskedPan=4500#############01|holderAuthentRelegation=N|holderAuthentStatus=3D_FAILURE|tokenPan=g011040a730424d1ba6|transactionOrigin=INTERNET|paymentPattern=ONE_SHOT"); diff --git a/payment-sdk/src/test/java/com/worldline/sips/api/SealCalculatorTest.java b/payment-sdk/src/test/java/com/worldline/sips/api/SealCalculatorTest.java index 401f02b..a2a3294 100644 --- a/payment-sdk/src/test/java/com/worldline/sips/api/SealCalculatorTest.java +++ b/payment-sdk/src/test/java/com/worldline/sips/api/SealCalculatorTest.java @@ -1,7 +1,10 @@ package com.worldline.sips.api; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + import com.worldline.sips.exception.SealCalculationException; -import com.worldline.sips.model.PaymentMeanBrand; +import com.worldline.sips.model.NamedPaymentMeanBrand; import com.worldline.sips.model.data.Address; import com.worldline.sips.model.data.Currency; import com.worldline.sips.model.data.CustomerAddress; @@ -10,14 +13,10 @@ import com.worldline.sips.model.request.PaymentRequest; import com.worldline.sips.model.response.InitializationResponse; import com.worldline.sips.security.SealCalculator; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - import java.net.MalformedURLException; import java.net.URL; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; class SealCalculatorTest { @@ -40,7 +39,7 @@ void setUp() throws Exception { @Test void getSealString() { String actual = SealCalculator.getSealString(paymentRequest); - String expected = "10http://test.comcustomerIdIR_WS_2.35customCSS.css"; + String expected = "10http://test.comcustomerIdIR_WS_2.46customCSS.css"; assertEquals(expected, actual, "Sealstring is incorrect!"); } @@ -48,16 +47,16 @@ void getSealString() { void getSealString_with_Currency() { paymentRequest.setCurrencyCode(Currency.EUR); String actual = SealCalculator.getSealString(paymentRequest); - String expected = "10http://test.com978customerIdIR_WS_2.35customCSS.css"; + String expected = "10http://test.com978customerIdIR_WS_2.46customCSS.css"; assertEquals(expected, actual, "Sealstring is incorrect!"); } @Test void getSealString_with_list() { - paymentRequest.getPaymentMeanBrandList().add(PaymentMeanBrand.VISA); - paymentRequest.getPaymentMeanBrandList().add(PaymentMeanBrand.BCMC); + paymentRequest.getPaymentMeanBrandList().add(NamedPaymentMeanBrand.VISA); + paymentRequest.getPaymentMeanBrandList().add(NamedPaymentMeanBrand.BCMC); String actual = SealCalculator.getSealString(paymentRequest); - String expected = "10http://test.comcustomerIdIR_WS_2.35BCMCVISAcustomCSS.css"; + String expected = "10http://test.comcustomerIdIR_WS_2.46BCMCVISAcustomCSS.css"; assertEquals(expected, actual, "Sealstring is incorrect!"); } @@ -79,7 +78,7 @@ void getSealString_with_Container() { paymentRequest.setCustomerContact(customerContact); String actual = SealCalculator.getSealString(paymentRequest); - String expected = "10http://test.comcustomerBusinessNamecustomerCityfirstNamelastNamecustomerIddeliveryCompanydeliveryZipcodeIR_WS_2.35customCSS.css"; + String expected = "10http://test.comcustomerBusinessNamecustomerCityfirstNamelastNamecustomerIddeliveryCompanydeliveryZipcodeIR_WS_2.46customCSS.css"; assertEquals(expected, actual, "Sealstring is incorrect!"); } @@ -87,7 +86,7 @@ void getSealString_with_Container() { void getSealString_with_ignoredField() { paymentRequest.setKeyVersion(200); String actual = SealCalculator.getSealString(paymentRequest); - String expected = "10http://test.comcustomerIdIR_WS_2.35customCSS.css"; + String expected = "10http://test.comcustomerIdIR_WS_2.46customCSS.css"; assertEquals(expected, actual, "Sealstring is incorrect!"); } diff --git a/sdk-common/src/main/java/com/worldline/sips/helper/SealStringStyle.java b/sdk-common/src/main/java/com/worldline/sips/helper/SealStringStyle.java index 69cbce6..9474cef 100644 --- a/sdk-common/src/main/java/com/worldline/sips/helper/SealStringStyle.java +++ b/sdk-common/src/main/java/com/worldline/sips/helper/SealStringStyle.java @@ -42,8 +42,12 @@ public void appendDetail(StringBuffer buffer, String fieldName, Object value) { @Override protected void appendDetail(StringBuffer buffer, String fieldName, Object[] array) { + try { Arrays.sort(array); - super.appendDetail(buffer, fieldName, array); + } catch (ClassCastException ignored) { + System.out.println("test"); + } + super.appendDetail(buffer, fieldName, array); } @Override diff --git a/sdk-common/src/main/java/com/worldline/sips/model/NamedPaymentMeanBrand.java b/sdk-common/src/main/java/com/worldline/sips/model/NamedPaymentMeanBrand.java new file mode 100644 index 0000000..cadcaee --- /dev/null +++ b/sdk-common/src/main/java/com/worldline/sips/model/NamedPaymentMeanBrand.java @@ -0,0 +1,96 @@ +package com.worldline.sips.model; + +import static com.worldline.sips.model.NamedPaymentMeanType.CARD; +import static com.worldline.sips.model.NamedPaymentMeanType.CREDIT_TRANSFER; +import static com.worldline.sips.model.NamedPaymentMeanType.DIRECT_DEBIT; +import static com.worldline.sips.model.NamedPaymentMeanType.EMPTY; +import static com.worldline.sips.model.NamedPaymentMeanType.ONLINE_CREDIT; +import static com.worldline.sips.model.NamedPaymentMeanType.PROVIDER; +import static com.worldline.sips.model.NamedPaymentMeanType.VOUCHER; +import static com.worldline.sips.model.NamedPaymentMeanType.WALLET; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonValue; + +public enum NamedPaymentMeanBrand implements PaymentMeanBrand { + _1EUROCOM(ONLINE_CREDIT), + _3XCBCOFINOGA(CARD), + ACCEPTGIRO(CREDIT_TRANSFER), + ACCORD(CARD), + ACCORD_KDO(CARD), + ACCORD_3X(ONLINE_CREDIT), + ACCORD_4X(ONLINE_CREDIT), + AMEX(CARD), + AURORE(CARD), + BCACB_3X(ONLINE_CREDIT), + BCACB_4X(ONLINE_CREDIT), + BCACUP(CARD), + BCMC(CARD), + CACF_3X(ONLINE_CREDIT), + CACF_4X(ONLINE_CREDIT), + CADHOC(CARD), + CADOCARTE(CARD), + CB(CARD), + CBCONLINE(CREDIT_TRANSFER), + CETELEM_3X(ONLINE_CREDIT), + CETELEM_4X(ONLINE_CREDIT), + COFIDIS_3X(ONLINE_CREDIT), + COFIDIS_4X(ONLINE_CREDIT), + CONECS(VOUCHER), + CUP(CARD), + CVA(CARD), + CVCO(VOUCHER), + DINNERS(CARD), + ECV(VOUCHER), + ELV(DIRECT_DEBIT), + FIVORY(WALLET), + FRANFINANCE_3X(ONLINE_CREDIT), + FRANFINANCE_4X(ONLINE_CREDIT), + GIROPAY(CREDIT_TRANSFER), + IDEAL(CREDIT_TRANSFER), + ILLICADO(CARD), + INCASSO(DIRECT_DEBIT), + JCB(CARD), + KBCONLINE(CREDIT_TRANSFER), + LEPOTCOMMUN(CARD), + LYDIA(PROVIDER), + MAESTRO(CARD), + MASTERCARD(CARD), + MASTERPASS(EMPTY), + PASSCADO(CARD), + PAY_BY_BANK(CREDIT_TRANSFER), + PAYLIB(EMPTY), + PAYPAL(WALLET), + PAYTRAIL(CREDIT_TRANSFER), + POSTFINANCE(CARD), + PRESTO(ONLINE_CREDIT), + SEPA_DIRECT_DEBIT(DIRECT_DEBIT), + SOFINCO(CARD), + SOFORTUBERWEISUNG(CREDIT_TRANSFER), + SPIRITOFCADEAU(CARD), + UNKNOWN(EMPTY), + VISA(CARD), + VISACHECKOUT(WALLET), + VISA_ELECTRON(CARD), + VPAY(CARD); + + final String realName; + final NamedPaymentMeanType namedPaymentMeanType; + + NamedPaymentMeanBrand(NamedPaymentMeanType namedPaymentMeanType) { + String name = name(); + this.namedPaymentMeanType = namedPaymentMeanType; + this.realName = name.charAt(0) == '_' ? name.substring(1) : name; + } + + @Override + @JsonValue + public String getRealName() { + return this.realName; + } + + @JsonIgnore + public NamedPaymentMeanType getPaymentMeanType() { + return namedPaymentMeanType; + } +} diff --git a/sdk-common/src/main/java/com/worldline/sips/model/NamedPaymentMeanType.java b/sdk-common/src/main/java/com/worldline/sips/model/NamedPaymentMeanType.java new file mode 100644 index 0000000..6a9d116 --- /dev/null +++ b/sdk-common/src/main/java/com/worldline/sips/model/NamedPaymentMeanType.java @@ -0,0 +1,11 @@ +package com.worldline.sips.model; + +public enum NamedPaymentMeanType implements PaymentMeanType { + CARD, CREDIT_TRANSFER, DIRECT_DEBIT, + VOUCHER, WALLET, ONLINE_CREDIT, EMPTY, PROVIDER; + + @Override + public String getName() { + return name(); + } +} diff --git a/sdk-common/src/main/java/com/worldline/sips/model/PaymentMeanBrand.java b/sdk-common/src/main/java/com/worldline/sips/model/PaymentMeanBrand.java index 7a22b51..4076e7d 100644 --- a/sdk-common/src/main/java/com/worldline/sips/model/PaymentMeanBrand.java +++ b/sdk-common/src/main/java/com/worldline/sips/model/PaymentMeanBrand.java @@ -1,106 +1,22 @@ package com.worldline.sips.model; import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonValue; -import com.worldline.sips.exception.UnknownStatusException; -import static com.worldline.sips.model.PaymentMeanType.CARD; -import static com.worldline.sips.model.PaymentMeanType.CREDIT_TRANSFER; -import static com.worldline.sips.model.PaymentMeanType.DIRECT_DEBIT; -import static com.worldline.sips.model.PaymentMeanType.EMPTY; -import static com.worldline.sips.model.PaymentMeanType.ONLINE_CREDIT; -import static com.worldline.sips.model.PaymentMeanType.PROVIDER; -import static com.worldline.sips.model.PaymentMeanType.VOUCHER; -import static com.worldline.sips.model.PaymentMeanType.WALLET; - -public enum PaymentMeanBrand { - _1EUROCOM(ONLINE_CREDIT), - _3XCBCOFINOGA(CARD), - ACCEPTGIRO(CREDIT_TRANSFER), - ACCORD(CARD), - ACCORD_KDO(CARD), - ACCORD_3X(ONLINE_CREDIT), - ACCORD_4X(ONLINE_CREDIT), - AMEX(CARD), - AURORE(CARD), - BCACB_3X(ONLINE_CREDIT), - BCACB_4X(ONLINE_CREDIT), - BCACUP(CARD), - BCMC(CARD), - CACF_3X(ONLINE_CREDIT), - CACF_4X(ONLINE_CREDIT), - CADHOC(CARD), - CADOCARTE(CARD), - CB(CARD), - CBCONLINE(CREDIT_TRANSFER), - CETELEM_3X(ONLINE_CREDIT), - CETELEM_4X(ONLINE_CREDIT), - COFIDIS_3X(ONLINE_CREDIT), - COFIDIS_4X(ONLINE_CREDIT), - CONECS(VOUCHER), - CUP(CARD), - CVA(CARD), - CVCO(VOUCHER), - DINNERS(CARD), - ECV(VOUCHER), - ELV(DIRECT_DEBIT), - FIVORY(WALLET), - FRANFINANCE_3X(ONLINE_CREDIT), - FRANFINANCE_4X(ONLINE_CREDIT), - GIROPAY(CREDIT_TRANSFER), - IDEAL(CREDIT_TRANSFER), - ILLICADO(CARD), - INCASSO(DIRECT_DEBIT), - JCB(CARD), - KBCONLINE(CREDIT_TRANSFER), - LEPOTCOMMUN(CARD), - LYDIA(PROVIDER), - MAESTRO(CARD), - MASTERCARD(CARD), - MASTERPASS(EMPTY), - PASSCADO(CARD), - PAY_BY_BANK(CREDIT_TRANSFER), - PAYLIB(EMPTY), - PAYPAL(WALLET), - PAYTRAIL(CREDIT_TRANSFER), - POSTFINANCE(CARD), - PRESTO(ONLINE_CREDIT), - SEPA_DIRECT_DEBIT(DIRECT_DEBIT), - SOFINCO(CARD), - SOFORTUBERWEISUNG(CREDIT_TRANSFER), - SPIRITOFCADEAU(CARD), - VISA(CARD), - VISA_ELECTRON(CARD), - VPAY(CARD); - - final String realName; - final PaymentMeanType paymentMeanType; - - PaymentMeanBrand(PaymentMeanType paymentMeanType) { - String name = name(); - this.paymentMeanType = paymentMeanType; - this.realName = name.charAt(0) == '_' ? name.substring(1) : name; - } +public interface PaymentMeanBrand { + @JsonValue + String getRealName(); + @JsonCreator - public static PaymentMeanBrand fromRealName(String string) throws UnknownStatusException { - for (PaymentMeanBrand responseCode : PaymentMeanBrand.values()) { + static PaymentMeanBrand fromRealName(String string) { + if (string == null) return null; + for (NamedPaymentMeanBrand responseCode : NamedPaymentMeanBrand.values()) { if (responseCode.getRealName().equals(string)) { return responseCode; } } - - throw new UnknownStatusException(string + " is an unknown payment mean brand!"); - } - - @JsonValue - public String getRealName() { - return this.realName; - } - - @JsonIgnore - public PaymentMeanType getPaymentMeanType() { - return paymentMeanType; + + return new UnknownPaymentMeanBrand(string); } } diff --git a/sdk-common/src/main/java/com/worldline/sips/model/PaymentMeanType.java b/sdk-common/src/main/java/com/worldline/sips/model/PaymentMeanType.java index 27ef74a..d96d0ba 100644 --- a/sdk-common/src/main/java/com/worldline/sips/model/PaymentMeanType.java +++ b/sdk-common/src/main/java/com/worldline/sips/model/PaymentMeanType.java @@ -3,16 +3,19 @@ import com.fasterxml.jackson.annotation.JsonCreator; import org.apache.commons.lang3.StringUtils; -public enum PaymentMeanType { - CARD, CREDIT_TRANSFER, DIRECT_DEBIT, - VOUCHER, WALLET, ONLINE_CREDIT, EMPTY, PROVIDER; - +public interface PaymentMeanType { + String getName(); + + @JsonCreator - public static PaymentMeanType fromValue(String value) { + static PaymentMeanType fromValue(String value) { if (StringUtils.isBlank(value)) { - return PaymentMeanType.EMPTY; + return NamedPaymentMeanType.EMPTY; + } + try { + return NamedPaymentMeanType.valueOf(value); + } catch (IllegalArgumentException e) { + return new UnknownPaymentMeanType(value); } - return PaymentMeanType.valueOf(value); } - } diff --git a/sdk-common/src/main/java/com/worldline/sips/model/UnknownPaymentMeanBrand.java b/sdk-common/src/main/java/com/worldline/sips/model/UnknownPaymentMeanBrand.java new file mode 100644 index 0000000..32634a0 --- /dev/null +++ b/sdk-common/src/main/java/com/worldline/sips/model/UnknownPaymentMeanBrand.java @@ -0,0 +1,14 @@ +package com.worldline.sips.model; + +public class UnknownPaymentMeanBrand implements PaymentMeanBrand { + private final String realName; + + public UnknownPaymentMeanBrand(String realName) { + this.realName = realName; + } + + @Override + public String getRealName() { + return realName; + } +} diff --git a/sdk-common/src/main/java/com/worldline/sips/model/UnknownPaymentMeanType.java b/sdk-common/src/main/java/com/worldline/sips/model/UnknownPaymentMeanType.java new file mode 100644 index 0000000..eb99b9e --- /dev/null +++ b/sdk-common/src/main/java/com/worldline/sips/model/UnknownPaymentMeanType.java @@ -0,0 +1,14 @@ +package com.worldline.sips.model; + +public class UnknownPaymentMeanType implements PaymentMeanType { + private final String name; + + public UnknownPaymentMeanType(String name) { + this.name = name; + } + + @Override + public String getName() { + return name; + } +} From a19dd5b7d3328e071f05a80f857a2e5bcd32fa33 Mon Sep 17 00:00:00 2001 From: Arthur PELLOUX-PRAYER Date: Mon, 21 Nov 2022 16:49:14 +0100 Subject: [PATCH 15/15] Add support for unknown payment brand and mean Fix payment test --- .../worldline/sips/utils/WalletSipsTest.java | 25 ++++-- .../model/data/S10TransactionReference.java | 3 +- .../sips/model/request/PaymentRequest.java | 19 +++-- .../response/InitializationResponse.java | 11 --- .../worldline/sips/api/PaypageClientTest.java | 80 +++++++++++++++---- .../sips/api/SealCalculatorTest.java | 7 +- .../java/com/worldline/sips/SIPSRequest.java | 2 +- .../java/com/worldline/sips/SIPSResponse.java | 4 +- ...AlphabeticalReflectionToStringBuilder.java | 7 +- .../sips/helper/SealStringStyle.java | 11 ++- .../SortedReflectionToStringBuilder.java | 28 +++++-- .../sips/security/SealCalculator.java | 34 ++++---- .../sips/util/ObjectMapperHolder.java | 8 +- 13 files changed, 165 insertions(+), 74 deletions(-) diff --git a/office-sdk/src/test/java/com/worldline/sips/utils/WalletSipsTest.java b/office-sdk/src/test/java/com/worldline/sips/utils/WalletSipsTest.java index 370532d..b06e9e2 100644 --- a/office-sdk/src/test/java/com/worldline/sips/utils/WalletSipsTest.java +++ b/office-sdk/src/test/java/com/worldline/sips/utils/WalletSipsTest.java @@ -18,10 +18,13 @@ public class WalletSipsTest { private SipsClient sipsClient; + + public static final String SECRET_KEY = "yJb7SGlw6-_uy7E0aq8HG_V_rGPzZDuF7tzcvS-gzD4"; - @BeforeEach + + @BeforeEach public void setUp() throws Exception { - sipsClient = new SipsClient(OfficeEnvironment.TEST, "201040040170001", 1, "rxSP61eeP_oNi5TxCD7Ngy9YcwC8MLw6OlmFGGcsY54"); + sipsClient = new SipsClient(OfficeEnvironment.TEST, "011122211100002", 1, SECRET_KEY); } @Test @@ -35,9 +38,21 @@ void testDeleteWalletMean() throws Exception { @Test void testSendWalletRequest() throws Exception { - GetWalletDataResponse response = sipsClient.send(new GetWalletDataRequest("1")); - System.out.println(response); - } + GetWalletDataRequest req = new GetWalletDataRequest("ATCTR59_3884977603"); + System.out.println(ObjectMapperHolder.INSTANCE.get().writerFor(GetWalletDataRequest.class).writeValueAsString(req)); + GetWalletDataResponse response = sipsClient.send(req); +// System.out.println("Response"); + System.out.println(ObjectMapperHolder.INSTANCE.get().writerFor(GetWalletDataResponse.class).writeValueAsString(response)); +// for (WalletPaymentMeanData walletPaymentMeanData : response.getWalletPaymentMeanDataList()) { +// YearMonth panExpiryDate = walletPaymentMeanData.getPanExpiryDate(); +// // we check the expiry date (we don't care about expired cards after 3 months) +// if (panExpiryDate == null || panExpiryDate.isAfter(YearMonth.now().plus(3, ChronoUnit.MONTHS))) { +// System.out.println("yeet " + panExpiryDate); +// continue; +// } +// System.out.println("sus " + panExpiryDate); +// } + } @Test void testResponseDeserialization() throws Exception { diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/data/S10TransactionReference.java b/payment-sdk/src/main/java/com/worldline/sips/model/data/S10TransactionReference.java index 76fd3e3..5f74753 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/data/S10TransactionReference.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/data/S10TransactionReference.java @@ -13,8 +13,9 @@ public S10TransactionReference() { } - public S10TransactionReference(int s10TransactionId) { + public S10TransactionReference(int s10TransactionId, LocalDate date) { this.s10TransactionId = s10TransactionId; + this.s10TransactionIdDate = date; } public int getS10TransactionId() { diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/request/PaymentRequest.java b/payment-sdk/src/main/java/com/worldline/sips/model/request/PaymentRequest.java index b92a642..d8b51b8 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/request/PaymentRequest.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/request/PaymentRequest.java @@ -1,7 +1,6 @@ package com.worldline.sips.model.request; import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.worldline.sips.SIPSRequest; import com.worldline.sips.configuration.PaymentConfiguration; @@ -29,7 +28,6 @@ @JsonPropertyOrder(alphabetic = true) @JsonInclude(JsonInclude.Include.NON_EMPTY) public class PaymentRequest extends SIPSRequest { - private static final String INTERFACE_VERSION = PaymentConfiguration.INTERFACE_VERSION; private final TreeSet paymentMeanBrandList = new TreeSet<>(); @@ -65,12 +63,22 @@ public class PaymentRequest extends SIPSRequest { private String templateName; private PaypageData paypageData; private S10TransactionReference s10TransactionReference; + + private String interfaceVersion = PaymentConfiguration.INTERFACE_VERSION; public PaymentRequest() { super(""); } - public Integer getAmount() { + public String getInterfaceVersion() { + return interfaceVersion; + } + + public void setInterfaceVersion(String interfaceVersion) { + this.interfaceVersion = interfaceVersion; + } + + public Integer getAmount() { return amount; } @@ -206,11 +214,6 @@ public void setHolderContact(Contact holderContact) { this.holderContact = holderContact; } - @JsonProperty("interfaceVersion") - public String getInterfaceVersion() { - return INTERFACE_VERSION; - } - public String getIntermediateServiceProviderId() { return intermediateServiceProviderId; } diff --git a/payment-sdk/src/main/java/com/worldline/sips/model/response/InitializationResponse.java b/payment-sdk/src/main/java/com/worldline/sips/model/response/InitializationResponse.java index e52ba5f..1e603a2 100644 --- a/payment-sdk/src/main/java/com/worldline/sips/model/response/InitializationResponse.java +++ b/payment-sdk/src/main/java/com/worldline/sips/model/response/InitializationResponse.java @@ -2,8 +2,6 @@ import com.worldline.sips.SIPSResponse; import com.worldline.sips.model.data.RedirectionStatusCode; -import com.worldline.sips.model.data.ResponseCode; - import java.net.URL; /** @@ -16,8 +14,6 @@ public class InitializationResponse extends SIPSResponse { private String redirectionStatusMessage; private URL redirectionUrl; private String redirectionVersion; - private ResponseCode responseCode; - public String getErrorFieldName() { return errorFieldName; } @@ -66,11 +62,4 @@ public void setRedirectionVersion(String redirectionVersion) { this.redirectionVersion = redirectionVersion; } - public ResponseCode getResponseCode() { - return responseCode; - } - - public void setResponseCode(ResponseCode responseCode) { - this.responseCode = responseCode; - } } diff --git a/payment-sdk/src/test/java/com/worldline/sips/api/PaypageClientTest.java b/payment-sdk/src/test/java/com/worldline/sips/api/PaypageClientTest.java index 0949472..2818960 100644 --- a/payment-sdk/src/test/java/com/worldline/sips/api/PaypageClientTest.java +++ b/payment-sdk/src/test/java/com/worldline/sips/api/PaypageClientTest.java @@ -1,45 +1,54 @@ package com.worldline.sips.api; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + import com.worldline.sips.SipsClient; import com.worldline.sips.configuration.PaymentEnvironment; import com.worldline.sips.exception.IncorrectProxyConfException; import com.worldline.sips.model.data.Currency; import com.worldline.sips.model.data.OrderChannel; import com.worldline.sips.model.data.RedirectionStatusCode; +import com.worldline.sips.model.data.S10TransactionReference; import com.worldline.sips.model.request.PaymentRequest; import com.worldline.sips.model.response.InitializationResponse; import com.worldline.sips.model.response.PaypageResponse; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - +import com.worldline.sips.security.SealCalculator; +import com.worldline.sips.util.ObjectMapperHolder; import java.net.URL; +import java.time.LocalDate; import java.util.HashMap; import java.util.Map; -import java.util.UUID; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; +import java.util.concurrent.ThreadLocalRandom; +import java.util.stream.Collectors; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; class PaypageClientTest { + + public static final String SECRET_KEY = "002001000000003_KEY1"; private SipsClient paypageClient; + private SipsClient decodeClient; private PaymentRequest paymentRequest; private Map responseParameters; @BeforeEach void setUp() throws Exception { - paypageClient = new SipsClient(PaymentEnvironment.SIMU, "002001000000001", 1, "002001000000001_KEY1"); + paypageClient = new SipsClient(PaymentEnvironment.SIMU, "002001000000003", 1, SECRET_KEY); + decodeClient = new SipsClient(PaymentEnvironment.SIMU, "002001000000001", 1, "002001000000001_KEY1"); paymentRequest = new PaymentRequest(); paymentRequest.setAmount(2); + paymentRequest.setCurrencyCode(Currency.EUR); paymentRequest.setOrderChannel(OrderChannel.INTERNET); paymentRequest.setNormalReturnUrl(new URL("http://localhost")); - paymentRequest.setTransactionReference(UUID.randomUUID().toString().substring(0, 12).replace("-", "")); + paymentRequest.setS10TransactionReference(new S10TransactionReference(ThreadLocalRandom.current().nextInt(0, 1_000_000), LocalDate.now())); +// paymentRequest.setTransactionReference("1"); responseParameters = new HashMap<>(); responseParameters.put("InterfaceVersion", "HP_2.0"); - } @Test @@ -54,14 +63,51 @@ void testClientProxyException() { @Test void execute() throws Exception { InitializationResponse initializationResponse = paypageClient.send(paymentRequest); - assertEquals(RedirectionStatusCode.TRANSACTION_INITIALIZED, initializationResponse.getRedirectionStatusCode(), "Initialization failed!"); + + System.out.println(ObjectMapperHolder.INSTANCE.get().writerFor(PaymentRequest.class) + .writeValueAsString(paymentRequest)); + System.err.println(ObjectMapperHolder.INSTANCE.get().writerFor(InitializationResponse.class) + .writeValueAsString(initializationResponse)); + assertEquals(RedirectionStatusCode.TRANSACTION_INITIALIZED, initializationResponse.getRedirectionStatusCode(), "Initialization failed! " + initializationResponse.getRedirectionStatusCode().name()); + } + + @Test + void computeSealFromDoc_success() throws Exception { + PaymentRequest request = ObjectMapperHolder.INSTANCE.get().readerFor(PaymentRequest.class).readValue("{\n" + + " \"amount\": \"2500\",\n" + + " \"automaticResponseUrl\": \"https://automatic-response-url.fr/\",\n" + + " \"normalReturnUrl\": \"https://normal-return-url/\",\n" + + " \"captureDay\": \"0\",\n" + + " \"captureMode\": \"AUTHOR_CAPTURE\",\n" + + " \"currencyCode\": \"978\",\n" + + " \"customerContact\":{\n" + + " \"email\":\"customer@email.com\"\n" + + " },\n" + + " \"interfaceVersion\": \"IR_WS_2.22\",\n" + + " \"keyVersion\": \"1\",\n" + + " \"merchantId\": \"011223344550000\",\n" + + " \"orderChannel\": \"INTERNET\",\n" + + " \"orderId\": \"ORD101\",\n" + + " \"returnContext\": \"ReturnContext\",\n" + + " \"transactionOrigin\": \"SO_WEBAPPLI\",\n" + + " \"transactionReference\": \"TREFEXA2012\",\n" + + " \"seal\": \"322b943d833417c1570e0a282641e8e29d6a5b968c9b846694b5610e18ab5b81\"\n" + + "}"); + assertEquals("2500https://automatic-response-url.fr/0AUTHOR_CAPTURE978customer@email.comIR_WS_2.22011223344550000https://normal-return-url/INTERNETORD101ReturnContextSO_WEBAPPLITREFEXA2012", SealCalculator.getSealString(request), "Seal strings don't match"); + assertEquals("322b943d833417c1570e0a282641e8e29d6a5b968c9b846694b5610e18ab5b81", SealCalculator.calculate(SealCalculator.getSealString(request), "secret123")); } @Test void decodeResponse_with_succeeded_request() throws Exception { responseParameters.put("Data", "captureDay=0|captureMode=AUTHOR_CAPTURE|currencyCode=978|merchantId=002001000000001|orderChannel=INTERNET|responseCode=00|transactionDateTime=2018-02-06T07:54:23+01:00|transactionReference=b4fb98a9c2c|keyVersion=1|acquirerResponseCode=00|amount=2|authorisationId=12345|guaranteeIndicator=Y|cardCSCResultCode=4D|panExpiryDate=201902|paymentMeanBrand=VISA|paymentMeanType=CARD|customerIpAddress=194.78.195.168|maskedPan=4500#############01|holderAuthentRelegation=N|holderAuthentStatus=3D_SUCCESS|tokenPan=g011040a730424d1ba6|transactionOrigin=INTERNET|paymentPattern=ONE_SHOT"); responseParameters.put("Seal", "56bddfce68695b9b8a9de51c426aae31bb303fb15570f343975eaa3bd33c8c59"); - PaypageResponse paypageResponse = paypageClient.decodeResponse(PaypageResponse.class, responseParameters); + PaypageResponse paypageResponse = decodeClient.decodeResponse(PaypageResponse.class, responseParameters); + assertNotNull(paypageResponse.getData(), "Data field is empty!"); + assertNotNull(paypageResponse.getData().getResponseCode()); + + String rawJson = responseParameters.entrySet().stream().map(e -> "\"" + e.getKey() + "\":\"" + e.getValue() + "\"").collect(Collectors.joining(",", "{", "}")); + + paypageResponse = decodeClient.decodeResponse(PaypageResponse.class, rawJson); assertNotNull(paypageResponse.getData(), "Data field is empty!"); assertNotNull(paypageResponse.getData().getResponseCode()); } @@ -70,7 +116,7 @@ void decodeResponse_with_succeeded_request() throws Exception { void decodeResponse_with_cancelled_request() throws Exception { responseParameters.put("Data", "captureDay=0|captureMode=AUTHOR_CAPTURE|currencyCode=978|merchantId=002001000000001|orderChannel=INTERNET|responseCode=17|transactionDateTime=2018-02-06T07:43:55+01:00|transactionReference=e1445438c15|keyVersion=1|amount=2|customerIpAddress=194.78.195.168|paymentPattern=ONE_SHOT"); responseParameters.put("Seal", "8f488030781e3196726ce0658dbc26f19781f7c7fbe212b39d63d3f4d1d77301"); - PaypageResponse paypageResponse = paypageClient.decodeResponse(PaypageResponse.class, responseParameters); + PaypageResponse paypageResponse = decodeClient.decodeResponse(PaypageResponse.class, responseParameters); assertNotNull(paypageResponse.getData(), "Data field is empty!"); assertNotNull(paypageResponse.getData().getResponseCode()); } @@ -78,8 +124,8 @@ void decodeResponse_with_cancelled_request() throws Exception { @Test void decodeResponse_with_cancelled_request_unknown() throws Exception { responseParameters.put("Data", "captureDay=0|captureMode=AUTHOR_CAPTURE|currencyCode=978|merchantId=011122211100002|orderChannel=INTERNET|responseCode=17|transactionDateTime=2022-11-21T10:58:26+01:00|transactionReference=20221121896|keyVersion=1|amount=99|paymentMeanBrand=UNKNOWN|paymentMeanType=CARD|customerEmail=dl-fr-rcs-store@worldline.com|customerId=ATCBE606_196784528|customerIpAddress=160.92.8.86|merchantWalletId=ATCBE606_196784528|orderId=ATCBE0007452752|returnContext=b2261cc1c58baa7bc95ed414d48c9282cdf008094d56457bc3c3bbafdd82e168#SHOP_BE_REF#1626#WEB#false#false#false#true#FR#147.161.183.78#null#null#false#null#null#null#0#FR#fr|paymentPattern=ONE_SHOT|customerMobilePhone=null|mandateAuthentMethod=null|mandateUsage=null|transactionActors=null|mandateId=null|captureLimitDate=null|dccStatus=null|dccResponseCode=null|dccAmount=null|dccCurrencyCode=null|dccExchangeRate=null|dccExchangeRateValidity=null|dccProvider=null|statementReference=null|panEntryMode=null|walletType=null|holderAuthentMethod=null|holderAuthentProgram=null|paymentMeanId=null|instalmentNumber=null|instalmentDatesList=null|instalmentTransactionReferencesList=null|instalmentAmountsList=null|settlementMode=null|mandateCertificationType=null|valueDate=null|creditorId=null|acquirerResponseIdentifier=null|acquirerResponseMessage=null|paymentMeanTradingName=null|additionalAuthorisationNumber=null|issuerWalletInformation=null|s10TransactionId=896|s10TransactionIdDate=20221121|preAuthenticationColor=null|preAuthenticationInfo=null|preAuthenticationProfile=null|preAuthenticationThreshold=null|preAuthenticationValue=null|invoiceReference=null|s10transactionIdsList=null|cardProductCode=null|cardProductName=null|cardProductProfile=null|issuerCode=null|issuerCountryCode=null|acquirerNativeResponseCode=null|settlementModeComplement=null|preAuthorisationProfile=null|preAuthorisationProfileValue=null|preAuthorisationRuleResultList=null|preAuthenticationProfileValue=null|preAuthenticationRuleResultList=null|paymentMeanBrandSelectionStatus=null|transactionPlatform=PROD|avsAddressResponseCode=null|avsPostcodeResponseCode=null|customerCompanyName=null|customerBusinessName=null|customerLegalId=null|customerPositionOccupied=null|paymentAttemptNumber=1|holderContactEmail=null|installmentIntermediateServiceProviderOperationIdsList=null|holderAuthentType=null|acquirerContractNumber=null|secureReference=null|authentExemptionReasonList=null|paymentAccountReference=null|schemeTransactionIdentifier=null|guaranteeLimitDateTime=null|paymentMeanDataProvider=null"); - responseParameters.put("Seal", "abcdfb8ee60361aa29856f0c4d1f2947cebbc89189227dda1c32a4bf8d852413"); - PaypageResponse paypageResponse = paypageClient.decodeResponse(PaypageResponse.class, responseParameters); + responseParameters.put("Seal", "14aba0bb3002a8fa88fc3e8fb1b61e2af103009d9489b0685f7f235590b00580"); + PaypageResponse paypageResponse = decodeClient.decodeResponse(PaypageResponse.class, responseParameters); assertNotNull(paypageResponse.getData(), "Data field is empty!"); assertNotNull(paypageResponse.getData().getResponseCode()); } @@ -88,7 +134,7 @@ void decodeResponse_with_cancelled_request_unknown() throws Exception { void decodeResponse_with_refused_request() throws Exception { responseParameters.put("Data", "captureDay=0|captureMode=AUTHOR_CAPTURE|currencyCode=978|merchantId=002001000000001|orderChannel=INTERNET|responseCode=05|transactionDateTime=2018-02-06T07:50:34+01:00|transactionReference=8bd59312ff4|keyVersion=1|amount=2|guaranteeIndicator=N|panExpiryDate=201803|paymentMeanBrand=VISA|paymentMeanType=CARD|customerIpAddress=194.78.195.168|maskedPan=4500#############01|holderAuthentRelegation=N|holderAuthentStatus=3D_FAILURE|tokenPan=g011040a730424d1ba6|transactionOrigin=INTERNET|paymentPattern=ONE_SHOT"); responseParameters.put("Seal", "e8c5bf4551ec60ce9b8ece6a98bdb1b5fde511539a391bc4ba314aaeac93b5be"); - PaypageResponse paypageResponse = paypageClient.decodeResponse(PaypageResponse.class, responseParameters); + PaypageResponse paypageResponse = decodeClient.decodeResponse(PaypageResponse.class, responseParameters); assertNotNull(paypageResponse.getData(), "Data field is empty!"); assertNotNull(paypageResponse.getData().getResponseCode()); } diff --git a/payment-sdk/src/test/java/com/worldline/sips/api/SealCalculatorTest.java b/payment-sdk/src/test/java/com/worldline/sips/api/SealCalculatorTest.java index a2a3294..44c1a1d 100644 --- a/payment-sdk/src/test/java/com/worldline/sips/api/SealCalculatorTest.java +++ b/payment-sdk/src/test/java/com/worldline/sips/api/SealCalculatorTest.java @@ -21,7 +21,7 @@ class SealCalculatorTest { private static final String ENCODED_REQUEST_SEAL = "198e5f278e3f8548e174e84492953c4871732278b7e2aa2cbf20bb1ab85914ea"; - private static final String ENCODED_RESPONSE_SEAL = "dd6eb8dd6c951b1ddc1af121007aaabe8ad4fda1d15ce386cfa455821d602025"; + private static final String ENCODED_RESPONSE_SEAL = "c3eb508b0d419e3bd2bb1a0416c2a48585fa6d683aa8d1a3dfba8ee877079f9f"; private static final String DEMO_KEY = "superSafeSecretKey"; private static final String RESPONSE_DEMO_KEY = "002001000000002_KEY1"; @@ -112,9 +112,8 @@ void calculate_response_seal() throws MalformedURLException, SealCalculationExce initializationResponse.setRedirectionStatusCode(RedirectionStatusCode.TRANSACTION_INITIALIZED); initializationResponse.setRedirectionStatusMessage("INITIALISATION REQUEST ACCEPTED"); initializationResponse.setRedirectionVersion("IR_WS_2.0"); - initializationResponse.setRedirectionUrl(new URL("https://payment-web.simu.sips-services.com/payment")); - initializationResponse.setRedirectionData("FTEx33MrE9Nc0gvtIS0aydJngXH8uuirg3ZpFD_KRM22C9e3IFDdBdSZB3kdQwcyIjWhKpM9mHYTCaCCy7Vm0YWrLscP-TJ895c2GXsTKlwEkO_VEU-2j2VGVcbYAKE9kcoV6jnVU5OJE1AMXEXnm1AkMrm3riB35p7x-WUdnaU0oKIhsit2M4_mci3fWH9WNTqo-A07qPd9-5zRKCr2F91Z8R4HogmLYdx_xh6BOyXKp693Smrq-2H64A2BOC6n89JQT-e9GNBM_up1YMa-vvS3-b6bMoZ01ngO7n2-NttxvXn78XEDDDVQfYZGPrpjywvDhGTfhBun1mdbSfzGPOwd6dcLre4Nguht3JCsT27EyLOxGEjCDwMjKJ0Gb2toChEMRv7TtX2SlXGMuyUr24oToHGbdt6zOm3q1R7XnCqnVYT_YNnNPf6lppQCW81FVvdX5zfbW65tQzja0CFC2ss-kyT0v4owm8LLNMy2rEU2JYnQQrT2qhQYf8lGxL2qkC0S1TpPLRzK-ry3mkEcBgwxFKbB2DX4kRamx4n6v_Yke2PS1PUPoWbdruRkK1mDJAJhSorV4O3LeeM1B3LkuPNU2xZw__I55zaOyIy2sWz52Su6gapGcsw8qTNOhcOwQi1sYaSGviCfKF75zC-GCjbHGoyHfO5RBswwmqBMNbVc7l2FIAw8ZDwn18E07pDWNeMwaeWYrYhR_n1BfhaW03H5TojvjnEMMSfd11nab0PjFE5zWB3r--OadfE7m-NqHL70WKLPYNfvKdzXzoI3ejc3SmWycXMpJgENZAFVzy4MojbVby3prA4IXQ_xSEisoWoGJb1Kg2LxEUih9Jqpi9vinH_nqt29lHFKnWSIuhT8UdsBYvFRGYyrbxPOOz1eNBqvHO49eI2hpKeL280_eR4HmLPiiDASog3BgDFB2_Ed6upm_N1PUEdQ1xmwXkiL7fqnaFABXySxsTVhxyRgXGSAmA0gmeYwFf7bGIKUc-FPwqWewDxRnIfnz6Eh3qDG41xEr5URpc0LCzzo5XjFt5h7wmp3FftmSai4rCFIM6B4Jd9lljeXgAMayzfig77_S_JMtEDw6oqzbX6QpBsKnfnrAtxk26LL07qB5Yw9qj-NEbWf28GOPN9--xY5AeUbya5nyNQiT-3TyebxnjUysTrTuq1DptPflIrUuIwAewT6K1I-XRYDpgdTRwWFzTIi2kItzGcbozxMJi0S6eJnOQNb9zNSrUBysDlSGVct1UsHqYQO56_-uyAwZ7lv23WIZdgbUaGELoPsba8Jg9rzR-aZ0zEe9owORSbAh5qkk0ByvOQniLqGYn36AJbKiSrSjRG1n9vBjjzffvsWOQHlG_tPV6WPVaXvanjaHrg_v2tjtqWPCUCRFg6seM4KiZ3G5-WPkPX0LW19iu4ypazFsfgElIfF7--XuN2wnrbf5tvPxpk-EHACkcFUQ7ozBw5xjRG1n9vBjjzffvsWOQHlGzGBbU3BAx_KVN_SQuZCNZ66O6O6FdOnZF_dC9vfuhZx5livIUUGTQOiFt4JQv_tJ3gl32WWN5eAAxrLN-KDvv_z_69h-FQfvm0DChFKn5h9Jb54QR0qamngPqTNqRQxNcmK3onHxmG7IIS9Gsltfie7sc4Lt9p_hqLAC28DDefH03yQ0l15QSQSA7t8x3rtGuflj5D19C1tfYruMqWsxbF_OuasNvoqSnJcHI_HyMMnf7eGnYHEcQk4vutjrpZhcH1TRZ3nQYrrxzId10uYeGeB7NXgInfbYearASIu2_vnMuJj1F84sjXcMM29qxh5KvOAaCle_EK7_SCamPY6SzkmTCyJprTaIBkhUUjUDdem4rN_XaLIav0orq8E4IwU740RtZ_bwY483377FjkB5RsKKPYjzvh_RlAEOH7vo0AIf7eGnYHEcQk4vutjrpZhcI0RtZ_bwY483377FjkB5Rv07-b-FhxhFkrKQcO0J0LIaKn33u4Hp88PYNHX40sIyNK3sqPZPiYGDU7q6T76kxla1JZwz-5wSgABK-wV16UlA1v3M1KtQHKwOVIZVy3VSwephA7nr_67IDBnuW_bdYjqqqfJtu70VoEtZOvxckajWtSWcM_ucEoAASvsFdelJcaipDQGiSLyw4gWeiGVvJAJHG6sS8x21XuBIuCbQ8l9Orcf_-QEVEHjGdswxxpSUovuFIRWVkRniMqau0PF2uF2Vi5vBX5AQYvblDS0I-Nk5mOOxtF3rdTMKSdmHaylZGleYPX4zPU6HmEV4ipdMcHx_vB89SS_gwRtQ9PWLJh3HJwvIO2GJs6lrufoKpeHVk9jne_ybEoDL1qOawB6ESQK5q5UXSwdR3YaB8M0qw-UPPibFlDSsbVF-zNvfbA8IBQL83Jj6EwBHBwT0RHvrvQ9-0nLg03cckYVc3IJh-dMok6Z5Ga3fsi_953xGMoOX4_z-gTn5pXhDYgI-0g_CKeAtgLeNsxz-PlTwW_U_kfW6Q3V7HDgOi-QZxxNSTMSkQpAdC3JcbHIGuEHVGxs5zWWT5tmsYkXbS11VEduPVXb9NpuUzUB5GLL8W3y9w3hTgLI1bKcCSsF4b3mgLEwNNGbEzYudvCLn3MP8g5BKQ-GlMMZU93_ANjsgNXUNK3j0SHC1NaycxVaWqmVP9uWp1U"); - + initializationResponse.setRedirectionUrl(new URL("https://payment-gateway.net/")); + initializationResponse.setRedirectionData("4AgbsrffvPgzDghQysbOJIZBJTZsk1KNlTmoOCtSORkMfzQgSR5OEw0gAE2bAAFbHuYQXuBmiEfuwD81QlmDInPmanHWkKNA3X3jUbC8Jh9oPTfgoPO4PNo20aNt6yb5z8cDOX8J_rNvwzfJetyCxEVrB93g9YRFX4n3mM85FC5o"); String sealString = SealCalculator.getSealString(initializationResponse); String actual = SealCalculator.calculate(sealString, RESPONSE_DEMO_KEY); assertEquals(ENCODED_RESPONSE_SEAL, actual, "Encoded seal is incorrect!"); diff --git a/sdk-common/src/main/java/com/worldline/sips/SIPSRequest.java b/sdk-common/src/main/java/com/worldline/sips/SIPSRequest.java index 1c6a72a..eedcc56 100644 --- a/sdk-common/src/main/java/com/worldline/sips/SIPSRequest.java +++ b/sdk-common/src/main/java/com/worldline/sips/SIPSRequest.java @@ -21,7 +21,7 @@ public abstract class SIPSRequest implements Seal private String seal; private String merchantId; private Integer keyVersion; - private String sealAlgorithm; + private String sealAlgorithm = "HMAC-SHA-256"; /** * @param endpoint the http endpoint targeted by this request diff --git a/sdk-common/src/main/java/com/worldline/sips/SIPSResponse.java b/sdk-common/src/main/java/com/worldline/sips/SIPSResponse.java index 1fabeec..db5d8f6 100644 --- a/sdk-common/src/main/java/com/worldline/sips/SIPSResponse.java +++ b/sdk-common/src/main/java/com/worldline/sips/SIPSResponse.java @@ -23,9 +23,7 @@ public abstract class SIPSResponse implements Sealable { public void verifySeal(String secretKey) throws IncorrectSealException, SealCalculationException { if (seal != null) { String sealString = SealCalculator.getSealString(this); - System.out.println(sealString); - String correctSeal = SealCalculator.calculate( - sealString, secretKey); + String correctSeal = SealCalculator.calculate(sealString, secretKey); if (! StringUtils.equals(correctSeal, seal)) { throw new IncorrectSealException("The response has been tampered with!"); } diff --git a/sdk-common/src/main/java/com/worldline/sips/helper/AlphabeticalReflectionToStringBuilder.java b/sdk-common/src/main/java/com/worldline/sips/helper/AlphabeticalReflectionToStringBuilder.java index 4e0e37f..87bd153 100644 --- a/sdk-common/src/main/java/com/worldline/sips/helper/AlphabeticalReflectionToStringBuilder.java +++ b/sdk-common/src/main/java/com/worldline/sips/helper/AlphabeticalReflectionToStringBuilder.java @@ -4,9 +4,14 @@ public class AlphabeticalReflectionToStringBuilder extends SortedReflectionToStringBuilder { - public AlphabeticalReflectionToStringBuilder(Object object, ToStringStyle style) { + private AlphabeticalReflectionToStringBuilder(Object object, ToStringStyle style) { super(object, style); setComparator(new AlphabeticalFieldComparator()); } + public static AlphabeticalReflectionToStringBuilder newInstance(Object object, SealStringStyle sealStringStyle) { + AlphabeticalReflectionToStringBuilder res = new AlphabeticalReflectionToStringBuilder(object, sealStringStyle); + sealStringStyle.setReflectionToStringBuilder(res); + return res; + } } diff --git a/sdk-common/src/main/java/com/worldline/sips/helper/SealStringStyle.java b/sdk-common/src/main/java/com/worldline/sips/helper/SealStringStyle.java index 9474cef..c644a70 100644 --- a/sdk-common/src/main/java/com/worldline/sips/helper/SealStringStyle.java +++ b/sdk-common/src/main/java/com/worldline/sips/helper/SealStringStyle.java @@ -12,7 +12,14 @@ * @see com.worldline.sips.security.Sealable */ public final class SealStringStyle extends RecursiveToStringStyle { - public SealStringStyle() { + + private SortedReflectionToStringBuilder reflectionToStringBuilder; + + public void setReflectionToStringBuilder(SortedReflectionToStringBuilder reflectionToStringBuilder) { + this.reflectionToStringBuilder = reflectionToStringBuilder; + } + + public SealStringStyle() { super(); setUseClassName(false); setUseIdentityHashCode(false); @@ -31,7 +38,7 @@ public void appendDetail(StringBuffer buffer, String fieldName, Object value) { if (! ClassUtils.isPrimitiveWrapper(value.getClass()) && ! String.class.equals(value.getClass()) && accept(value.getClass())) { - buffer.append(AlphabeticalReflectionToStringBuilder.toString(value, this)); + buffer.append(reflectionToStringBuilder.initFrom(value).toString()); } else { if (value instanceof YearMonth) { value = ((YearMonth) value).toString().replace("-", ""); diff --git a/sdk-common/src/main/java/com/worldline/sips/helper/SortedReflectionToStringBuilder.java b/sdk-common/src/main/java/com/worldline/sips/helper/SortedReflectionToStringBuilder.java index dd3b7b0..f349913 100644 --- a/sdk-common/src/main/java/com/worldline/sips/helper/SortedReflectionToStringBuilder.java +++ b/sdk-common/src/main/java/com/worldline/sips/helper/SortedReflectionToStringBuilder.java @@ -1,18 +1,21 @@ package com.worldline.sips.helper; -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; -import org.apache.commons.lang3.builder.ToStringSummary; - import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.function.Function; +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import org.apache.commons.lang3.builder.ToStringSummary; public class SortedReflectionToStringBuilder extends ReflectionToStringBuilder { private Comparator comparator; + private final Map, Function> customSerializers = new HashMap<>(); public SortedReflectionToStringBuilder(Object object, ToStringStyle style) { super(object, style); @@ -57,7 +60,11 @@ public String toString() { field.setAccessible(true); // Warning: Field.get(Object) creates wrappers objects // for primitive types. - final Object fieldValue = this.getValue(field); + Object fieldValue = this.getValue(field); + Function serializer = customSerializers.get(field.getType()); + if (serializer != null) { + fieldValue = serializer.apply(fieldValue); + } if (! isExcludeNullValues() || fieldValue != null) { this.append(fieldName, fieldValue, ! field.isAnnotationPresent(ToStringSummary.class)); } @@ -73,7 +80,16 @@ public String toString() { getStyle().appendEnd(this.getStringBuffer(), this.getObject()); return this.getStringBuffer().toString(); } - + + public void addSerializer(Class clazz, Function serializer) { + customSerializers.put(clazz, serializer); + } + public SortedReflectionToStringBuilder initFrom(Object value) { + SortedReflectionToStringBuilder copy = new SortedReflectionToStringBuilder(value, getStyle()); + copy.comparator = this.comparator; + copy.customSerializers.putAll(customSerializers); + return copy; + } } diff --git a/sdk-common/src/main/java/com/worldline/sips/security/SealCalculator.java b/sdk-common/src/main/java/com/worldline/sips/security/SealCalculator.java index 0c5148f..6d8d786 100644 --- a/sdk-common/src/main/java/com/worldline/sips/security/SealCalculator.java +++ b/sdk-common/src/main/java/com/worldline/sips/security/SealCalculator.java @@ -5,14 +5,16 @@ import com.worldline.sips.exception.SealCalculationException; import com.worldline.sips.helper.AlphabeticalReflectionToStringBuilder; import com.worldline.sips.helper.SealStringStyle; -import org.apache.commons.codec.binary.Hex; -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; - -import javax.crypto.Mac; -import javax.crypto.spec.SecretKeySpec; import java.nio.charset.StandardCharsets; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.YearMonth; +import java.time.format.DateTimeFormatter; +import javax.crypto.Mac; +import javax.crypto.spec.SecretKeySpec; +import org.apache.commons.codec.binary.Hex; /** * Utility class to compute seals. @@ -51,26 +53,30 @@ public static String calculate(String sealString, String key) throws SealCalcula * @return a String, formatted as described in the API docs. */ public static String getSealString(SIPSRequest request) { - ReflectionToStringBuilder reflectionToStringBuilder = new AlphabeticalReflectionToStringBuilder(request, new SealStringStyle()); - reflectionToStringBuilder.setExcludeFieldNames("keyVersion", "endpoint"); - reflectionToStringBuilder.setExcludeNullValues(true); - reflectionToStringBuilder.setAppendStatics(true); + AlphabeticalReflectionToStringBuilder reflectionToStringBuilder = AlphabeticalReflectionToStringBuilder.newInstance(request, new SealStringStyle()); + configure(reflectionToStringBuilder); return reflectionToStringBuilder.toString(); } - /** + /** * Sort & concatenate the fields of a given {@link SIPSResponse}, needed to correctly verify a response. * * @param response the response that's needs to be verified * @return a String, formatted as described in the API docs. */ public static String getSealString(SIPSResponse response) { - ReflectionToStringBuilder reflectionToStringBuilder = new AlphabeticalReflectionToStringBuilder(response, new SealStringStyle()); - reflectionToStringBuilder.setExcludeFieldNames("seal"); - reflectionToStringBuilder.setExcludeNullValues(true); - + AlphabeticalReflectionToStringBuilder reflectionToStringBuilder = AlphabeticalReflectionToStringBuilder.newInstance(response, new SealStringStyle()); + configure(reflectionToStringBuilder); return reflectionToStringBuilder.toString(); } + private static void configure(AlphabeticalReflectionToStringBuilder reflectionToStringBuilder) { + reflectionToStringBuilder.addSerializer(YearMonth.class,o -> DateTimeFormatter.ofPattern("yyyyMM").format((YearMonth) o)); + reflectionToStringBuilder.addSerializer(LocalDateTime.class,o -> DateTimeFormatter.ISO_OFFSET_DATE_TIME.format((LocalDateTime) o)); + reflectionToStringBuilder.addSerializer(LocalDate.class,o -> DateTimeFormatter.BASIC_ISO_DATE.format((LocalDate) o)); + reflectionToStringBuilder.setExcludeFieldNames("keyVersion", "endpoint", "sealAlgorithm", "seal"); + reflectionToStringBuilder.setExcludeNullValues(true); + } + } diff --git a/sdk-common/src/main/java/com/worldline/sips/util/ObjectMapperHolder.java b/sdk-common/src/main/java/com/worldline/sips/util/ObjectMapperHolder.java index 493162c..11e8d03 100644 --- a/sdk-common/src/main/java/com/worldline/sips/util/ObjectMapperHolder.java +++ b/sdk-common/src/main/java/com/worldline/sips/util/ObjectMapperHolder.java @@ -6,6 +6,9 @@ import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer; import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer; import com.fasterxml.jackson.datatype.jsr310.deser.YearMonthDeserializer; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; +import com.fasterxml.jackson.datatype.jsr310.ser.YearMonthSerializer; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.YearMonth; @@ -30,8 +33,11 @@ private static ObjectMapper create() { .configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, false) .registerModule(new JavaTimeModule() .addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ISO_OFFSET_DATE_TIME)) + .addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ISO_OFFSET_DATE_TIME)) .addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.BASIC_ISO_DATE)) - .addDeserializer(YearMonth.class, new YearMonthDeserializer(DateTimeFormatter.ofPattern("yyyyMM")))); + .addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.BASIC_ISO_DATE)) + .addDeserializer(YearMonth.class, new YearMonthDeserializer(DateTimeFormatter.ofPattern("yyyyMM"))) + .addSerializer(YearMonth.class, new YearMonthSerializer(DateTimeFormatter.ofPattern("yyyyMM")))); } public ObjectMapper get() {