diff --git a/CHANGES.MD b/CHANGES.MD index b15d11f..920c577 100644 --- a/CHANGES.MD +++ b/CHANGES.MD @@ -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) ================= diff --git a/src/main/java/com/siftscience/model/TransactionFieldSet.java b/src/main/java/com/siftscience/model/TransactionFieldSet.java index a5c3f48..4e55f54 100644 --- a/src/main/java/com/siftscience/model/TransactionFieldSet.java +++ b/src/main/java/com/siftscience/model/TransactionFieldSet.java @@ -31,6 +31,12 @@ public class TransactionFieldSet extends BaseAppBrowserSiteBrandFieldSet 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 @@ -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; + } } diff --git a/src/test/java/com/siftscience/TransactionEventTest.java b/src/test/java/com/siftscience/TransactionEventTest.java index 65ed2f8..9077ebd 100644 --- a/src/test/java/com/siftscience/TransactionEventTest.java +++ b/src/test/java/com/siftscience/TransactionEventTest.java @@ -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(); + } }