From 7d6317cc2f164d16c506dddc2e17f74ac6e60097 Mon Sep 17 00:00:00 2001 From: rsomavarapu-sift <50379761+rsomavarapu-sift@users.noreply.github.com> Date: Wed, 19 Feb 2020 16:52:17 -0800 Subject: [PATCH] adding support for ordered_from, brand_name, site_* top level fields, and *_language fields in browser and app complex fields (#52) * adding support for ordered_from, brand_name, site_* top level fields, and *_language fields in browser and app complex fields --- CHANGES.MD | 7 + README.md | 4 +- build.gradle | 2 +- .../model/AddItemToCartFieldSet.java | 2 +- .../model/AddPromotionFieldSet.java | 2 +- src/main/java/com/siftscience/model/App.java | 10 ++ .../model/BaseAccountFieldSet.java | 2 +- .../model/BaseAppBrowserFieldSet.java | 29 ---- .../BaseAppBrowserSiteBrandFieldSet.java | 58 +++++++ .../model/BaseContentFieldSet.java | 4 +- .../siftscience/model/BaseOrderFieldSet.java | 12 +- .../java/com/siftscience/model/Browser.java | 21 +++ .../model/ContentStatusFieldSet.java | 2 +- .../model/CustomEventFieldSet.java | 2 +- .../com/siftscience/model/LoginFieldSet.java | 2 +- .../com/siftscience/model/LogoutFieldSet.java | 2 +- .../model/OrderStatusFieldSet.java | 2 +- .../com/siftscience/model/OrderedFrom.java | 27 ++++ .../model/RemoveItemFromCartFieldSet.java | 2 +- .../model/SecurityNotificationFieldSet.java | 2 +- .../model/TransactionFieldSet.java | 12 +- .../model/UpdatePasswordFieldSet.java | 2 +- .../model/VerificationFieldSet.java | 2 +- ... BaseAppBrowserSiteBrandFieldSetTest.java} | 74 +++++++-- ...entWithSiteBrandOrderedFromFieldsTest.java | 141 ++++++++++++++++++ .../java/com/siftscience/CustomEventTest.java | 6 + src/test/java/com/siftscience/TestUtils.java | 7 + .../com/siftscience/TransactionEventTest.java | 20 +++ ...entWithSiteBrandOrderedFromFieldsTest.java | 141 ++++++++++++++++++ 29 files changed, 541 insertions(+), 58 deletions(-) delete mode 100644 src/main/java/com/siftscience/model/BaseAppBrowserFieldSet.java create mode 100644 src/main/java/com/siftscience/model/BaseAppBrowserSiteBrandFieldSet.java create mode 100644 src/main/java/com/siftscience/model/OrderedFrom.java rename src/test/java/com/siftscience/{BaseAppBrowserFieldSetTest.java => BaseAppBrowserSiteBrandFieldSetTest.java} (73%) create mode 100644 src/test/java/com/siftscience/CreateOrderEventWithSiteBrandOrderedFromFieldsTest.java create mode 100644 src/test/java/com/siftscience/UpdateOrderEventWithSiteBrandOrderedFromFieldsTest.java diff --git a/CHANGES.MD b/CHANGES.MD index 17059ba..bfbd22c 100644 --- a/CHANGES.MD +++ b/CHANGES.MD @@ -1,3 +1,10 @@ +3.3.0 (2020-02-19) +================= +- Add support for `$client_language` field to `$app` complex field +- Add support for `$accept_language` and `$content_language` fields to `$browser` complex field +- Add support for `$brand_name`, `$site_country` and `$site_domain` fields to custom events and all reserved events except `$chargeback`, `$link_session_to_user` and `$flag_content` +- Add support for `$ordered_from` complex field to `$create_order`, `$update_order`, and `$transaction` events + 3.2.0 (2019-07-31) ================= - Add support for `$tags` field to `$booking` complex field diff --git a/README.md b/README.md index ba4e197..94db91a 100644 --- a/README.md +++ b/README.md @@ -13,13 +13,13 @@ Java 1.7 or later. com.siftscience sift-java - 3.2.0 + 3.3.0 ``` ### Gradle ``` dependencies { - compile 'com.siftscience:sift-java:3.2.0' + compile 'com.siftscience:sift-java:3.3.0' } ``` ### Other diff --git a/build.gradle b/build.gradle index 27372bf..5fada3d 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ apply plugin: 'signing' apply plugin: 'java-library-distribution' group = 'com.siftscience' -version = '3.2.0' +version = '3.3.0' repositories { mavenCentral() diff --git a/src/main/java/com/siftscience/model/AddItemToCartFieldSet.java b/src/main/java/com/siftscience/model/AddItemToCartFieldSet.java index 74f28a2..0537c55 100644 --- a/src/main/java/com/siftscience/model/AddItemToCartFieldSet.java +++ b/src/main/java/com/siftscience/model/AddItemToCartFieldSet.java @@ -3,7 +3,7 @@ import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; -public class AddItemToCartFieldSet extends BaseAppBrowserFieldSet { +public class AddItemToCartFieldSet extends BaseAppBrowserSiteBrandFieldSet { public static AddItemToCartFieldSet fromJson(String json) { return gson.fromJson(json, AddItemToCartFieldSet.class); } diff --git a/src/main/java/com/siftscience/model/AddPromotionFieldSet.java b/src/main/java/com/siftscience/model/AddPromotionFieldSet.java index 83fd122..5e935a3 100644 --- a/src/main/java/com/siftscience/model/AddPromotionFieldSet.java +++ b/src/main/java/com/siftscience/model/AddPromotionFieldSet.java @@ -5,7 +5,7 @@ import java.util.List; -public class AddPromotionFieldSet extends BaseAppBrowserFieldSet { +public class AddPromotionFieldSet extends BaseAppBrowserSiteBrandFieldSet { public static AddPromotionFieldSet fromJson(String json) { return gson.fromJson(json, AddPromotionFieldSet.class); } diff --git a/src/main/java/com/siftscience/model/App.java b/src/main/java/com/siftscience/model/App.java index 3d80add..bb80d89 100644 --- a/src/main/java/com/siftscience/model/App.java +++ b/src/main/java/com/siftscience/model/App.java @@ -11,6 +11,7 @@ public class App { @Expose @SerializedName("$device_unique_id") private String deviceUniqueId; @Expose @SerializedName("$app_name") private String appName; @Expose @SerializedName("$app_version") private String appVersion; + @Expose @SerializedName("$client_language") private String clientLanguage; public String getOperatingSystem() { return operatingSystem; @@ -74,4 +75,13 @@ public App setAppVersion(String appVersion) { this.appVersion = appVersion; return this; } + + public String getClientLanguage() { + return clientLanguage; + } + + public App setClientLanguage(String clientLanguage) { + this.clientLanguage = clientLanguage; + return this; + } } diff --git a/src/main/java/com/siftscience/model/BaseAccountFieldSet.java b/src/main/java/com/siftscience/model/BaseAccountFieldSet.java index 73f32d1..09ce580 100644 --- a/src/main/java/com/siftscience/model/BaseAccountFieldSet.java +++ b/src/main/java/com/siftscience/model/BaseAccountFieldSet.java @@ -6,7 +6,7 @@ import java.util.List; public abstract class BaseAccountFieldSet> - extends BaseAppBrowserFieldSet { + extends BaseAppBrowserSiteBrandFieldSet { @Expose @SerializedName("$user_email") private String userEmail; @Expose @SerializedName("$name") private String name; @Expose @SerializedName("$phone") private String phone; diff --git a/src/main/java/com/siftscience/model/BaseAppBrowserFieldSet.java b/src/main/java/com/siftscience/model/BaseAppBrowserFieldSet.java deleted file mode 100644 index 058f253..0000000 --- a/src/main/java/com/siftscience/model/BaseAppBrowserFieldSet.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.siftscience.model; - -import com.google.gson.annotations.Expose; -import com.google.gson.annotations.SerializedName; - -public abstract class BaseAppBrowserFieldSet> - extends EventsApiRequestFieldSet { - @Expose @SerializedName("$app") private App app; - @Expose @SerializedName("$browser") private Browser browser; - - public App getApp() { - return app; - } - - public T setApp(App app) { - this.app = app; - return (T) this; - } - - public Browser getBrowser() { - return browser; - } - - public T setBrowser(Browser browser) { - this.browser = browser; - return (T) this; - } - -} diff --git a/src/main/java/com/siftscience/model/BaseAppBrowserSiteBrandFieldSet.java b/src/main/java/com/siftscience/model/BaseAppBrowserSiteBrandFieldSet.java new file mode 100644 index 0000000..2dd5efd --- /dev/null +++ b/src/main/java/com/siftscience/model/BaseAppBrowserSiteBrandFieldSet.java @@ -0,0 +1,58 @@ +package com.siftscience.model; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public abstract class BaseAppBrowserSiteBrandFieldSet> + extends EventsApiRequestFieldSet { + @Expose @SerializedName("$app") private App app; + @Expose @SerializedName("$browser") private Browser browser; + @Expose @SerializedName("$brand_name") private String brandName; + @Expose @SerializedName("$site_country") private String siteCountry; + @Expose @SerializedName("$site_domain") private String siteDomain; + + public App getApp() { + return app; + } + + public T setApp(App app) { + this.app = app; + return (T) this; + } + + public Browser getBrowser() { + return browser; + } + + public T setBrowser(Browser browser) { + this.browser = browser; + return (T) this; + } + + public String getBrandName() { + return brandName; + } + + public T setBrandName(String brandName) { + this.brandName = brandName; + return (T) this; + } + + public String getSiteCountry() { + return siteCountry; + } + + public T setSiteCountry(String siteCountry) { + this.siteCountry = siteCountry; + return (T) this; + } + + public String getSiteDomain() { + return siteDomain; + } + + public T setSiteDomain(String siteDomain) { + this.siteDomain = siteDomain; + return (T) this; + } +} diff --git a/src/main/java/com/siftscience/model/BaseContentFieldSet.java b/src/main/java/com/siftscience/model/BaseContentFieldSet.java index a36eb3d..1300dc7 100644 --- a/src/main/java/com/siftscience/model/BaseContentFieldSet.java +++ b/src/main/java/com/siftscience/model/BaseContentFieldSet.java @@ -3,10 +3,8 @@ import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; -import java.util.List; - public abstract class BaseContentFieldSet> - extends BaseAppBrowserFieldSet { + extends BaseAppBrowserSiteBrandFieldSet { @Expose @SerializedName("$content_id") private String contentId; @Expose @SerializedName("$status") private String status; diff --git a/src/main/java/com/siftscience/model/BaseOrderFieldSet.java b/src/main/java/com/siftscience/model/BaseOrderFieldSet.java index 27132e8..2e9c755 100644 --- a/src/main/java/com/siftscience/model/BaseOrderFieldSet.java +++ b/src/main/java/com/siftscience/model/BaseOrderFieldSet.java @@ -6,7 +6,7 @@ import java.util.List; public abstract class BaseOrderFieldSet> - extends BaseAppBrowserFieldSet { + extends BaseAppBrowserSiteBrandFieldSet { @Expose @SerializedName("$order_id") private String orderId; @Expose @SerializedName("$user_email") private String userEmail; @Expose @SerializedName("$amount") private Long amount; @@ -20,6 +20,7 @@ public abstract class BaseOrderFieldSet> @Expose @SerializedName("$promotions") private List promotions; @Expose @SerializedName("$shipping_method") private String shippingMethod; @Expose @SerializedName("$bookings") private List bookings; + @Expose @SerializedName("$ordered_from") private OrderedFrom orderedFrom; public String getOrderId() { return orderId; @@ -141,4 +142,13 @@ public T setShippingMethod(String shippingMethod) { this.shippingMethod = shippingMethod; return (T) this; } + + public OrderedFrom getOrderedFrom() { + return orderedFrom; + } + + public T setOrderedFrom(OrderedFrom orderedFrom) { + this.orderedFrom = orderedFrom; + return (T) this; + } } diff --git a/src/main/java/com/siftscience/model/Browser.java b/src/main/java/com/siftscience/model/Browser.java index 38a6971..a1aa30e 100644 --- a/src/main/java/com/siftscience/model/Browser.java +++ b/src/main/java/com/siftscience/model/Browser.java @@ -5,6 +5,8 @@ public class Browser { @Expose @SerializedName("$user_agent") private String userAgent; + @Expose @SerializedName("$accept_language") private String acceptLanguage; + @Expose @SerializedName("$content_language") private String contentLanguage; public String getUserAgent() { return userAgent; @@ -14,4 +16,23 @@ public Browser setUserAgent(String userAgent) { this.userAgent = userAgent; return this; } + + public String getAcceptLanguage() { + return acceptLanguage; + } + + public Browser setAcceptLanguage(String acceptLanguage) { + this.acceptLanguage = acceptLanguage; + return this; + } + + public String getContentLanguage() { + return contentLanguage; + } + + public Browser setContentLanguage(String contentLanguage) { + this.contentLanguage = contentLanguage; + return this; + } + } diff --git a/src/main/java/com/siftscience/model/ContentStatusFieldSet.java b/src/main/java/com/siftscience/model/ContentStatusFieldSet.java index 0ad0b59..4c99bdc 100644 --- a/src/main/java/com/siftscience/model/ContentStatusFieldSet.java +++ b/src/main/java/com/siftscience/model/ContentStatusFieldSet.java @@ -3,7 +3,7 @@ import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; -public class ContentStatusFieldSet extends BaseAppBrowserFieldSet { +public class ContentStatusFieldSet extends BaseAppBrowserSiteBrandFieldSet { public static ContentStatusFieldSet fromJson(String json) { return gson.fromJson(json, ContentStatusFieldSet.class); } diff --git a/src/main/java/com/siftscience/model/CustomEventFieldSet.java b/src/main/java/com/siftscience/model/CustomEventFieldSet.java index 2ae2a6f..58ff587 100644 --- a/src/main/java/com/siftscience/model/CustomEventFieldSet.java +++ b/src/main/java/com/siftscience/model/CustomEventFieldSet.java @@ -3,7 +3,7 @@ import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; -public class CustomEventFieldSet extends BaseAppBrowserFieldSet { +public class CustomEventFieldSet extends BaseAppBrowserSiteBrandFieldSet { public static CustomEventFieldSet fromJson(String json) { return gson.fromJson(json, CustomEventFieldSet.class); } diff --git a/src/main/java/com/siftscience/model/LoginFieldSet.java b/src/main/java/com/siftscience/model/LoginFieldSet.java index 5e97e95..d565abe 100644 --- a/src/main/java/com/siftscience/model/LoginFieldSet.java +++ b/src/main/java/com/siftscience/model/LoginFieldSet.java @@ -5,7 +5,7 @@ import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; -public class LoginFieldSet extends BaseAppBrowserFieldSet { +public class LoginFieldSet extends BaseAppBrowserSiteBrandFieldSet { public static LoginFieldSet fromJson(String json) { return gson.fromJson(json, LoginFieldSet.class); } diff --git a/src/main/java/com/siftscience/model/LogoutFieldSet.java b/src/main/java/com/siftscience/model/LogoutFieldSet.java index eeb9adc..d292286 100644 --- a/src/main/java/com/siftscience/model/LogoutFieldSet.java +++ b/src/main/java/com/siftscience/model/LogoutFieldSet.java @@ -1,6 +1,6 @@ package com.siftscience.model; -public class LogoutFieldSet extends BaseAppBrowserFieldSet { +public class LogoutFieldSet extends BaseAppBrowserSiteBrandFieldSet { public static LogoutFieldSet fromJson(String json) { return gson.fromJson(json, LogoutFieldSet.class); } diff --git a/src/main/java/com/siftscience/model/OrderStatusFieldSet.java b/src/main/java/com/siftscience/model/OrderStatusFieldSet.java index bbb2ae8..b7b83d5 100644 --- a/src/main/java/com/siftscience/model/OrderStatusFieldSet.java +++ b/src/main/java/com/siftscience/model/OrderStatusFieldSet.java @@ -3,7 +3,7 @@ import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; -public class OrderStatusFieldSet extends BaseAppBrowserFieldSet { +public class OrderStatusFieldSet extends BaseAppBrowserSiteBrandFieldSet { public static OrderStatusFieldSet fromJson(String json) { return gson.fromJson(json, OrderStatusFieldSet.class); } diff --git a/src/main/java/com/siftscience/model/OrderedFrom.java b/src/main/java/com/siftscience/model/OrderedFrom.java new file mode 100644 index 0000000..5a529f4 --- /dev/null +++ b/src/main/java/com/siftscience/model/OrderedFrom.java @@ -0,0 +1,27 @@ +package com.siftscience.model; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class OrderedFrom { + @Expose @SerializedName("$store_address") private Address storeAddress; + @Expose @SerializedName("$store_id") private String storeId; + + public Address getStoreAddress() { + return storeAddress; + } + + public OrderedFrom setStoreAddress(Address storeAddress) { + this.storeAddress = storeAddress; + return this; + } + + public String getStoreId() { + return storeId; + } + + public OrderedFrom setStoreId(String storeId) { + this.storeId = storeId; + return this; + } +} diff --git a/src/main/java/com/siftscience/model/RemoveItemFromCartFieldSet.java b/src/main/java/com/siftscience/model/RemoveItemFromCartFieldSet.java index 19cbcda..0005910 100644 --- a/src/main/java/com/siftscience/model/RemoveItemFromCartFieldSet.java +++ b/src/main/java/com/siftscience/model/RemoveItemFromCartFieldSet.java @@ -3,7 +3,7 @@ import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; -public class RemoveItemFromCartFieldSet extends BaseAppBrowserFieldSet { +public class RemoveItemFromCartFieldSet extends BaseAppBrowserSiteBrandFieldSet { public static RemoveItemFromCartFieldSet fromJson(String json) { return gson.fromJson(json, RemoveItemFromCartFieldSet.class); } diff --git a/src/main/java/com/siftscience/model/SecurityNotificationFieldSet.java b/src/main/java/com/siftscience/model/SecurityNotificationFieldSet.java index 34ed82c..8bc4cd9 100644 --- a/src/main/java/com/siftscience/model/SecurityNotificationFieldSet.java +++ b/src/main/java/com/siftscience/model/SecurityNotificationFieldSet.java @@ -4,7 +4,7 @@ import com.google.gson.annotations.SerializedName; public class SecurityNotificationFieldSet extends - BaseAppBrowserFieldSet { + BaseAppBrowserSiteBrandFieldSet { public static SecurityNotificationFieldSet fromJson(String json) { return gson.fromJson(json, SecurityNotificationFieldSet.class); } diff --git a/src/main/java/com/siftscience/model/TransactionFieldSet.java b/src/main/java/com/siftscience/model/TransactionFieldSet.java index fad9e7d..5556c79 100644 --- a/src/main/java/com/siftscience/model/TransactionFieldSet.java +++ b/src/main/java/com/siftscience/model/TransactionFieldSet.java @@ -3,7 +3,7 @@ import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; -public class TransactionFieldSet extends BaseAppBrowserFieldSet { +public class TransactionFieldSet extends BaseAppBrowserSiteBrandFieldSet { @Expose @SerializedName("$amount") private Long amount; @Expose @SerializedName("$currency_code") private String currencyCode; @Expose @SerializedName("$user_email") private String userEmail; @@ -16,6 +16,7 @@ public class TransactionFieldSet extends BaseAppBrowserFieldSet { +public class UpdatePasswordFieldSet extends BaseAppBrowserSiteBrandFieldSet { public static UpdatePasswordFieldSet fromJson(String json) { return gson.fromJson(json, UpdatePasswordFieldSet.class); } diff --git a/src/main/java/com/siftscience/model/VerificationFieldSet.java b/src/main/java/com/siftscience/model/VerificationFieldSet.java index 9f85957..e3a00da 100644 --- a/src/main/java/com/siftscience/model/VerificationFieldSet.java +++ b/src/main/java/com/siftscience/model/VerificationFieldSet.java @@ -3,7 +3,7 @@ import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; -public class VerificationFieldSet extends BaseAppBrowserFieldSet { +public class VerificationFieldSet extends BaseAppBrowserSiteBrandFieldSet { public static VerificationFieldSet fromJson(String json) { return gson.fromJson(json, VerificationFieldSet.class); } diff --git a/src/test/java/com/siftscience/BaseAppBrowserFieldSetTest.java b/src/test/java/com/siftscience/BaseAppBrowserSiteBrandFieldSetTest.java similarity index 73% rename from src/test/java/com/siftscience/BaseAppBrowserFieldSetTest.java rename to src/test/java/com/siftscience/BaseAppBrowserSiteBrandFieldSetTest.java index ddaebdd..430c169 100644 --- a/src/test/java/com/siftscience/BaseAppBrowserFieldSetTest.java +++ b/src/test/java/com/siftscience/BaseAppBrowserSiteBrandFieldSetTest.java @@ -9,7 +9,7 @@ import com.siftscience.model.AddItemToCartFieldSet; import com.siftscience.model.AddPromotionFieldSet; import com.siftscience.model.App; -import com.siftscience.model.BaseAppBrowserFieldSet; +import com.siftscience.model.BaseAppBrowserSiteBrandFieldSet; import com.siftscience.model.Browser; import com.siftscience.model.ContentStatusFieldSet; import com.siftscience.model.CreateAccountFieldSet; @@ -45,7 +45,7 @@ import org.junit.Test; import org.skyscreamer.jsonassert.JSONAssert; -public class BaseAppBrowserFieldSetTest { +public class BaseAppBrowserSiteBrandFieldSetTest { private static final String DUMMY_API_KEY = "YOUR_API_KEY"; private static final String DUMMY_ACCOUNT_ID = "YOUR_ACCOUNT_ID"; @@ -93,7 +93,7 @@ public void testAllSubclasses() { }; for (Class subclass : subclasses) { - assertThat(subclass, typeCompatibleWith(BaseAppBrowserFieldSet.class)); + assertThat(subclass, typeCompatibleWith(BaseAppBrowserSiteBrandFieldSet.class)); } } @@ -101,15 +101,18 @@ public void testAllSubclasses() { public void testApp() throws Exception { String appName = "Calculator"; String operatingSystem = "iOS"; + String clientLanguage = "en-US"; test( new TestFieldSet().setTestField(DUMMY_TEST_FIELD) .setUserId(DUMMY_USERID) .setApp(new App().setAppName(appName) - .setOperatingSystem(operatingSystem)), + .setOperatingSystem(operatingSystem) + .setClientLanguage(clientLanguage)), String.format(REQUEST_BODY_TEMPLATE, ",\n" + " \"$app\" : {\n" + " \"$os\" : \"" + operatingSystem + "\",\n" + - " \"$app_name\" : \"" + appName + "\"\n" + + " \"$app_name\" : \"" + appName + "\",\n" + + " \"$client_language\" : \"" + clientLanguage + "\"\n" + " }\n") ); } @@ -117,13 +120,20 @@ public void testApp() throws Exception { @Test public void testBrowser() throws Exception { String userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3)"; + String acceptLanguage = "en-US"; + String contentLanguage = "en-GB"; test( new TestFieldSet().setTestField(DUMMY_TEST_FIELD) .setUserId(DUMMY_USERID) - .setBrowser(new Browser().setUserAgent(userAgent)), + .setBrowser(new Browser() + .setUserAgent(userAgent) + .setAcceptLanguage(acceptLanguage) + .setContentLanguage(contentLanguage)), String.format(REQUEST_BODY_TEMPLATE, ",\n" + " \"$browser\" : {\n" + - " \"$user_agent\": \"" + userAgent + "\"\n" + + " \"$user_agent\": \"" + userAgent + "\",\n" + + " \"$accept_language\": \"" + acceptLanguage + "\",\n" + + " \"$content_language\": \"" + contentLanguage + "\"\n" + " }\n") ); } @@ -136,6 +146,52 @@ public void testNeitherAppNorBrowser() throws Exception { ); } + @Test + public void testSiteCountry() throws Exception { + String siteCountry = "US"; + test( + new TestFieldSet() + .setTestField(DUMMY_TEST_FIELD) + .setUserId(DUMMY_USERID) + .setSiteCountry(siteCountry), + String.format(REQUEST_BODY_TEMPLATE, ", \"$site_country\" : \"US\" }\n") + ); + } + + @Test + public void testSiteDomain() throws Exception { + String siteDomain = "sift.com"; + test( + new TestFieldSet() + .setTestField(DUMMY_TEST_FIELD) + .setUserId(DUMMY_USERID) + .setSiteDomain(siteDomain), + String.format(REQUEST_BODY_TEMPLATE, ", \"$site_domain\" : \"sift.com\" }\n") + ); + } + + @Test + public void testBrandName() throws Exception { + String brandName = "sift"; + test( + new TestFieldSet() + .setTestField(DUMMY_TEST_FIELD) + .setUserId(DUMMY_USERID) + .setBrandName(brandName), + String.format(REQUEST_BODY_TEMPLATE, ", \"$brand_name\" : \"sift\" }\n") + ); + } + + @Test + public void testNoSiteBrandFields() throws Exception { + test( + new TestFieldSet() + .setTestField(DUMMY_TEST_FIELD) + .setUserId(DUMMY_USERID), + String.format(REQUEST_BODY_TEMPLATE, "") + ); + } + private void test(TestFieldSet t, String expectedRequestBody) throws Exception { // Start a new mock server and enqueue a mock response. MockWebServer server = new MockWebServer(); @@ -174,8 +230,8 @@ private void test(TestFieldSet t, String expectedRequestBody) throws Exception { server.shutdown(); } - private static class TestFieldSet extends BaseAppBrowserFieldSet { - public TestFieldSet fromJson(String json) { + private static class TestFieldSet extends BaseAppBrowserSiteBrandFieldSet { + public BaseAppBrowserSiteBrandFieldSetTest.TestFieldSet fromJson(String json) { return gson.fromJson(json, TestFieldSet.class); } diff --git a/src/test/java/com/siftscience/CreateOrderEventWithSiteBrandOrderedFromFieldsTest.java b/src/test/java/com/siftscience/CreateOrderEventWithSiteBrandOrderedFromFieldsTest.java new file mode 100644 index 0000000..41d76d3 --- /dev/null +++ b/src/test/java/com/siftscience/CreateOrderEventWithSiteBrandOrderedFromFieldsTest.java @@ -0,0 +1,141 @@ +package com.siftscience; + +import static java.net.HttpURLConnection.HTTP_OK; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import com.siftscience.model.CreateOrderFieldSet; +import com.siftscience.model.PaymentMethod; +import okhttp3.OkHttpClient; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; +import org.json.JSONException; +import org.junit.Assert; +import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; + +public class CreateOrderEventWithSiteBrandOrderedFromFieldsTest { + + @Test + public void testCreateOrderEvent() throws JSONException, IOException, + InterruptedException { + + // The expected JSON payload of the request. + String expectedRequestBody = "{\n" + + " \"$type\": \"$create_order\",\n" + + " \"$api_key\": \"YOUR_API_KEY\",\n" + + " \"$user_id\": \"billy_jones_301\",\n" + + " \"$session_id\": \"gigtleqddo84l8cm15qe4il\",\n" + + " \"$order_id\": \"ORDER-28168441\",\n" + + " \"$user_email\": \"bill@gmail.com\",\n" + + " \"$amount\": 115940000,\n" + + " \"$currency_code\": \"USD\",\n" + + " \"$site_country\": \"US\",\n" + + " \"$site_domain\": \"sift.com\",\n" + + " \"$brand_name\": \"sift\",\n" + + " \"$payment_methods\": [\n" + + " {\n" + + " \"$payment_type\": \"$credit_card\",\n" + + " \"$payment_gateway\": \"$braintree\",\n" + + " \"$card_bin\": \"542486\",\n" + + " \"$card_last4\": \"4444\"\n" + + " }\n" + + " ],\n" + + " \"$billing_address\": {\n" + + " \"$name\": \"Bill Jones\",\n" + + " \"$phone\": \"1-415-555-6041\",\n" + + " \"$address_1\": \"2100 Main Street\",\n" + + " \"$address_2\": \"Apt 3B\",\n" + + " \"$city\": \"New London\",\n" + + " \"$region\": \"New Hampshire\",\n" + + " \"$country\": \"US\",\n" + + " \"$zipcode\": \"03257\"\n" + + " },\n" + + " \"$shipping_address\": {\n" + + " \"$name\": \"Bill Jones\",\n" + + " \"$phone\": \"1-415-555-6041\",\n" + + " \"$address_1\": \"2100 Main Street\",\n" + + " \"$address_2\": \"Apt 3B\",\n" + + " \"$city\": \"New London\",\n" + + " \"$region\": \"New Hampshire\",\n" + + " \"$country\": \"US\",\n" + + " \"$zipcode\": \"03257\"\n" + + " },\n" + + " \"$expedited_shipping\": true,\n" + + " \"$shipping_method\": \"$physical\",\n" + + " \"$ordered_from\" : {\n" + + " \"$store_id\" : \"123\",\n" + + " \"$store_address\" : {\n" + + " \"$address_1\" : \"2100 Main Street\",\n" + + " \"$address_2\" : \"Apt 3B\",\n" + + " \"$city\" : \"New London\",\n" + + " \"$country\" : \"US\",\n" + + " \"$name\" : \"Bill Jones\",\n" + + " \"$phone\" : \"1-415-555-6040\",\n" + + " \"$region\" : \"New Hampshire\",\n" + + " \"$zipcode\" : \"03257\"\n" + + " }\n" + + " }\n" + + "}\n"; + + // Start a new mock server and enqueue a mock response. + MockWebServer server = new MockWebServer(); + MockResponse response = new MockResponse(); + response.setResponseCode(HTTP_OK); + response.setBody("{\n" + + " \"status\" : 0,\n" + + " \"error_message\" : \"OK\",\n" + + " \"time\" : 1327604222,\n" + + " \"request\" : \"" + TestUtils.unescapeJson(expectedRequestBody) + "\"\n" + + "}"); + server.enqueue(response); + server.start(); + + // Create a new client and link it to the mock server. + SiftClient client = new SiftClient("YOUR_API_KEY", "YOUR_ACCOUNT_ID", + new OkHttpClient.Builder() + .addInterceptor(OkHttpUtils.urlRewritingInterceptor(server)) + .build()); + + // Payment methods. + List paymentMethodList = new ArrayList<>(); + paymentMethodList.add(TestUtils.samplePaymentMethod1()); + + // Build and execute the request against the mock server. + EventRequest request = client.buildRequest( + new CreateOrderFieldSet() + .setUserId("billy_jones_301") + .setSessionId("gigtleqddo84l8cm15qe4il") + .setOrderId("ORDER-28168441") + .setUserEmail("bill@gmail.com") + .setAmount(115940000L) + .setCurrencyCode("USD") + .setBillingAddress(TestUtils.sampleAddress2()) + .setOrderedFrom(TestUtils.sampleOrderedFrom()) + .setSiteDomain("sift.com") + .setSiteCountry("US") + .setBrandName("sift") + .setPaymentMethods(paymentMethodList) + .setShippingAddress(TestUtils.sampleAddress2()) + .setExpeditedShipping(true) + .setShippingMethod("$physical")); + + EventResponse siftResponse = request.send(); + + // Verify the request. + RecordedRequest request1 = server.takeRequest(); + Assert.assertEquals("POST", request1.getMethod()); + Assert.assertEquals("/v205/events", request1.getPath()); + JSONAssert.assertEquals(expectedRequestBody, request.getFieldSet().toJson(), true); + + // Verify the response. + Assert.assertEquals(HTTP_OK, siftResponse.getHttpStatusCode()); + Assert.assertEquals(0, (int) siftResponse.getBody().getStatus()); + JSONAssert.assertEquals(response.getBody().readUtf8(), + siftResponse.getBody().toJson(), true); + + server.shutdown(); + } +} diff --git a/src/test/java/com/siftscience/CustomEventTest.java b/src/test/java/com/siftscience/CustomEventTest.java index 6dd4eb5..0efaebd 100644 --- a/src/test/java/com/siftscience/CustomEventTest.java +++ b/src/test/java/com/siftscience/CustomEventTest.java @@ -19,6 +19,9 @@ public void testCustomEvent() throws Exception { " \"$api_key\" : \"YOUR_API_KEY\",\n" + " \"$user_id\" : \"billy_jones_301\",\n" + " \"recipient_user_id\" : \"marylee819\",\n" + + " \"$site_country\": \"US\",\n" + + " \"$site_domain\": \"sift.com\",\n" + + " \"$brand_name\": \"sift\",\n" + " \"call_duration\" : 4428\n" + "}"; @@ -45,6 +48,9 @@ public void testCustomEvent() throws Exception { SiftRequest request = client.buildRequest(new CustomEventFieldSet() .setEventType("make_call") .setUserId("billy_jones_301") + .setSiteCountry("US") + .setSiteDomain("sift.com") + .setBrandName("sift") .setCustomField("recipient_user_id", "marylee819") .setCustomField("call_duration", 4428)); diff --git a/src/test/java/com/siftscience/TestUtils.java b/src/test/java/com/siftscience/TestUtils.java index 09f6ab7..3afc6ea 100644 --- a/src/test/java/com/siftscience/TestUtils.java +++ b/src/test/java/com/siftscience/TestUtils.java @@ -6,6 +6,7 @@ import com.siftscience.model.Discount; import com.siftscience.model.Guest; import com.siftscience.model.Item; +import com.siftscience.model.OrderedFrom; import com.siftscience.model.PaymentMethod; import com.siftscience.model.Promotion; import com.siftscience.model.Segment; @@ -138,6 +139,12 @@ static Booking sampleBooking() { .setQuantity(1L); } + static OrderedFrom sampleOrderedFrom() { + return new OrderedFrom() + .setStoreId("123") + .setStoreAddress(sampleAddress1()); + } + static Guest sampleGuest1() { return new Guest() .setName("John Doe") diff --git a/src/test/java/com/siftscience/TransactionEventTest.java b/src/test/java/com/siftscience/TransactionEventTest.java index 638bca3..2ddbfc0 100644 --- a/src/test/java/com/siftscience/TransactionEventTest.java +++ b/src/test/java/com/siftscience/TransactionEventTest.java @@ -26,6 +26,22 @@ public void testTransactionEvent() throws Exception { " \"$transaction_status\" : \"$success\",\n" + " \"$order_id\" : \"ORDER-123124124\",\n" + " \"$transaction_id\" : \"719637215\",\n" + + " \"$site_country\": \"US\",\n" + + " \"$site_domain\": \"sift.com\",\n" + + " \"$brand_name\": \"sift\",\n" + + " \"$ordered_from\" : {\n" + + " \"$store_id\" : \"123\",\n" + + " \"$store_address\" : {\n" + + " \"$address_1\" : \"2100 Main Street\",\n" + + " \"$address_2\" : \"Apt 3B\",\n" + + " \"$city\" : \"New London\",\n" + + " \"$country\" : \"US\",\n" + + " \"$name\" : \"Bill Jones\",\n" + + " \"$phone\" : \"1-415-555-6040\",\n" + + " \"$region\" : \"New Hampshire\",\n" + + " \"$zipcode\" : \"03257\"\n" + + " }\n" + + " },\n" + "\n" + " \"$billing_address\" : {\n" + " \"$name\" : \"Bill Jones\",\n" + @@ -90,11 +106,15 @@ public void testTransactionEvent() throws Exception { .setUserEmail("bill@gmail.com") .setTransactionType("$sale") .setTransactionStatus("$success") + .setSiteCountry("US") + .setSiteDomain("sift.com") + .setBrandName("sift") .setOrderId("ORDER-123124124") .setTransactionId("719637215") .setBillingAddress(TestUtils.sampleAddress2()) .setPaymentMethod(TestUtils.samplePaymentMethod1()) .setShippingAddress(TestUtils.sampleAddress2()) + .setOrderedFrom(TestUtils.sampleOrderedFrom()) .setSessionId("gigtleqddo84l8cm15qe4il") .setSellerUserId("slinkys_emporium") .setCustomField("digital_wallet", "apple_pay") diff --git a/src/test/java/com/siftscience/UpdateOrderEventWithSiteBrandOrderedFromFieldsTest.java b/src/test/java/com/siftscience/UpdateOrderEventWithSiteBrandOrderedFromFieldsTest.java new file mode 100644 index 0000000..5f52ded --- /dev/null +++ b/src/test/java/com/siftscience/UpdateOrderEventWithSiteBrandOrderedFromFieldsTest.java @@ -0,0 +1,141 @@ +package com.siftscience; + +import static java.net.HttpURLConnection.HTTP_OK; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import com.siftscience.model.PaymentMethod; +import com.siftscience.model.UpdateOrderFieldSet; +import okhttp3.OkHttpClient; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; +import org.json.JSONException; +import org.junit.Assert; +import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; + +public class UpdateOrderEventWithSiteBrandOrderedFromFieldsTest { + + @Test + public void testUpdateOrderEvent() throws JSONException, IOException, + InterruptedException { + + // The expected JSON payload of the request. + String expectedRequestBody = "{\n" + + " \"$type\": \"$update_order\",\n" + + " \"$api_key\": \"YOUR_API_KEY\",\n" + + " \"$user_id\": \"billy_jones_301\",\n" + + " \"$session_id\": \"gigtleqddo84l8cm15qe4il\",\n" + + " \"$order_id\": \"ORDER-28168441\",\n" + + " \"$user_email\": \"bill@gmail.com\",\n" + + " \"$amount\": 115940000,\n" + + " \"$currency_code\": \"USD\",\n" + + " \"$site_country\": \"US\",\n" + + " \"$site_domain\": \"sift.com\",\n" + + " \"$brand_name\": \"sift\",\n" + + " \"$payment_methods\": [\n" + + " {\n" + + " \"$payment_type\": \"$credit_card\",\n" + + " \"$payment_gateway\": \"$braintree\",\n" + + " \"$card_bin\": \"542486\",\n" + + " \"$card_last4\": \"4444\"\n" + + " }\n" + + " ],\n" + + " \"$billing_address\": {\n" + + " \"$name\": \"Bill Jones\",\n" + + " \"$phone\": \"1-415-555-6041\",\n" + + " \"$address_1\": \"2100 Main Street\",\n" + + " \"$address_2\": \"Apt 3B\",\n" + + " \"$city\": \"New London\",\n" + + " \"$region\": \"New Hampshire\",\n" + + " \"$country\": \"US\",\n" + + " \"$zipcode\": \"03257\"\n" + + " },\n" + + " \"$shipping_address\": {\n" + + " \"$name\": \"Bill Jones\",\n" + + " \"$phone\": \"1-415-555-6041\",\n" + + " \"$address_1\": \"2100 Main Street\",\n" + + " \"$address_2\": \"Apt 3B\",\n" + + " \"$city\": \"New London\",\n" + + " \"$region\": \"New Hampshire\",\n" + + " \"$country\": \"US\",\n" + + " \"$zipcode\": \"03257\"\n" + + " },\n" + + " \"$expedited_shipping\": true,\n" + + " \"$shipping_method\": \"$physical\",\n" + + " \"$ordered_from\" : {\n" + + " \"$store_id\" : \"123\",\n" + + " \"$store_address\" : {\n" + + " \"$address_1\" : \"2100 Main Street\",\n" + + " \"$address_2\" : \"Apt 3B\",\n" + + " \"$city\" : \"New London\",\n" + + " \"$country\" : \"US\",\n" + + " \"$name\" : \"Bill Jones\",\n" + + " \"$phone\" : \"1-415-555-6040\",\n" + + " \"$region\" : \"New Hampshire\",\n" + + " \"$zipcode\" : \"03257\"\n" + + " }\n" + + " }\n" + + "}\n"; + + // Start a new mock server and enqueue a mock response. + MockWebServer server = new MockWebServer(); + MockResponse response = new MockResponse(); + response.setResponseCode(HTTP_OK); + response.setBody("{\n" + + " \"status\" : 0,\n" + + " \"error_message\" : \"OK\",\n" + + " \"time\" : 1327604222,\n" + + " \"request\" : \"" + TestUtils.unescapeJson(expectedRequestBody) + "\"\n" + + "}"); + server.enqueue(response); + server.start(); + + // Create a new client and link it to the mock server. + SiftClient client = new SiftClient("YOUR_API_KEY", "YOUR_ACCOUNT_ID", + new OkHttpClient.Builder() + .addInterceptor(OkHttpUtils.urlRewritingInterceptor(server)) + .build()); + + // Payment methods. + List paymentMethodList = new ArrayList<>(); + paymentMethodList.add(TestUtils.samplePaymentMethod1()); + + // Build and execute the request against the mock server. + EventRequest request = client.buildRequest( + new UpdateOrderFieldSet() + .setUserId("billy_jones_301") + .setSessionId("gigtleqddo84l8cm15qe4il") + .setOrderId("ORDER-28168441") + .setUserEmail("bill@gmail.com") + .setAmount(115940000L) + .setCurrencyCode("USD") + .setBillingAddress(TestUtils.sampleAddress2()) + .setOrderedFrom(TestUtils.sampleOrderedFrom()) + .setSiteDomain("sift.com") + .setSiteCountry("US") + .setBrandName("sift") + .setPaymentMethods(paymentMethodList) + .setShippingAddress(TestUtils.sampleAddress2()) + .setExpeditedShipping(true) + .setShippingMethod("$physical")); + + EventResponse siftResponse = request.send(); + + // Verify the request. + RecordedRequest request1 = server.takeRequest(); + Assert.assertEquals("POST", request1.getMethod()); + Assert.assertEquals("/v205/events", request1.getPath()); + JSONAssert.assertEquals(expectedRequestBody, request.getFieldSet().toJson(), true); + + // Verify the response. + Assert.assertEquals(HTTP_OK, siftResponse.getHttpStatusCode()); + Assert.assertEquals(0, (int) siftResponse.getBody().getStatus()); + JSONAssert.assertEquals(response.getBody().readUtf8(), + siftResponse.getBody().toJson(), true); + + server.shutdown(); + } +}