webhooks

package
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 1, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var WebhookSubscriptions = []string{
	"user.created",
	"quota.reached",
	"subscription.created",
	"subscription.updated",
	"subscription.deleted",
	"ping",
}

Functions

This section is empty.

Types

type KobbleWebhooks

type KobbleWebhooks struct{}

KobbleWebhooks is a struct that provides methods to work with webhooks.

func NewKobbleWebhooks

func NewKobbleWebhooks() *KobbleWebhooks

NewKobbleWebhooks creates a new instance of the KobbleWebhooks struct.

func (*KobbleWebhooks) ConstructEvent added in v1.0.4

func (k *KobbleWebhooks) ConstructEvent(body any, signature string, secret string) (WebhookEvent, error)

ConstructEvent construct a webhook event payload and verify its integrity. The `body` parameter is eventually serialized to a `Buffer` object in order to compute the signature. A `Buffer` can therefore be passed directly, but other types are accepted as well:

  • A Go struct is serialized using `json.Marshal`.
  • For any other type, native string conversion is attempted. The result is assumed to be UTF-8 encoded.

The expected `signature` is the one sent in the webhook header `Kobble-Signature`. The `secret` is the one associated with the webhook expected to receive the event. The fully typesafe payload is returned if the signature is valid.

type WebhookEvent

type WebhookEvent struct {
	Type string `json:"type"`
	Data any    `json:"data"`
}

type WebhookPingData

type WebhookPingData struct {
	WebhookID string `json:"webhook_id"`
}

type WebhookPingEvent

type WebhookPingEvent struct {
	Type string          `json:"type"`
	Data WebhookPingData `json:"data"`
}

type WebhookQuotaReachedData

type WebhookQuotaReachedData struct {
	QuotaID   string `json:"quota_id"`
	QuotaName string `json:"quota_name"`
	Usage     int    `json:"usage"`
	Limit     int    `json:"limit"`
	UserID    string `json:"user_id"`
}

type WebhookQuotaReachedEvent

type WebhookQuotaReachedEvent struct {
	Type string                  `json:"type"`
	Data WebhookQuotaReachedData `json:"data"`
}

type WebhookSubscription

type WebhookSubscription string

type WebhookSubscriptionCreatedEvent

type WebhookSubscriptionCreatedEvent struct {
	Type string                  `json:"type"`
	Data WebhookSubscriptionData `json:"data"`
}

type WebhookSubscriptionData

type WebhookSubscriptionData struct {
	Provider struct {
		SubscriptionID string `json:"subscription_id"`
		ProductID      string `json:"product_id"`
		PriceID        string `json:"price_id"`
	} `json:"provider"`
	ProjectID         string  `json:"project_id"`
	ProductID         string  `json:"product_id"`
	PriceID           string  `json:"price_id"`
	UserID            string  `json:"user_id"`
	Email             string  `json:"email"`
	StartDate         *string `json:"start_date,omitempty"`
	EndedAt           *string `json:"ended_at,omitempty"`
	CancelAt          *string `json:"cancel_at,omitempty"`
	CanceledAt        *string `json:"canceled_at,omitempty"`
	CancelAtPeriodEnd bool    `json:"cancel_at_period_end"`
	Status            string  `json:"status"`
	TrialEnd          *string `json:"trial_end,omitempty"`
	TrialStart        *string `json:"trial_start,omitempty"`
}

type WebhookSubscriptionDeletedEvent

type WebhookSubscriptionDeletedEvent struct {
	Type string                  `json:"type"`
	Data WebhookSubscriptionData `json:"data"`
}

type WebhookSubscriptionUpdatedEvent

type WebhookSubscriptionUpdatedEvent struct {
	Type string                  `json:"type"`
	Data WebhookSubscriptionData `json:"data"`
}

type WebhookUserCreatedData

type WebhookUserCreatedData struct {
	ID         string  `json:"id"`
	Email      string  `json:"email"`
	Name       *string `json:"name,omitempty"`
	CreatedAt  string  `json:"created_at"`
	IsVerified bool    `json:"is_verified"`
}

type WebhookUserCreatedEvent

type WebhookUserCreatedEvent struct {
	Type string                 `json:"type"`
	Data WebhookUserCreatedData `json:"data"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL