v1

package
v0.0.0-...-b3f3fbb Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2015 License: Apache-2.0 Imports: 37 Imported by: 1

Documentation

Overview

Package v1 provides API functionality for the version:

1.x

Index

Constants

View Source
const (
	// AuthLifetime is the duration for which an authorization is considered valid
	// TODO @configure
	AuthLifetime = 15 * time.Minute
	// AuthUserIDKey is the key for the user ID entry in the authorization container
	AuthUserIDKey = "userID"
	// AuthCookieName is the cookie name for cookie-based authentication
	AuthCookieName = "auth"
)
View Source
const (
	StatusImplementationError = "implementationError"
	StatusUnauthorized        = "unauthorized"
	StatusError               = "error"
	StatusSuccess             = "success"
)
View Source
const (
	// APIVersion is the current version of the API
	//
	// Version history:
	//
	//   - 1.2: Deprecating "Error" field. Will be removed in version 2
	//
	//   - 1.1: Include version number in service response
	APIVersion = "1.2"
)
View Source
const Debug = false

Debug flag whether debugging is turned on

View Source
const (

	// ServicePath is the (sub-)path under which the API service v1.x resides in
	ServicePath = "/" + serviceVersion
)

Variables

View Source
var (
	ErrReadJson = ServiceResponse{
		http.StatusBadRequest,
		APIVersion,
		StatusImplementationError,
		"could not read request",
		nil,
		nil,
	}
	ErrUnauthorized = ServiceResponse{
		http.StatusUnauthorized,
		APIVersion,
		StatusUnauthorized,
		"unauthorized",
		nil,
		nil,
	}
	ErrDatabase = ServiceResponse{
		http.StatusInternalServerError,
		APIVersion,
		StatusError,
		"database error",
		nil,
		nil,
	}
	ErrSystem = ServiceResponse{
		http.StatusInternalServerError,
		APIVersion,
		StatusError,
		"internal error",
		nil,
		nil,
	}
	ErrInval = ServiceResponse{
		http.StatusBadRequest,
		APIVersion,
		StatusImplementationError,
		"invalid value",
		nil,
		nil,
	}
	ErrNotFound = ServiceResponse{
		http.StatusNotFound,
		APIVersion,
		StatusError,
		"resource not found",
		nil,
		nil,
	}
	ErrConflict = ServiceResponse{
		http.StatusConflict,
		APIVersion,
		StatusError,
		"resource already exits",
		nil,
		nil,
	}
	ErrReadParam = ServiceResponse{
		http.StatusBadRequest,
		APIVersion,
		StatusError,
		"parameter malformed",
		nil,
		nil,
	}
	ErrMethod = ServiceResponse{
		http.StatusMethodNotAllowed,
		APIVersion,
		StatusError,
		"method not allowed",
		nil,
		nil,
	}
)

default service responses

View Source
var Log log15.Logger

Log is the default logger for the API service v1

Functions

This section is empty.

Types

type AdminAPI

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

API represents the admin API in version 1.x

func NewAdminAPI

func NewAdminAPI(ctx *service.Context) *AdminAPI

NewAPI creates a new admin API

func (*AdminAPI) AuthHandler

func (a *AdminAPI) AuthHandler(success, failed http.Handler) http.Handler

AuthHandler wraps the given handler with an authorization method using the Authorization Header and the authorization container

When the request can be authorized, the success handler will be called, otherwise the failed handler will be called

func (*AdminAPI) AuthRequiredHandler

func (a *AdminAPI) AuthRequiredHandler(parent http.Handler) http.Handler

AuthRequiredHandler wraps the given handler with an authorization method using the Authorization Header and the authorization container

A failed authorization will lead to a http.StatusUnauthorized header

func (*AdminAPI) AuthorizationHandler

func (a *AdminAPI) AuthorizationHandler() http.Handler

AuthorizationHandler implements /authorization requests

func (*AdminAPI) AuthorizeHandler

func (a *AdminAPI) AuthorizeHandler() http.Handler

AuthorizeHandler handles new authorizations

func (*AdminAPI) CurrencyGetAllRequest

func (a *AdminAPI) CurrencyGetAllRequest() http.Handler

return a handler brokering get a currency

func (*AdminAPI) CurrencyGetRequest

func (a *AdminAPI) CurrencyGetRequest() http.Handler

return a handler brokering get all currencies

func (*AdminAPI) GetUserID

func (a *AdminAPI) GetUserID() http.Handler

GetUserID returns a utility handler. This endpoint displays the user ID, which is stored in the authorization container

func (*AdminAPI) PaymentMethodGetRequest

func (a *AdminAPI) PaymentMethodGetRequest() http.Handler

func (*AdminAPI) PaymentMethodRequest

func (a *AdminAPI) PaymentMethodRequest() http.Handler

handler to create or change a principal

PUT creates new principal POST can be used to change the principals metadata

func (*AdminAPI) PrincipalNameRequest

func (a *AdminAPI) PrincipalNameRequest() http.Handler

func (*AdminAPI) PrincipalRequest

func (a *AdminAPI) PrincipalRequest() http.Handler

handler to create or change a principal

PUT creates new principal POST can be used to change the principals metadata

func (*AdminAPI) ProjectGetRequest

func (a *AdminAPI) ProjectGetRequest() http.Handler

return a hanlder to get project items

func (*AdminAPI) ProjectRequest

func (a *AdminAPI) ProjectRequest() http.Handler

return a handler to add and manipulate projects

func (*AdminAPI) ProviderGetAllRequest

func (a *AdminAPI) ProviderGetAllRequest() http.Handler

return a handler brokering get a provider

func (*AdminAPI) ProviderGetRequest

func (a *AdminAPI) ProviderGetRequest() http.Handler

return a handler brokering get provider by give id

type AdminAPIResponse

type AdminAPIResponse struct {
	ServiceResponse
}

type used for formated AdminAPI Responses

type CurrencyAdminAPIResponse

type CurrencyAdminAPIResponse struct {
	AdminAPIResponse
}

type GetCredentialsResponse

type GetCredentialsResponse struct {
	Authorization string
}

GetCredentialsResponse is the response for all GET /user/credentials requests ready to be JSON-encoded

type GetPaymentRequest

type GetPaymentRequest struct {
	ProjectKey string
	PaymentId  string

	Ident     string
	Timestamp int64
	Nonce     string
	// contains filtered or unexported fields
}

GetPaymentRequest represents a get payment request

func (*GetPaymentRequest) HashFunc

func (r *GetPaymentRequest) HashFunc() func() hash.Hash

func (*GetPaymentRequest) Message

func (r *GetPaymentRequest) Message() ([]byte, error)

func (*GetPaymentRequest) ReadFromRequest

func (r *GetPaymentRequest) ReadFromRequest(req *http.Request) error

func (*GetPaymentRequest) RequestProjectKey

func (r *GetPaymentRequest) RequestProjectKey() string

func (*GetPaymentRequest) Signature

func (r *GetPaymentRequest) Signature() ([]byte, error)

func (*GetPaymentRequest) Time

func (r *GetPaymentRequest) Time() time.Time

type InitPaymentRequest

type InitPaymentRequest struct {
	ProjectKey string
	Ident      string
	Amount     jsonutil.RequiredInt64
	Subunits   jsonutil.RequiredInt8
	Currency   string
	Country    string

	PaymentMethodID    int64  `json:"PaymentMethodId,string"`
	Locale             string `json:",omitempty"`
	CallbackURL        string `json:",omitempty"`
	CallbackAPIVersion string `json:",omitempty"`
	CallbackProjectKey string `json:",omitempty"`
	ReturnURL          string `json:",omitempty"`
	Expires            int64  `json:",string,omitempty"`

	Metadata map[string]string

	Timestamp int64 `json:",string"`
	Nonce     string

	HexSignature string `json:"Signature"`
	// contains filtered or unexported fields
}

InitPaymentRequest is the request JSON struct for POST /payment

func (*InitPaymentRequest) HashFunc

func (r *InitPaymentRequest) HashFunc() func() hash.Hash

HashFunc returns the hash function used to generate a signature

func (*InitPaymentRequest) Message

func (r *InitPaymentRequest) Message() ([]byte, error)

Return the signature base string (msg)

func (*InitPaymentRequest) PopulatePaymentFields

func (r *InitPaymentRequest) PopulatePaymentFields(p *payment.Payment)

func (*InitPaymentRequest) ReadJSON

func (r *InitPaymentRequest) ReadJSON(rd io.Reader) error

func (*InitPaymentRequest) RequestProjectKey

func (r *InitPaymentRequest) RequestProjectKey() string

func (*InitPaymentRequest) Signature

func (r *InitPaymentRequest) Signature() ([]byte, error)

Return the (binary) signature from the request

implementing AuthenticatedRequest

func (*InitPaymentRequest) Time

func (r *InitPaymentRequest) Time() time.Time

func (*InitPaymentRequest) Validate

func (r *InitPaymentRequest) Validate() error

Validate input

type InitPaymentResponse

type InitPaymentResponse struct {
	Confirmation struct {
		Ident    string
		Amount   int64 `json:",string"`
		Subunits int8  `json:",string"`
		Currency string
		Country  string

		PaymentMethodID    int64             `json:"PaymentMethodId,string,omitempty"`
		Locale             string            `json:",omitempty"`
		CallbackURL        string            `json:",omitempty"`
		CallbackAPIVersion string            `json:",omitempty"`
		CallbackProjectKey string            `json:",omitempty"`
		ReturnURL          string            `json:",omitempty"`
		Expires            int64             `json:",string,omitempty"`
		Metadata           map[string]string `json:",omitempty"`
	}
	Payment struct {
		PaymentId payment.PaymentID
		// RFC3339 date/time string
		Created     string
		Token       string
		RedirectURL string `json:",omitempty"`
	}
	Timestamp int64 `json:",string"`
	Nonce     string
	Signature string
}

InitPaymentResponse is the JSON response struct for POST /payment

func (*InitPaymentResponse) ConfirmationFromPayment

func (r *InitPaymentResponse) ConfirmationFromPayment(p *payment.Payment)

ConfirmationFromPayment populates the response "Confirmation" object with the fields from the given payment

func (*InitPaymentResponse) HashFunc

func (r *InitPaymentResponse) HashFunc() func() hash.Hash

HashFunc returns the hash function for signing an init payment response

func (*InitPaymentResponse) Message

func (r *InitPaymentResponse) Message() ([]byte, error)

Returns the signature base string

implementing SignableMessage

type PaymentAPI

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

API represents the payment API in the version 1.x

func NewPaymentAPI

func NewPaymentAPI(ctx *service.Context) (*PaymentAPI, error)

NewAPI creates a new payment API

func (*PaymentAPI) GetPayment

func (a *PaymentAPI) GetPayment() http.Handler

func (*PaymentAPI) InitPayment

func (a *PaymentAPI) InitPayment() http.Handler

type PaymentMethodRequest

type PaymentMethodRequest struct {
	MethodKey string
	Provider  string
	Status    string
	CreatedBy string
	Metadata  map[string]string
}

PaymentMethodRequest is the request JSON struct for POST - PUT project/(id)/method/

type PrincipalAdminAPIResponse

type PrincipalAdminAPIResponse struct {
	AdminAPIResponse
}

type ProjectAdminAPIResponse

type ProjectAdminAPIResponse struct {
	AdminAPIResponse
}

type ProjectKeyRequester

type ProjectKeyRequester interface {
	service.Signed
	RequestProjectKey() string
	Time() time.Time
}

type ProviderAdminAPIResponse

type ProviderAdminAPIResponse struct {
	AdminAPIResponse
}

type Service

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

Service represents the API service version 1.x

func NewService

func NewService(ctx *service.Context, mux *mux.Router) (*Service, error)

NewService creates a new API service It requires a valid service context and takes a router to which the service routes will be attached

type ServiceResponse

type ServiceResponse struct {
	HttpStatus int `json:"-"`
	Version    string
	Status     string
	Info       string
	Response   interface{}
	Error      interface{}
}

ServiceResponse represents a general response container for (payment-related) API requests

func (*ServiceResponse) Write

type UserAdminAPIResponse

type UserAdminAPIResponse struct {
	AdminAPIResponse
}

Jump to

Keyboard shortcuts

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