doitpay

package module
v0.0.0-...-8beb111 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2023 License: MIT Imports: 24 Imported by: 0

README

Doitpay Go SDK

The official Doitpay Go SDK offers an easy and user-friendly method to access Doitpay's REST API in applications coded in Go.

  • Package version: 1.0.0

Getting Started

Installation

Install doitpay-go in your Go application:

go get github.com/automotechnologies/doitpay-go

Place the package in your project directory and include the following in the import:

import doitpay "github.com/automotechnologies/doitpay-go"

Authorization

To utilize the SDK, initialize it with your confidential API key which you can get from the Doitpay Dashboard. If you haven't, you can register for a free Dashboard account here.

dtp := doitpay.NewClient("API-KEY")

Documentation

Access comprehensive API details and sample usages for each of our products by following the links provided below.

Read more at:

Contact Us

support@doitpay.co

Documentation

Overview

Package doitpay provides the binding for Doitpay APIs.

Index

Constants

This section is empty.

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")

	// ContextAPIKeys takes a string apikey as authentication for the request
	ContextAPIKeys = contextKey("apiKeys")

	// ContextServerIndex uses a server configuration from the index.
	ContextServerIndex = contextKey("serverIndex")

	// ContextOperationServerIndices uses a server configuration from the index mapping.
	ContextOperationServerIndices = contextKey("serverOperationIndices")

	// ContextServerVariables overrides a server configuration variables.
	ContextServerVariables = contextKey("serverVariables")

	// ContextOperationServerVariables overrides a server configuration variables using operation specific values.
	ContextOperationServerVariables = contextKey("serverOperationVariables")
)

Functions

func CacheExpires

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

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

Types

type APIClient

type APIClient struct {

	// API Services
	BalanceAPI        balance.PublicBalanceAPI
	InvoiceAPI        invoice.PublicInvoiceAPI
	SimulateAPI       simulate.PublicSimulateAPI
	VirtualAccountAPI virtualaccount.PublicVirtualAccountAPI
	// contains filtered or unexported fields
}

APIClient manages communication with the Doitpay API API v1.0 In most cases there should be only one, shared, APIClient.

func NewClient

func NewClient(apiKey string) *APIClient

NewClient creates a new API client. Requires a userAgent string describing your application. optionally a custom http.Client to allow for advanced features such as caching.

func (*APIClient) CallAPI

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

CallAPI do the request.

func (*APIClient) Decode

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

func (*APIClient) GetAPIKey

func (c *APIClient) GetAPIKey() string

Get API Key.

func (*APIClient) GetConfig

func (c *APIClient) GetConfig() common.IConfiguration

Allow modification of underlying config for alternate implementations and testing Caution: modifying the configuration while live can cause data races and potentially unwanted behavior

func (*APIClient) PrepareRequest

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

PrepareRequest build the request

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 APIResponse 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 Configuration

type Configuration struct {
	Host             string            `json:"host,omitempty"`
	Scheme           string            `json:"scheme,omitempty"`
	DefaultHeader    map[string]string `json:"defaultHeader,omitempty"`
	UserAgent        string            `json:"userAgent,omitempty"`
	Debug            bool              `json:"debug,omitempty"`
	Servers          ServerConfigurations
	OperationServers map[string]ServerConfigurations
	HTTPClient       *http.Client
}

Configuration stores the configuration of the API client

func NewConfiguration

func NewConfiguration() *Configuration

NewConfiguration returns a new Configuration object

func (*Configuration) AddDefaultHeader

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

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

func (*Configuration) GetConfig

func (c *Configuration) GetConfig() Configuration

func (*Configuration) ServerURL

func (c *Configuration) ServerURL(index int, variables map[string]string) (string, error)

ServerURL returns URL based on server settings

func (*Configuration) ServerURLWithContext

func (c *Configuration) ServerURLWithContext(ctx context.Context, endpoint string) (string, error)

ServerURLWithContext returns a new server URL given an endpoint

type GenericDoitpayError

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

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

func (GenericDoitpayError) Body

func (e GenericDoitpayError) Body() []byte

Body returns the raw bytes of the response

func (GenericDoitpayError) Error

func (e GenericDoitpayError) Error() string

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

func (GenericDoitpayError) Model

func (e GenericDoitpayError) Model() interface{}

Model returns the unpacked model of the error

type ServerConfiguration

type ServerConfiguration struct {
	URL         string
	Description string
	Variables   map[string]ServerVariable
}

ServerConfiguration stores the information about a server

type ServerConfigurations

type ServerConfigurations []ServerConfiguration

ServerConfigurations stores multiple ServerConfiguration items

func (ServerConfigurations) URL

func (sc ServerConfigurations) URL(index int, variables map[string]string) (string, error)

URL formats template on a index using given variables

type ServerVariable

type ServerVariable struct {
	Description  string
	DefaultValue string
	EnumValues   []string
}

ServerVariable stores the information about a server variable

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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