From 98f88d288790586cf530f54292d0f934e5580b53 Mon Sep 17 00:00:00 2001 From: Carlos Puerma Date: Wed, 8 May 2019 17:00:56 +0200 Subject: [PATCH 1/3] Make billing address validation optional by setting an environment variable --- src/main/java/com/beanstream/api/ProfilesAPI.java | 10 +++++++--- src/main/java/com/beanstream/util/ProfilesUtils.java | 6 ++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/beanstream/api/ProfilesAPI.java b/src/main/java/com/beanstream/api/ProfilesAPI.java index e7c1bc4..d78813c 100644 --- a/src/main/java/com/beanstream/api/ProfilesAPI.java +++ b/src/main/java/com/beanstream/api/ProfilesAPI.java @@ -61,6 +61,8 @@ public class ProfilesAPI { private Configuration config; private HttpsConnector connector; private final Gson gson = new Gson(); + private final boolean validateBillingAddress = + Boolean.valueOf(System.getProperty("bamboraSDK.profiles.validateBillingAddress", "true")); public ProfilesAPI(Configuration config) { this.config = config; @@ -186,7 +188,7 @@ private ProfileResponse createProfile(Card card, Token token, ProfileRequest req = new ProfileRequest(card, token, billing, custom, language, comments); - ProfilesUtils.validateProfileReq(req); + ProfilesUtils.validateProfileReq(req, validateBillingAddress); String url = PaymentsUrls.getProfilesUrl(config.getPlatform(), config.getVersion()); @@ -253,8 +255,10 @@ public ProfileResponse updateProfile(PaymentProfile profile) Gateway.assertNotNull(profile, "profile to update is null"); ProfilesUtils.validateProfileId(profile.getId()); - ProfilesUtils.validateBillingAddr(profile.getBilling()); - + if (validateBillingAddress){ + ProfilesUtils.validateBillingAddr(profile.getBilling()); + } + String url = PaymentsUrls.getProfilesUrl(config.getPlatform(), config.getVersion(), profile.getId()); diff --git a/src/main/java/com/beanstream/util/ProfilesUtils.java b/src/main/java/com/beanstream/util/ProfilesUtils.java index da26d7a..e4f14d5 100644 --- a/src/main/java/com/beanstream/util/ProfilesUtils.java +++ b/src/main/java/com/beanstream/util/ProfilesUtils.java @@ -68,7 +68,7 @@ public static void validateBillingAddr(Address billing) * a BeanstreamApiException with a bad request status, if any required * property is missing */ - public static void validateProfileReq(ProfileRequest profileRequest) + public static void validateProfileReq(ProfileRequest profileRequest, boolean validateBillingAddress) throws BeanstreamApiException { Gateway.assertNotNull(profileRequest, "profile request object is null"); Card card = profileRequest.getCard(); @@ -88,6 +88,8 @@ public static void validateProfileReq(ProfileRequest profileRequest) validateToken(token); } - validateBillingAddr(billing); + if (validateBillingAddress){ + validateBillingAddr(billing); + } } } From ab29150cc325abc2e615bbd377be3391633d3823 Mon Sep 17 00:00:00 2001 From: Carlos Puerma Date: Wed, 8 May 2019 17:16:11 +0200 Subject: [PATCH 2/3] Add unit test --- .../beanstream/api/test/ProfilesAPITest.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/test/java/com/beanstream/api/test/ProfilesAPITest.java b/src/test/java/com/beanstream/api/test/ProfilesAPITest.java index d30d89d..013ddaf 100644 --- a/src/test/java/com/beanstream/api/test/ProfilesAPITest.java +++ b/src/test/java/com/beanstream/api/test/ProfilesAPITest.java @@ -134,6 +134,27 @@ public void invalidBillingAddrCreateProfile() { } + @Test + public void testProfileCreationWhenDisabledAddressValidation() { + + System.setProperty("bamboraSDK.profiles.validateBillingAddress", "false"); + + Address nullBillingAddress = null; + Card card = getTestCard(); + + try { + ProfileResponse createdProfile = gateway.profiles().createProfile(card, nullBillingAddress); + + Assert.assertNotNull(createdProfile.getId()); + Assert.assertNotNull(createdProfile.getCode()); + + } catch (BeanstreamApiException ex) { + Assert.assertTrue("", ex.getHttpStatusCode() == 400); + }finally { + System.clearProperty("bamboraSDK.profiles.validateBillingAddress"); + } + } + @Test public void testProfileCrudUsingCard() throws BeanstreamApiException { String profileId = null; From f15519887aea53ab7318ccfe50110597d386784f Mon Sep 17 00:00:00 2001 From: Carlos Puerma Date: Wed, 8 May 2019 18:05:36 +0200 Subject: [PATCH 3/3] Add unit test --- src/test/java/com/beanstream/api/test/ProfilesAPITest.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/test/java/com/beanstream/api/test/ProfilesAPITest.java b/src/test/java/com/beanstream/api/test/ProfilesAPITest.java index 013ddaf..a953b25 100644 --- a/src/test/java/com/beanstream/api/test/ProfilesAPITest.java +++ b/src/test/java/com/beanstream/api/test/ProfilesAPITest.java @@ -135,7 +135,7 @@ public void invalidBillingAddrCreateProfile() { } @Test - public void testProfileCreationWhenDisabledAddressValidation() { + public void testProfileCreationWhenDisabledAddressValidation() throws BeanstreamApiException { System.setProperty("bamboraSDK.profiles.validateBillingAddress", "false"); @@ -148,8 +148,6 @@ public void testProfileCreationWhenDisabledAddressValidation() { Assert.assertNotNull(createdProfile.getId()); Assert.assertNotNull(createdProfile.getCode()); - } catch (BeanstreamApiException ex) { - Assert.assertTrue("", ex.getHttpStatusCode() == 400); }finally { System.clearProperty("bamboraSDK.profiles.validateBillingAddress"); }