Skip to content

HR169/adyen-go-api-library

 
 

Repository files navigation

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:

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

Prerequisites

Documentation

Installation

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

go get github.com/HRInnovationLab/adyen-go-api-library/v5

Usage examples

Using APIs with APIKey

import (
	"github.com/HRInnovationLab/adyen-go-api-library/v5/src/checkout"
	"github.com/HRInnovationLab/adyen-go-api-library/v5/src/common"
	"github.com/HRInnovationLab/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/HRInnovationLab/adyen-go-api-library/v5/src/checkout"
    "github.com/HRInnovationLab/adyen-go-api-library/v5/src/common"
	"github.com/HRInnovationLab/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/HRInnovationLab/adyen-go-api-library/v5/src/recurring"
    "github.com/HRInnovationLab/adyen-go-api-library/v5/src/common"
	"github.com/HRInnovationLab/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/HRInnovationLab/adyen-go-api-library/v5/src/adyen"
    "github.com/HRInnovationLab/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/HRInnovationLab/adyen-go-api-library/v5/src/common"
	"github.com/HRInnovationLab/adyen-go-api-library/v5/src/checkout"
	"github.com/HRInnovationLab/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.

About

Adyen API Library for Go

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 99.7%
  • Other 0.3%