webhook

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ContentTypeJSON is the content type for JSON.
	ContentTypeJSON = "application/json"
	// Default signature header
	DefaultSignatureHeader = "X-Webhook-Signature"
)
View Source
const (
	EventPaymentCreated   = "payment.created"
	EventPaymentPending   = "payment.pending"
	EventPaymentCompleted = "payment.completed"
	EventPaymentFailed    = "payment.failed"
)

Event types

View Source
const (
	TaskFireEvent = "webhook:fire_event"
)

Worker task types

Variables

This section is empty.

Functions

func SignPayload

func SignPayload(payload []byte, secretKey []byte) (string, error)

SignPayload signs a payload using a secret key and returns the signature as a base64 encoded string

func TranslateEventsToWebhookEvents

func TranslateEventsToWebhookEvents(enq webhookEnqueuer) events.Listener

TranslateEventsToWebhookEvents translates the events from the events package to the webhook events.

func VerifySignature

func VerifySignature(payload []byte, signature string, secretKey []byte) error

VerifySignature verifies a signature against a payload using a secret key

Types

type Enqueuer

type Enqueuer struct {
	// contains filtered or unexported fields
}

Enqueuer is a helper struct for enqueuing email tasks.

func NewEnqueuer

func NewEnqueuer(client *asynq.Client, opt ...EnqueuerOption) *Enqueuer

NewEnqueuer creates a new email enqueuer. This function accepts EnqueuerOption to configure the enqueuer. Default values are used if no option is provided. Default values are:

  • queue name: "default"
  • task deadline: 1 minute
  • max retry: 3

func (*Enqueuer) FireEvent

func (e *Enqueuer) FireEvent(ctx context.Context, event string, payload interface{}) error

FireEvent enqueues a task to fire an event. This function returns an error if the task could not be enqueued.

type EnqueuerOption

type EnqueuerOption func(*Enqueuer)

EnqueuerOption is a function that configures an enqueuer.

func WithMaxRetry

func WithMaxRetry(n int) EnqueuerOption

WithMaxRetry configures the max retry.

func WithQueueName

func WithQueueName(name string) EnqueuerOption

WithQueueName configures the queue name.

func WithTaskDeadline

func WithTaskDeadline(d time.Duration) EnqueuerOption

WithTaskDeadline configures the task deadline.

type FireEventPayload

type FireEventPayload struct {
	Event   string      `json:"event"`
	Payload interface{} `json:"payload"`
}

FireEventPayload is the payload for the webhook:fire_event task.

type PaymentData

type PaymentData struct {
	PaymentID  string        `json:"payment_id"`      // The ID of the payment
	ExternalID string        `json:"external_id"`     // The ID of the payment in your system. E.g. the order ID, etc.
	Amount     uint64        `json:"amount"`          // The amount of the payment in base units (e.g. lamports, etc.)
	Currency   string        `json:"currency"`        // The currency of the payment: SOL, USDC, or any token mint address.
	Status     string        `json:"status"`          // The status of the payment: new, pending, completed, or failed.
	CreatedAt  string        `json:"created_at"`      // The time the payment was created.
	TxID       string        `json:"tx_id,omitempty"` // The transaction ID of the payment.
	Err        *PaymentError `json:"error,omitempty"` // The error details if the payment failed.
}

Payment data payload

type PaymentError

type PaymentError struct {
	Code    string `json:"code"`
	Message string `json:"message"`
	Details string `json:"details"`
}

Payment error payload

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is the webhook service implementation.

func NewService

func NewService(opts ...ServiceOption) *Service

NewService creates a new webhook service.

func (*Service) FireEvent

func (s *Service) FireEvent(event string, payload interface{}) error

FireEvent sends a webhook event to the webhook url.

func (*Service) Send

func (s *Service) Send(url string, payload interface{}) (*http.Response, error)

Send post request to webhook url with payload.

type ServiceOption

type ServiceOption func(*Service)

ServiceOption is a function that configures the webhook service.

func WithHTTPClient

func WithHTTPClient(client *http.Client) ServiceOption

WithHTTPClient configures the webhook service with a custom HTTP client.

func WithSignatureHeader

func WithSignatureHeader(header string) ServiceOption

WithSignatureHeader configures the webhook service with a custom signature header.

func WithSignatureSecret

func WithSignatureSecret(secret []byte) ServiceOption

WithSignatureSecret configures the webhook service with a custom signature secret.

func WithWebhookURI

func WithWebhookURI(uri string) ServiceOption

WithWebhookURI configures the webhook service with a custom webhook URI.

type WebhookRequestPayload

type WebhookRequestPayload struct {
	Event     string      `json:"event"`                // The name of the event that triggered the webhook
	EventID   string      `json:"event_id,omitempty"`   // The ID of the event that triggered the webhook
	WebhookID string      `json:"webhook_id,omitempty"` // The ID of the webhook that triggered the webhook
	Data      interface{} `json:"data"`                 // The data associated with the event that triggered the webhook
}

Webhook request payload

type Worker

type Worker struct {
	// contains filtered or unexported fields
}

Worker is a task handler for email delivery.

func NewWorker

func NewWorker(svc service) *Worker

NewWorker creates a new email task handler.

func (*Worker) FireEvent

func (w *Worker) FireEvent(ctx context.Context, t *asynq.Task) error

FireEvent sends a webhook event to the specified URL.

func (*Worker) Register

func (w *Worker) Register(mux *asynq.ServeMux)

Register registers task handlers for email delivery.

Jump to

Keyboard shortcuts

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