Skip to content

Commit ff69f36

Browse files
[PAY-5475] Support for $card_bin_metadata field in Events API (#117)
1 parent 09641de commit ff69f36

File tree

8 files changed

+158
-5
lines changed

8 files changed

+158
-5
lines changed

CHANGES.MD

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
3.18.0 (2025-03-28)
2+
=================
3+
- Added support for `$card_bin_metadata` complex field to `$payment_method`
4+
15
3.17.1 (2024-12-31)
26
=================
37
- Included HTTP Status codes into `SiftException` message when possible

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ Java 1.7 or later.
1313
<dependency>
1414
<groupId>com.siftscience</groupId>
1515
<artifactId>sift-java</artifactId>
16-
<version>3.17.1</version>
16+
<version>3.18.0</version>
1717
</dependency>
1818
```
1919
### Gradle
2020
```
2121
dependencies {
22-
compile 'com.siftscience:sift-java:3.17.1'
22+
compile 'com.siftscience:sift-java:3.18.0'
2323
}
2424
```
2525
### Other

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ apply plugin: 'signing'
55
apply plugin: 'java-library-distribution'
66

77
group = 'com.siftscience'
8-
version = '3.17.1'
8+
version = '3.18.0'
99

1010
repositories {
1111
mavenCentral()

src/main/java/com/siftscience/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
public class Constants {
44

55
public static final String API_VERSION = "v205";
6-
public static final String LIB_VERSION = "3.17.1";
6+
public static final String LIB_VERSION = "3.18.0";
77
public static final String USER_AGENT_HEADER = String.format("SiftScience/%s sift-java/%s", API_VERSION, LIB_VERSION);
88
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.siftscience.model;
2+
3+
import com.google.gson.annotations.Expose;
4+
import com.google.gson.annotations.SerializedName;
5+
6+
public class CardBinMetadata {
7+
@Expose @SerializedName("$bank") private String bank;
8+
@Expose @SerializedName("$brand") private String brand;
9+
@Expose @SerializedName("$country") private String country;
10+
@Expose @SerializedName("$level") private String level;
11+
@Expose @SerializedName("$type") private String type;
12+
13+
public String getBank() {
14+
return bank;
15+
}
16+
17+
public CardBinMetadata setBank(String bank) {
18+
this.bank = bank;
19+
return this;
20+
}
21+
22+
public String getBrand() {
23+
return brand;
24+
}
25+
26+
public CardBinMetadata setBrand(String brand) {
27+
this.brand = brand;
28+
return this;
29+
}
30+
31+
public String getCountry() {
32+
return country;
33+
}
34+
35+
public CardBinMetadata setCountry(String country) {
36+
this.country = country;
37+
return this;
38+
}
39+
40+
public String getLevel() {
41+
return level;
42+
}
43+
44+
public CardBinMetadata setLevel(String level) {
45+
this.level = level;
46+
return this;
47+
}
48+
49+
public String getType() {
50+
return type;
51+
}
52+
53+
public CardBinMetadata setType(String type) {
54+
this.type = type;
55+
return this;
56+
}
57+
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class PaymentMethod {
3535
@Expose @SerializedName("$sepa_direct_debit_mandate") private Boolean sepaDirectDebitMandate;
3636
@Expose @SerializedName("$wallet_address") private String walletAddress;
3737
@Expose @SerializedName("$wallet_type") private String walletType;
38+
@Expose @SerializedName("$card_bin_metadata") private CardBinMetadata cardBinMetadata;
3839

3940
public String getPaymentType() {
4041
return paymentType;
@@ -305,4 +306,13 @@ public PaymentMethod setWalletType(String walletType) {
305306
this.walletType = walletType;
306307
return this;
307308
}
309+
310+
public CardBinMetadata getCardBinMetadata() {
311+
return cardBinMetadata;
312+
}
313+
314+
public PaymentMethod setCardBinMetadata(CardBinMetadata cardBinMetadata) {
315+
this.cardBinMetadata = cardBinMetadata;
316+
return this;
317+
}
308318
}

src/test/java/com/siftscience/SiftRequestTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void testUserAgentHeader() throws Exception {
2929

3030
// then
3131
RecordedRequest recordedRequest = server.takeRequest();
32-
assertEquals("SiftScience/v205 sift-java/3.17.1",
32+
assertEquals("SiftScience/v205 sift-java/3.18.0",
3333
recordedRequest.getHeader("User-Agent"));
3434
}
3535

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

Lines changed: 82 additions & 0 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;
@@ -794,4 +796,84 @@ public void testTransactionEventWithExtraWithdrawalFields() throws Exception {
794796

795797
server.shutdown();
796798
}
799+
800+
@Test
801+
public void testTransactionEventWithBinMetadata() throws Exception {
802+
String expectedRequestBody = "{\n" +
803+
" \"$type\" : \"$transaction\",\n" +
804+
" \"$api_key\" : \"YOUR_API_KEY\",\n" +
805+
" \"$user_id\" : \"billy_jones_301\",\n" +
806+
" \"$amount\" : 506790000,\n" +
807+
" \"$currency_code\" : \"EUR\",\n" +
808+
"\n" +
809+
" \"$user_email\" : \"bill@gmail.com\",\n" +
810+
" \"$transaction_type\" : \"$buy\",\n" +
811+
" \"$transaction_id\" : \"719637215\",\n" +
812+
"\n" +
813+
" \"$payment_method\" : {\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" +
825+
" },\n" +
826+
"}";
827+
828+
// Start a new mock server and enqueue a mock response.
829+
MockWebServer server = new MockWebServer();
830+
MockResponse response = new MockResponse();
831+
response.setResponseCode(HTTP_OK);
832+
response.setBody("{\n" +
833+
" \"status\" : 0,\n" +
834+
" \"error_message\" : \"OK\",\n" +
835+
" \"time\" : 1327604222,\n" +
836+
" \"request\" : \"" + TestUtils.unescapeJson(expectedRequestBody) + "\"\n" +
837+
"}");
838+
server.enqueue(response);
839+
server.start();
840+
841+
// Create a new client and link it to the mock server.
842+
SiftClient client = new SiftClient("YOUR_API_KEY", "YOUR_ACCOUNT_ID",
843+
new OkHttpClient.Builder()
844+
.addInterceptor(OkHttpUtils.urlRewritingInterceptor(server))
845+
.build());
846+
847+
// 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"));
855+
EventRequest request = client.buildRequest(new TransactionFieldSet()
856+
.setUserId("billy_jones_301")
857+
.setAmount(506790000L)
858+
.setCurrencyCode("EUR")
859+
.setUserEmail("bill@gmail.com")
860+
.setTransactionType("$buy")
861+
.setTransactionId("719637215")
862+
.setPaymentMethod(paymentMethod));
863+
EventResponse siftResponse = request.send();
864+
865+
// Verify the request.
866+
RecordedRequest request1 = server.takeRequest();
867+
Assert.assertEquals("POST", request1.getMethod());
868+
Assert.assertEquals("/v205/events", request1.getPath());
869+
JSONAssert.assertEquals(expectedRequestBody, request.getFieldSet().toJson(), true);
870+
871+
// Verify the response.
872+
Assert.assertEquals(HTTP_OK, siftResponse.getHttpStatusCode());
873+
Assert.assertEquals(0, (int) siftResponse.getBody().getStatus());
874+
JSONAssert.assertEquals(response.getBody().readUtf8(),
875+
siftResponse.getBody().toJson(), true);
876+
877+
server.shutdown();
878+
}
797879
}

0 commit comments

Comments
 (0)