Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// URL the client connects to
URL string
// ID sent by the client in the `Websocket-Id` header when connecting
WebSocketID string
// Feature that the websocket is specified for
WebSocketAuthorizedFeature string
// contains filtered or unexported fields
}
Client is the client used to receive webhook requests from Stripe and send back webhook responses from the local endpoint to Stripe.
func NewClient ¶
func NewClient(url string, webSocketID string, websocketAuthorizedFeature string, cfg *Config) *Client
NewClient returns a new Client.
func (*Client) Run ¶
func (c *Client) Run()
Run starts listening for incoming webhook requests from Stripe.
func (*Client) SendMessage ¶
func (c *Client) SendMessage(msg *OutgoingMessage)
SendMessage sends a message to Stripe through the websocket.
type Config ¶
type Config struct {
ConnectAttemptWait time.Duration
Dialer *ws.Dialer
Log *log.Logger
// Force use of unencrypted ws:// protocol instead of wss://
NoWSS bool
PingPeriod time.Duration
PongWait time.Duration
// Interval at which the websocket client should reset the connection
ReconnectInterval time.Duration
WriteWait time.Duration
EventHandler EventHandler
}
Config contains the optional configuration parameters of a Client.
type EventHandler ¶ added in v0.2.4
type EventHandler interface {
ProcessEvent(IncomingMessage)
}
EventHandler handles an event.
type EventHandlerFunc ¶ added in v0.2.4
type EventHandlerFunc func(IncomingMessage)
EventHandlerFunc is an adapter to allow the use of ordinary functions as event handlers. If f is a function with the appropriate signature, EventHandlerFunc(f) is a EventHandler that calls f.
func (EventHandlerFunc) ProcessEvent ¶ added in v0.2.4
func (f EventHandlerFunc) ProcessEvent(msg IncomingMessage)
ProcessEvent calls f(msg).
type IncomingMessage ¶
type IncomingMessage struct {
*WebhookEvent
*RequestLogEvent
}
IncomingMessage represents any incoming message sent by Stripe.
func (*IncomingMessage) UnmarshalJSON ¶
func (m *IncomingMessage) UnmarshalJSON(data []byte) error
UnmarshalJSON deserializes incoming messages sent by Stripe into the appropriate structure.
type OutgoingMessage ¶
type OutgoingMessage struct {
*WebhookResponse
}
OutgoingMessage represents any outgoing message sent to Stripe.
func NewWebhookResponse ¶
func NewWebhookResponse(webhookID, webhookConversationID, forwardURL string, status int, body string, headers map[string]string) *OutgoingMessage
NewWebhookResponse returns a new webhookResponse message.
func (OutgoingMessage) MarshalJSON ¶
func (m OutgoingMessage) MarshalJSON() ([]byte, error)
MarshalJSON serializes outgoing messages sent to Stripe.
type RequestLogEvent ¶ added in v0.2.4
type RequestLogEvent struct {
EventPayload string `json:"event_payload"`
// RequestLogID is the `resp_` id for the response event which is used as the request log event throughout the system.
// This is different from the `EventPayload.RequestID` which is the `req_` id for the user's actual request, which they
// can use to find their request in the dashboard.
RequestLogID string `json:"request_log_id"`
Type string `json:"type"`
}
RequestLogEvent represents incoming request log event messages sent by Stripe.
type WebhookEndpoint ¶
type WebhookEndpoint struct {
APIVersion *string `json:"api_version"`
}
WebhookEndpoint contains properties about the fake "endpoint" used to format the webhook event.
type WebhookEvent ¶
type WebhookEvent struct {
Endpoint WebhookEndpoint `json:"endpoint"`
EventPayload string `json:"event_payload"`
HTTPHeaders map[string]string `json:"http_headers"`
Type string `json:"type"`
WebhookConversationID string `json:"webhook_conversation_id"`
WebhookID string `json:"webhook_id"`
}
WebhookEvent represents incoming webhook event messages sent by Stripe.
type WebhookResponse ¶
type WebhookResponse struct {
ForwardURL string `json:"forward_url"`
Status int `json:"status"`
HTTPHeaders map[string]string `json:"http_headers"`
Body string `json:"body"`
Type string `json:"type"`
WebhookConversationID string `json:"webhook_conversation_id"`
WebhookID string `json:"webhook_id"`
}
WebhookResponse represents outgoing webhook response messages sent to Stripe.