From 9c9b29a076769e74b424c7e1fd61e0f8624f3821 Mon Sep 17 00:00:00 2001 From: Michael Kelly Date: Thu, 14 Mar 2019 17:42:26 +0900 Subject: [PATCH] add /sandbox/item/fire_webhook endpoint --- .../com/plaid/client/PlaidApiService.java | 5 +++ .../SandboxItemFireWebhookRequest.java | 17 ++++++++ .../SandboxItemFireWebhookResponse.java | 14 +++++++ .../SandboxItemFireWebhookTest.java | 40 +++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 src/main/java/com/plaid/client/request/SandboxItemFireWebhookRequest.java create mode 100644 src/main/java/com/plaid/client/response/SandboxItemFireWebhookResponse.java create mode 100644 src/test/java/com/plaid/client/integration/SandboxItemFireWebhookTest.java diff --git a/src/main/java/com/plaid/client/PlaidApiService.java b/src/main/java/com/plaid/client/PlaidApiService.java index 3e056c16f..295a92d6e 100644 --- a/src/main/java/com/plaid/client/PlaidApiService.java +++ b/src/main/java/com/plaid/client/PlaidApiService.java @@ -29,6 +29,7 @@ import com.plaid.client.request.ItemRemoveRequest; import com.plaid.client.request.ItemStripeTokenCreateRequest; import com.plaid.client.request.ItemWebhookUpdateRequest; +import com.plaid.client.request.SandboxItemFireWebhookRequest; import com.plaid.client.request.SandboxItemResetLoginRequest; import com.plaid.client.request.SandboxPublicTokenCreateRequest; import com.plaid.client.request.TransactionsGetRequest; @@ -57,6 +58,7 @@ import com.plaid.client.response.ItemRemoveResponse; import com.plaid.client.response.ItemStripeTokenCreateResponse; import com.plaid.client.response.ItemWebhookUpdateResponse; +import com.plaid.client.response.SandboxItemFireWebhookResponse; import com.plaid.client.response.SandboxItemResetLoginResponse; import com.plaid.client.response.SandboxPublicTokenCreateResponse; import com.plaid.client.response.TransactionsGetResponse; @@ -103,6 +105,9 @@ public interface PlaidApiService { // sandbox-only endpoints //////////////////////////////////////////////////////// //////////////////////////////////////////////////////// + @POST("/sandbox/item/fire_webhook") + Call sandboxItemFireWebhook(@Body SandboxItemFireWebhookRequest request); + @POST("/sandbox/item/reset_login") Call sandboxItemResetLogin(@Body SandboxItemResetLoginRequest request); diff --git a/src/main/java/com/plaid/client/request/SandboxItemFireWebhookRequest.java b/src/main/java/com/plaid/client/request/SandboxItemFireWebhookRequest.java new file mode 100644 index 000000000..d17620483 --- /dev/null +++ b/src/main/java/com/plaid/client/request/SandboxItemFireWebhookRequest.java @@ -0,0 +1,17 @@ +package com.plaid.client.request; + +import com.plaid.client.request.common.BaseAccessTokenRequest; + +/** + * Request for the /sandbox/item/fire_webhook endpoint. + * + * @see https://plaid.com/docs/api/#TODO + */ +public final class SandboxItemFireWebhookRequest extends BaseAccessTokenRequest { + private String webhookCode; + + public SandboxItemFireWebhookRequest(String accessToken, String webhookCode) { + super(accessToken); + this.webhookCode = webhookCode; + } +} diff --git a/src/main/java/com/plaid/client/response/SandboxItemFireWebhookResponse.java b/src/main/java/com/plaid/client/response/SandboxItemFireWebhookResponse.java new file mode 100644 index 000000000..fada42fa5 --- /dev/null +++ b/src/main/java/com/plaid/client/response/SandboxItemFireWebhookResponse.java @@ -0,0 +1,14 @@ +package com.plaid.client.response; + +import java.util.Date; + +/** + * Response from /sandbox/item/fire_webhook endpoint. + */ +public final class SandboxItemFireWebhookResponse extends BaseResponse { + private boolean webhookFired; + + public boolean getWebhookFired() { + return webhookFired; + } +} diff --git a/src/test/java/com/plaid/client/integration/SandboxItemFireWebhookTest.java b/src/test/java/com/plaid/client/integration/SandboxItemFireWebhookTest.java new file mode 100644 index 000000000..c95d5034f --- /dev/null +++ b/src/test/java/com/plaid/client/integration/SandboxItemFireWebhookTest.java @@ -0,0 +1,40 @@ +package com.plaid.client.integration; + +import com.plaid.client.request.ItemWebhookUpdateRequest; +import com.plaid.client.request.SandboxItemFireWebhookRequest; +import com.plaid.client.request.common.Product; +import com.plaid.client.response.ErrorResponse; +import com.plaid.client.response.ItemWebhookUpdateResponse; +import com.plaid.client.response.SandboxItemFireWebhookResponse; +import org.junit.Test; +import retrofit2.Response; + +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.assertTrue; + +public class SandboxItemFireWebhookTest extends AbstractItemIntegrationTest { + @Override + protected List setupItemProducts() { + return Arrays.asList(Product.TRANSACTIONS); + } + + @Override + protected String setupItemInstitutionId() { + return TARTAN_BANK_INSTITUTION_ID; + } + + @Test + public void testSuccess() throws Exception { + // Set a webhook + Response webhookResponse = client().service().itemWebhookUpdate( + new ItemWebhookUpdateRequest(getItemPublicTokenExchangeResponse().getAccessToken(), "https://baz.xyz/foo-test-hook")).execute(); + // Fire a webhook + Response response = + client().service().sandboxItemFireWebhook(new SandboxItemFireWebhookRequest(getItemPublicTokenExchangeResponse().getAccessToken(), "DEFAULT_UPDATE")).execute(); + + assertSuccessResponse(response); + assertTrue(response.body().getWebhookFired()); + } +}