checkout

package module
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2020 License: MIT Imports: 7 Imported by: 0

README ¶

Checkout.com Go

Status

The official Checkout Go client library.

🚀 Installation

Make sure your project is using Go Modules (it will have a go.mod file in its root if it already is):

go mod init

Then, reference checkout-sdk-go in a Go program with import:

import (
    "github.com/checkout/checkout-sdk-go"
)

Run any of the normal go commands (build/install/test). The Go toolchain will resolve and fetch the checkout-sdk-go module automatically.

📖 Documentation

You can see the SDK documentation here.

For details on all the functionality in this library, see the GoDoc documentation.

Below are a few simple examples:

Tokens
import (
    "github.com/checkout/checkout-sdk-go"
    uuid "github.com/google/uuid"
)

idempotencyKey := uuid.New().String()
config, err := checkout.Create(secretKey, true, &publicKey, &idempotencyKey)
if err != nil {
    return
}
var client = tokens.NewClient(*config)
var card = &tokens.Card{
    Type:        common.Card,
    Number:      "4242424242424242",
    ExpiryMonth: 2,
    ExpiryYear:  2022,
    Name:        "Customer Name",
    CVV:         "100",
}
var request = &tokens.Request{
    Card: card,
}
response, err := client.Request(request)
Payments
import (
    "github.com/checkout/checkout-sdk-go"
    "github.com/checkout/checkout-sdk-go/payments"
    uuid "github.com/google/uuid"
)

idempotencyKey := uuid.New().String()
config, err := checkout.Create(secretKey, true, &publicKey, &idempotencyKey)
if err != nil {
    return
}
var client = payments.NewClient(*config)
var source = payments.TokenSource{
    Type:  common.Token.String(),
    Token: "tok_",
}
var request = &payments.Request{
    Source:   source,
    Amount:   "100",
    Currency: "USD",
    Reference: "Payment Reference",
    Customer: &payments.Customer{
        Email: "example@email.com",
        Name:  "First Name Last Name",
    },
    Metadata: map[string]string{
        "udf1": "User Define",
    },
}
response, err := client.Request(request)
Payment Detail
import (
    "github.com/checkout/checkout-sdk-go"
    "github.com/checkout/checkout-sdk-go/payments"
    uuid "github.com/google/uuid"
)

idempotencyKey := uuid.New().String()
config, err := checkout.Create(secretKey, true, &publicKey, &idempotencyKey)
if err != nil {
    return
}
var client = payments.NewClient(*config)
response, err := client.Get("pay_")
Actions
import (
    "github.com/checkout/checkout-sdk-go"
    "github.com/checkout/checkout-sdk-go/payments"
    uuid "github.com/google/uuid"
)

idempotencyKey := uuid.New().String()
config, err := checkout.Create(secretKey, true, &publicKey, &idempotencyKey)
if err != nil {
    return
}
var client = payments.NewClient(*config)
response, err := client.Actions("pay_")
Captures
import (
    "github.com/checkout/checkout-sdk-go"
    "github.com/checkout/checkout-sdk-go/payments"
    uuid "github.com/google/uuid"
)

idempotencyKey := uuid.New().String()
config, err := checkout.Create(secretKey, true, &publicKey, &idempotencyKey)
if err != nil {
    return
}
var client = payments.NewClient(*config)
request := &payments.CapturesRequest{
    Amount:    100,
    Reference: "Reference",
    Metadata: map[string]string{
        "udf1": "User Define",
    },
}
response, err := client.Captures("pay_", request)
Voids
import (
    "github.com/checkout/checkout-sdk-go"
    "github.com/checkout/checkout-sdk-go/payments"
    uuid "github.com/google/uuid"
)

idempotencyKey := uuid.New().String()
config, err := checkout.Create(secretKey, true, &publicKey, &idempotencyKey)
if err != nil {
    return
}
var client = payments.NewClient(*config)
request := &payments.VoidsRequest{
    Reference: "Reference",
    Metadata: map[string]string{
        "udf1": "User Define",
    },
}
response, err := client.Voids("pay_", request)
Refunds
import (
    "github.com/checkout/checkout-sdk-go"
    "github.com/checkout/checkout-sdk-go/payments"
    uuid "github.com/google/uuid"
)

idempotencyKey := uuid.New().String()
config, err := checkout.Create(secretKey, true, &publicKey, &idempotencyKey)
if err != nil {
    return
}
var client = payments.NewClient(*config)
request := &payments.RefundsRequest{
    Amount:    100,
    Reference: "Reference",
    Metadata: map[string]string{
        "udf1": "User Define",
    },
}
response, err := client.Refunds("pay_", request)

For any requests, bug or comments, please open an issue or submit a pull request.

Documentation ¶

Index ¶

Constants ¶

View Source
const ClientVersion = "0.0.1"

ClientVersion ...

Variables ¶

View Source
var DefaultConfig = Config{
	URI: sandboxURI,
}

DefaultConfig ...

Functions ¶

func Bool ¶

func Bool(v bool) *bool

Bool returns a pointer to the bool value passed in.

func BoolSlice ¶

func BoolSlice(v []bool) []*bool

BoolSlice returns a slice of bool pointers given a slice of bools.

func BoolValue ¶

func BoolValue(v *bool) bool

BoolValue returns the value of the bool pointer passed in or false if the pointer is nil.

func Float64 ¶

func Float64(v float64) *float64

Float64 returns a pointer to the float64 value passed in.

func Float64Slice ¶

func Float64Slice(v []float64) []*float64

Float64Slice returns a slice of float64 pointers given a slice of float64s.

func Float64Value ¶

func Float64Value(v *float64) float64

Float64Value returns the value of the float64 pointer passed in or 0 if the pointer is nil.

func NewIdempotencyKey ¶

func NewIdempotencyKey() string

NewIdempotencyKey -

func String ¶

func String(v string) *string

String returns a pointer to the string value passed in.

func StringSlice ¶

func StringSlice(v []string) []*string

StringSlice returns a slice of string pointers given a slice of strings.

func StringValue ¶

func StringValue(v *string) string

StringValue returns the value of the string pointer passed in or "" if the pointer is nil.

Types ¶

type Config ¶

type Config struct {
	PublicKey         string
	SecretKey         string
	URI               string
	IdempotencyKey    *string
	CancellationToken string
}

Config ...

func Create ¶

func Create(secretKey string, useSandbox bool, publicKey *string, idempotencyKey *string) (*Config, error)

Create ...

type HTTPClient ¶

type HTTPClient interface {
	Get(param string) (*StatusResponse, error)
	Post(param string, request interface{}) (*StatusResponse, error)
	Put(param string, request interface{}) (*StatusResponse, error)
	Patch(param string, request interface{}) (*StatusResponse, error)
	Delete(param string) (*StatusResponse, error)
	Upload(param, boundary string, body *bytes.Buffer) (*StatusResponse, error)
	Download(path string) (*StatusResponse, error)
}

HTTPClient ...

type Headers ¶

type Headers struct {
	CKORequestID *string `json:"cko-request-id,omitempty"`
	CKOVersion   *string `json:"cko-version,omitempty"`
}

Headers ...

type StatusResponse ¶

type StatusResponse struct {
	Status       string     `json:"status,omitempty"`
	StatusCode   int        `json:"status_code,omitempty"`
	ResponseBody []byte     `json:"response_body,omitempty"`
	ResponseCSV  [][]string `json:"response_csv,omitempty"`
	Headers      *Headers   `json:"headers,omitempty"`
}

StatusResponse ...

Directories ¶

Path Synopsis

Jump to

Keyboard shortcuts

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