Documentation
¶
Overview ¶
Package stripe provides the HTTP client for the Stripe API.
Index ¶
- Constants
- func DashboardBaseURLForAPIBaseURL(apiBaseURL string) string
- func IsV2Path(path string) bool
- func IsValidAPIPath(path string) bool
- func TelemetryOptedOut(optoutVar string) bool
- func ValidateAPIBaseURL(apiBaseURL string) error
- func ValidateDashboardBaseURL(dashboardBaseURL string) error
- func WithEventMetadata(ctx context.Context, metadata *CLIAnalyticsEventMetadata) context.Context
- func WithTelemetryClient(ctx context.Context, client TelemetryClient) context.Context
- type AnalyticsTelemetryClient
- type CLIAnalyticsEventMetadata
- func (e *CLIAnalyticsEventMetadata) SetCobraCommandContext(cmd *cobra.Command)
- func (e *CLIAnalyticsEventMetadata) SetCommandFlags(commandFlags string)
- func (e *CLIAnalyticsEventMetadata) SetCommandPath(commandPath string)
- func (e *CLIAnalyticsEventMetadata) SetMachineUUID(machineUUID string)
- func (e *CLIAnalyticsEventMetadata) SetMerchant(merchant string)
- func (e *CLIAnalyticsEventMetadata) SetPluginName(pluginName string)
- func (e *CLIAnalyticsEventMetadata) SetPluginVersion(pluginVersion string)
- func (e *CLIAnalyticsEventMetadata) SetUserAgent(userAgent string)
- type Client
- type Credentials
- type NoOpTelemetryClient
- type RequestPerformer
- type TelemetryClient
Constants ¶
const ( V1ContentType = "application/x-www-form-urlencoded" V2ContentType = "application/json" V1Request = "v1" V2Request = "v2" )
v1 and v2 API interop constants
const ( // DefaultAPIBaseURL is the default base URL for API requests DefaultAPIBaseURL = "https://api.stripe.com" APIBaseURLRegexp = `^https:\/\/api\.stripe\.com\/v\d+$` // DefaultFilesAPIBaseURL is the default base URL for Files API requsts DefaultFilesAPIBaseURL = "https://files.stripe.com/" // DefaultDashboardBaseURL is the default base URL for dashboard requests DefaultDashboardBaseURL = "https://dashboard.stripe.com" )
const APIVersion = "2019-03-14"
APIVersion is API version used in CLI
const DefaultTelemetryEndpoint = "https://r.stripe.com/0"
DefaultTelemetryEndpoint is the default URL for the telemetry destination
Variables ¶
This section is empty.
Functions ¶
func DashboardBaseURLForAPIBaseURL ¶ added in v1.42.1
DashboardBaseURLForAPIBaseURL derives the matching dashboard base URL for a given API base URL. This keeps dev and QA hosts aligned without requiring a separate dashboard override in the common case.
func IsV2Path ¶ added in v1.24.0
IsV2Path reports whether path targets the V2 API. The trailing slash is required to avoid false positives on paths like /v2x/...
func IsValidAPIPath ¶ added in v1.45.3
IsValidAPIPath reports whether the resolved URL path is under a recognized Stripe API prefix. This prevents path-traversal attacks (e.g. /v2x/../v1.41/containers/create) from reaching non-Stripe endpoints.
func TelemetryOptedOut ¶ added in v1.7.4
TelemetryOptedOut returns true if the user has opted out of telemetry, false otherwise.
func ValidateAPIBaseURL ¶ added in v1.21.10
ValidateAPIBaseURL returns an error if apiBaseURL isn't allowed
func ValidateDashboardBaseURL ¶ added in v1.21.10
ValidateDashboardBaseURL returns an error if dashboardBaseURL isn't allowed
func WithEventMetadata ¶ added in v1.7.4
func WithEventMetadata(ctx context.Context, metadata *CLIAnalyticsEventMetadata) context.Context
WithEventMetadata returns a new copy of context.Context with the provided CLIAnalyticsEventMetadata
func WithTelemetryClient ¶ added in v1.7.4
func WithTelemetryClient(ctx context.Context, client TelemetryClient) context.Context
WithTelemetryClient returns a new copy of context.Context with the provided telemetryClient
Types ¶
type AnalyticsTelemetryClient ¶ added in v1.7.4
type AnalyticsTelemetryClient struct {
BaseURL *url.URL
HTTPClient *http.Client
// contains filtered or unexported fields
}
AnalyticsTelemetryClient sends event information to r.stripe.com
func (*AnalyticsTelemetryClient) SendAPIRequestEvent ¶ added in v1.7.4
func (a *AnalyticsTelemetryClient) SendAPIRequestEvent(ctx context.Context, requestID string, livemode bool) (*http.Response, error)
SendAPIRequestEvent is a special function for API requests
func (*AnalyticsTelemetryClient) SendEvent ¶ added in v1.7.4
func (a *AnalyticsTelemetryClient) SendEvent(ctx context.Context, eventName string, eventValue string)
SendEvent sends a telemetry event to r.stripe.com
func (*AnalyticsTelemetryClient) Wait ¶ added in v1.7.4
func (a *AnalyticsTelemetryClient) Wait()
Wait will return when all in-flight telemetry requests are complete.
type CLIAnalyticsEventMetadata ¶ added in v1.7.4
type CLIAnalyticsEventMetadata struct {
InvocationID string `url:"invocation_id"` // The invocation id is unique to each context object and represents all events coming from one command / gRPC method call
UserAgent string `url:"user_agent"` // the application that is used to create this request
CommandPath string `url:"command_path"` // the command or gRPC method that initiated this request
CommandFlags string `url:"command_flags"` // Comma-separated list of flags that were passed to the command (only includes flag names, not their values)
PluginName string `url:"plugin_name,omitempty"` // the plugin being installed, when relevant
PluginVersion string `url:"plugin_version,omitempty"` // the version of the plugin being installed/uninstalled/upgraded
Merchant string `url:"merchant"` // the merchant ID: ex. acct_xxxx
CLIVersion string `url:"cli_version"` // the version of the CLI
OS string `url:"os"` // the OS of the system
Arch string `url:"arch"` // the CPU architecture of the system
MachineUUID string `url:"machine_uuid,omitempty"` // the persistent machine UUID
GeneratedResource bool `url:"generated_resource"` // whether or not this was a generated resource
AIAgent string `url:"ai_agent,omitempty"` // the AI coding agent that invoked the CLI, if any
AgentHostKind string `url:"agent_host_kind,omitempty"` // where the agent ran: desktop, terminal, ide, remote, sdk, mcp, chat, ci, or other
AgentVersion string `url:"agent_version,omitempty"` // the agent's own version, when it reports one
InstallMethod string `url:"install_method,omitempty"` // how the CLI was installed
InTmux bool `url:"in_tmux"` // whether the CLI was invoked from within tmux
InScreen bool `url:"in_screen"` // whether the CLI was invoked from within GNU Screen
TerminalProgram string `url:"terminal_program,omitempty"` // the terminal program that invoked the CLI, if any
}
CLIAnalyticsEventMetadata is the structure that holds telemetry data context that is ultimately sent to the Stripe Analytics Service.
func GetEventMetadata ¶ added in v1.7.4
func GetEventMetadata(ctx context.Context) *CLIAnalyticsEventMetadata
GetEventMetadata returns the CLIAnalyticsEventMetadata from the provided context
func NewEventMetadata ¶ added in v1.7.4
func NewEventMetadata() *CLIAnalyticsEventMetadata
NewEventMetadata initializes an instance of CLIAnalyticsEventContext
func (*CLIAnalyticsEventMetadata) SetCobraCommandContext ¶ added in v1.7.4
func (e *CLIAnalyticsEventMetadata) SetCobraCommandContext(cmd *cobra.Command)
SetCobraCommandContext sets the telemetry values for the command being executed.
func (*CLIAnalyticsEventMetadata) SetCommandFlags ¶ added in v1.21.9
func (e *CLIAnalyticsEventMetadata) SetCommandFlags(commandFlags string)
SetCommandFlags sets the flags on the CLIAnalyticsEventContext object
func (*CLIAnalyticsEventMetadata) SetCommandPath ¶ added in v1.7.4
func (e *CLIAnalyticsEventMetadata) SetCommandPath(commandPath string)
SetCommandPath sets the commandPath on the CLIAnalyticsEventContext object
func (*CLIAnalyticsEventMetadata) SetMachineUUID ¶ added in v1.44.1
func (e *CLIAnalyticsEventMetadata) SetMachineUUID(machineUUID string)
SetMachineUUID sets the persistent machine UUID on the CLIAnalyticsEventContext object
func (*CLIAnalyticsEventMetadata) SetMerchant ¶ added in v1.7.4
func (e *CLIAnalyticsEventMetadata) SetMerchant(merchant string)
SetMerchant sets the merchant on the CLIAnalyticsEventContext object
func (*CLIAnalyticsEventMetadata) SetPluginName ¶ added in v1.41.0
func (e *CLIAnalyticsEventMetadata) SetPluginName(pluginName string)
SetPluginName sets the plugin name on the CLIAnalyticsEventContext object
func (*CLIAnalyticsEventMetadata) SetPluginVersion ¶ added in v1.44.1
func (e *CLIAnalyticsEventMetadata) SetPluginVersion(pluginVersion string)
SetPluginVersion sets the plugin version on the CLIAnalyticsEventContext object
func (*CLIAnalyticsEventMetadata) SetUserAgent ¶ added in v1.7.4
func (e *CLIAnalyticsEventMetadata) SetUserAgent(userAgent string)
SetUserAgent sets the userAgent on the CLIAnalyticsEventContext object
type Client ¶
type Client struct {
// The base URL (protocol + hostname) used for all requests sent by this
// client.
BaseURL *url.URL
// Credentials holds the auth credentials for the request. If Token is
// empty, the Authorization header is omitted.
Credentials Credentials
// When this is enabled, request and response headers will be printed to
// stdout.
Verbose bool
// List of request and response headers that should be printed when Verbose is true.
// Defaults to the standard set of relevant for Stripe headers.
VerbosePrintableHeaders []string
// When true, 3xx responses are returned directly instead of being followed.
NoFollowRedirects bool
// contains filtered or unexported fields
}
Client is the API client used to send requests to Stripe.
type Credentials ¶ added in v1.44.1
Credentials holds the auth credentials for a Stripe API request. For plain API keys only Token is set. For OAK tokens all three fields are populated.
func NewAPIKeyCredentials ¶ added in v1.44.1
func NewAPIKeyCredentials(key string) Credentials
NewAPIKeyCredentials returns Credentials using a standard Stripe API key.
func NewOAKCredentials ¶ added in v1.45.0
func NewOAKCredentials(token, context string, livemode bool) Credentials
NewOAKCredentials returns Credentials for an OAK (User Access Token).
func (Credentials) ApplyAccountContextHeaders ¶ added in v1.45.2
func (c Credentials) ApplyAccountContextHeaders(headers http.Header, account, context string)
ApplyAccountContextHeaders sets Stripe-Account and/or Stripe-Context in headers from the caller-supplied account and context values. For UAT credentials the OAK compartment ID is prepended as "context/value" unless the value already equals the compartment ID. When account is set under UAT, Stripe-Context is intentionally omitted.
func (Credentials) Livemode ¶ added in v1.44.1
func (c Credentials) Livemode() bool
Livemode reports the effective livemode for the credentials. For OAK tokens this is explicit; for plain API keys it is inferred from the key string.
func (Credentials) SetRequestHeaders ¶ added in v1.44.1
func (c Credentials) SetRequestHeaders(req *http.Request)
SetRequestHeaders applies all auth-related headers to req.
type NoOpTelemetryClient ¶ added in v1.7.4
type NoOpTelemetryClient struct {
}
NoOpTelemetryClient does not call any endpoint and returns an empty response
func (*NoOpTelemetryClient) SendAPIRequestEvent ¶ added in v1.7.4
func (a *NoOpTelemetryClient) SendAPIRequestEvent(ctx context.Context, requestID string, livemode bool) (*http.Response, error)
SendAPIRequestEvent does nothing
type RequestPerformer ¶ added in v1.14.1
type RequestPerformer interface {
PerformRequest(ctx context.Context, method, path string, params string, configure func(*http.Request) error) (*http.Response, error)
}
RequestPerformer is an interface for executing requests against the Stripe API, usually satisfied by providing a stripe.Client.
type TelemetryClient ¶ added in v1.7.4
type TelemetryClient interface {
SendAPIRequestEvent(ctx context.Context, requestID string, livemode bool) (*http.Response, error)
SendEvent(ctx context.Context, eventName string, eventValue string)
}
TelemetryClient is an interface that can send two types of events: an API request, and just general events.
func GetTelemetryClient ¶ added in v1.7.4
func GetTelemetryClient(ctx context.Context) TelemetryClient
GetTelemetryClient returns the CLIAnalyticsEventMetadata from the provided context