Skip to content

Commit

Permalink
[PAY-5294] - added deposit/withdrawal transaction fields support
Browse files Browse the repository at this point in the history
  • Loading branch information
ademianenko-sift committed Nov 15, 2024
1 parent 94562da commit ba7af16
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 1 deletion.
5 changes: 4 additions & 1 deletion CHANGES.MD
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
3.17.0 (2024-11-15)
=================
- Added support for `$wager` event type
- Added support for `$wager` event type in Events API
- Added support for `$minimum_deposit_amount`, `$maximum_deposit_amount`,
`$minimum_withdrawal_amount`, `$maximum_withdrawal_amount`, `$current_balance`,
and `$new_balance` fields to `$transaction` events

3.16.0 (2024-09-26)
=================
Expand Down
60 changes: 60 additions & 0 deletions src/main/java/com/siftscience/model/TransactionFieldSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public class TransactionFieldSet extends BaseAppBrowserSiteBrandFieldSet<Transac
@Expose @SerializedName("$digital_orders") private List<DigitalOrder> digitalOrders;
@Expose @SerializedName("$receiver_wallet_address") private String receiverWalletAddress;
@Expose @SerializedName("$receiver_external_address") private Boolean receiverExternalAddress;
@Expose @SerializedName("$minimum_deposit_amount") private Long minimumDepositAmount;
@Expose @SerializedName("$maximum_deposit_amount") private Long maximumDepositAmount;
@Expose @SerializedName("$minimum_withdrawal_amount") private Long minimumWithdrawalAmount;
@Expose @SerializedName("$maximum_withdrawal_amount") private Long maximumWithdrawalAmount;
@Expose @SerializedName("$current_balance") private Long currentBalance;
@Expose @SerializedName("$new_balance") private Long newBalance;


@Override
Expand Down Expand Up @@ -258,4 +264,58 @@ public TransactionFieldSet setReceiverExternalAddress(Boolean receiverExternalAd
this.receiverExternalAddress = receiverExternalAddress;
return this;
}

public Long getMinimumDepositAmount() {
return minimumDepositAmount;
}

public TransactionFieldSet setMinimumDepositAmount(Long minimumDepositAmount) {
this.minimumDepositAmount = minimumDepositAmount;
return this;
}

public Long getMaximumDepositAmount() {
return maximumDepositAmount;
}

public TransactionFieldSet setMaximumDepositAmount(Long maximumDepositAmount) {
this.maximumDepositAmount = maximumDepositAmount;
return this;
}

public Long getMinimumWithdrawalAmount() {
return minimumWithdrawalAmount;
}

public TransactionFieldSet setMinimumWithdrawalAmount(Long minimumWithdrawalAmount) {
this.minimumWithdrawalAmount = minimumWithdrawalAmount;
return this;
}

public Long getMaximumWithdrawalAmount() {
return maximumWithdrawalAmount;
}

public TransactionFieldSet setMaximumWithdrawalAmount(Long maximumWithdrawalAmount) {
this.maximumWithdrawalAmount = maximumWithdrawalAmount;
return this;
}

public Long getCurrentBalance() {
return currentBalance;
}

public TransactionFieldSet setCurrentBalance(Long currentBalance) {
this.currentBalance = currentBalance;
return this;
}

public Long getNewBalance() {
return newBalance;
}

public TransactionFieldSet setNewBalance(Long newBalance) {
this.newBalance = newBalance;
return this;
}
}
128 changes: 128 additions & 0 deletions src/test/java/com/siftscience/TransactionEventTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -666,4 +666,132 @@ public void testTransactionEventWithCryptoFields() throws Exception {

server.shutdown();
}

@Test
public void testTransactionEventWithExtraDepositFields() throws Exception {
String expectedRequestBody = "{\n" +
" \"$type\" : \"$transaction\",\n" +
" \"$api_key\" : \"YOUR_API_KEY\",\n" +
" \"$user_id\" : \"billy_jones_301\",\n" +
" \"$amount\" : 500000,\n" +
" \"$currency_code\" : \"USD\",\n" +
" \"$transaction_type\" : \"$deposit\",\n" +
" \"$transaction_id\" : \"719637215\",\n" +
" \"$minimum_deposit_amount\" : 5000,\n" +
" \"$maximum_deposit_amount\" : 100000000,\n" +
" \"$current_balance\" : 500000,\n" +
" \"$new_balance\" : 1000000,\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.
EventRequest request = client.buildRequest(new TransactionFieldSet()
.setUserId("billy_jones_301")
.setAmount(500000L)
.setCurrencyCode("USD")
.setTransactionType("$deposit")
.setTransactionId("719637215")
.setMinimumDepositAmount(5000L)
.setMaximumDepositAmount(100000000L)
.setCurrentBalance(500000L)
.setNewBalance(1000000L));

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();
}

@Test
public void testTransactionEventWithExtraWithdrawalFields() throws Exception {
String expectedRequestBody = "{\n" +
" \"$type\" : \"$transaction\",\n" +
" \"$api_key\" : \"YOUR_API_KEY\",\n" +
" \"$user_id\" : \"billy_jones_301\",\n" +
" \"$amount\" : 500000,\n" +
" \"$currency_code\" : \"USD\",\n" +
" \"$transaction_type\" : \"$withdrawal\",\n" +
" \"$transaction_id\" : \"719637215\",\n" +
" \"$minimum_withdrawal_amount\" : 5000,\n" +
" \"$maximum_withdrawal_amount\" : 100000000,\n" +
" \"$current_balance\" : 1000000,\n" +
" \"$new_balance\" : 500000,\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.
EventRequest request = client.buildRequest(new TransactionFieldSet()
.setUserId("billy_jones_301")
.setAmount(500000L)
.setCurrencyCode("USD")
.setTransactionType("$withdrawal")
.setTransactionId("719637215")
.setMinimumWithdrawalAmount(5000L)
.setMaximumWithdrawalAmount(100000000L)
.setCurrentBalance(1000000L)
.setNewBalance(500000L));

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();
}
}

0 comments on commit ba7af16

Please sign in to comment.