The official Checkout Go client library.
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.
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:
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)
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)
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, ¶ms)
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_")
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_")
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, ¶ms)
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, ¶ms)
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, ¶ms)
For any requests, bug or comments, please open an issue or submit a pull request.