adyen-go-api-library

command module
v6.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 22, 2022 License: MIT Imports: 3 Imported by: 0

README

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/adyen/adyen-go-api-library/v6

Usage examples

Using APIs with APIKey

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

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL