common

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2020 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LibName    = "adyen-go-api-library"
	LibVersion = "1.0.1"
)

Variables

View Source
var (
	// ContextOAuth2 takes an oauth2.TokenSource as authentication for the Request.
	ContextOAuth2 = contextKey("token")

	// ContextBasicAuth takes BasicAuth as authentication for the Request.
	ContextBasicAuth = contextKey("basic")

	// ContextAccessToken takes a string oauth2 access token as authentication for the Request.
	ContextAccessToken = contextKey("accesstoken")

	// ContextAPIKey takes an APIKey as authentication for the Request
	ContextAPIKey = contextKey("apikey")
)
View Source
var ErrInvalidNullable = errors.New("nullable cannot have non-zero Value and ExplicitNull simultaneously")

Functions

func CacheExpires

func CacheExpires(r *http.Response) time.Time

CacheExpires helper function to determine remaining time before repeating a Request.

func PtrBool

func PtrBool(v bool) *bool

PtrBool is a helper routine that returns a pointer to given integer value.

func PtrFloat32

func PtrFloat32(v float32) *float32

PtrFloat32 is a helper routine that returns a pointer to given float value.

func PtrFloat64

func PtrFloat64(v float64) *float64

PtrFloat64 is a helper routine that returns a pointer to given float value.

func PtrInt

func PtrInt(v int) *int

PtrInt is a helper routine that returns a pointer to given integer value.

func PtrInt32

func PtrInt32(v int32) *int32

PtrInt32 is a helper routine that returns a pointer to given integer value.

func PtrInt64

func PtrInt64(v int64) *int64

PtrInt64 is a helper routine that returns a pointer to given integer value.

func PtrString

func PtrString(v string) *string

PtrString is a helper routine that returns a pointer to given string value.

func PtrTime

func PtrTime(v time.Time) *time.Time

PtrTime is helper routine that returns a pointer to given Time value.

func SelectHeaderAccept

func SelectHeaderAccept(accepts []string) string

SelectHeaderAccept join all accept types and return

func SelectHeaderContentType

func SelectHeaderContentType(contentTypes []string) string

SelectHeaderContentType select a content type from the available list.

Types

type APIError

type APIError struct {
	RawBody []byte
	Err     string
	Status  float64
	Message string
	Code    string
	Type    string
}

APIError Provides access to the body, error and model on returned errors.

func NewAPIError

func NewAPIError(body []byte, errMsg string) APIError

NewAPIError returns a new error instance

func (APIError) Error

func (e APIError) Error() string

Error returns non-empty string if there was an error.

type APIKey

type APIKey struct {
	Key    string
	Prefix string
}

APIKey provides API key based authentication to a Request passed via context using ContextAPIKey

type APIResponse

type APIResponse struct {
	*http.Response `json:"-"`
	Message        string `json:"message,omitempty"`
	// Operation is the name of the OpenAPI operation.
	Operation string `json:"operation,omitempty"`
	// RequestURL is the Request URL. This value is always available, even if the
	// embedded *http.Response is nil.
	RequestURL string `json:"url,omitempty"`
	// Method is the HTTP method used for the Request.  This value is always
	// available, even if the embedded *http.Response is nil.
	Method string `json:"method,omitempty"`
	// Payload holds the contents of the Response body (which may be nil or empty).
	// This is provided here as the raw Response.Body() reader will have already
	// been drained.
	Payload []byte `json:"-"`
}

APIResponse stores the API Response returned by the server.

func NewAPIResponse

func NewAPIResponse(r *http.Response) *APIResponse

NewAPIResponse returns a new APIResonse object.

func NewAPIResponseWithError

func NewAPIResponseWithError(errorMessage string) *APIResponse

NewAPIResponseWithError returns a new APIResponse object with the provided error message.

type BasicAuth

type BasicAuth struct {
	UserName string `json:"userName,omitempty"`
	Password string `json:"password,omitempty"`
}

BasicAuth provides basic http authentication to a Request passed via context using ContextBasicAuth

type Client

type Client struct {
	Cfg *Config
}

Client manages communication with the Adyen API In most cases there should be only one, shared, APIClient.

func (*Client) CallAPI

func (c *Client) CallAPI(request *http.Request) (*http.Response, error)

CallAPI do the Request.

func (*Client) Decode

func (c *Client) Decode(v interface{}, b []byte, contentType string) (err error)

func (*Client) MakeHTTPPostRequest

func (c *Client) MakeHTTPPostRequest(req interface{}, res interface{}, path string, ctxs ...context.Context) (*http.Response, error)

MakeHTTPPostRequest is a generic method used to make HTTP POST requests

func (*Client) PrepareRequest

func (c *Client) PrepareRequest(
	ctx context.Context,
	path string, method string,
	postBody interface{},
	headerParams map[string]string,
	queryParams url.Values) (localVarRequest *http.Request, err error)

PrepareRequest build the Request

type Config

type Config struct {
	Username                string        `json:"username,omitempty"`
	Password                string        `json:"password,omitempty"`
	MerchantAccount         string        `json:"merchantAccount,omitempty"`
	Environment             Environment   `json:"environment,omitempty"`
	Endpoint                string        `json:"endpoint,omitempty"`
	MarketPayEndpoint       string        `json:"marketPayEndpoint,omitempty"`
	ApiKey                  string        `json:"apiKey,omitempty"`
	ConnectionTimeoutMillis time.Duration `json:"connectionTimeoutMillis,omitempty"`
	CertificatePath         string        `json:"certificatePath,omitempty"`

	//Checkout Specific
	CheckoutEndpoint string `json:"checkoutEndpoint,omitempty"`

	//Terminal API Specific
	TerminalApiCloudEndpoint string `json:"terminalApiCloudEndpoint,omitempty"`
	TerminalApiLocalEndpoint string `json:"terminalApiLocalEndpoint,omitempty"`
	TerminalCertificatePath  string `json:"terminalCertificatePath,omitempty"`

	LiveEndpointURLPrefix string            `json:"liveEndpointURLPrefix,omitempty"`
	DefaultHeader         map[string]string `json:"defaultHeader,omitempty"`
	Debug                 bool              `json:"debug,omitempty"`
	UserAgent             string            `json:"userAgent,omitempty"`
	HTTPClient            *http.Client
}

Config stores the configuration of the API client

func (*Config) AddDefaultHeader

func (c *Config) AddDefaultHeader(key string, value string)

AddDefaultHeader adds a new HTTP header to the default header in the Request

func (*Config) GetCheckoutEndpoint

func (c *Config) GetCheckoutEndpoint() (string, error)

type Environment

type Environment string
const (
	TestEnv Environment = "TEST"
	LiveEnv Environment = "LIVE"
)

type NullableBool

type NullableBool struct {
	Value        bool
	ExplicitNull bool
}

func (NullableBool) MarshalJSON

func (v NullableBool) MarshalJSON() ([]byte, error)

func (*NullableBool) UnmarshalJSON

func (v *NullableBool) UnmarshalJSON(src []byte) error

type NullableFloat32

type NullableFloat32 struct {
	Value        float32
	ExplicitNull bool
}

func (NullableFloat32) MarshalJSON

func (v NullableFloat32) MarshalJSON() ([]byte, error)

func (*NullableFloat32) UnmarshalJSON

func (v *NullableFloat32) UnmarshalJSON(src []byte) error

type NullableFloat64

type NullableFloat64 struct {
	Value        float64
	ExplicitNull bool
}

func (NullableFloat64) MarshalJSON

func (v NullableFloat64) MarshalJSON() ([]byte, error)

func (*NullableFloat64) UnmarshalJSON

func (v *NullableFloat64) UnmarshalJSON(src []byte) error

type NullableInt

type NullableInt struct {
	Value        int
	ExplicitNull bool
}

func (NullableInt) MarshalJSON

func (v NullableInt) MarshalJSON() ([]byte, error)

func (*NullableInt) UnmarshalJSON

func (v *NullableInt) UnmarshalJSON(src []byte) error

type NullableInt32

type NullableInt32 struct {
	Value        int32
	ExplicitNull bool
}

func (NullableInt32) MarshalJSON

func (v NullableInt32) MarshalJSON() ([]byte, error)

func (*NullableInt32) UnmarshalJSON

func (v *NullableInt32) UnmarshalJSON(src []byte) error

type NullableInt64

type NullableInt64 struct {
	Value        int64
	ExplicitNull bool
}

func (NullableInt64) MarshalJSON

func (v NullableInt64) MarshalJSON() ([]byte, error)

func (*NullableInt64) UnmarshalJSON

func (v *NullableInt64) UnmarshalJSON(src []byte) error

type NullableString

type NullableString struct {
	Value        string
	ExplicitNull bool
}

func (NullableString) MarshalJSON

func (v NullableString) MarshalJSON() ([]byte, error)

func (*NullableString) UnmarshalJSON

func (v *NullableString) UnmarshalJSON(src []byte) error

type NullableTime

type NullableTime struct {
	Value        time.Time
	ExplicitNull bool
}

func (NullableTime) MarshalJSON

func (v NullableTime) MarshalJSON() ([]byte, error)

func (*NullableTime) UnmarshalJSON

func (v *NullableTime) UnmarshalJSON(src []byte) error

type Service

type Service struct {
	Client   *Client
	BasePath func() string
}

Service type is the struct implemented by individual API services

Jump to

Keyboard shortcuts

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