Skip to content

Commit

Permalink
Small connect fixes for billing meters
Browse files Browse the repository at this point in the history
  • Loading branch information
charliecruzan-stripe committed Sep 20, 2024
1 parent 3bf89da commit 6f71f17
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
12 changes: 11 additions & 1 deletion pkg/cmd/listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,22 @@ func (lc *listenCmd) createVisitor(logger *log.Logger, format string, printJSON
VisitData: func(de websocket.DataElement) error {
switch data := de.Data.(type) {
case proxy.V2EventPayload:
if strings.ToUpper(format) == outputFormatJSON || printJSON {
fmt.Println(de.Marshaled)
return nil
}

maybeConnect := ""
if data.IsConnect() {
maybeConnect = "connect "
}

localTime := time.Now().Format(timeLayout)

color := ansi.Color(os.Stdout)
outputStr := fmt.Sprintf("%s --> %s [%s]",
outputStr := fmt.Sprintf("%s --> %s%s [%s]",
color.Faint(localTime),
maybeConnect,
ansi.Bold(data.Type),
ansi.Linkify(data.ID, data.URLForEventID(lc.deviceToken), logger.Out),
)
Expand Down
16 changes: 10 additions & 6 deletions pkg/fixtures/triggers/v1.billing.meter.error_report_triggered.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,17 @@
"Authorization": "Bearer ${billing_meter_event_session:authentication_token}"
},
"params": {
"event_name": "${list_billing_meters_after_creation:data.0.event_name}",
"timestamp":"${time-now-RFC3339}",
"identifier": "${generate-uuid}",
"payload": {
"value":"1"
"events": [
{
"event_name": "${list_billing_meters_after_creation:data.0.event_name}",
"timestamp":"${time-now-RFC3339}",
"identifier": "${generate-uuid}",
"payload": {
"value":"1"
}
}
}
]
}
}
]
}
12 changes: 8 additions & 4 deletions pkg/fixtures/triggers/v1.billing.meter.no_meter_found.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@
"Authorization": "Bearer ${billing_meter_event_session:authentication_token}"
},
"params": {
"event_name": "${generate-uuid}",
"timestamp":"${time-now-RFC3339}",
"payload": {
"value":"10"
"events": [
{
"event_name": "${generate-uuid}",
"timestamp":"${time-now-RFC3339}",
"payload": {
"value":"10"
}
}
]
}
}
]
Expand Down
5 changes: 5 additions & 0 deletions pkg/proxy/v2_stripe_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ type primaryRelatedObject struct {
func (e *V2EventPayload) URLForEventID(cliEndpointID string) string {
return fmt.Sprintf("https://dashboard.stripe.com/workbench/webhooks/%s?event=%s", cliEndpointID, e.ID)
}

// IsConnect returns true if this event is associated with a connected account
func (e *V2EventPayload) IsConnect() bool {
return e.Context != ""
}

0 comments on commit 6f71f17

Please sign in to comment.