server

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: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidRequest   = errors.New("invalid_request")
	ErrInvalidParameter = errors.New("invalid_parameter")
	ErrForbidden        = errors.New("forbidden")
	ErrNotFound         = errors.New("not_found")
)

Predefined errors.

Error codes map

View Source
var ErrorMessages = map[error]string{
	ErrInvalidRequest:   "Invalid request payload",
	ErrInvalidParameter: "Some parameters are invalid",
	ErrForbidden:        "Forbidden. You don't have permission to access this account",
	ErrNotFound:         "Not found",
}

Error messages

Functions

func MakeHTTPHandler

func MakeHTTPHandler(e Endpoints, log logger, authMdw middlewareFunc) http.Handler

MakeHTTPHandler returns an http.Handler that can be used to serve the API.

func NewError

func NewError(err error) *httpencoder.ErrorResponse

NewError creates a new error

Types

type Config

type Config struct {
	AppName    string // AppName is the name of the application to be displayed in the payment page and wallet.
	AppIconURI string // AppIconURI is the URI of the application icon to be displayed in the payment page and wallet.
}

type CreatePaymentRequest

type CreatePaymentRequest struct {
	ExternalID string `json:"external_id,omitempty" validate:"min_len:1|max_len:50"`
	Amount     uint64 `json:"amount,omitempty" validate:"required|gt:0"`
	Message    string `json:"message,omitempty" validate:"min_len:2|max_len:100"`
	TTL        int64  `json:"ttl,omitempty" validate:"min:0|max:86400"`
}

CreatePaymentRequest is the request type for the CreatePayment method. For more information about the fields, see the struct definition in payment/payment.go.CreatePaymentParams

type CreatePaymentResponse

type CreatePaymentResponse struct {
	Payment *payments.Payment `json:"payment"`
}

CreatePaymentResponse is the response type for the CreatePayment method.

type Endpoints

type Endpoints struct {
	GetAppInfo                 endpoint.Endpoint
	CreatePayment              endpoint.Endpoint
	CancelPayment              endpoint.Endpoint
	GetPayment                 endpoint.Endpoint
	GetPaymentByExternalID     endpoint.Endpoint
	GeneratePaymentLink        endpoint.Endpoint
	GeneratePaymentTransaction endpoint.Endpoint
	GetExchangeRate            endpoint.Endpoint
}

Endpoints is a collection of all the endpoints that comprise a server.

func MakeEndpoints

func MakeEndpoints(ps paymentService, jup jupiterClient, cfg Config) Endpoints

MakeEndpoints returns an Endpoints struct where each field is an endpoint that comprises the server.

type GeneratePaymentLinkRequest

type GeneratePaymentLinkRequest struct {
	PaymentID  uuid.UUID `json:"-" validate:"-" label:"Payment ID"`
	Mint       string    `json:"mint,omitempty" validate:"-" label:"Selected Mint"`
	ApplyBonus bool      `json:"apply_bonus,omitempty" validate:"bool" label:"Apply Bonus"`
}

GeneratePaymentLinkRequest is the request type for the GeneratePaymentLink method.

type GeneratePaymentLinkResponse

type GeneratePaymentLinkResponse struct {
	Link string `json:"link"`
}

GeneratePaymentLinkResponse is the response type for the GeneratePaymentLink method.

type GeneratePaymentTransactionRequest

type GeneratePaymentTransactionRequest struct {
	PaymentID    string `json:"-" validate:"required|uuid" label:"Payment ID"`
	SourceWallet string `json:"account" validate:"required" label:"Account public key"`
	Mint         string `json:"-" validate:"-"`
	ApplyBonus   string `json:"-" validate:"bool"`
}

GeneratePaymentTransactionRequest is the request type for the GeneratePaymentTransaction method.

type GeneratePaymentTransactionResponse

type GeneratePaymentTransactionResponse struct {
	Transaction string `json:"transaction"`
	Message     string `json:"message,omitempty"`
}

GeneratePaymentTransactionResponse is the response type for the GeneratePaymentTransaction method.

type GetAppInfoResponse

type GetAppInfoResponse struct {
	Label string `json:"label"`
	Icon  string `json:"icon"`
}

GetAppInfoResponse is the response type for the GetAppInfo method.

type GetExchangeRateRequest

type GetExchangeRateRequest struct {
	InCurrency  string `json:"in_currency" validate:"required" label:"In Currency"`
	OutCurrency string `json:"out_currency" validate:"required" label:"Out Currency"`
	Amount      uint64 `json:"amount" validate:"required|gte:0" label:"Amount"`
	SwapMode    string `json:"swap_mode" validate:"required|in:ExactIn,ExactOut" label:"Swap Mode"`
}

GetExchangeRateRequest is the request type for the GetExchangeRate method.

type GetExchangeRateResponse

type GetExchangeRateResponse struct {
	ExchangeRate jupiter.Rate `json:"exchange_rate"`
}

GetExchangeRateResponse is the response type for the GetExchangeRate method.

type GetPaymentResponse

type GetPaymentResponse struct {
	Payment     *payments.Payment     `json:"payment"`
	Transaction *payments.Transaction `json:"transaction,omitempty"`
}

GetPaymentResponse is the response type for the GetPayment method.

Jump to

Keyboard shortcuts

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