Skip to content

Adyen/adyen-go-api-library

Repository files navigation

Go

Adyen Golang API Client Library

Go Reference

This is the officially supported golang library for using Adyen's APIs.

Supported API versions

The Library supports all APIs under the following services:

API Description Service constructor Supported version
Checkout API Our latest integration for accepting online payments. client.Checkout() v71
Payouts API Endpoints for sending funds to your customers. client.Payout() v68
Recurring API Endpoints for managing saved payment details. client.Recurring() v68
BIN lookup API The BIN Lookup API provides endpoints for retrieving information based on a given BIN. client.BinLookup() v54
Disputes API You can use the Disputes API to automate the dispute handling process so that you can respond to disputes and chargebacks as soon as they are initiated. The Disputes API lets you retrieve defense reasons, supply and delete defense documents, and accept or defend disputes. client.Disputes() v30
POS Terminal Management API Endpoints for managing your point-of-sale payment terminals. client.PosTerminalManagement() v1
Management API Configure and manage your Adyen company and merchant accounts, stores, and payment terminals. client.Management() v3
Data Protection API Adyen Data Protection API provides a way for you to process Subject Erasure Requests as mandated in GDPR. client.DataProtection() v1
Balance Control API The Balance Control API lets you transfer funds between merchant accounts that belong to the same legal entity and are under the same company account. client.BalanceControl() v1
Legal Entity Management API Manage legal entities that contain information required for verification. client.LegalEntity() v3
Configuration API The Configuration API enables you to create a platform where you can onboard your users as account holders and create balance accounts, cards, and business accounts. client.BalancePlatform() v2
Transfers API The Transfers API provides endpoints that can be used to get information about all your transactions, move funds within your balance platform or send funds from your balance platform to a transfer instrument. client.Transfers() v4
Stored Value API Manage both online and point-of-sale gift cards and other stored-value cards. client.StoredValue() v46
Payments API Our classic integration for online payments. client.Payments() v68
Account API Deprecated: This API is used for the classic integration. If you are just starting your implementation, refer to our new integration guide instead. client.PlatformsAccount() v6
Fund API Deprecated: This API is used for the classic integration. If you are just starting your implementation, refer to our new integration guide instead. client.PlatformsFund() v6
Hosted onboarding API Deprecated: This API is used for the classic integration. If you are just starting your implementation, refer to our new integration guide instead. client.PlatformsHostedOnboardingPage() v6
Notification Configuration API Deprecated: This API is used for the classic integration. If you are just starting your implementation, refer to our new integration guide instead. client.PlatformsNotificationConfiguration() v6

For more information, refer to our documentation or the API Explorer.

Supported Webhook versions

The library supports all webhooks under the following model directories:

Webhooks Description Package Supported Version
Payment Webhooks Adyen uses webhooks to send notifications about payment status updates, newly available reports, and other events that can be subscribed to. For more information, refer to our documentation. webhook v1
Authentication Webhooks Adyen sends this webhook when the process of cardholder authentication is finalized, whether it is completed successfully, fails, or expires. acswebhook v1
Configuration Webhooks You can use these webhooks to build your implementation. For example, you can use this information to update internal statuses when the status of a capability is changed. configurationwebhook v2
Transfer Webhooks You can use these webhooks to build your implementation. For example, you can use this information to update balances in your own dashboards or to keep track of incoming funds. transferwebhook v4
Report Webhooks You can download reports programmatically by making an HTTP GET request, or manually from your Balance Platform Customer Area reportwebhook v1
Management Webhooks Adyen uses webhooks to inform your system about events that happen with your Adyen company and merchant accounts, stores, payment terminals, and payment methods when using Management API. managementwebhook v3
Transaction Webhooks Adyen sends webhooks to inform your system about incoming and outgoing transfers in your platform. You can use these webhooks to build your implementation. For example, you can use this information to update balances in your own dashboards or to keep track of incoming funds. transactionwebhook v4
Platforms Notifications Webhooks Deprecated: This API is used for the classic integration. If you are just starting your implementation, refer to our new integration guide instead. platformsnotificationevents v6

Prerequisites

Documentation

Installation

You can use go modules to add our library to your project

go get github.com/adyen/adyen-go-api-library/v9@v9.4.0

Usage examples

Using APIs with APIKey

import (
	"context"
	"github.com/adyen/adyen-go-api-library/v9/src/checkout"
	"github.com/adyen/adyen-go-api-library/v9/src/common"
	"github.com/adyen/adyen-go-api-library/v9/src/adyen"
)

client := adyen.NewClient(&common.Config{
    ApiKey:      "your api key",
    Environment: common.TestEnv,
})
service := client.Checkout()

req := service.PaymentsApi.PaymentMethodsInput()
req = req.PaymentMethodsRequest(checkout.PaymentMethodsRequest{
    MerchantAccount: "your merchant account",
})
res, httpRes, err := service.PaymentsApi.PaymentMethods(context.Background(), req)

Using APIs with APIKey for Live env

import (
    "github.com/adyen/adyen-go-api-library/v9/src/checkout"
    "github.com/adyen/adyen-go-api-library/v9/src/common"
    "github.com/adyen/adyen-go-api-library/v9/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
})
service := client.Checkout()

req := service.PaymentsApi.PaymentMethodsInput()
req = req.PaymentMethodsRequest(checkout.PaymentMethodsRequest{
    MerchantAccount: "your merchant account",
})
res, httpRes, err := service.PaymentsApi.PaymentMethods(context.Background(), req)

Using API with Basic Auth

import (
    "github.com/adyen/adyen-go-api-library/v9/src/recurring"
    "github.com/adyen/adyen-go-api-library/v9/src/common"
    "github.com/adyen/adyen-go-api-library/v9/src/adyen"
)

client := adyen.NewClient(&common.Config{
    Username:    "your ws user",
    Password:    "your secret password",
    Environment: common.TestEnv,
    UserAgent:   "Custom Application",
})
service := client.Recurring()

req := service.ListRecurringDetailsInput()
req = req.RecurringDetailsRequest(recurring.RecurringDetailsRequest{
    MerchantAccount: "your merchant account",
    Recurring: &recurring.Recurring{
        Contract: common.PtrString("RECURRING"),
    },
    ShopperReference: "ref",
})
res, httpRes, err := service.ListRecurringDetails(context.Background(), req)

Unmarshalling JSON Strings

In some setups you might need to unmarshal JSON strings to request objects. For example, when using the libraries in combination with Dropin/Components. Please use following methodology when unmarshalling JSON strings:

import (
	"encoding/json"
	"github.com/adyen/adyen-go-api-library/v9/src/checkout"
)
paymentRequest := checkout.PaymentRequest{}
error := json.Unmarshal([]byte("YOUR_JSON_STRING"), &paymentRequest)

Using the webhook parser

import (
	"github.com/adyen/adyen-go-api-library/v9/src/webhook"
)

msg, err := webhook.HandleRequest(`{"live": "false", "notificationItems": []}`)

Getting error details

import (
	"github.com/adyen/adyen-go-api-library/v9/src/common"
	"github.com/adyen/adyen-go-api-library/v9/src/checkout"
	"github.com/adyen/adyen-go-api-library/v9/src/adyen"
)

client := adyen.NewClient(&common.Config{
    ApiKey:      "your api key",
    Environment: common.TestEnv,
})
service := client.Checkout()

req := service.PaymentsApi.PaymentsInput()
paymentMethod := checkout.IdealDetailsAsCheckoutPaymentMethod(checkout.NewIdealDetails("1121"))
_, httpRes, err := service.PaymentsApi.Payments(context.Background(), req.PaymentRequest(checkout.PaymentRequest{
    Reference: "123456781235",
    Amount: checkout.Amount{
        Value:    1250,
        Currency: "EUR",
    },
    CountryCode:     common.PtrString("NL"),
    MerchantAccount: "your merchant account",
    Channel:         common.PtrString("Web"),
    ReturnUrl:       "http://localhost:3000/redirect",
    PaymentMethod:   paymentMethod,
}))

httpStatusCode := httpRes.StatusCode
errorMessage := err.(common.APIError).Message
errorCode := err.(common.APIError).Code
errorType := err.(common.APIError).Type

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{
        Timeout: 512 * time.Millisecond,
    },
    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 an issue here.

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.

Feedback

We value your input! Help us enhance our API Libraries and improve the integration experience by providing your feedback. Please take a moment to fill out our feedback form to share your thoughts, suggestions or ideas.

Licence

MIT license. For more information, see the LICENSE file.