Tools-2 icon

Libraries

We provide server-side API libraries in several languages. Because the libraries are connected to managed package systems (Composer, Gradle, Maven, npm, NuGet, PyPi, RubyGems) they are easy to include in your project. Installing a library is not required, but will save you development time, because a library:

  • Uses an API version that is up to date.

  • Has generated models to help you construct requests.

    For a point-of-sale integration with Terminal API, the libraries are wrappers around Terminal API. They include the models to create Terminal API requests.

    • If your Terminal API integration uses cloud communications, you can use the C#, Go, Java, Node, PHP, or Ruby libraries.
    • If your Terminal API integration uses local communications, you can use the C#, Java, or Node libraries. These also take care of protecting local communications.

  • Sends the request to Adyen using its built-in HTTP client, so you do not have to create your own.

Try our example integration

Requirements

  • Java 11 or later.

Installation

You can use Maven, adding this dependency to your project's POM.

Add the API library
Expand view
Copy link to code block
Copy code
Copy code
<dependency>
<groupId>com.adyen</groupId>
<artifactId>adyen-java-api-library</artifactId>
<version>LATEST_VERSION</version>
</dependency>

You can find the latest version on GitHub. Alternatively, you can download the release on GitHub.

Using the library

Set up the client as a singleton resource that you use for the API requests to Adyen and make a test payment request. For example, to make a test credit card payment for 10 EUR (1000 in minor units):

Make a test payment request using the API library
Expand view
Copy link to code block
Copy code
Copy code
// Import the required classes
import com.adyen.Client;
import com.adyen.enums.Environment;
import com.adyen.service.checkout.PaymentsApi;
import com.adyen.model.checkout.*;
// Setup the client and service.
Client client = new Client("ADYEN_API_KEY", Environment.TEST);
PaymentsApi paymentsApi = new PaymentsApi(client);
// Create a payment request.
PaymentRequest paymentRequest = new PaymentRequest();
paymentRequest.setMerchantAccount("YOUR_MERCHANT_ACCOUNT");
CardDetails cardDetails = new CardDetails();
cardDetails.encryptedCardNumber("test_4111111111111111")
.encryptedSecurityCode("test_737")
.encryptedExpiryMonth("test_03")
.encryptedExpiryYear("test_2030");
paymentRequest.setPaymentMethod(new CheckoutPaymentMethod(cardDetails));
Amount amount = new Amount().currency("EUR").value(1000L);
paymentRequest.setAmount(amount);
paymentRequest.setReference("My first Adyen test payment with an API library/SDK");
paymentRequest.setReturnUrl("https://your-company.com/checkout?shopperOrder=12xy..");
// Add your idempotency key.
RequestOptions requestOptions = new RequestOptions();
requestOptions.setIdempotencyKey("YOUR_IDEMPOTENCY_KEY");
// Make a request to the /payments endpoint.
PaymentResponse paymentResponse = paymentsApi.payments(paymentRequest, requestOptions);

Next steps