Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
3.19.0 (2025-04-24)
=================
- Added support for `$exchange_rate` complex field to `$transaction`, `$create_order`,
`$update_order` and `$wager` events, `$booking`, `$discount` and `$item` event fields

3.18.0 (2025-03-28)
=================
- Added support for `$card_bin_metadata` complex field to `$payment_method`
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ Java 1.7 or later.
<dependency>
<groupId>com.siftscience</groupId>
<artifactId>sift-java</artifactId>
<version>3.18.0</version>
<version>3.19.0</version>
</dependency>
```
### Gradle
```
dependencies {
compile 'com.siftscience:sift-java:3.18.0'
compile 'com.siftscience:sift-java:3.19.0'
}
```
### Other
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apply plugin: 'signing'
apply plugin: 'java-library-distribution'

group = 'com.siftscience'
version = '3.18.0'
version = '3.19.0'

repositories {
mavenCentral()
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/siftscience/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
public class Constants {

public static final String API_VERSION = "v205";
public static final String LIB_VERSION = "3.18.0";
public static final String LIB_VERSION = "3.19.0";
public static final String USER_AGENT_HEADER = String.format("SiftScience/%s sift-java/%s", API_VERSION, LIB_VERSION);
}
10 changes: 10 additions & 0 deletions src/main/java/com/siftscience/model/BaseOrderFieldSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public abstract class BaseOrderFieldSet<T extends BaseOrderFieldSet<T>>
@Expose @SerializedName(USER_EMAIL) private String userEmail;
@Expose @SerializedName("$amount") private Long amount;
@Expose @SerializedName("$currency_code") private String currencyCode;
@Expose @SerializedName("$exchange_rate") private ExchangeRate exchangeRate;
@Expose @SerializedName("$billing_address") private Address billingAddress;
@Expose @SerializedName("$shipping_address") private Address shippingAddress;
@Expose @SerializedName("$payment_methods") private List<PaymentMethod> paymentMethods;
Expand Down Expand Up @@ -63,6 +64,15 @@ public T setCurrencyCode(String currencyCode) {
return (T) this;
}

public ExchangeRate getExchangeRate() {
return exchangeRate;
}

public T setExchangeRate(ExchangeRate exchangeRate) {
this.exchangeRate = exchangeRate;
return (T) this;
}

public Boolean getExpeditedShipping() {
return expeditedShipping;
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/siftscience/model/Booking.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class Booking {
@Expose @SerializedName("$end_time") private Long endTime;
@Expose @SerializedName("$price") private Long price;
@Expose @SerializedName("$currency_code") private String currencyCode;
@Expose @SerializedName("$exchange_rate") private ExchangeRate exchangeRate;
@Expose @SerializedName("$quantity") private Long quantity;
@Expose @SerializedName("$iata_carrier_code") private String iataCarrierCode;
@Expose @SerializedName("$guests") private List<Guest> guests;
Expand Down Expand Up @@ -77,6 +78,15 @@ public Booking setCurrencyCode(String currencyCode) {
return this;
}

public ExchangeRate getExchangeRate() {
return exchangeRate;
}

public Booking setExchangeRate(ExchangeRate exchangeRate) {
this.exchangeRate = exchangeRate;
return this;
}

public Long getQuantity() {
return quantity;
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/siftscience/model/Discount.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class Discount {
@Expose @SerializedName("$percentage_off") private Double percentageOff;
@Expose @SerializedName("$amount") private Long amount;
@Expose @SerializedName("$currency_code") private String currencyCode;
@Expose @SerializedName("$exchange_rate") private ExchangeRate exchangeRate;
@Expose @SerializedName("$minimum_purchase_amount") private Long minimumPurchaseAmount;

public Double getPercentageOff() {
Expand Down Expand Up @@ -36,6 +37,15 @@ public Discount setCurrencyCode(String currencyCode) {
return this;
}

public ExchangeRate getExchangeRate() {
return exchangeRate;
}

public Discount setExchangeRate(ExchangeRate exchangeRate) {
this.exchangeRate = exchangeRate;
return this;
}

public Long getMinimumPurchaseAmount() {
return minimumPurchaseAmount;
}
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/com/siftscience/model/ExchangeRate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.siftscience.model;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class ExchangeRate {
@Expose @SerializedName("$quote_currency_code") private String quoteCurrencyCode;
@Expose @SerializedName("$rate") private Float rate;

public String getQuoteCurrencyCode() {
return quoteCurrencyCode;
}

public ExchangeRate setQuoteCurrencyCode(String quoteCurrencyCode) {
this.quoteCurrencyCode = quoteCurrencyCode;
return this;
}

public Float getRate() {
return rate;
}

public ExchangeRate setRate(Float rate) {
this.rate = rate;
return this;
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/siftscience/model/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class Item {
@Expose @SerializedName("$product_title") private String productTitle;
@Expose @SerializedName("$price") private Long price;
@Expose @SerializedName("$currency_code") private String currencyCode;
@Expose @SerializedName("$exchange_rate") private ExchangeRate exchangeRate;
@Expose @SerializedName("$quantity") private Long quantity;
@Expose @SerializedName("$upc") private String upc;
@Expose @SerializedName("$sku") private String sku;
Expand Down Expand Up @@ -70,6 +71,15 @@ public String getCurrencyCode() {
return currencyCode;
}

public ExchangeRate getExchangeRate() {
return exchangeRate;
}

public Item setExchangeRate(ExchangeRate exchangeRate) {
this.exchangeRate = exchangeRate;
return this;
}

public Item setCurrencyCode(String currencyCode) {
this.currencyCode = currencyCode;
return this;
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/siftscience/model/TransactionFieldSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
public class TransactionFieldSet extends BaseAppBrowserSiteBrandFieldSet<TransactionFieldSet> {
@Expose @SerializedName("$amount") private Long amount;
@Expose @SerializedName("$currency_code") private String currencyCode;
@Expose @SerializedName("$exchange_rate") private ExchangeRate exchangeRate;
@Expose @SerializedName(USER_EMAIL) private String userEmail;
@Expose @SerializedName("$transaction_type") private String transactionType;
@Expose @SerializedName("$transaction_status") private String transactionStatus;
Expand Down Expand Up @@ -66,6 +67,15 @@ public TransactionFieldSet setCurrencyCode(String currencyCode) {
return this;
}

public ExchangeRate getExchangeRate() {
return exchangeRate;
}

public TransactionFieldSet setExchangeRate(ExchangeRate exchangeRate) {
this.exchangeRate = exchangeRate;
return this;
}

public String getUserEmail() {
return userEmail;
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/siftscience/model/WagerFieldSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class WagerFieldSet extends EventsApiRequestFieldSet<WagerFieldSet> {
@Expose @SerializedName("$wager_status") private String wagerStatus;
@Expose @SerializedName("$amount") private Long amount;
@Expose @SerializedName("$currency_code") private String currencyCode;
@Expose @SerializedName("$exchange_rate") private ExchangeRate exchangeRate;
@Expose @SerializedName("$wager_event_type") private String wagerEventType;
@Expose @SerializedName("$wager_event_name") private String wagerEventName;
@Expose @SerializedName("$wager_event_id") private String wagerEventId;
Expand Down Expand Up @@ -69,6 +70,15 @@ public WagerFieldSet setCurrencyCode(String currencyCode) {
return this;
}

public ExchangeRate getExchangeRate() {
return exchangeRate;
}

public WagerFieldSet setExchangeRate(ExchangeRate exchangeRate) {
this.exchangeRate = exchangeRate;
return this;
}

public String getWagerEventType() {
return wagerEventType;
}
Expand Down
104 changes: 104 additions & 0 deletions src/test/java/com/siftscience/CreateOrderEventTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
import static java.net.HttpURLConnection.HTTP_OK;
import static java.util.Collections.singletonList;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -11,6 +12,7 @@
import com.siftscience.model.Booking;
import com.siftscience.model.CreateOrderFieldSet;
import com.siftscience.model.DigitalOrder;
import com.siftscience.model.ExchangeRate;
import com.siftscience.model.Item;
import com.siftscience.model.PaymentMethod;
import com.siftscience.model.Promotion;
Expand Down Expand Up @@ -1045,4 +1047,106 @@ public void testCreateOrderEventWithCryptoFields() throws JSONException, IOExcep

server.shutdown();
}

@Test
public void testCreateOrderEventWithExchangeRate() 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" +
" \"$order_id\" : \"ORDER-28168441\",\n" +
" \"$amount\" : 115940000,\n" +
" \"$currency_code\" : \"EUR\",\n" +
" \"$exchange_rate\" : {\n" +
" \"$quote_currency_code\" : \"USD\",\n" +
" \"$rate\" : 1.15\n" +
" },\n" +
" \"$bookings\" : [\n" +
" {\n" +
" \"$price\" : 49900000,\n" +
" \"$currency_code\" : \"EUR\",\n" +
" \"$exchange_rate\" : {\n" +
" \"$quote_currency_code\" : \"USD\",\n" +
" \"$rate\" : 1.15\n" +
" }\n" +
" }\n" +
" ],\n" +
" \"$promotions\" : [\n" +
" {\n" +
" \"$discount\" : {\n" +
" \"$amount\" : 5000000,\n" +
" \"$currency_code\" : \"EUR\",\n" +
" \"$exchange_rate\" : {\n" +
" \"$quote_currency_code\" : \"USD\",\n" +
" \"$rate\" : 1.15\n" +
" }\n" +
" }\n" +
" }\n" +
" ],\n" +
" \"$items\" : [\n" +
" {\n" +
" \"$price\" : 39990000,\n" +
" \"$currency_code\" : \"EUR\",\n" +
" \"$exchange_rate\" : {\n" +
" \"$quote_currency_code\" : \"USD\",\n" +
" \"$rate\" : 1.15\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_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());

// Build and execute the request against the mock server.
// It includes booking, promotion and item with ExchangeRate
EventRequest request = client.buildRequest(
new CreateOrderFieldSet()
.setUserId("billy_jones_301")
.setOrderId("ORDER-28168441")
.setAmount(115940000L)
.setCurrencyCode("EUR")
.setExchangeRate(new ExchangeRate()
.setQuoteCurrencyCode("USD")
.setRate(1.15f))
.setBookings(singletonList(TestUtils.sampleBookingWithExchangeRate()))
.setPromotions(singletonList(TestUtils.samplePromotionWithExchangeRate()))
.setItems(singletonList(TestUtils.sampleItemWithExchangeRate()))
);

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();
}
}
2 changes: 1 addition & 1 deletion src/test/java/com/siftscience/SiftRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void testUserAgentHeader() throws Exception {

// then
RecordedRequest recordedRequest = server.takeRequest();
assertEquals("SiftScience/v205 sift-java/3.18.0",
assertEquals("SiftScience/v205 sift-java/3.19.0",
recordedRequest.getHeader("User-Agent"));
}

Expand Down
Loading