Skip to content

Commit a967c1c

Browse files
CardBinMetadata and tests
1 parent fb250d5 commit a967c1c

File tree

7 files changed

+32
-264
lines changed

7 files changed

+32
-264
lines changed

CHANGES.MD

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
3.18.0 (2025-02-13)
1+
3.18.0 (2025-03-28)
22
=================
3-
- Added support for `$amount_usd` in `$transaction`, `$create_order`, `$update_order`, `$wager` event types and in `$discount` complex field
4-
- Added support for `$price_usd` in `$booking` and `$item` complex fields
5-
- Added support for `$card_bin_country`, `$card_type`, and `$card_brand` for `$payment_method` complex type
3+
- Added support for `$card_bin_metadata` complex field to `$payment_method`
64

75
3.17.1 (2024-12-31)
86
=================

src/main/java/com/siftscience/model/CardBinMetadata.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ public class CardBinMetadata {
88
@SerializedName("$country") private String country;
99
@Expose @SerializedName("$level") private String level;
1010
@Expose @SerializedName("$type") private String type;
11-
@Expose @SerializedName("$brand") private Address brand;
12-
@Expose @SerializedName("$bank") private Address bank;
11+
@Expose @SerializedName("$brand") private String brand;
12+
@Expose @SerializedName("$bank") private String bank;
1313

1414
public String getCountry() {
1515
return country;
@@ -38,20 +38,20 @@ public CardBinMetadata setType(String type) {
3838
return this;
3939
}
4040

41-
public Address getBrand() {
41+
public String getBrand() {
4242
return brand;
4343
}
4444

45-
public CardBinMetadata setBrand(Address brand) {
45+
public CardBinMetadata setBrand(String brand) {
4646
this.brand = brand;
4747
return this;
4848
}
4949

50-
public Address getBank() {
50+
public String getBank() {
5151
return bank;
5252
}
5353

54-
public CardBinMetadata setBank(Address bank) {
54+
public CardBinMetadata setBank(String bank) {
5555
this.bank = bank;
5656
return this;
5757
}

src/test/java/com/siftscience/CreateOrderEventTest.java

Lines changed: 0 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
44
import static java.net.HttpURLConnection.HTTP_OK;
5-
import static java.util.Collections.singletonList;
65
import java.io.IOException;
76
import java.util.ArrayList;
87
import java.util.Arrays;
@@ -1046,108 +1045,4 @@ public void testCreateOrderEventWithCryptoFields() throws JSONException, IOExcep
10461045

10471046
server.shutdown();
10481047
}
1049-
1050-
@Test
1051-
public void testCreateOrderEventBookingWithPromoWithAmountUsd() throws JSONException,
1052-
IOException, InterruptedException {
1053-
1054-
// The expected JSON payload of the request.
1055-
String expectedRequestBody = "{\n" +
1056-
" \"$type\" : \"$create_order\",\n" +
1057-
" \"$api_key\" : \"YOUR_API_KEY\",\n" +
1058-
" \"$user_id\" : \"billy_jones_301\",\n" +
1059-
"\n" +
1060-
" \"$order_id\" : \"ORDER-28168441\",\n" +
1061-
" \"$user_email\" : \"bill@gmail.com\",\n" +
1062-
" \"$amount\" : 115940000,\n" +
1063-
" \"$amount_usd\" : 155540000,\n" +
1064-
" \"$currency_code\" : \"EUR\",\n" +
1065-
" \"$payment_methods\" : [\n" +
1066-
" {\n" +
1067-
" \"$payment_type\" : \"$credit_card\",\n" +
1068-
" \"$payment_gateway\" : \"$braintree\",\n" +
1069-
" \"$card_bin\" : \"542486\",\n" +
1070-
" \"$card_last4\" : \"4444\",\n" +
1071-
" \"$card_bin_country\": \"US\",\n" +
1072-
" \"$card_type\" : \"Gold\",\n" +
1073-
" \"$card_brand\" : \"Visa\"\n" +
1074-
" }\n" +
1075-
" ],\n" +
1076-
" \"$bookings\": [\n" +
1077-
" {\n" +
1078-
" \"$booking_type\": \"$flight\",\n" +
1079-
" \"$title\": \"SFO - LAS, 2 Adults\",\n" +
1080-
" \"$start_time\": 12038412903,\n" +
1081-
" \"$end_time\": 12048412903,\n" +
1082-
" \"$price\": 49900000,\n" +
1083-
" \"$price_usd\": 55500000,\n" +
1084-
" \"$currency_code\": \"EUR\",\n" +
1085-
" \"$quantity\": 1,\n" +
1086-
" }\n" +
1087-
" ],\n" +
1088-
"\n" +
1089-
" \"$promotions\" : [\n" +
1090-
" {\n" +
1091-
" \"$promotion_id\" : \"FirstTimeBuyer\",\n" +
1092-
" \"$status\" : \"$success\",\n" +
1093-
" \"$description\" : \"$5 off\",\n" +
1094-
" \"$discount\" : {\n" +
1095-
" \"$amount\" : 5000000,\n" +
1096-
" \"$amount_usd\" : 5550000,\n" +
1097-
" \"$currency_code\" : \"EUR\"\n" +
1098-
" }\n" +
1099-
" }\n" +
1100-
" ]\n" +
1101-
"}";
1102-
1103-
// Start a new mock server and enqueue a mock response.
1104-
MockWebServer server = new MockWebServer();
1105-
MockResponse response = new MockResponse();
1106-
response.setResponseCode(HTTP_OK);
1107-
response.setBody("{\n" +
1108-
" \"status\" : 0,\n" +
1109-
" \"error_message\" : \"OK\",\n" +
1110-
" \"time\" : 1327604222,\n" +
1111-
" \"request\" : \"" + TestUtils.unescapeJson(expectedRequestBody) + "\"\n" +
1112-
"}");
1113-
server.enqueue(response);
1114-
server.start();
1115-
1116-
// Create a new client and link it to the mock server.
1117-
SiftClient client = new SiftClient("YOUR_API_KEY", "YOUR_ACCOUNT_ID",
1118-
new OkHttpClient.Builder()
1119-
.addInterceptor(OkHttpUtils.urlRewritingInterceptor(server))
1120-
.build());
1121-
1122-
// Build and execute the request against the mock server.
1123-
EventRequest request = client.buildRequest(
1124-
new CreateOrderFieldSet()
1125-
.setUserId("billy_jones_301")
1126-
.setOrderId("ORDER-28168441")
1127-
.setUserEmail("bill@gmail.com")
1128-
.setAmount(115940000L)
1129-
.setAmountUsd(155540000L)
1130-
.setCurrencyCode("EUR")
1131-
.setPaymentMethods(singletonList(TestUtils.samplePaymentMethodBinMetadata()))
1132-
.setBookings(singletonList(TestUtils.sampleBookingWithPriceUsd()))
1133-
.setPromotions(singletonList(TestUtils.samplePromotionWithAmountUsd()))
1134-
);
1135-
1136-
EventResponse siftResponse = request.send();
1137-
1138-
// Verify the request.
1139-
RecordedRequest request1 = server.takeRequest();
1140-
Assert.assertEquals("POST", request1.getMethod());
1141-
Assert.assertEquals("/v205/events", request1.getPath());
1142-
JSONAssert.assertEquals(expectedRequestBody, request.getFieldSet().toJson(), true);
1143-
1144-
// Verify the response.
1145-
Assert.assertEquals(HTTP_OK, siftResponse.getHttpStatusCode());
1146-
Assert.assertNotNull(siftResponse.getBody());
1147-
Assert.assertEquals(0, (int) siftResponse.getBody().getStatus());
1148-
JSONAssert.assertEquals(response.getBody().readUtf8(),
1149-
siftResponse.getBody().toJson(), true);
1150-
1151-
server.shutdown();
1152-
}
11531048
}

src/test/java/com/siftscience/TestUtils.java

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,6 @@ static PaymentMethod samplePaymentMethod2() {
6060
.setCardLast4("4444");
6161
}
6262

63-
static PaymentMethod samplePaymentMethodBinMetadata() {
64-
return new PaymentMethod()
65-
.setPaymentType("$credit_card")
66-
.setPaymentGateway("$braintree")
67-
.setCardBin("542486")
68-
.setCardLast4("4444")
69-
.setCardBinCountry("US")
70-
.setCardBrand("Visa")
71-
.setCardType("Gold");
72-
}
73-
7463
static PaymentMethod samplePaymentMethodAch() {
7564
return new PaymentMethod()
7665
.setPaymentType("$ach_credit")
@@ -172,22 +161,6 @@ static Item sampleItem2() {
172161
.setQuantity(2L);
173162
}
174163

175-
static Item sampleItemPriceUsd() {
176-
return new Item()
177-
.setItemId("B004834GQO")
178-
.setProductTitle("The Slanket Blanket-Texas Tea")
179-
.setPrice(39990000L)
180-
.setPriceUsd(44490000L)
181-
.setUpc("67862114510011")
182-
.setSku("004834GQ")
183-
.setBrand("Slanket")
184-
.setManufacturer("Slanket")
185-
.setCategory("Blankets & Throws")
186-
.setTags(sampleTags2())
187-
.setColor("Texas Tea")
188-
.setQuantity(2L);
189-
}
190-
191164
static Booking sampleBooking() {
192165
List<Guest> guests = new ArrayList<>();
193166
guests.add(sampleGuest1());
@@ -210,18 +183,6 @@ static Booking sampleBooking() {
210183
.setQuantity(1L);
211184
}
212185

213-
static Booking sampleBookingWithPriceUsd() {
214-
return new Booking()
215-
.setBookingType("$flight")
216-
.setTitle("SFO - LAS, 2 Adults")
217-
.setStartTime(12038412903L)
218-
.setEndTime(12048412903L)
219-
.setPrice(49900000L)
220-
.setPriceUsd(55500000L)
221-
.setCurrencyCode("EUR")
222-
.setQuantity(1L);
223-
}
224-
225186
static OrderedFrom sampleOrderedFrom() {
226187
return new OrderedFrom()
227188
.setStoreId("123")
@@ -269,13 +230,6 @@ static Discount sampleDiscount2() {
269230
.setCurrencyCode("USD");
270231
}
271232

272-
static Discount sampleDiscountWithAmountUsd() {
273-
return new Discount()
274-
.setAmount(5000000L)
275-
.setAmountUsd(5550000L)
276-
.setCurrencyCode("EUR");
277-
}
278-
279233
static CreditPoint sampleCreditPoint() {
280234
return new CreditPoint()
281235
.setAmount(100L)
@@ -307,11 +261,4 @@ static Promotion samplePromotion3() {
307261
.setDiscount(sampleDiscount2());
308262
}
309263

310-
static Promotion samplePromotionWithAmountUsd() {
311-
return new Promotion()
312-
.setPromotionId("FirstTimeBuyer")
313-
.setStatus("$success")
314-
.setDescription("$5 off")
315-
.setDiscount(sampleDiscountWithAmountUsd());
316-
}
317264
}

src/test/java/com/siftscience/TransactionEventTest.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import java.util.ArrayList;
66
import java.util.List;
77

8+
import com.siftscience.model.CardBinMetadata;
89
import com.siftscience.model.DigitalOrder;
10+
import com.siftscience.model.PaymentMethod;
911
import com.siftscience.model.TransactionFieldSet;
1012
import okhttp3.OkHttpClient;
1113
import okhttp3.mockwebserver.MockResponse;
@@ -796,27 +798,30 @@ public void testTransactionEventWithExtraWithdrawalFields() throws Exception {
796798
}
797799

798800
@Test
799-
public void testTransactionEventWithAmountUsdAndBinMetadata() throws Exception {
801+
public void testTransactionEventWithBinMetadata() throws Exception {
800802
String expectedRequestBody = "{\n" +
801803
" \"$type\" : \"$transaction\",\n" +
802804
" \"$api_key\" : \"YOUR_API_KEY\",\n" +
803805
" \"$user_id\" : \"billy_jones_301\",\n" +
804806
" \"$amount\" : 506790000,\n" +
805-
" \"$amount_usd\" : 555790000,\n" +
806807
" \"$currency_code\" : \"EUR\",\n" +
807808
"\n" +
808809
" \"$user_email\" : \"bill@gmail.com\",\n" +
809810
" \"$transaction_type\" : \"$buy\",\n" +
810811
" \"$transaction_id\" : \"719637215\",\n" +
811812
"\n" +
812813
" \"$payment_method\" : {\n" +
813-
" \"$payment_type\" : \"$credit_card\",\n" +
814-
" \"$payment_gateway\" : \"$braintree\",\n" +
815-
" \"$card_bin\" : \"542486\",\n" +
816-
" \"$card_last4\" : \"4444\",\n" +
817-
" \"$card_bin_country\": \"US\",\n" +
818-
" \"$card_type\" : \"Gold\",\n" +
819-
" \"$card_brand\" : \"Visa\"\n" +
814+
" \"$payment_type\" : \"$credit_card\",\n" +
815+
" \"$payment_gateway\" : \"$braintree\",\n" +
816+
" \"$card_bin\" : \"542486\",\n" +
817+
" \"$card_last4\" : \"4444\",\n" +
818+
" \"$card_bin_metadata\": {\n" +
819+
" \"$country\": \"US\",\n" +
820+
" \"$level\" : \"Gold\",\n" +
821+
" \"$type\" : \"CREDIT\",\n" +
822+
" \"$brand\" : \"VISA\",\n" +
823+
" \"$bank\" : \"Chase\"\n" +
824+
" },\n" +
820825
" },\n" +
821826
"}";
822827

@@ -840,15 +845,21 @@ public void testTransactionEventWithAmountUsdAndBinMetadata() throws Exception {
840845
.build());
841846

842847
// Build and execute the request against the mock server.
848+
PaymentMethod paymentMethod = TestUtils.samplePaymentMethod1()
849+
.setCardBinMetadata(new CardBinMetadata()
850+
.setCountry("US")
851+
.setLevel("Gold")
852+
.setType("CREDIT")
853+
.setBrand("VISA")
854+
.setBank("Chase"));
843855
EventRequest request = client.buildRequest(new TransactionFieldSet()
844856
.setUserId("billy_jones_301")
845857
.setAmount(506790000L)
846-
.setAmountUsd(555790000L)
847858
.setCurrencyCode("EUR")
848859
.setUserEmail("bill@gmail.com")
849860
.setTransactionType("$buy")
850861
.setTransactionId("719637215")
851-
.setPaymentMethod(TestUtils.samplePaymentMethodBinMetadata()));
862+
.setPaymentMethod(paymentMethod));
852863
EventResponse siftResponse = request.send();
853864

854865
// Verify the request.

0 commit comments

Comments
 (0)