Skip to content

Commit c1f096d

Browse files
committed
code review feedback
1 parent 0689baa commit c1f096d

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

src/main/java/com/stripe/StripeClient.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.stripe.net.Webhook.Signature;
99
import java.net.PasswordAuthentication;
1010
import java.net.Proxy;
11+
import lombok.Builder;
1112
import lombok.Getter;
1213

1314
/**
@@ -73,7 +74,9 @@ public StripeClient withStripeContext(StripeContext context) {
7374

7475
StripeResponseGetter responseGetter = this.getResponseGetter();
7576

76-
// We can only create a new client for LiveStripeResponseGetter
77+
// We can only create a new client for LiveStripeResponseGetter because it's the only class with
78+
// `getOptions()`. If we add that method to the interface in a later major, we could remove this
79+
// check.
7780
if (!(responseGetter instanceof LiveStripeResponseGetter)) {
7881
throw new IllegalStateException(
7982
"Cannot create a client with custom context for non-Live response getters");
@@ -88,20 +91,7 @@ public StripeClient withStripeContext(StripeContext context) {
8891
ClientStripeResponseGetterOptions existingOptions =
8992
(ClientStripeResponseGetterOptions) options;
9093

91-
return new ClientStripeResponseGetterOptions(
92-
existingOptions.getAuthenticator(),
93-
existingOptions.getClientId(),
94-
existingOptions.getConnectTimeout(),
95-
existingOptions.getReadTimeout(),
96-
existingOptions.getMaxNetworkRetries(),
97-
existingOptions.getConnectionProxy(),
98-
existingOptions.getProxyCredential(),
99-
existingOptions.getApiBase(),
100-
existingOptions.getFilesBase(),
101-
existingOptions.getConnectBase(),
102-
existingOptions.getMeterEventsBase(),
103-
existingOptions.getStripeAccount(),
104-
contextString);
94+
return existingOptions.toBuilder().stripeContext(contextString).build();
10595
});
10696

10797
// Create and return a new StripeClient with the new response getter
@@ -1100,6 +1090,8 @@ public com.stripe.service.WebhookEndpointService webhookEndpoints() {
11001090
}
11011091

11021092
// The end of the section generated from our OpenAPI spec
1093+
@SuppressWarnings("ObjectToString")
1094+
@Builder(toBuilder = true)
11031095
static class ClientStripeResponseGetterOptions extends StripeResponseGetterOptions {
11041096
// When adding setting here keep them in sync with settings in RequestOptions and
11051097
// in the RequestOptions.merge method

src/main/java/com/stripe/StripeEventNotificationHandler.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@
6363
import com.stripe.events.V2MoneyManagementTransactionUpdatedEventNotification;
6464
import com.stripe.exception.SignatureVerificationException;
6565
import com.stripe.model.v2.core.EventNotification;
66+
import java.util.ArrayList;
67+
import java.util.Collections;
6668
import java.util.HashMap;
69+
import java.util.List;
6770

6871
// event-notification-class-imports: The end of the section generated from our OpenAPI spec
6972

@@ -109,6 +112,9 @@ public boolean isKnownEventType() {
109112
}
110113
}
111114

115+
// this is intentionally naiive to avoid the performance cost of interacting with `volatile`. We
116+
// expect that registrations are done synchronously at startup time and handling will happen
117+
// async, so thread-safe reads aren't important here.
112118
private boolean hasHandledEvent = false;
113119

114120
private final String webhookSecret;
@@ -533,9 +539,9 @@ public StripeEventNotificationHandler onV2MoneyManagementTransactionUpdated(
533539
*
534540
* @return A sorted list of event type strings
535541
*/
536-
public java.util.List<String> getRegisteredEventTypes() {
537-
java.util.List<String> eventTypes = new java.util.ArrayList<>(this.registeredHandlers.keySet());
538-
java.util.Collections.sort(eventTypes);
542+
public List<String> getRegisteredEventTypes() {
543+
List<String> eventTypes = new ArrayList<>(this.registeredHandlers.keySet());
544+
Collections.sort(eventTypes);
539545
return eventTypes;
540546
}
541547
}

0 commit comments

Comments
 (0)