|
6 | 6 | import java.util.List; |
7 | 7 |
|
8 | 8 | import com.siftscience.model.DigitalOrder; |
9 | | -import com.siftscience.model.PaymentMethod; |
10 | 9 | import com.siftscience.model.TransactionFieldSet; |
11 | 10 | import okhttp3.OkHttpClient; |
12 | 11 | import okhttp3.mockwebserver.MockResponse; |
@@ -667,4 +666,132 @@ public void testTransactionEventWithCryptoFields() throws Exception { |
667 | 666 |
|
668 | 667 | server.shutdown(); |
669 | 668 | } |
| 669 | + |
| 670 | + @Test |
| 671 | + public void testTransactionEventWithExtraDepositFields() throws Exception { |
| 672 | + String expectedRequestBody = "{\n" + |
| 673 | + " \"$type\" : \"$transaction\",\n" + |
| 674 | + " \"$api_key\" : \"YOUR_API_KEY\",\n" + |
| 675 | + " \"$user_id\" : \"billy_jones_301\",\n" + |
| 676 | + " \"$amount\" : 500000,\n" + |
| 677 | + " \"$currency_code\" : \"USD\",\n" + |
| 678 | + " \"$transaction_type\" : \"$deposit\",\n" + |
| 679 | + " \"$transaction_id\" : \"719637215\",\n" + |
| 680 | + " \"$minimum_deposit_amount\" : 5000,\n" + |
| 681 | + " \"$maximum_deposit_amount\" : 100000000,\n" + |
| 682 | + " \"$current_balance\" : 500000,\n" + |
| 683 | + " \"$new_balance\" : 1000000,\n" + |
| 684 | + "}"; |
| 685 | + |
| 686 | + // Start a new mock server and enqueue a mock response. |
| 687 | + MockWebServer server = new MockWebServer(); |
| 688 | + MockResponse response = new MockResponse(); |
| 689 | + response.setResponseCode(HTTP_OK); |
| 690 | + response.setBody("{\n" + |
| 691 | + " \"status\" : 0,\n" + |
| 692 | + " \"error_message\" : \"OK\",\n" + |
| 693 | + " \"time\" : 1327604222,\n" + |
| 694 | + " \"request\" : \"" + TestUtils.unescapeJson(expectedRequestBody) + "\"\n" + |
| 695 | + "}"); |
| 696 | + server.enqueue(response); |
| 697 | + server.start(); |
| 698 | + |
| 699 | + // Create a new client and link it to the mock server. |
| 700 | + SiftClient client = new SiftClient("YOUR_API_KEY", "YOUR_ACCOUNT_ID", |
| 701 | + new OkHttpClient.Builder() |
| 702 | + .addInterceptor(OkHttpUtils.urlRewritingInterceptor(server)) |
| 703 | + .build()); |
| 704 | + |
| 705 | + // Build and execute the request against the mock server. |
| 706 | + EventRequest request = client.buildRequest(new TransactionFieldSet() |
| 707 | + .setUserId("billy_jones_301") |
| 708 | + .setAmount(500000L) |
| 709 | + .setCurrencyCode("USD") |
| 710 | + .setTransactionType("$deposit") |
| 711 | + .setTransactionId("719637215") |
| 712 | + .setMinimumDepositAmount(5000L) |
| 713 | + .setMaximumDepositAmount(100000000L) |
| 714 | + .setCurrentBalance(500000L) |
| 715 | + .setNewBalance(1000000L)); |
| 716 | + |
| 717 | + EventResponse siftResponse = request.send(); |
| 718 | + |
| 719 | + // Verify the request. |
| 720 | + RecordedRequest request1 = server.takeRequest(); |
| 721 | + Assert.assertEquals("POST", request1.getMethod()); |
| 722 | + Assert.assertEquals("/v205/events", request1.getPath()); |
| 723 | + JSONAssert.assertEquals(expectedRequestBody, request.getFieldSet().toJson(), true); |
| 724 | + |
| 725 | + // Verify the response. |
| 726 | + Assert.assertEquals(HTTP_OK, siftResponse.getHttpStatusCode()); |
| 727 | + Assert.assertEquals(0, (int) siftResponse.getBody().getStatus()); |
| 728 | + JSONAssert.assertEquals(response.getBody().readUtf8(), |
| 729 | + siftResponse.getBody().toJson(), true); |
| 730 | + |
| 731 | + server.shutdown(); |
| 732 | + } |
| 733 | + |
| 734 | + @Test |
| 735 | + public void testTransactionEventWithExtraWithdrawalFields() throws Exception { |
| 736 | + String expectedRequestBody = "{\n" + |
| 737 | + " \"$type\" : \"$transaction\",\n" + |
| 738 | + " \"$api_key\" : \"YOUR_API_KEY\",\n" + |
| 739 | + " \"$user_id\" : \"billy_jones_301\",\n" + |
| 740 | + " \"$amount\" : 500000,\n" + |
| 741 | + " \"$currency_code\" : \"USD\",\n" + |
| 742 | + " \"$transaction_type\" : \"$withdrawal\",\n" + |
| 743 | + " \"$transaction_id\" : \"719637215\",\n" + |
| 744 | + " \"$minimum_withdrawal_amount\" : 5000,\n" + |
| 745 | + " \"$maximum_withdrawal_amount\" : 100000000,\n" + |
| 746 | + " \"$current_balance\" : 1000000,\n" + |
| 747 | + " \"$new_balance\" : 500000,\n" + |
| 748 | + "}"; |
| 749 | + |
| 750 | + // Start a new mock server and enqueue a mock response. |
| 751 | + MockWebServer server = new MockWebServer(); |
| 752 | + MockResponse response = new MockResponse(); |
| 753 | + response.setResponseCode(HTTP_OK); |
| 754 | + response.setBody("{\n" + |
| 755 | + " \"status\" : 0,\n" + |
| 756 | + " \"error_message\" : \"OK\",\n" + |
| 757 | + " \"time\" : 1327604222,\n" + |
| 758 | + " \"request\" : \"" + TestUtils.unescapeJson(expectedRequestBody) + "\"\n" + |
| 759 | + "}"); |
| 760 | + server.enqueue(response); |
| 761 | + server.start(); |
| 762 | + |
| 763 | + // Create a new client and link it to the mock server. |
| 764 | + SiftClient client = new SiftClient("YOUR_API_KEY", "YOUR_ACCOUNT_ID", |
| 765 | + new OkHttpClient.Builder() |
| 766 | + .addInterceptor(OkHttpUtils.urlRewritingInterceptor(server)) |
| 767 | + .build()); |
| 768 | + |
| 769 | + // Build and execute the request against the mock server. |
| 770 | + EventRequest request = client.buildRequest(new TransactionFieldSet() |
| 771 | + .setUserId("billy_jones_301") |
| 772 | + .setAmount(500000L) |
| 773 | + .setCurrencyCode("USD") |
| 774 | + .setTransactionType("$withdrawal") |
| 775 | + .setTransactionId("719637215") |
| 776 | + .setMinimumWithdrawalAmount(5000L) |
| 777 | + .setMaximumWithdrawalAmount(100000000L) |
| 778 | + .setCurrentBalance(1000000L) |
| 779 | + .setNewBalance(500000L)); |
| 780 | + |
| 781 | + EventResponse siftResponse = request.send(); |
| 782 | + |
| 783 | + // Verify the request. |
| 784 | + RecordedRequest request1 = server.takeRequest(); |
| 785 | + Assert.assertEquals("POST", request1.getMethod()); |
| 786 | + Assert.assertEquals("/v205/events", request1.getPath()); |
| 787 | + JSONAssert.assertEquals(expectedRequestBody, request.getFieldSet().toJson(), true); |
| 788 | + |
| 789 | + // Verify the response. |
| 790 | + Assert.assertEquals(HTTP_OK, siftResponse.getHttpStatusCode()); |
| 791 | + Assert.assertEquals(0, (int) siftResponse.getBody().getStatus()); |
| 792 | + JSONAssert.assertEquals(response.getBody().readUtf8(), |
| 793 | + siftResponse.getBody().toJson(), true); |
| 794 | + |
| 795 | + server.shutdown(); |
| 796 | + } |
670 | 797 | } |
0 commit comments