Code Monkey home page Code Monkey logo

adyen-node-api-library's Introduction

Node js

Adyen API library for Node.js/TypeScript

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

This is the official Adyen API library for Node.js that we recommend for integrating with Adyen APIs.

Supported APIs

This library supports the following:

API name API version Description API object
BIN Lookup API v54 The BIN Lookup API provides endpoints for retrieving information based on a given BIN. BinLookup
Checkout API v70 Our latest integration for accepting online payments. CheckoutAPI
Configuration API v2 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. BalancePlatform
DataProtection API v1 Adyen 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) DataProtection
Legal Entity Management API v3 Manage legal entities that contain information required for verification. LegalEntityManagement
Local/Cloud-based Terminal API - Our point-of-sale integration. TerminalLocalAPI or TerminalCloudAPI
Management API v1 Configure and manage your Adyen company and merchant accounts, stores, and payment terminals. Management
Payments API v68 Our classic integration for online payments. ClassicIntegrationAPI
Payouts API v68 Endpoints for sending funds to your customers. Payout
Platforms APIs - Set of APIs when using Adyen for Platforms. This API is used for the classic integration. Platforms
Account API v6 Provides endpoints for managing account-related entities on your platform. These related entities include account holders, accounts, bank accounts, shareholders, and verification-related documents. Account
Fund API v6 Provides endpoints for managing the funds in the accounts on your platform. These management operations include, for example, the transfer of funds from one account to another, the payout of funds to an account holder, and the retrieval of balances in an account. Fund
Hosted onboarding API v6 Provides endpoints that you can use to generate links to Adyen-hosted pages, such as an onboarding page or a PCI compliance questionnaire. You can provide these links to your account holders so that they can complete their onboarding. HostedOnboardingPage
Notification Configuration API v6 Provides endpoints for setting up and testing notifications that inform you of events on your platform, for example when a verification check or a payout has been completed. NotificationConfiguration
POS Terminal Management API v1 Endpoints for managing your point-of-sale payment terminals. TerminalManagement
Recurring API v68 Endpoints for managing saved payment details. Recurring
Stored Value API v46 Manage both online and point-of-sale gift cards and other stored-value cards. StoredValue
Transfers API v3 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. Transfers

Supported Webhook versions

The library supports all webhooks under the following model directories:

Webhooks Description Model Name Supported Version
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. ConfigurationNotification v1
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. TransferNotification v3
Report Webhooks You can download reports programmatically by making an HTTP GET request, or manually from your Balance Platform Customer Area ReportNotification v1
Notification Webhooks We use webhooks to send you updates about payment status updates, newly available reports, and other events that you can subscribe to. For more information, refer to our documentation Notification v1
For more information, refer to our documentation or the API Explorer.

Before you begin

Before you begin to integrate:

Installation

Install the Node.JS package:

npm install --save @adyen/api-library

Alternatively, you can download the release on GitHub.

Updating

To update the Node.JS package:

npm update @adyen/api-library

Check for breaking changes on the releases page.

Usage

// Step 1: Require the parts of the module you want to use
const { Client, CheckoutAPI} = require('@adyen/api-library');

// Step 2: Initialize the client object
const client = new Client({apiKey: "YOUR_API_KEY", environment: "TEST"}); 

// Step 3: Initialize the API object
const checkoutApi = new CheckoutAPI(client);

// Step 4: Create the request object
  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"
  };
  
// Step 5: Make the request
checkoutAPI.payments(paymentRequest)
  .then(paymentResponse => console.log(paymentResponse.pspReference))
  .catch(error => console.log(error));

Step 1: Require the parts of the module you want to use

Use the Node.js require function to load the Client and API objects from the Adyen module. For the name of the API objects, see Supported APIs.

For example, to use the Checkout API:

const { Client, CheckoutAPI} = require('@adyen/api-library');

Step 2: Initialize the client object

Initialize the client object, passing the following:

For example:

const client = new Client({apiKey: "YOUR_API_KEY", environment: "TEST"}); 

Step 3: Initialize the API object

Initialize the API object you want to use, passing the client object from the previous step.

For example, for the Checkout API:

const checkoutApi = new CheckoutAPI(client);

Step 4: Create the request object

Create a the request object. For example, for a request to the /payments endpoint:

  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"
  };

Step 5: Make the request

Use the API object's method to make the request. For example, to make a request to the /payments endpoint using the CheckoutAPI object:

checkoutAPI.payments(paymentRequest)
  .then(paymentResponse => console.log(paymentResponse.pspReference))
  .catch(error => console.log(error));

Client setup when going live

For APIS that require your Live URL Prefix (Binlookup, BalanceControl, Checkout, Payout and Recurring) the client is set up as follows in order to start processing live payments:

const { Client } = require('@adyen/api-library');

const client = new Client({apiKey: "YOUR_API_KEY", environment: "TEST", liveEndpointUrlPrefix: "YOUR_LIVE_URL_PREFIX"}); 

Usage in TypeScript

Alternatively, you can use the Types included in this module for Typescript and async syntax.

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

  const makePaymentsRequest = async () => {
    const paymentsRequest : 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(paymentsRequest);
    console.log(paymentResponse.pspReference);
  }

  makePaymentsRequest();

Custom HTTP client configuration

By default, Node.js https is used to make API requests. Alternatively, you can set a custom HttpClient for your Client object.

For example, to set axios as your HTTP client:

const {Client, Config} = require('@adyen/api-library');
const axios = require("axios");
// ... more code
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;
    }
  }
});
// ... more code

Parsing and Authenticating Banking Webhooks

Parse an AccountHolderNotificationRequest webhook;

let bankingWebhookHandler = new BankingWebhookHandler(YOUR_BANKING_WEBHOOK);
const accountHolderNotificationRequest: AccountHolderNotificationRequest = bankingWebhookHandler.getAccountHolderNotificationRequest();
const genericWebhook = bankingWebhookHandler.getGenericWebhook();

Parse a generic Banking webhook;

let bankingWebhookHandler = new BankingWebhookHandler(YOUR_BANKING_WEBHOOK);
const genericWebhook = bankingWebhookHandler.getGenericWebhook();

Verify the authenticity (where you retrieve the hmac key from the CA and the signature from the webhook header);

const isValid = hmacValidator.validateBankingHMAC("YOUR_HMAC_KEY", "YOUR_HMAC_SIGNATURE", jsonString)

Proxy configuration

To configure a proxy connection, set the proxy property of your HttpURLConnectionClient object.

For example:

const {HttpURLConnectionClient, Client, Config} = require('@adyen/api-library');
// ... more code
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;

// ... more code

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.

Example integration

Clone our Node.js example integration to see how the Adyen API library for Node.js can be used. The integration includes code comments that highlight key features and concepts.

Contributing

We strongly encourage you to contribute to this repository by:

  • Adding new features and functionality.
  • Fixing bugs and issues.
  • Making general improvements.

To learn how to create a pull request, read our contribution guidelines.

Support

To request a feature, report a bug, or report a security vulnerability, create a GitHub issue.

For other questions, contact our support team.

License

This repository is available under the MIT license.

See also

adyen-node-api-library's People

Contributors

acampos1916 avatar adyenautomationbot avatar aleffio avatar alexandrosmor avatar cyattilakiss avatar dependabot-preview[bot] avatar dependabot[bot] avatar github-actions[bot] avatar icebergrage avatar jillingk avatar jlengrand avatar juhohei-sc avatar kadobot avatar kilianb avatar krisstallenberg avatar leandromagnabosco avatar lukenorris avatar maassenbas avatar meisolsson avatar michaelpaul avatar msilvagarcia avatar peterojo avatar renovate-bot avatar renovate[bot] avatar rikterbeek avatar samcottle avatar sergiobergaminicodeploy avatar wboereboom avatar wilsonpinto avatar zaiddreakh avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.