Back to godoc.org

Package common

v1.1.0
Latest Go to latest

The latest major version is .

Published: Feb 4, 2020 | License: GPL3 | Module: github.com/paysuper/paysuper-checkout

Index

Constants

const (
	Prefix                   = "internal.dispatcher"
	UnmarshalKey             = "dispatcher"
	UnmarshalGlobalConfigKey = "dispatcher.global"
	NoAuthGroupPath          = "/api/v1"
)
const (
	RequestParameterId        = "id"
	RequestParameterOrderId   = "order_id"
	RequestParameterZipUsa    = "zip_usa"
	RequestParameterReceiptId = "receipt_id"

	QueryParameterNameUtmMedium   = "utm_medium"
	QueryParameterNameUtmCampaign = "utm_campaign"
	QueryParameterNameUtmSource   = "utm_source"

	ErrorMessageMask = "field validation for '%s' failed on the '%s' tag"

	HeaderAcceptLanguage      = "Accept-Language"
	HeaderUserAgent           = "User-Agent"
	HeaderXApiSignatureHeader = "X-API-SIGNATURE"
	HeaderReferer             = "referer"

	CustomerTokenCookiesName = "_ps_ctkn"

	ErrorFieldService = "service"
	ErrorFieldMethod  = "method"
	ErrorFieldRequest = "request"

	InternalErrorTemplate = "internal error"

	ValidationParameterOrderId   = "OrderId"
	ValidationParameterOrderUuid = "OrderUuid"
)

Variables

var (
	BinderDefault     = &Binder{}
	EchoBinderDefault = &echo.DefaultBinder{}
)
var (
	ErrorUnknown                       = NewManagementApiResponseError("co000001", "unknown error. try request later")
	ErrorValidationFailed              = NewManagementApiResponseError("co000002", "validation failed")
	ErrorInternal                      = NewManagementApiResponseError("co000003", InternalErrorTemplate)
	ErrorIncorrectOrderId              = NewManagementApiResponseError("co000004", "incorrect order identifier")
	ErrorMessageSignatureHeaderIsEmpty = NewManagementApiResponseError("co000005", "header with request signature can't be empty")
	ErrorRequestParamsIncorrect        = NewManagementApiResponseError("co000006", "incorrect request parameters")
	ErrorRequestDataInvalid            = NewManagementApiResponseError("co000007", "request data invalid")
	ErrorMessageIncorrectZip           = NewManagementApiResponseError("co000008", "incorrect zip code")

	ValidationErrors = map[string]grpc.ResponseErrorMessage{
		ValidationParameterOrderId:   ErrorIncorrectOrderId,
		ValidationParameterOrderUuid: ErrorIncorrectOrderId,
	}
)
var FuncMap = template.FuncMap{
	"Marshal": func(v interface{}) template.JS {
		a, _ := json.Marshal(v)
		return template.JS(a)
	},
}

func CheckProjectAuthRequestSignature

func CheckProjectAuthRequestSignature(dispatch HandlerSet, ctx echo.Context, projectId string) error

CheckProjectAuthRequestSignature

func ExtractBinderContext

func ExtractBinderContext(ctx echo.Context) echo.Binder

ExtractBinderContext

func ExtractRawBodyContext

func ExtractRawBodyContext(ctx echo.Context) []byte

ExtractRawBodyContext

func GetValidationError

func GetValidationError(err error) (rspErr billing.ResponseErrorMessage)

GetValidationError

func LogSrvCallFailedGRPC

func LogSrvCallFailedGRPC(log logger.Logger, err error, name, method string, req interface{})

func NewManagementApiResponseError

func NewManagementApiResponseError(code, msg string, details ...string) grpc.ResponseErrorMessage

NewManagementApiResponseError

func NewValidationError

func NewValidationError(details string) grpc.ResponseErrorMessage

NewValidationError

func RequestResponseHeadersToString

func RequestResponseHeadersToString(headers map[string][]string) string

RequestResponseHeadersToString

func SetBinder

func SetBinder(ctx echo.Context, binder echo.Binder)

SetBinder

func SetRawBodyContext

func SetRawBodyContext(ctx echo.Context, rawBody []byte)

SetRawBodyContext

type Binder

type Binder struct{}

func (*Binder) Bind

func (b *Binder) Bind(i interface{}, ctx echo.Context) (err error)

type Config

type Config struct {
	CookieDomain string `envconfig:"COOKIE_DOMAIN" required:"true"`
	AllowOrigin  string `envconfig:"ALLOW_ORIGIN" default:"*"`

	// OrderInlineFormUrlMask url like a https://checkout.tst.pay.super.com/pay/order/
	OrderInlineFormUrlMask string `envconfig:"ORDER_INLINE_FORM_URL_MASK" required:"true"`

	CustomerTokenCookiesLifetimeHours int64 `envconfig:"CUSTOMER_TOKEN_COOKIES_LIFETIME" default:"720"`
}

type Dictionary

type Dictionary struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type Groups

type Groups struct {
	Common *echo.Group
}

Groups

type Handler

type Handler interface {
	Route(groups *Groups)
}

Handler

type HandlerSet

type HandlerSet struct {
	Services Services
	Validate *validator.Validate
	AwareSet provider.AwareSet
}

HandlerSet

func (HandlerSet) BindAndValidate

func (h HandlerSet) BindAndValidate(req interface{}, ctx echo.Context) *echo.HTTPError

BindAndValidate

func (HandlerSet) SrvCallHandler

func (h HandlerSet) SrvCallHandler(req interface{}, err error, name, method string) *echo.HTTPError

SrvCallHandler returns error if present, otherwise response as JSON with 200 OK

type Handlers

type Handlers []Handler

Handlers

type OrderJsonBinder

type OrderJsonBinder struct{}

func (*OrderJsonBinder) Bind

func (cb *OrderJsonBinder) Bind(i interface{}, ctx echo.Context) (err error)

Bind

type PaymentCreateProcessBinder

type PaymentCreateProcessBinder struct{}

func (*PaymentCreateProcessBinder) Bind

func (cb *PaymentCreateProcessBinder) Bind(i interface{}, ctx echo.Context) (err error)

Bind

type Services

type Services struct {
	Billing billing.BillingService
}

Services

type Template

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

Template

func NewTemplate

func NewTemplate(tpl *template.Template) *Template

NewTemplate

func (*Template) Render

func (t *Template) Render(w io.Writer, name string, data interface{}, c echo.Context) error

Render

type Validator

type Validator interface {
	Use(validator *validator.Validate)
}

Validate

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier