Developer-friendly & type-safe Go SDK specifically catered to leverage client API.
To add the SDK as a dependency to your project:
go get github.com/mollie/mollie-api-golang
package main
import (
"context"
client "github.com/mollie/mollie-api-golang"
"github.com/mollie/mollie-api-golang/models/components"
"github.com/mollie/mollie-api-golang/models/operations"
"log"
"os"
)
func main() {
ctx := context.Background()
s := client.New(
client.WithSecurity(components.Security{
APIKey: client.String(os.Getenv("CLIENT_API_KEY")),
}),
)
res, err := s.Balances.List(ctx, operations.ListBalancesRequest{
Currency: client.String("EUR"),
From: client.String("bal_gVMhHKqSSRYJyPsuoPNFH"),
Limit: client.Int64(50),
Testmode: client.Bool(false),
IdempotencyKey: client.String("123e4567-e89b-12d3-a456-426"),
})
if err != nil {
log.Fatal(err)
}
if res.Object != nil {
// handle response
}
}
This SDK supports the following security schemes globally:
Name | Type | Scheme | Environment Variable |
---|---|---|---|
APIKey |
http | HTTP Bearer | CLIENT_API_KEY |
OAuth |
oauth2 | OAuth2 token | CLIENT_O_AUTH |
You can set the security parameters through the WithSecurity
option when initializing the SDK client instance. The selected scheme will be used by default to authenticate with the API for all operations that support it. For example:
package main
import (
"context"
client "github.com/mollie/mollie-api-golang"
"github.com/mollie/mollie-api-golang/models/components"
"github.com/mollie/mollie-api-golang/models/operations"
"log"
"os"
)
func main() {
ctx := context.Background()
s := client.New(
client.WithSecurity(components.Security{
APIKey: client.String(os.Getenv("CLIENT_API_KEY")),
}),
)
res, err := s.Balances.List(ctx, operations.ListBalancesRequest{
Currency: client.String("EUR"),
From: client.String("bal_gVMhHKqSSRYJyPsuoPNFH"),
Limit: client.Int64(50),
Testmode: client.Bool(false),
IdempotencyKey: client.String("123e4567-e89b-12d3-a456-426"),
})
if err != nil {
log.Fatal(err)
}
if res.Object != nil {
// handle response
}
}
Available methods
- List - List balances
- Get - Get balance
- GetPrimary - Get primary balance
- GetReport - Get balance report
- ListTransactions - List balance transactions
- List - List capabilities
- Create - Create client link
- Create - Create customer
- List - List customers
- Get - Get customer
- Update - Update customer
- Delete - Delete customer
- CreatePayment - Create customer payment
- ListPayments - List customer payments
- Get - Get organization
- GetCurrent - Get current organization
- GetPartner - Get partner status
- Create - Create payment link
- List - List payment links
- Get - Get payment link
- Update - Update payment link
- Delete - Delete payment link
- ListPayments - Get payment link payments
- Create - Create payment
- List - List payments
- Get - Get payment
- Update - Update payment
- Cancel - Cancel payment
- ReleaseAuthorization - Release payment authorization
- Create - Create profile
- List - List profiles
- Get - Get profile
- Update - Update profile
- Delete - Delete profile
- GetCurrent - Get current profile
- Create - Create payment refund
- List - List payment refunds
- Get - Get payment refund
- Cancel - Cancel payment refund
- All - List all refunds
- Create - Create sales invoice
- List - List sales invoices
- Get - Get sales invoice
- Update - Update sales invoice
- Delete - Delete sales invoice
- List - List settlements
- Get - Get settlement
- GetOpen - Get open settlement
- GetNext - Get next settlement
- ListPayments - List settlement payments
- ListCaptures - List settlement captures
- ListRefunds - List settlement refunds
- ListChargebacks - List settlement chargebacks
- Create - Create subscription
- List - List customer subscriptions
- Get - Get subscription
- Update - Update subscription
- Cancel - Cancel subscription
- All - List all subscriptions
- ListPayments - List subscription payments
- RequestApplePaySession - Request Apple Pay payment session
- Get - Get a Webhook Event
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
To change the default retry strategy for a single API call, simply provide a retry.Config
object to the call by using the WithRetries
option:
package main
import (
"context"
client "github.com/mollie/mollie-api-golang"
"github.com/mollie/mollie-api-golang/models/components"
"github.com/mollie/mollie-api-golang/models/operations"
"github.com/mollie/mollie-api-golang/retry"
"log"
"models/operations"
"os"
)
func main() {
ctx := context.Background()
s := client.New(
client.WithSecurity(components.Security{
APIKey: client.String(os.Getenv("CLIENT_API_KEY")),
}),
)
res, err := s.Balances.List(ctx, operations.ListBalancesRequest{
Currency: client.String("EUR"),
From: client.String("bal_gVMhHKqSSRYJyPsuoPNFH"),
Limit: client.Int64(50),
Testmode: client.Bool(false),
IdempotencyKey: client.String("123e4567-e89b-12d3-a456-426"),
}, operations.WithRetries(
retry.Config{
Strategy: "backoff",
Backoff: &retry.BackoffStrategy{
InitialInterval: 1,
MaxInterval: 50,
Exponent: 1.1,
MaxElapsedTime: 100,
},
RetryConnectionErrors: false,
}))
if err != nil {
log.Fatal(err)
}
if res.Object != nil {
// handle response
}
}
If you'd like to override the default retry strategy for all operations that support retries, you can use the WithRetryConfig
option at SDK initialization:
package main
import (
"context"
client "github.com/mollie/mollie-api-golang"
"github.com/mollie/mollie-api-golang/models/components"
"github.com/mollie/mollie-api-golang/models/operations"
"github.com/mollie/mollie-api-golang/retry"
"log"
"os"
)
func main() {
ctx := context.Background()
s := client.New(
client.WithRetryConfig(
retry.Config{
Strategy: "backoff",
Backoff: &retry.BackoffStrategy{
InitialInterval: 1,
MaxInterval: 50,
Exponent: 1.1,
MaxElapsedTime: 100,
},
RetryConnectionErrors: false,
}),
client.WithSecurity(components.Security{
APIKey: client.String(os.Getenv("CLIENT_API_KEY")),
}),
)
res, err := s.Balances.List(ctx, operations.ListBalancesRequest{
Currency: client.String("EUR"),
From: client.String("bal_gVMhHKqSSRYJyPsuoPNFH"),
Limit: client.Int64(50),
Testmode: client.Bool(false),
IdempotencyKey: client.String("123e4567-e89b-12d3-a456-426"),
})
if err != nil {
log.Fatal(err)
}
if res.Object != nil {
// handle response
}
}
Handling errors in this SDK should largely match your expectations. All operations return a response object or an error, they will never return both.
By Default, an API error will return apierrors.APIError
. When custom error responses are specified for an operation, the SDK may also return their associated error. You can refer to respective Errors tables in SDK docs for more details on possible error types for each operation.
For example, the List
function may return the following errors:
Error Type | Status Code | Content Type |
---|---|---|
apierrors.ErrorResponse | 400, 404 | application/hal+json |
apierrors.APIError | 4XX, 5XX | */* |
package main
import (
"context"
"errors"
client "github.com/mollie/mollie-api-golang"
"github.com/mollie/mollie-api-golang/models/apierrors"
"github.com/mollie/mollie-api-golang/models/components"
"github.com/mollie/mollie-api-golang/models/operations"
"log"
"os"
)
func main() {
ctx := context.Background()
s := client.New(
client.WithSecurity(components.Security{
APIKey: client.String(os.Getenv("CLIENT_API_KEY")),
}),
)
res, err := s.Balances.List(ctx, operations.ListBalancesRequest{
Currency: client.String("EUR"),
From: client.String("bal_gVMhHKqSSRYJyPsuoPNFH"),
Limit: client.Int64(50),
Testmode: client.Bool(false),
IdempotencyKey: client.String("123e4567-e89b-12d3-a456-426"),
})
if err != nil {
var e *apierrors.ErrorResponse
if errors.As(err, &e) {
// handle error
log.Fatal(e.Error())
}
var e *apierrors.APIError
if errors.As(err, &e) {
// handle error
log.Fatal(e.Error())
}
}
}
The default server can be overridden globally using the WithServerURL(serverURL string)
option when initializing the SDK client instance. For example:
package main
import (
"context"
client "github.com/mollie/mollie-api-golang"
"github.com/mollie/mollie-api-golang/models/components"
"github.com/mollie/mollie-api-golang/models/operations"
"log"
"os"
)
func main() {
ctx := context.Background()
s := client.New(
client.WithServerURL("https://api.mollie.com/v2"),
client.WithSecurity(components.Security{
APIKey: client.String(os.Getenv("CLIENT_API_KEY")),
}),
)
res, err := s.Balances.List(ctx, operations.ListBalancesRequest{
Currency: client.String("EUR"),
From: client.String("bal_gVMhHKqSSRYJyPsuoPNFH"),
Limit: client.Int64(50),
Testmode: client.Bool(false),
IdempotencyKey: client.String("123e4567-e89b-12d3-a456-426"),
})
if err != nil {
log.Fatal(err)
}
if res.Object != nil {
// handle response
}
}
The Go SDK makes API calls that wrap an internal HTTP client. The requirements for the HTTP client are very simple. It must match this interface:
type HTTPClient interface {
Do(req *http.Request) (*http.Response, error)
}
The built-in net/http
client satisfies this interface and a default client based on the built-in is provided by default. To replace this default with a client of your own, you can implement this interface yourself or provide your own client configured as desired. Here's a simple example, which adds a client with a 30 second timeout.
import (
"net/http"
"time"
"github.com/mollie/mollie-api-golang"
)
var (
httpClient = &http.Client{Timeout: 30 * time.Second}
sdkClient = client.New(client.WithClient(httpClient))
)
This can be a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration.
This SDK defines the following custom types to assist with marshalling and unmarshalling data.
types.Date
is a wrapper around time.Time that allows for JSON marshaling a date string formatted as "2006-01-02".
d1 := types.NewDate(time.Now()) // returns *types.Date
d2 := types.DateFromTime(time.Now()) // returns types.Date
d3, err := types.NewDateFromString("2019-01-01") // returns *types.Date, error
d4, err := types.DateFromString("2019-01-01") // returns types.Date, error
d5 := types.MustNewDateFromString("2019-01-01") // returns *types.Date and panics on error
d6 := types.MustDateFromString("2019-01-01") // returns types.Date and panics on error
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.
While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation. We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.