Adyen Golang API Client Library
The Adyen API Library for golang enables you to work with Adyen APIs.
Integration
The Library supports all APIs under the following services:
- checkout
- checkout utility
- payments
- payouts
- recurring
- notifications
- BIN lookup
Requirements
Installation
You can use go modules to add our library to your project
Go module
go get github.com/adyen/adyen-go-api-library/v4
Documentation
Usage examples
Using APIs with APIKey
import (
"github.com/adyen/adyen-go-api-library/v4/src/checkout"
"github.com/adyen/adyen-go-api-library/v4/src/common"
"github.com/adyen/adyen-go-api-library/v4/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/v4/src/checkout"
"github.com/adyen/adyen-go-api-library/v4/src/common"
"github.com/adyen/adyen-go-api-library/v4/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/v4/src/recurring"
"github.com/adyen/adyen-go-api-library/v4/src/common"
"github.com/adyen/adyen-go-api-library/v4/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/v4/src/adyen"
"github.com/adyen/adyen-go-api-library/v4/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/v4/src/common"
"github.com/adyen/adyen-go-api-library/v4/src/checkout"
"github.com/adyen/adyen-go-api-library/v4/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.