New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@adyen/api-library

Package Overview
Dependencies
Maintainers
1
Versions
95
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@adyen/api-library

The Adyen API Library for NodeJS enables you to work with Adyen APIs.

  • 12.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
15K
decreased by-75.17%
Maintainers
1
Weekly downloads
 
Created
Source

Node js

Adyen Node.js API Library

Node.js CI Coverage Status Downloads npm bundle size (scoped) Version Quality Gate Status

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

Supported API versions

The Library supports all APIs under the following services:

APIDescriptionService NameSupported version
BIN lookup APIThe BIN Lookup API provides endpoints for retrieving information based on a given BIN.BinLookupv52
Checkout APIOur latest integration for accepting online payments.CheckoutAPIv69
Configuration APIThe 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.BalancePlatformv2
DataProtection APIAdyen Data Protection API provides a way for you to process Subject Erasure Requests as mandated in GDPR. Use our API to submit a request to delete shopper's data, including payment details and other related information (for example, delivery address or shopper email)DataProtectionv1
Legal Entity Management APIManage legal entities that contain information required for verification.LegalEntityManagementv2
Local/Cloud-based Terminal APIOur point-of-sale integration.TerminalLocalAPI or TerminalCloudAPI-
Management APIConfigure and manage your Adyen company and merchant accounts, stores, and payment terminals.Managementv1
Payments APIOur classic integration for online payments.ClassicIntegrationAPIv68
Payouts APIEndpoints for sending funds to your customers.Payoutv68
Platforms APIsSet of APIs when using Adyen for Platforms. This API is used for the classic integration.Platforms-
Account APIPlatforms subclassAccountv6
Fund APIPlatforms subclassFundv6
Hosted onboarding APIPlatforms subclassHostedOnboardingPagev6
Notification Configuration APIPlatforms subclassNotificationConfigurationv6
Platforms Notifications WebhooksModels onlyv6
POS Terminal Management APIEndpoints for managing your point-of-sale payment terminals.TerminalManagementv1
Recurring APIEndpoints for managing saved payment details.Recurringv68
Stored Value APIManage both online and point-of-sale gift cards and other stored-value cards.StoredValuev46
Transfers APIThe 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.Transfersv3
WebhooksAdyen 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.Models onlyv1

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

Prerequisites

Installation

You can use NPM to add our library to your project

NPM

npm install --save @adyen/api-library

Alternatively, you can download the release on GitHub.

Using the library

Client initialisation

General use with API key

Set up the client as a singleton resource; you can then use it to create service objects for the API calls that you make to Adyen:

  const { Client } = require('@adyen/api-library');
  const client = new Client({apiKey: "YOUR_API_KEY", environment: "TEST"});
General use with API key for live environment
 const { Client } = require('@adyen/api-library');
 const client = new Client({apiKey: "YOUR_API_KEY", environment: "LIVE"});
General use with basic auth
  const { Client } = require('@adyen/api-library');
  const client = new Client({username: "YOUR_USERNAME", password: "YOUR_PASSWORD", environment: "TEST"});

Consuming Services

Every API the library supports is represented by a service object. The name of the service matching the corresponding API is listed in the Integrations section of this document.

  const { Client, CheckoutAPI	} = require('@adyen/api-library');
  const client = new Client({apiKey: "YOUR_API_KEY", environment: "TEST"});

  const paymentRequest = {
    amount: {
      currency: "USD",
      value: 1000 // value in minor units
    },
    reference: "Your order number",
    paymentMethod: {
      type: "scheme",
      encryptedCardNumber: "test_4111111111111111",
      encryptedExpiryMonth: "test_03",
      encryptedExpiryYear: "test_2030",
      encryptedSecurityCode: "test_737"
    },
    shopperReference: "YOUR_UNIQUE_SHOPPER_ID_IOfW3k9G2PvXFu2j",
    storePaymentMethod: true,
    shopperInteraction: "Ecommerce",
    recurringProcessingModel: "CardOnFile",
    returnUrl: "https://your-company.com/...",
    merchantAccount: "YOUR_MERCHANT_ACCOUNT"
  };
  const checkoutAPI = new CheckoutAPI(client);
  checkoutAPI.payments(paymentRequest)
    .then( paymentResponse => console.log(paymentResponse.pspReference))
    .catch(error => console.log(error));

Alternatively you can make use of the Types included in this library using Typescript, and/or use the async syntax:

  const { Client, CheckoutAPI } = require('@adyen/api-library');
  const client = new Client({apiKey: "YOUR_API_KEY", environment: "TEST"});

  import { Types } from '@adyen/api-library';

  const doPaymentsRequest = async ()  => {
    const paymentRequest : Types.checkout.PaymentRequest = {
      amount: {
        currency: "USD",
        value: 1000 // value in minor units
      },
      reference: "Your order number",
      paymentMethod: {
        type: Types.checkout.CardDetails.TypeEnum.Scheme,
        encryptedCardNumber: "test_4111111111111111",
        encryptedExpiryMonth: "test_03",
        encryptedExpiryYear: "test_2030",
        encryptedSecurityCode: "test_737"
      },
      shopperReference: "YOUR_UNIQUE_SHOPPER_ID_IOfW3k9G2PvXFu2j",
      storePaymentMethod: true,
      shopperInteraction: Types.checkout.PaymentRequest.ShopperInteractionEnum.Ecommerce,
      recurringProcessingModel: Types.checkout.PaymentRequest.RecurringProcessingModelEnum.CardOnFile,
      returnUrl: "https://your-company.com/...",
      merchantAccount: "YOUR_MERCHANT_ACCOUNT"
    };
    const checkoutAPI = new CheckoutAPI(client);
    const paymentResponse : Types.checkout.PaymentResponse = await checkoutAPI.payments(paymentRequest);
    console.log(paymentResponse.pspReference);
  }

  doPaymentsRequest();

Custom HTTP Client Configuration

By default, NodeJS https will be used to submit requests to the API. But you can change that by injecting your own HttpClient on your client instance. In the example below, we use axios:

const {Client, Config} = require('@adyen/api-library');
const axios = require("axios");
...
const config = new Config();
const client = new Client({
  config,
  httpClient: {
    async request(endpoint, json, config, isApiKeyRequired, requestOptions) {
        const response = await axios({
            method: 'POST',
            url: endpoint,
            data: JSON.parse(json),
            headers: {
                "X-API-Key": config.apiKey,
                "Content-type": "application/json"
            },
        });

        return response.data;
    }
  }
});
...

Proxy configuration

You can configure a proxy connection by injecting your own HttpURLConnectionClient on your client instance and changing the proxy setter value.

Example:

const {HttpURLConnectionClient, Client, Config} = require('@adyen/api-library');
...
const config = new Config();
const client = new Client({ config });
const httpClient = new HttpURLConnectionClient();
httpClient.proxy = { host: "http://google.com", port: 8888,  };

client.setEnvironment('TEST');
client.httpClient = httpClient;
...

Example integration

For a closer look at how our NodeJS library works, clone our example integration. This includes commented code, highlighting key features and concepts, and examples of API calls that can be made using the library.

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 to create a pull request.

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.

Licence

This repository is available under the MIT license.

See also

Keywords

FAQs

Package last updated on 20 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc