Adyen Golang API Client Library
This is the officially supported golang library for using Adyen's APIs.
Integration
The Library supports all APIs under the following services:
- Checkout API: Our latest integration for accepting online payments. Current supported version: v67
- Payments API: Our classic integration for online payments. Current supported version: v64
- Recurring API: Endpoints for managing saved payment details. Current supported version: v49
- Payouts API: Endpoints for sending funds to your customers. Current supported version: v64
- Platforms APIs: Set of APIs when using Adyen for Platforms.
- Account API Current supported version: v6
- Fund API Current supported version: v6
- Notification Configuration API Current supported version: v6
- Cloud-based Terminal API: Our point-of-sale integration.
For more information, refer to our documentation or the API Explorer.
Prerequisites
- Go 1.13 or higher
- Adyen test account
- API key. For testing, your API credential needs to have the API PCI Payments role.
Documentation
- https://docs.adyen.com/developers/development-resources/libraries
- https://docs.adyen.com/developers/checkout
Installation
You can use go modules to add our library to your project
go get github.com/adyen/adyen-go-api-library/v5
Usage examples
Using APIs with APIKey
import (
"github.com/adyen/adyen-go-api-library/v5/src/checkout"
"github.com/adyen/adyen-go-api-library/v5/src/common"
"github.com/adyen/adyen-go-api-library/v5/src/adyen"
)
client := adyen.NewClient(&common.Config{
ApiKey: "your api key",
Environment: common.TestEnv,
})
res, httpRes, err := client.Checkout.PaymentMethods(&checkout.PaymentMethodsRequest{
MerchantAccount: "your merchant account",
})
Using APIs with APIKey for Live env
import (
"github.com/adyen/adyen-go-api-library/v5/src/checkout"
"github.com/adyen/adyen-go-api-library/v5/src/common"
"github.com/adyen/adyen-go-api-library/v5/src/adyen"
)
client := adyen.NewClient(&common.Config{
ApiKey: "your api key",
Environment: common.LiveEnv,
LiveEndpointURLPrefix: "1797a841fbb37ca7-AdyenDemo", // Refer to https://docs.adyen.com/development-resources/live-endpoints#live-url-prefix
})
res, httpRes, err := client.Checkout.PaymentMethods(&checkout.PaymentMethodsRequest{
MerchantAccount: "your merchant account",
})
Using API with Basic Auth
import (
"github.com/adyen/adyen-go-api-library/v5/src/recurring"
"github.com/adyen/adyen-go-api-library/v5/src/common"
"github.com/adyen/adyen-go-api-library/v5/src/adyen"
)
client := adyen.NewClient(&common.Config{
Username: USER,
Password: PASS,
Environment: common.TestEnv,
ApplicationName: "adyen-api-go-library",
})
res, httpRes, err := client.Recurring.ListRecurringDetails(&recurring.RecurringDetailsRequest{
MerchantAccount: MerchantAccount,
Recurring: &recurring.RecurringType{
Contract: "RECURRING",
},
ShopperReference: "ref",
})
Using Notifications parser
import (
"github.com/adyen/adyen-go-api-library/v5/src/adyen"
"github.com/adyen/adyen-go-api-library/v5/src/common"
)
client := adyen.NewClient(&common.Config{
ApiKey: "your api key",
Environment: common.TestEnv,
})
notification, err := client.Notification.HandleNotificationRequest(jsonRequestString)
Getting error details
import (
"github.com/adyen/adyen-go-api-library/v5/src/common"
"github.com/adyen/adyen-go-api-library/v5/src/checkout"
"github.com/adyen/adyen-go-api-library/v5/src/adyen"
)
client := adyen.NewClient(&common.Config{
ApiKey: "your api key",
Environment: common.TestEnv,
})
res, httpRes, err := client.Checkout.Payments(&checkout.PaymentRequest{
Reference: "123456781235",
Amount: checkout.Amount{
Value: 1250,
Currency: "EUR",
},
CountryCode: "NL",
MerchantAccount: MerchantAccount,
Channel: "Web",
ReturnUrl: "http://localhost:3000/redirect",
PaymentMethod: map[string]interface{}{
"type": "ideal",
"issuer": "1121",
},
})
errorText := err.Error()
errorMessage := err.(common.APIError).Message
errorCode := err.(common.APIError).Code
errorType := err.(common.APIError).Type
httpStatusCode := httpRes.StatusCode
httpStatus := httpRes.Status
Custom HTTP Client Configuration
By default, Go http.DefaultClient
will be used to submit requests to the API. But you can change that by injecting your own HttpClient on your client instance.
client := adyen.NewClient(&common.Config{
HTTPClient: &http.Client{
CheckRedirect: redirectPolicyFunc,
Timeout: 10 * time.MilliSeconds,
},
Environment: common.TestEnv,
ApiKey: "your api key",
})
Proxy configuration
You can configure a proxy connection by injecting your own http.Client
with a custom Transport on your client instance.
Example:
//creating the proxyURL
proxyURL, _ := url.Parse("http://myproxy:7000")
transport := &http.Transport{
Proxy: http.ProxyURL(proxyURL),
}
client = adyen.NewClient(&common.Config{
HTTPClient: &http.Client{
Transport: transport,
},
Environment: common.TestEnv,
ApiKey: "your api key",
})
Support
If you have a feature request, or spotted a bug or a technical problem, create a github issue. For other questions, contact our support team.
Contributing
We strongly encourage you to join us in contributing to this repository so everyone can benefit from:
- New features and functionality
- Resolved bug fixes and issues
- Any general improvements
Read our contribution guidelines to find out how.
Licence
MIT license. For more information, see the LICENSE file.