Documentation ¶
Index ¶
- Constants
- func SignPayload(payload []byte, secretKey []byte) (string, error)
- func TranslateEventsToWebhookEvents(enq webhookEnqueuer) events.Listener
- func VerifySignature(payload []byte, signature string, secretKey []byte) error
- type Enqueuer
- type EnqueuerOption
- type FireEventPayload
- type PaymentData
- type PaymentError
- type Service
- type ServiceOption
- type WebhookRequestPayload
- type Worker
Constants ¶
const ( // ContentTypeJSON is the content type for JSON. ContentTypeJSON = "application/json" // Default signature header DefaultSignatureHeader = "X-Webhook-Signature" )
const ( EventPaymentCreated = "payment.created" EventPaymentPending = "payment.pending" EventPaymentCompleted = "payment.completed" EventPaymentFailed = "payment.failed" )
Event types
const (
TaskFireEvent = "webhook:fire_event"
)
Worker task types
Variables ¶
This section is empty.
Functions ¶
func SignPayload ¶
SignPayload signs a payload using a secret key and returns the signature as a base64 encoded string
func TranslateEventsToWebhookEvents ¶
TranslateEventsToWebhookEvents translates the events from the events package to the webhook events.
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
type EnqueuerOption ¶
type EnqueuerOption func(*Enqueuer)
EnqueuerOption is a function that configures an enqueuer.
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.
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