https://github.com/gojuno/go-checkout
Checkout.com API client
https://github.com/gojuno/go-checkout
Last synced: 3 months ago
JSON representation
Checkout.com API client
- Host: GitHub
- URL: https://github.com/gojuno/go-checkout
- Owner: gojuno
- License: bsd-3-clause
- Created: 2019-02-07T10:44:33.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-21T09:40:16.000Z (over 7 years ago)
- Last Synced: 2024-06-20T08:14:20.688Z (about 2 years ago)
- Language: Go
- Size: 18.6 KB
- Stars: 1
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Checkout.com API client [](http://godoc.org/github.com/gojuno/go-checkout) [](https://travis-ci.org/gojuno/go-checkout) [](https://goreportcard.com/report/github.com/gojuno/go-checkout)
This repo contains Checkout.com API client written in Go.
Checkout.com API documentation: https://docs.checkout.com/v2.0/docs/integration-options
Before using this client you need to register an account.
## How to install
Download package:
```
go get github.com/gojuno/go-checkout
```
Client uses `github.com/pkg/errors`, so you may need to download this package as well:
```
go get github.com/pkg/errors
```
Go modules are supported as well.
## How to use
To init client you will need `secret_key` which you can get from your Checkout.com account profile.
```
import "github.com/gojuno/go-checkout"
...
// Init client
client := checkout.New(
checkout.OptSecretKey("your_secret_key"),
)
paymentClient := payment.NewClient(client)
// Create new payment
p, err := paymentClient.Create(
context.Background(),
"payment_idempotency_key",
&payment.CreateParams{
Source: payment.CreationSource{
Type: payment.SourceTypeID,
ID: "src_vjkl7cyod4zejpkk5dwpvla7ca",
},
Amount: 2000,
Currency: "USD",
},
)
// Refund payment
err = paymentClient.Refund(
context.Background(),
p.ID,
"refund_idempotency_key",
&payment.RefundParams{
Amount: 1000,
},
)
```
## Custom HTTP client
By default client uses `http.DefaultClient`. You can set custom HTTP client using `checkout.OptHTTPClient` option:
```
httpClient := &http.Client{
Timeout: time.Minute,
}
client := checkout.New(
checkout.OptSecretKey("your_secret_key"),
checkout.OptHTTPClient(httpClient),
)
```
You can use any HTTP client, implementing `checkout.HTTPClient` interface with method `Do(r *http.Request) (*http.Response, error)`. Built-in `net/http` client implements it, of course.
## Sandbox
Checkout.com supports sandbox and live environment. By default, client will use live endpoint. To use sandbox define sandbox endpoint when client is created.
```
client := checkout.New(
checkout.OptSecretKey("your_secret_key"),
checkout.OptEndpoint(checkout.EndpointSandbox),
)
```