Skip to content

patrick-breitenbach-cko/checkout-sdk-go

 
 

Repository files navigation

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:

API

If you're dealing with multiple keys, it is recommended you use client.API. This allows you to create as many clients as needed, each with their own individual key.

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

api := &client.API{}
api.Init(secretKey, &publicKey)

Tokens

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

config, err := checkout.Create(secretKey, &publicKey)
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"
)

idempotencyKey := checkout.NewIdempotencyKey()
params := checkout.Params{
    IdempotencyKey: &idempotencyKey,
}
config, err := checkout.Create(secretKey, &publicKey)

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: "[email protected]",
        Name:  "First Name Last Name",
    },
    Metadata: map[string]string{
        "udf1": "User Define",
    },
}
response, err := client.Request(request, &params)

Payment Detail

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

config, err := checkout.Create(secretKey, &publicKey)

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

config, err := checkout.Create(secretKey, &publicKey)
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"
)

idempotencyKey := checkout.NewIdempotencyKey()
params := checkout.Params{
    IdempotencyKey: &idempotencyKey,
}
config, err := checkout.Create(secretKey, &publicKey)
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, &params)

Voids

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

idempotencyKey := checkout.NewIdempotencyKey()
params := checkout.Params{
    IdempotencyKey: &idempotencyKey,
}
config, err := checkout.Create(secretKey, &publicKey)
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, &params)

Refunds

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

idempotencyKey := checkout.NewIdempotencyKey()
params := checkout.Params{
    IdempotencyKey: &idempotencyKey,
}
config, err := checkout.Create(secretKey, &publicKey)
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, &params)

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

About

Checkout.com SDK for Go

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%