diff --git a/CHANGES.MD b/CHANGES.MD
index 6c1f07c..4d1d339 100644
--- a/CHANGES.MD
+++ b/CHANGES.MD
@@ -1,3 +1,9 @@
+3.11.0 (2023-06-29)
+=================
+- Add support for `$user_email` field to `$add_item_to_cart`, `$add_promotion`, `$content_status`, `$flag_content`, `$remove_item_from_cart` and `$update_password` events
+- Add support for `$shipping_carrier` and `$shipping_tracking_numbers` fields to `$create_order` and `$update_order` events
+- Add support for `$reason` field to `$flag_content` event
+
3.10.0 (2023-06-06)
=================
- Remove support for `$keyless_user_id` field for Events API
diff --git a/README.md b/README.md
index 8045302..5359da2 100644
--- a/README.md
+++ b/README.md
@@ -13,13 +13,13 @@ Java 1.7 or later.
com.siftscience
sift-java
- 3.10.0
+ 3.11.0
```
### Gradle
```
dependencies {
- compile 'com.siftscience:sift-java:3.10.0'
+ compile 'com.siftscience:sift-java:3.11.0'
}
```
### Other
diff --git a/build.gradle b/build.gradle
index b94dd71..fe04259 100644
--- a/build.gradle
+++ b/build.gradle
@@ -5,7 +5,7 @@ apply plugin: 'signing'
apply plugin: 'java-library-distribution'
group = 'com.siftscience'
-version = '3.10.0'
+version = '3.11.0'
repositories {
mavenCentral()
diff --git a/src/main/java/com/siftscience/Constants.java b/src/main/java/com/siftscience/Constants.java
index 31e08d7..3663f94 100644
--- a/src/main/java/com/siftscience/Constants.java
+++ b/src/main/java/com/siftscience/Constants.java
@@ -3,6 +3,6 @@
public class Constants {
public static final String API_VERSION = "v205";
- public static final String LIB_VERSION = "3.8.0";
+ public static final String LIB_VERSION = "3.11.0";
public static final String USER_AGENT_HEADER = String.format("SiftScience/%s sift-java/%s", API_VERSION, LIB_VERSION);
}
diff --git a/src/main/java/com/siftscience/FieldSet.java b/src/main/java/com/siftscience/FieldSet.java
index 0c361bb..bc88ef8 100644
--- a/src/main/java/com/siftscience/FieldSet.java
+++ b/src/main/java/com/siftscience/FieldSet.java
@@ -36,6 +36,7 @@ public abstract class FieldSet> {
public static final String TIME = "$time";
public static final String IS_BAD = "$is_bad";
public static final String ABUSE_TYPE = "$abuse_type";
+ public static final String USER_EMAIL = "$user_email";
public static final String VERIFICATION_PHONE_NUMBER = "$verification_phone_number";
// Serialization happens in two stages. First, the object is serialized with `defaultGson`
diff --git a/src/main/java/com/siftscience/model/AddItemToCartFieldSet.java b/src/main/java/com/siftscience/model/AddItemToCartFieldSet.java
index 15dd5f9..5879004 100644
--- a/src/main/java/com/siftscience/model/AddItemToCartFieldSet.java
+++ b/src/main/java/com/siftscience/model/AddItemToCartFieldSet.java
@@ -9,6 +9,7 @@ public static AddItemToCartFieldSet fromJson(String json) {
}
@Expose @SerializedName("$item") private Item item;
+ @Expose @SerializedName(USER_EMAIL) private String userEmail;
@Expose @SerializedName(VERIFICATION_PHONE_NUMBER) private String verificationPhoneNumber;
@Override
@@ -25,6 +26,15 @@ public AddItemToCartFieldSet setItem(Item item) {
return this;
}
+ public String getUserEmail() {
+ return userEmail;
+ }
+
+ public AddItemToCartFieldSet setUserEmail(String userEmail) {
+ this.userEmail = userEmail;
+ return this;
+ }
+
public String getVerificationPhoneNumber() {
return verificationPhoneNumber;
}
diff --git a/src/main/java/com/siftscience/model/AddPromotionFieldSet.java b/src/main/java/com/siftscience/model/AddPromotionFieldSet.java
index 9836e59..83155b9 100644
--- a/src/main/java/com/siftscience/model/AddPromotionFieldSet.java
+++ b/src/main/java/com/siftscience/model/AddPromotionFieldSet.java
@@ -11,6 +11,7 @@ public static AddPromotionFieldSet fromJson(String json) {
}
@Expose @SerializedName("$promotions") private List promotions;
+ @Expose @SerializedName(USER_EMAIL) private String userEmail;
@Expose @SerializedName(VERIFICATION_PHONE_NUMBER) private String verificationPhoneNumber;
@Override
@@ -27,6 +28,15 @@ public AddPromotionFieldSet setPromotions(List promotions) {
return this;
}
+ public String getUserEmail() {
+ return userEmail;
+ }
+
+ public AddPromotionFieldSet setUserEmail(String userEmail) {
+ this.userEmail = userEmail;
+ return this;
+ }
+
public String getVerificationPhoneNumber() {
return verificationPhoneNumber;
}
diff --git a/src/main/java/com/siftscience/model/BaseAccountFieldSet.java b/src/main/java/com/siftscience/model/BaseAccountFieldSet.java
index 392518e..9c42907 100644
--- a/src/main/java/com/siftscience/model/BaseAccountFieldSet.java
+++ b/src/main/java/com/siftscience/model/BaseAccountFieldSet.java
@@ -7,7 +7,7 @@
public abstract class BaseAccountFieldSet>
extends BaseAppBrowserSiteBrandFieldSet {
- @Expose @SerializedName("$user_email") private String userEmail;
+ @Expose @SerializedName(USER_EMAIL) private String userEmail;
@Expose @SerializedName("$name") private String name;
@Expose @SerializedName("$phone") private String phone;
@Expose @SerializedName("$referrer_user_id") private String referrerUserId;
diff --git a/src/main/java/com/siftscience/model/BaseOrderFieldSet.java b/src/main/java/com/siftscience/model/BaseOrderFieldSet.java
index d12e556..98faefb 100644
--- a/src/main/java/com/siftscience/model/BaseOrderFieldSet.java
+++ b/src/main/java/com/siftscience/model/BaseOrderFieldSet.java
@@ -8,7 +8,7 @@
public abstract class BaseOrderFieldSet>
extends BaseAppBrowserSiteBrandFieldSet {
@Expose @SerializedName("$order_id") private String orderId;
- @Expose @SerializedName("$user_email") private String userEmail;
+ @Expose @SerializedName(USER_EMAIL) private String userEmail;
@Expose @SerializedName("$amount") private Long amount;
@Expose @SerializedName("$currency_code") private String currencyCode;
@Expose @SerializedName("$billing_address") private Address billingAddress;
@@ -19,6 +19,8 @@ public abstract class BaseOrderFieldSet>
@Expose @SerializedName("$seller_user_id") private String sellerUserId;
@Expose @SerializedName("$promotions") private List promotions;
@Expose @SerializedName("$shipping_method") private String shippingMethod;
+ @Expose @SerializedName("$shipping_carrier") private String shippingCarrier;
+ @Expose @SerializedName("$shipping_tracking_numbers") private List shippingTrackingNumbers;
@Expose @SerializedName("$bookings") private List bookings;
@Expose @SerializedName("$ordered_from") private OrderedFrom orderedFrom;
@Expose @SerializedName("$merchant_profile") private MerchantProfile merchantProfile;
@@ -146,6 +148,24 @@ public T setShippingMethod(String shippingMethod) {
return (T) this;
}
+ public String getShippingCarrier() {
+ return shippingCarrier;
+ }
+
+ public T setShippingCarrier(String shippingCarrier) {
+ this.shippingCarrier = shippingCarrier;
+ return (T) this;
+ }
+
+ public List getShippingTrackingNumbers() {
+ return shippingTrackingNumbers;
+ }
+
+ public T setShippingTrackingNumbers(List shippingTrackingNumbers) {
+ this.shippingTrackingNumbers = shippingTrackingNumbers;
+ return (T) this;
+ }
+
public OrderedFrom getOrderedFrom() {
return orderedFrom;
}
diff --git a/src/main/java/com/siftscience/model/ContentStatusFieldSet.java b/src/main/java/com/siftscience/model/ContentStatusFieldSet.java
index 47c108c..f7f447e 100644
--- a/src/main/java/com/siftscience/model/ContentStatusFieldSet.java
+++ b/src/main/java/com/siftscience/model/ContentStatusFieldSet.java
@@ -10,6 +10,7 @@ public static ContentStatusFieldSet fromJson(String json) {
@Expose @SerializedName("$content_id") private String contentId;
@Expose @SerializedName("$status") private String status;
+ @Expose @SerializedName(USER_EMAIL) private String userEmail;
@Expose @SerializedName(VERIFICATION_PHONE_NUMBER) private String verificationPhoneNumber;
@Override
@@ -35,6 +36,15 @@ public ContentStatusFieldSet setContentId(String contentId) {
return this;
}
+ public String getUserEmail() {
+ return userEmail;
+ }
+
+ public ContentStatusFieldSet setUserEmail(String userEmail) {
+ this.userEmail = userEmail;
+ return this;
+ }
+
public String getVerificationPhoneNumber() {
return verificationPhoneNumber;
}
diff --git a/src/main/java/com/siftscience/model/CustomEventFieldSet.java b/src/main/java/com/siftscience/model/CustomEventFieldSet.java
index e10dae2..1f89ba7 100644
--- a/src/main/java/com/siftscience/model/CustomEventFieldSet.java
+++ b/src/main/java/com/siftscience/model/CustomEventFieldSet.java
@@ -9,7 +9,7 @@ public static CustomEventFieldSet fromJson(String json) {
}
@Expose @SerializedName(EVENT_TYPE) private String eventType;
- @Expose @SerializedName("$user_email") private String userEmail;
+ @Expose @SerializedName(USER_EMAIL) private String userEmail;
@Expose @SerializedName("$name") private String name;
@Expose @SerializedName("$phone") private String phone;
@Expose @SerializedName(VERIFICATION_PHONE_NUMBER) private String verificationPhoneNumber;
diff --git a/src/main/java/com/siftscience/model/FlagContentFieldSet.java b/src/main/java/com/siftscience/model/FlagContentFieldSet.java
index 4c39ab9..a348505 100644
--- a/src/main/java/com/siftscience/model/FlagContentFieldSet.java
+++ b/src/main/java/com/siftscience/model/FlagContentFieldSet.java
@@ -8,8 +8,32 @@ public static FlagContentFieldSet fromJson(String json) {
return gson.fromJson(json, FlagContentFieldSet.class);
}
+ public enum FlagContentReason {
+ TOXIC("$toxic"),
+ IRRELEVANT("$irrelevant"),
+ COMMERCIAL("$commercial"),
+ PHISHING("$phishing"),
+ PRIVATE("$private"),
+ SCAM("$scam"),
+ COPYRIGHT("$copyright"),
+ OTHER("$other");
+
+ public final String value;
+
+ FlagContentReason(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String toString() {
+ return value;
+ }
+ }
+
@Expose @SerializedName("$content_id") private String contentId;
@Expose @SerializedName("$flagged_by") private String flaggedBy;
+ @Expose @SerializedName("$reason") private String reason;
+ @Expose @SerializedName(USER_EMAIL) private String userEmail;
@Expose @SerializedName(VERIFICATION_PHONE_NUMBER) private String verificationPhoneNumber;
@Override
@@ -35,6 +59,24 @@ public FlagContentFieldSet setFlaggedBy(String flaggedBy) {
return this;
}
+ public String getReason() {
+ return reason;
+ }
+
+ public FlagContentFieldSet setReason(FlagContentReason reason) {
+ this.reason = reason.value;
+ return this;
+ }
+
+ public String getUserEmail() {
+ return userEmail;
+ }
+
+ public FlagContentFieldSet setUserEmail(String userEmail) {
+ this.userEmail = userEmail;
+ return this;
+ }
+
public String getVerificationPhoneNumber() {
return verificationPhoneNumber;
}
diff --git a/src/main/java/com/siftscience/model/LoginFieldSet.java b/src/main/java/com/siftscience/model/LoginFieldSet.java
index f6bfa1c..01d16df 100644
--- a/src/main/java/com/siftscience/model/LoginFieldSet.java
+++ b/src/main/java/com/siftscience/model/LoginFieldSet.java
@@ -15,7 +15,7 @@ public static LoginFieldSet fromJson(String json) {
@Expose @SerializedName("$username") private String username;
@Expose @SerializedName("$social_sign_on_type") private String socialSignOnType;
@Expose @SerializedName("$account_types") private List accountTypes;
- @Expose @SerializedName("$user_email") private String userEmail;
+ @Expose @SerializedName(USER_EMAIL) private String userEmail;
@Expose @SerializedName(VERIFICATION_PHONE_NUMBER) private String verificationPhoneNumber;
@Override
diff --git a/src/main/java/com/siftscience/model/RemoveItemFromCartFieldSet.java b/src/main/java/com/siftscience/model/RemoveItemFromCartFieldSet.java
index 1d320a0..8916ced 100644
--- a/src/main/java/com/siftscience/model/RemoveItemFromCartFieldSet.java
+++ b/src/main/java/com/siftscience/model/RemoveItemFromCartFieldSet.java
@@ -9,6 +9,7 @@ public static RemoveItemFromCartFieldSet fromJson(String json) {
}
@Expose @SerializedName("$item") private Item item;
+ @Expose @SerializedName(USER_EMAIL) private String userEmail;
@Expose @SerializedName(VERIFICATION_PHONE_NUMBER) private String verificationPhoneNumber;
@Override
@@ -25,6 +26,15 @@ public RemoveItemFromCartFieldSet setItem(Item item) {
return this;
}
+ public String getUserEmail() {
+ return userEmail;
+ }
+
+ public RemoveItemFromCartFieldSet setUserEmail(String userEmail) {
+ this.userEmail = userEmail;
+ return this;
+ }
+
public String getVerificationPhoneNumber() {
return verificationPhoneNumber;
}
diff --git a/src/main/java/com/siftscience/model/TransactionFieldSet.java b/src/main/java/com/siftscience/model/TransactionFieldSet.java
index 3b376cd..a5c3f48 100644
--- a/src/main/java/com/siftscience/model/TransactionFieldSet.java
+++ b/src/main/java/com/siftscience/model/TransactionFieldSet.java
@@ -8,7 +8,7 @@
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;
+ @Expose @SerializedName(USER_EMAIL) private String userEmail;
@Expose @SerializedName("$transaction_type") private String transactionType;
@Expose @SerializedName("$transaction_status") private String transactionStatus;
@Expose @SerializedName("$order_id") private String orderId;
diff --git a/src/main/java/com/siftscience/model/UpdatePasswordFieldSet.java b/src/main/java/com/siftscience/model/UpdatePasswordFieldSet.java
index 2f86905..abaafa4 100644
--- a/src/main/java/com/siftscience/model/UpdatePasswordFieldSet.java
+++ b/src/main/java/com/siftscience/model/UpdatePasswordFieldSet.java
@@ -10,6 +10,7 @@ public static UpdatePasswordFieldSet fromJson(String json) {
@Expose @SerializedName("$reason") private String reason;
@Expose @SerializedName("$status") private String status;
+ @Expose @SerializedName(USER_EMAIL) private String userEmail;
@Expose @SerializedName(VERIFICATION_PHONE_NUMBER) private String verificationPhoneNumber;
@Override
@@ -31,6 +32,15 @@ public UpdatePasswordFieldSet setStatus(String status) {
return this;
}
+ public String getUserEmail() {
+ return userEmail;
+ }
+
+ public UpdatePasswordFieldSet setUserEmail(String userEmail) {
+ this.userEmail = userEmail;
+ return this;
+ }
+
public String getVerificationPhoneNumber() {
return verificationPhoneNumber;
}
diff --git a/src/test/java/com/siftscience/AddItemToCartEventTest.java b/src/test/java/com/siftscience/AddItemToCartEventTest.java
index 4ac4ac7..6cec72a 100644
--- a/src/test/java/com/siftscience/AddItemToCartEventTest.java
+++ b/src/test/java/com/siftscience/AddItemToCartEventTest.java
@@ -1,6 +1,7 @@
package com.siftscience;
import com.siftscience.model.AddItemToCartFieldSet;
+import com.siftscience.model.EventResponseBody;
import okhttp3.OkHttpClient;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
@@ -34,6 +35,7 @@ public void testAddItemToCart() throws Exception {
" \"$color\" : \"Texas Tea\",\n" +
" \"$quantity\" : 2\n" +
" },\n" +
+ " \"$user_email\" : \"billy_jones_301@email.com\",\n" +
" \"$verification_phone_number\" : \"+12345678901\"\n" +
"}";
@@ -57,13 +59,14 @@ public void testAddItemToCart() throws Exception {
.build());
// Build and execute the request against the mock server.
- SiftRequest request = client.buildRequest(new AddItemToCartFieldSet()
+ SiftRequest request = client.buildRequest(new AddItemToCartFieldSet()
.setUserId("billy_jones_301")
.setSessionId("gigtleqddo84l8cm15qe4il")
.setItem(TestUtils.sampleItem2())
+ .setUserEmail("billy_jones_301@email.com")
.setVerificationPhoneNumber("+12345678901"));
- SiftResponse siftResponse = request.send();
+ SiftResponse siftResponse = request.send();
// Verify the request.
RecordedRequest request1 = server.takeRequest();
@@ -73,6 +76,7 @@ public void testAddItemToCart() throws Exception {
// Verify the response.
Assert.assertEquals(HTTP_OK, siftResponse.getHttpStatusCode());
+ Assert.assertNotNull(siftResponse.getBody());
Assert.assertEquals(0, (int) siftResponse.getBody().getStatus());
JSONAssert.assertEquals(response.getBody().readUtf8(),
siftResponse.getBody().toJson(), true);
diff --git a/src/test/java/com/siftscience/AddPromotionEventTest.java b/src/test/java/com/siftscience/AddPromotionEventTest.java
index dba13d4..b1c3fdd 100644
--- a/src/test/java/com/siftscience/AddPromotionEventTest.java
+++ b/src/test/java/com/siftscience/AddPromotionEventTest.java
@@ -5,6 +5,7 @@
import java.util.List;
import com.siftscience.model.AddPromotionFieldSet;
+import com.siftscience.model.EventResponseBody;
import com.siftscience.model.Promotion;
import okhttp3.OkHttpClient;
import okhttp3.mockwebserver.MockResponse;
@@ -34,6 +35,7 @@ public void testAddPromotion() throws Exception {
" }\n" +
" }\n" +
" ],\n" +
+ " \"$user_email\" : \"billy_jones_301@email.com\",\n" +
" \"$verification_phone_number\" : \"+12345678901\"\n" +
"}";
@@ -61,12 +63,13 @@ public void testAddPromotion() throws Exception {
promotions.add(TestUtils.samplePromotion3());
// Build and execute the request against the mock server.
- SiftRequest request = client.buildRequest(new AddPromotionFieldSet()
+ SiftRequest request = client.buildRequest(new AddPromotionFieldSet()
.setUserId("billy_jones_301")
.setPromotions(promotions)
+ .setUserEmail("billy_jones_301@email.com")
.setVerificationPhoneNumber("+12345678901"));
- SiftResponse siftResponse = request.send();
+ SiftResponse siftResponse = request.send();
// Verify the request.
RecordedRequest request1 = server.takeRequest();
@@ -76,6 +79,7 @@ public void testAddPromotion() throws Exception {
// Verify the response.
Assert.assertEquals(HTTP_OK, siftResponse.getHttpStatusCode());
+ Assert.assertNotNull(siftResponse.getBody());
Assert.assertEquals(0, (int) siftResponse.getBody().getStatus());
JSONAssert.assertEquals(response.getBody().readUtf8(),
siftResponse.getBody().toJson(), true);
diff --git a/src/test/java/com/siftscience/ContentStatusEventTest.java b/src/test/java/com/siftscience/ContentStatusEventTest.java
index 5abb7f5..431d5db 100644
--- a/src/test/java/com/siftscience/ContentStatusEventTest.java
+++ b/src/test/java/com/siftscience/ContentStatusEventTest.java
@@ -3,6 +3,7 @@
import static java.net.HttpURLConnection.HTTP_OK;
import com.siftscience.model.ContentStatusFieldSet;
+import com.siftscience.model.EventResponseBody;
import okhttp3.OkHttpClient;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
@@ -20,6 +21,7 @@ public void testContentStatus() throws Exception {
" \"$user_id\" : \"billy_jones_301\",\n" +
" \"$content_id\" : \"9671500641\",\n" +
" \"$status\" : \"$paused\",\n" +
+ " \"$user_email\" : \"billy_jones_301@email.com\",\n" +
" \"$verification_phone_number\" : \"+12345678901\"\n" +
"}";
@@ -44,13 +46,14 @@ public void testContentStatus() throws Exception {
.build());
// Build and execute the request against the mock server.
- SiftRequest request = client.buildRequest(new ContentStatusFieldSet()
+ SiftRequest request = client.buildRequest(new ContentStatusFieldSet()
.setUserId("billy_jones_301")
.setContentId("9671500641")
.setStatus("$paused")
+ .setUserEmail("billy_jones_301@email.com")
.setVerificationPhoneNumber("+12345678901"));
- SiftResponse siftResponse = request.send();
+ SiftResponse siftResponse = request.send();
// Verify the request.
RecordedRequest request1 = server.takeRequest();
@@ -60,6 +63,7 @@ public void testContentStatus() throws Exception {
// Verify the response.
Assert.assertEquals(HTTP_OK, siftResponse.getHttpStatusCode());
+ Assert.assertNotNull(siftResponse.getBody());
Assert.assertEquals(0, (int) siftResponse.getBody().getStatus());
JSONAssert.assertEquals(response.getBody().readUtf8(),
siftResponse.getBody().toJson(), true);
diff --git a/src/test/java/com/siftscience/CreateOrderEventTest.java b/src/test/java/com/siftscience/CreateOrderEventTest.java
index 9272867..c83f3bf 100644
--- a/src/test/java/com/siftscience/CreateOrderEventTest.java
+++ b/src/test/java/com/siftscience/CreateOrderEventTest.java
@@ -1,10 +1,13 @@
package com.siftscience;
+import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
import static java.net.HttpURLConnection.HTTP_OK;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
+import com.siftscience.exception.InvalidFieldException;
import com.siftscience.model.Booking;
import com.siftscience.model.CreateOrderFieldSet;
import com.siftscience.model.DigitalOrder;
@@ -67,6 +70,8 @@ public void testCreateOrderEventWithBookings() throws JSONException, IOException
" },\n" +
" \"$expedited_shipping\" : true,\n" +
" \"$shipping_method\" : \"$physical\",\n" +
+ " \"$shipping_carrier\" : \"The Best Carrier\",\n" +
+ " \"$shipping_tracking_numbers\" : [\"track-1\", \"track-2\"],\n" +
" \"$bookings\": [\n" +
" {\n" +
" \"$booking_type\": \"$flight\",\n" +
@@ -196,6 +201,8 @@ public void testCreateOrderEventWithBookings() throws JSONException, IOException
.setShippingAddress(TestUtils.sampleAddress2())
.setExpeditedShipping(true)
.setShippingMethod("$physical")
+ .setShippingCarrier("The Best Carrier")
+ .setShippingTrackingNumbers(Arrays.asList("track-1", "track-2"))
.setBookings(bookingList)
.setSellerUserId("slinkys_emporium")
.setPromotions(promotionList)
@@ -215,6 +222,7 @@ public void testCreateOrderEventWithBookings() throws JSONException, IOException
// Verify the response.
Assert.assertEquals(HTTP_OK, siftResponse.getHttpStatusCode());
+ Assert.assertNotNull(siftResponse.getBody());
Assert.assertEquals(0, (int) siftResponse.getBody().getStatus());
JSONAssert.assertEquals(response.getBody().readUtf8(),
siftResponse.getBody().toJson(), true);
@@ -222,6 +230,338 @@ public void testCreateOrderEventWithBookings() throws JSONException, IOException
server.shutdown();
}
+ @Test
+ public void testCreateOrderEventWithBookingsShippingCarrierIsNull()
+ throws 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" +
+ "\n" +
+ " \"$session_id\" : \"gigtleqddo84l8cm15qe4il\",\n" +
+ " \"$order_id\" : \"ORDER-28168441\",\n" +
+ " \"$user_email\" : \"bill@gmail.com\",\n" +
+ " \"$amount\" : 115940000,\n" +
+ " \"$currency_code\" : \"USD\",\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" +
+ " \"$payment_methods\" : [\n" +
+ " {\n" +
+ " \"$payment_type\" : \"$credit_card\",\n" +
+ " \"$payment_gateway\" : \"$braintree\",\n" +
+ " \"$card_bin\" : \"542486\",\n" +
+ " \"$card_last4\" : \"4444\"\n" +
+ " }\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" +
+ " \"$shipping_carrier\" : null,\n" +
+ " \"$shipping_tracking_numbers\" : [\"track-1\", \"track-2\"],\n" +
+ " \"$bookings\": [\n" +
+ " {\n" +
+ " \"$booking_type\": \"$flight\",\n" +
+ " \"$title\": \"SFO - LAS, 2 Adults\",\n" +
+ " \"$start_time\": 12038412903,\n" +
+ " \"$end_time\": 12048412903,\n" +
+ " \"$guests\": [\n" +
+ " {\n" +
+ " \"$name\": \"John Doe\",\n" +
+ " \"$birth_date\": \"1985-01-19\",\n" +
+ " \"$loyalty_program\": \"skymiles\",\n" +
+ " \"$loyalty_program_id\": \"PSOV34DF\",\n" +
+ " \"$phone\": \"1-415-555-6040\",\n" +
+ " \"$email\": \"jdoe@domain.com\"\n" +
+ " },\n" +
+ " {\n" +
+ " \"$name\": \"Jane Doe\"\n" +
+ " }\n" +
+ " ],\n" +
+ " \"$segments\": [\n" +
+ " {\n" +
+ " \"$departure_address\":\n" +
+ " {\n" +
+ " \"$name\": \"Bill Jones\",\n" +
+ " \"$phone\": \"1-415-555-6040\",\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" +
+ " \"$arrival_address\":\n" +
+ " {\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" +
+ " \"$start_time\": 2190121220,\n" +
+ " \"$end_time\": 2290122129,\n" +
+ " \"$vessel_number\": \"LH454\",\n" +
+ " \"$fare_class\": \"Premium Economy\",\n" +
+ " \"$departure_airport_code\": \"SFO\",\n" +
+ " \"$arrival_airport_code\": \"LAS\"\n" +
+ " }\n" +
+ " ],\n" +
+ " \"$price\": 49900000,\n" +
+ " \"$currency_code\": \"USD\",\n" +
+ " \"$quantity\": 1,\n" +
+ " \"$tags\": [\n" +
+ " \"team-123\",\n" +
+ " \"region-123\"\n" +
+ " ]\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_BAD_REQUEST);
+ response.setBody("{\n" +
+ " \"status\" : 53,\n" +
+ " \"error_message\" : \"Invalid field value(s) for fields: $.$shipping_carrier, $.$shipping_tracking_numbers. Please check the documentation for valid field values.\",\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());
+
+ // Build the request body.
+ // Payment methods.
+ List paymentMethodList = new ArrayList<>();
+ paymentMethodList.add(TestUtils.samplePaymentMethod1());
+
+ // Bookings
+ List bookingList = new ArrayList<>();
+ bookingList.add(TestUtils.sampleBooking());
+
+ // 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())
+ .setPaymentMethods(paymentMethodList)
+ .setShippingAddress(TestUtils.sampleAddress2())
+ .setExpeditedShipping(true)
+ .setShippingMethod("$physical")
+ .setShippingCarrier(null)
+ .setShippingTrackingNumbers(Arrays.asList("track-1", "track-2"))
+ .setBookings(bookingList));
+
+ Assert.assertThrows(InvalidFieldException.class, request::send);
+
+ // Verify the request.
+ RecordedRequest request1 = server.takeRequest();
+ Assert.assertEquals("POST", request1.getMethod());
+ Assert.assertEquals("/v205/events", request1.getPath());
+
+ server.shutdown();
+ }
+
+ @Test
+ public void testCreateOrderEventWithBookingsShippingTrackingNumberIsNull()
+ throws 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" +
+ "\n" +
+ " \"$session_id\" : \"gigtleqddo84l8cm15qe4il\",\n" +
+ " \"$order_id\" : \"ORDER-28168441\",\n" +
+ " \"$user_email\" : \"bill@gmail.com\",\n" +
+ " \"$amount\" : 115940000,\n" +
+ " \"$currency_code\" : \"USD\",\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" +
+ " \"$payment_methods\" : [\n" +
+ " {\n" +
+ " \"$payment_type\" : \"$credit_card\",\n" +
+ " \"$payment_gateway\" : \"$braintree\",\n" +
+ " \"$card_bin\" : \"542486\",\n" +
+ " \"$card_last4\" : \"4444\"\n" +
+ " }\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" +
+ " \"$shipping_carrier\" : \"The Best Carrier\",\n" +
+ " \"$shipping_tracking_numbers\" : [null],\n" +
+ " \"$bookings\": [\n" +
+ " {\n" +
+ " \"$booking_type\": \"$flight\",\n" +
+ " \"$title\": \"SFO - LAS, 2 Adults\",\n" +
+ " \"$start_time\": 12038412903,\n" +
+ " \"$end_time\": 12048412903,\n" +
+ " \"$guests\": [\n" +
+ " {\n" +
+ " \"$name\": \"John Doe\",\n" +
+ " \"$birth_date\": \"1985-01-19\",\n" +
+ " \"$loyalty_program\": \"skymiles\",\n" +
+ " \"$loyalty_program_id\": \"PSOV34DF\",\n" +
+ " \"$phone\": \"1-415-555-6040\",\n" +
+ " \"$email\": \"jdoe@domain.com\"\n" +
+ " },\n" +
+ " {\n" +
+ " \"$name\": \"Jane Doe\"\n" +
+ " }\n" +
+ " ],\n" +
+ " \"$segments\": [\n" +
+ " {\n" +
+ " \"$departure_address\":\n" +
+ " {\n" +
+ " \"$name\": \"Bill Jones\",\n" +
+ " \"$phone\": \"1-415-555-6040\",\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" +
+ " \"$arrival_address\":\n" +
+ " {\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" +
+ " \"$start_time\": 2190121220,\n" +
+ " \"$end_time\": 2290122129,\n" +
+ " \"$vessel_number\": \"LH454\",\n" +
+ " \"$fare_class\": \"Premium Economy\",\n" +
+ " \"$departure_airport_code\": \"SFO\",\n" +
+ " \"$arrival_airport_code\": \"LAS\"\n" +
+ " }\n" +
+ " ],\n" +
+ " \"$price\": 49900000,\n" +
+ " \"$currency_code\": \"USD\",\n" +
+ " \"$quantity\": 1,\n" +
+ " \"$tags\": [\n" +
+ " \"team-123\",\n" +
+ " \"region-123\"\n" +
+ " ]\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_BAD_REQUEST);
+ response.setBody("{\n" +
+ " \"status\" : 53,\n" +
+ " \"error_message\" : \"Invalid field value(s) for fields: $.$shipping_tracking_numbers[0]. Please check the documentation for valid field values.\",\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());
+
+ // Build the request body.
+ // Payment methods.
+ List paymentMethodList = new ArrayList<>();
+ paymentMethodList.add(TestUtils.samplePaymentMethod1());
+
+ // Bookings
+ List bookingList = new ArrayList<>();
+ bookingList.add(TestUtils.sampleBooking());
+
+ // 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())
+ .setPaymentMethods(paymentMethodList)
+ .setShippingAddress(TestUtils.sampleAddress2())
+ .setExpeditedShipping(true)
+ .setShippingMethod("$physical")
+ .setShippingCarrier("The Best Carrier")
+ .setShippingTrackingNumbers(Arrays.asList((String) null))
+ .setBookings(bookingList));
+
+ Assert.assertThrows(InvalidFieldException.class, request::send);
+
+ // Verify the request.
+ RecordedRequest request1 = server.takeRequest();
+ Assert.assertEquals("POST", request1.getMethod());
+ Assert.assertEquals("/v205/events", request1.getPath());
+
+ server.shutdown();
+ }
+
@Test
public void testCreateOrderEventWithItems() throws JSONException, IOException,
InterruptedException {
@@ -267,6 +607,8 @@ public void testCreateOrderEventWithItems() throws JSONException, IOException,
" },\n" +
" \"$expedited_shipping\" : true,\n" +
" \"$shipping_method\" : \"$physical\",\n" +
+ " \"$shipping_carrier\" : \"The Best Carrier\",\n" +
+ " \"$shipping_tracking_numbers\" : [\"track-1\", \"track-2\"],\n" +
" \"$items\" : [\n" +
" {\n" +
" \"$item_id\" : \"12344321\",\n" +
@@ -365,6 +707,8 @@ public void testCreateOrderEventWithItems() throws JSONException, IOException,
.setShippingAddress(TestUtils.sampleAddress2())
.setExpeditedShipping(true)
.setShippingMethod("$physical")
+ .setShippingCarrier("The Best Carrier")
+ .setShippingTrackingNumbers(Arrays.asList("track-1", "track-2"))
.setItems(itemList)
.setSellerUserId("slinkys_emporium")
.setPromotions(promotionList)
@@ -383,6 +727,7 @@ public void testCreateOrderEventWithItems() throws JSONException, IOException,
// Verify the response.
Assert.assertEquals(HTTP_OK, siftResponse.getHttpStatusCode());
+ Assert.assertNotNull(siftResponse.getBody());
Assert.assertEquals(0, (int) siftResponse.getBody().getStatus());
JSONAssert.assertEquals(response.getBody().readUtf8(),
siftResponse.getBody().toJson(), true);
@@ -437,6 +782,8 @@ public void testCreateOrderEventwithSiteBrandOrderedFromFields() throws
" },\n" +
" \"$expedited_shipping\": true,\n" +
" \"$shipping_method\": \"$physical\",\n" +
+ " \"$shipping_carrier\" : \"The Best Carrier\",\n" +
+ " \"$shipping_tracking_numbers\" : [\"track-1\", \"track-2\"],\n" +
" \"$ordered_from\" : {\n" +
" \"$store_id\" : \"123\",\n" +
" \"$store_address\" : {\n" +
@@ -494,6 +841,8 @@ public void testCreateOrderEventwithSiteBrandOrderedFromFields() throws
.setShippingAddress(TestUtils.sampleAddress2())
.setExpeditedShipping(true)
.setShippingMethod("$physical")
+ .setShippingCarrier("The Best Carrier")
+ .setShippingTrackingNumbers(Arrays.asList("track-1", "track-2"))
.setVerificationPhoneNumber("+12345678901"));
EventResponse siftResponse = request.send();
@@ -506,6 +855,7 @@ public void testCreateOrderEventwithSiteBrandOrderedFromFields() throws
// Verify the response.
Assert.assertEquals(HTTP_OK, siftResponse.getHttpStatusCode());
+ Assert.assertNotNull(siftResponse.getBody());
Assert.assertEquals(0, (int) siftResponse.getBody().getStatus());
JSONAssert.assertEquals(response.getBody().readUtf8(),
siftResponse.getBody().toJson(), true);
diff --git a/src/test/java/com/siftscience/FlagContentEventTest.java b/src/test/java/com/siftscience/FlagContentEventTest.java
index a06a0cc..34776b7 100644
--- a/src/test/java/com/siftscience/FlagContentEventTest.java
+++ b/src/test/java/com/siftscience/FlagContentEventTest.java
@@ -1,7 +1,11 @@
package com.siftscience;
import static java.net.HttpURLConnection.HTTP_OK;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import com.siftscience.model.EventResponseBody;
import com.siftscience.model.FlagContentFieldSet;
import okhttp3.OkHttpClient;
import okhttp3.mockwebserver.MockResponse;
@@ -9,9 +13,28 @@
import okhttp3.mockwebserver.RecordedRequest;
import org.junit.Assert;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
import org.skyscreamer.jsonassert.JSONAssert;
+@RunWith(Parameterized.class)
public class FlagContentEventTest {
+
+ @Parameterized.Parameters
+ public static Collection