connectsdk

package module
v0.0.0-...-97c5a11 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: BSD-3-Clause, MIT Imports: 11 Imported by: 16

README

Worldline Connect Go SDK

Introduction

The Go SDK helps you to communicate with the Worldline Connect Server API. Its primary features are:

  • convenient go wrapper around the API calls and responses
    • marshalls Go request structs to HTTP requests
    • unmarshalls HTTP responses to Go response structs or Go exceptions
  • handling of all the details concerning authentication
  • handling of required metadata

Its use is demonstrated by an example for each possible call. The examples execute a call using the provided API keys.

See the Worldline Connect Developer Hub for more information on how to use the SDK.

Requirements

Go version 1.11 or higher is required. No additional packages are required.

Examples

This repository also contains some example code. This code is contained in the examples folder.

Installation

Source

To install the latest version of this repository, run the following command from a terminal:

go get github.com/Worldline-Global-Collect/connect-sdk-go
Release

Go 1.11 added module support and with that support for versions in go get. This means that, if your project uses modules, you can add @version to the go get command to get a specific version. For example, go get github.com/Worldline-Global-Collect/connect-sdk-go@2.9.0 will download version 2.9.0 of the SDK. See the releases page for an overview of available releases.

If your project does not use modules yet, you will need to use the instructions above to install from source. Note that new major versions may introduce breaking changes. We therefore recommend using modules in your project. See Migrating to Go Modules for more information.

Running tests

There are two types of tests: unit tests and integration tests. The unit tests will work out-of-the-box; for the integration tests some configuration is required. First, some environment variables need to be set:

  • connect.api.apiKeyId for the API key id to use. This can be retrieved from the Configuration Center.
  • connect.api.secretApiKey for the secret API key to use. This can be retrieved from the Configuration Center.
  • connect.api.merchantId for your merchant ID.
  • connect.api.proxyUrl for the URL to the proxy to use (optional). If set, it should be in the form scheme://[userinfo@]host[:port]. Examples: http://proxy.example.org, http://user:pass@proxy.example.org, http://proxy.example.org:3128.

The following commands can now be executed from the root directory of the SDK folder to execute the tests:

  • Unit tests:

    go test ./...
    
  • Both unit and integration tests:

    go test -tags=integration  ./...
    

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateCommunicator

func CreateCommunicator(apiKeyID, secretAPIKey, integrator string) (*communicator.Communicator, error)

CreateCommunicator creates a Communicator with default settings and the given apiKeyID and secretAPIKey

func CreateCommunicatorFromConfiguration

func CreateCommunicatorFromConfiguration(conf *configuration.CommunicatorConfiguration) (*communicator.Communicator, error)

CreateCommunicatorFromConfiguration creates a Communicator with the given CommunicatorConfiguration

func CreateCommunicatorWithDefaultMarshaller

func CreateCommunicatorWithDefaultMarshaller(apiEndpoint *url.URL, connection communicator.Connection, authenticator authentication.Authenticator, metadataProvider *communicator.MetadataProvider) (*communicator.Communicator, error)

CreateCommunicatorWithDefaultMarshaller creates a Communicator with the given components and a default marshaller

func CreateV1HMACConfiguration

func CreateV1HMACConfiguration(apiKeyID, secretAPIKey, integrator string) (*configuration.CommunicatorConfiguration, error)

CreateV1HMACConfiguration creates a CommunicatorConfiguration with default v1HMAC settings and the given apiKeyID and secretAPIKey

func NewBool

func NewBool(value bool) *bool

NewBool returns a pointer for a boolean value. This can be used to assign literals to domain or query parameter objets

func NewCallContext

func NewCallContext(idempotenceKey string) *communicator.CallContext

NewCallContext creates a CallContext using the given idempotenceKey

func NewInt32

func NewInt32(value int32) *int32

NewInt32 returns a pointer for an int32 value. This can be used to assign literals to domain or query parameter objets

func NewInt64

func NewInt64(value int64) *int64

NewInt64 returns a pointer for an int64 value. This can be used to assign literals to domain or query parameter objets

func NewString

func NewString(value string) *string

NewString returns a pointer for a string value. This can be used to assign literals to domain or query parameter objets

Types

type Client

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

Client is the Worldline Global Collect platform client. Thread-safe.

This client and all its child clients are bound to one specific value for the X-GCS-ClientMetaInfo header. To get a new client with a different header value, use WithClientMetaInfo.

func CreateClient

func CreateClient(apiKeyID, secretAPIKey, integrator string) (*Client, error)

CreateClient creates a Client with the given CommunicatorConfiguration

func CreateClientFromCommunicator

func CreateClientFromCommunicator(communicator *communicator.Communicator) (*Client, error)

CreateClientFromCommunicator creates a Client with the given Communicator

func CreateClientFromConfiguration

func CreateClientFromConfiguration(config *configuration.CommunicatorConfiguration) (*Client, error)

CreateClientFromConfiguration creates a Client with the given CommunicatorConfiguration

func CreateClientWithDefaultMarshaller

func CreateClientWithDefaultMarshaller(apiEndpoint *url.URL, connection communicator.Connection, authenticator authentication.Authenticator, metadataProvider *communicator.MetadataProvider) (*Client, error)

CreateClientWithDefaultMarshaller creates a Client with the given components and a default marshaller

func NewClient

func NewClient(communicator *communicator.Communicator) (*Client, error)

NewClient creates a new Client with the given communicator

func (*Client) Close

func (c *Client) Close() error

Close calls the internal closer of the communicator

func (*Client) DisableLogging

func (c *Client) DisableLogging()

DisableLogging turns off logging.

func (*Client) EnableLogging

func (c *Client) EnableLogging(communicatorLogger logging.CommunicatorLogger)

EnableLogging turns on logging using the given communicator logger.

func (*Client) SetBodyObfuscator

func (c *Client) SetBodyObfuscator(bodyObfuscator obfuscation.BodyObfuscator)

SetBodyObfuscator sets the body obfuscator to use.

func (*Client) SetHeaderObfuscator

func (c *Client) SetHeaderObfuscator(headerObfuscator obfuscation.HeaderObfuscator)

SetHeaderObfuscator sets the header obfuscator to use.

func (*Client) V1

func (c *Client) V1() *apiv1.Client

V1 represents API v1

func (*Client) WithClientMetaInfo

func (c *Client) WithClientMetaInfo(clientMetaInfo string) (*Client, error)

WithClientMetaInfo returns a new Client which uses the passed metadata for the X-GCS-ClientMetaInfo header.

  • clientMetaInfo is a JSON string containing the metadata for the client
  • can give an error if the given clientMetaInfo is not a valid JSON string

type CommunicatorBuilder

type CommunicatorBuilder struct {
	APIEndpoint      *url.URL
	Connection       communicator.Connection
	MetadataProvider *communicator.MetadataProvider
	Authenticator    authentication.Authenticator
	Marshaller       json.Marshaller
}

CommunicatorBuilder is the builder for Communicator objects

func CreateCommunicatorBuilder

func CreateCommunicatorBuilder(apiKeyID, secretAPIKey, integrator string) (*CommunicatorBuilder, error)

CreateCommunicatorBuilder creates a CommunicatorBuilder with the given CommunicatorConfiguration

func CreateCommunicatorBuilderFromConfiguration

func CreateCommunicatorBuilderFromConfiguration(config *configuration.CommunicatorConfiguration) (*CommunicatorBuilder, error)

CreateCommunicatorBuilderFromConfiguration creates a CommunicatorBuilder with the given CommunicatorConfiguration

func NewCommunicatorBuilder

func NewCommunicatorBuilder() *CommunicatorBuilder

NewCommunicatorBuilder creates a CommunicatorBuilder object

func (*CommunicatorBuilder) Build

Build creates a Communicator object based on the builder parameters

func (*CommunicatorBuilder) WithAPIEndpoint

func (c *CommunicatorBuilder) WithAPIEndpoint(endpoint *url.URL) *CommunicatorBuilder

WithAPIEndpoint sets the Worldline Global Collect platform API endpoint to be used by the Communicator

func (*CommunicatorBuilder) WithAuthenticator

WithAuthenticator sets the Authenticator to be used by the Communicator

func (*CommunicatorBuilder) WithConnection

func (c *CommunicatorBuilder) WithConnection(connection communicator.Connection) *CommunicatorBuilder

WithConnection sets the Connection to be used by the Communicator

func (*CommunicatorBuilder) WithMarshaller

func (c *CommunicatorBuilder) WithMarshaller(marshaller json.Marshaller) *CommunicatorBuilder

WithMarshaller sets the Marshaller to be used by the Communicator

func (*CommunicatorBuilder) WithMetadataProvider

func (c *CommunicatorBuilder) WithMetadataProvider(provider *communicator.MetadataProvider) *CommunicatorBuilder

WithMetadataProvider sets the MetadataProvider to be used by the Communicator

Jump to

Keyboard shortcuts

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