Skip to content

Commit

Permalink
Removed parseSnapshotEvent (#1886)
Browse files Browse the repository at this point in the history
  • Loading branch information
prathmesh-stripe authored Oct 1, 2024
1 parent 81feaf1 commit c5b83e6
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 110 deletions.
39 changes: 0 additions & 39 deletions src/main/java/com/stripe/StripeClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,45 +59,6 @@ public ThinEvent parseThinEvent(String payload, String sigHeader, String secret)
return ApiResource.GSON.fromJson(payload, ThinEvent.class);
}

/**
* Returns an Event instance using the provided JSON payload. Throws a JsonSyntaxException if the
* payload is not valid JSON, and a SignatureVerificationException if the signature verification
* fails for any reason.
*
* @param payload the payload sent by Stripe.
* @param sigHeader the contents of the signature header sent by Stripe.
* @param secret secret used to generate the signature.
* @return the Event instance
* @throws SignatureVerificationException if the verification fails.
*/
public com.stripe.model.Event parseSnapshotEvent(String payload, String sigHeader, String secret)
throws SignatureVerificationException {
com.stripe.model.Event event = Webhook.constructEvent(payload, sigHeader, secret);
event.setResponseGetter(this.getResponseGetter());
return event;
}

/**
* Returns an Event instance using the provided JSON payload. Throws a JsonSyntaxException if the
* payload is not valid JSON, and a SignatureVerificationException if the signature verification
* fails for any reason.
*
* @param payload the payload sent by Stripe.
* @param sigHeader the contents of the signature header sent by Stripe.
* @param secret secret used to generate the signature.
* @param tolerance maximum difference in seconds allowed between the header's timestamp and the
* current time
* @return the Event instance
* @throws SignatureVerificationException if the verification fails.
*/
public com.stripe.model.Event parseSnapshotEvent(
String payload, String sigHeader, String secret, long tolerance)
throws SignatureVerificationException {
com.stripe.model.Event event = Webhook.constructEvent(payload, sigHeader, secret, tolerance);
event.setResponseGetter(this.getResponseGetter());
return event;
}

// The beginning of the section generated from our OpenAPI spec
public com.stripe.service.AccountLinkService accountLinks() {
return new com.stripe.service.AccountLinkService(this.getResponseGetter());
Expand Down
71 changes: 0 additions & 71 deletions src/test/java/com/stripe/net/WebhookTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@
import com.google.gson.JsonSyntaxException;
import com.stripe.BaseStripeTest;
import com.stripe.Stripe;
import com.stripe.StripeClient;
import com.stripe.exception.SignatureVerificationException;
import com.stripe.exception.StripeException;
import com.stripe.model.Account;
import com.stripe.model.Event;
import com.stripe.model.terminal.Reader;
import java.lang.reflect.Type;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.time.Clock;
Expand All @@ -23,8 +20,6 @@
import java.util.Map;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.mockito.stubbing.Answer;

public class WebhookTest extends BaseStripeTest {
public static String secret = null;
Expand Down Expand Up @@ -259,70 +254,4 @@ public void testTimestampWithClockOutsideTolerance()

assertTrue(Webhook.Signature.verifyHeader(payload, sigHeader, secret, 10, clock));
}

@Test
public void testStripeClientConstructEvent()
throws StripeException, NoSuchAlgorithmException, InvalidKeyException {
StripeResponseGetter responseGetter = Mockito.spy(new LiveStripeResponseGetter());
StripeClient client = new StripeClient(responseGetter);

Mockito.doAnswer((Answer<Reader>) invocation -> new Reader())
.when(responseGetter)
.request(
Mockito.<ApiRequest>argThat(
(req) ->
req.getMethod().equals(ApiResource.RequestMethod.DELETE)
&& req.getPath().equals("/v1/terminal/readers/rdr_123")),
Mockito.<Type>any());

final String payload =
"{\"id\": \"evt_test_webhook\",\"api_version\":\""
+ Stripe.API_VERSION
+ "\","
+ "\"object\": \"event\",\"data\": {\"object\": {\"id\": \"rdr_123\",\"object\": \"terminal.reader\"}}}";

final Map<String, Object> options = new HashMap<>();
options.put("payload", payload);
final String sigHeader = generateSigHeader(options);

final Event event = client.parseSnapshotEvent(payload, sigHeader, secret);

final Reader reader = (Reader) event.getDataObjectDeserializer().getObject().get();
reader.delete();

Mockito.verify(responseGetter).request(Mockito.any(), Mockito.any());
}

@Test
public void testStripeClientConstructEventWithTolerance()
throws StripeException, NoSuchAlgorithmException, InvalidKeyException {
StripeResponseGetter responseGetter = Mockito.spy(new LiveStripeResponseGetter());
StripeClient client = new StripeClient(responseGetter);

Mockito.doAnswer((Answer<Reader>) invocation -> new Reader())
.when(responseGetter)
.request(
Mockito.argThat(
(req) ->
req.getMethod().equals(ApiResource.RequestMethod.DELETE)
&& req.getPath().equals("/v1/terminal/readers/rdr_123")),
Mockito.any());

final String payload =
"{\"id\": \"evt_test_webhook\",\"api_version\":\""
+ Stripe.API_VERSION
+ "\","
+ "\"object\": \"event\",\"data\": {\"object\": {\"id\": \"rdr_123\",\"object\": \"terminal.reader\"}}}";

final Map<String, Object> options = new HashMap<>();
options.put("payload", payload);
final String sigHeader = generateSigHeader(options);

final Event event = client.parseSnapshotEvent(payload, sigHeader, secret, 500);

final Reader reader = (Reader) event.getDataObjectDeserializer().getObject().get();
reader.delete();

Mockito.verify(responseGetter).request(Mockito.any(), Mockito.any());
}
}

0 comments on commit c5b83e6

Please sign in to comment.