Skip to content

Commit

Permalink
display API version when running listen (#764)
Browse files Browse the repository at this point in the history
* ready message now includes the stripe API version if available

* modified a test to check for the extra params expected from the new backend API
  • Loading branch information
lemuel-stripe committed Oct 19, 2021
1 parent ebe5970 commit 74cfd44
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/cmd/listen.go
Expand Up @@ -228,7 +228,7 @@ func createVisitor(logger *log.Logger, format string, printJSON bool) *websocket
case websocket.Reconnecting:
ansi.StartSpinner(s, "Session expired, reconnecting...", logger.Out)
case websocket.Ready:
ansi.StopSpinner(s, fmt.Sprintf("Ready! Your webhook signing secret is %s (^C to quit)", ansi.Bold(se.Data[0])), logger.Out)
ansi.StopSpinner(s, fmt.Sprintf("Ready! %sYour webhook signing secret is %s (^C to quit)", se.Data[0], ansi.Bold(se.Data[1])), logger.Out)
case websocket.Done:
ansi.StopSpinner(s, "", logger.Out)
}
Expand Down
9 changes: 8 additions & 1 deletion pkg/proxy/proxy.go
Expand Up @@ -162,9 +162,16 @@ func (p *Proxy) Run(ctx context.Context) error {
<-p.webSocketClient.Connected()
nAttempts = 0

displayedAPIVersion := ""
if p.cfg.UseLatestAPIVersion && session.LatestVersion != "" {
displayedAPIVersion = "You are using Stripe API Version [" + session.LatestVersion + "]. "
} else if !p.cfg.UseLatestAPIVersion && session.DefaultVersion != "" {
displayedAPIVersion = "You are using Stripe API Version [" + session.DefaultVersion + "]. "
}

p.cfg.OutCh <- websocket.StateElement{
State: websocket.Ready,
Data: []string{session.Secret},
Data: []string{displayedAPIVersion, session.Secret},
}
}()

Expand Down
2 changes: 2 additions & 0 deletions pkg/stripeauth/client.go
Expand Up @@ -104,6 +104,8 @@ func (c *Client) Authorize(ctx context.Context, deviceName string, websocketFeat
"websocket_authorized_feature": session.WebSocketAuthorizedFeature,
"reconnect_delay": session.ReconnectDelay,
"display_connect_filter_warning": session.DisplayConnectFilterWarning,
"default_version": session.DefaultVersion,
"latest_version": session.LatestVersion,
}).Debug("Got successful response from Stripe")

return session, nil
Expand Down
4 changes: 4 additions & 0 deletions pkg/stripeauth/client_test.go
Expand Up @@ -18,6 +18,8 @@ func TestAuthorize(t *testing.T) {
WebSocketID: "some-id",
WebSocketURL: "wss://example.com/subscribe/acct_123",
WebSocketAuthorizedFeature: "webhook-payloads",
DefaultVersion: "2014-01-31",
LatestVersion: "2020-08-27",
}
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "application/json")
Expand All @@ -42,6 +44,8 @@ func TestAuthorize(t *testing.T) {
require.Equal(t, "some-id", session.WebSocketID)
require.Equal(t, "wss://example.com/subscribe/acct_123", session.WebSocketURL)
require.Equal(t, "webhook-payloads", session.WebSocketAuthorizedFeature)
require.Equal(t, "2014-01-31", session.DefaultVersion)
require.Equal(t, "2020-08-27", session.LatestVersion)
}

func TestUserAgent(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions pkg/stripeauth/messages.go
Expand Up @@ -9,4 +9,6 @@ type StripeCLISession struct {
WebSocketAuthorizedFeature string `json:"websocket_authorized_feature"`
WebSocketID string `json:"websocket_id"`
WebSocketURL string `json:"websocket_url"`
DefaultVersion string `json:"default_version"`
LatestVersion string `json:"latest_version"`
}

0 comments on commit 74cfd44

Please sign in to comment.