* Bump @typescript-eslint/eslint-plugin from 5.41.0 to 5.43.0 (#1039) Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 5.41.0 to 5.43.0. - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases) - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/CHANGELOG.md) - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v5.43.0/packages/eslint-plugin) --- updated-dependencies: - dependency-name: "@typescript-eslint/eslint-plugin" dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Add renovate.json (#1042) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update dependency @types/jest to v27.5.2 (#1043) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Arribatec/fix terminal comms typo (#1029) * Fix the namings of CommunicationOKFlag * Revert "Fix the namings of CommunicationOKFlag" This reverts commit 15e85c2665947a87ce7cfd8b6dae5df0fde16cb1. * Updated with correct linting * Update pOIStatus.ts Co-authored-by: jillingk <93914435+jillingk@users.noreply.github.com> Co-authored-by: Wouter Boereboom <62436079+wboereboom@users.noreply.github.com> * Update dependency eslint to v8.27.0 (#1047) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update dependency @typescript-eslint/parser to v5.43.0 (#1046) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Changed name of Value to BarcodeValue corresponding to docs(and API) (#1051) * Update actions/setup-node action to v3 (#1053) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Bump @typescript-eslint/parser from 5.43.0 to 5.45.0 (#1067) Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 5.43.0 to 5.45.0. - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases) - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md) - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v5.45.0/packages/parser) --- updated-dependencies: - dependency-name: "@typescript-eslint/parser" dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Update actions/checkout action to v3 (#1052) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Wouter Boereboom <62436079+wboereboom@users.noreply.github.com> * add dataProtection service to library (#1063) * add dataProtection service to library * add missing import * fix mock class for unit test * fix: add balancePlatform to services index (#1068) * Delete dependabot.yml (#1059) * Update dependency eslint to v8.28.0 (#1057) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update dependency typescript to v4.9.3 (#1050) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update dependency ts-loader to v9 (#1055) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * update .npmignore (#1072) * Pw 7156/update readme (#1069) * update README * fix link to integration section * add webhooks to README.md * fix bullet lists in README * minor code example fix * process feedback * Update README.md Co-authored-by: Jeantwan Teuma <Morerice@users.noreply.github.com> * Update README.md Co-authored-by: Jeantwan Teuma <Morerice@users.noreply.github.com> * Grammar Co-authored-by: Jeantwan Teuma <Morerice@users.noreply.github.com> * Add banner to README (#1074) * Update dependency typescript to v4.9.4 (#1073) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * add basic auth option to the client (#1076) * remove API calls from unit tests. Remove ASCII headers from test files, use typings index in test classes. add missing entries to typings index class (#1075) * PW-7502: Bind QueryString type to URLSearchParams (#1077) * chore(deps): update dependency @types/node to v14.18.36 (#1044) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency nock to v13.3.0 (#1081) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * update unit tests to test uniform error handling over APIs (#1079) Co-authored-by: jillingk <93914435+jillingk@users.noreply.github.com> * Remove LGTM badges from README (#1080) * PW-7514: Fully Generated Management API client (#1064) * PW-7514: Update models * PW-7514: Switch to JAR based installation * PW-7514: Default API template * PW-7514: Customize API template * PW-7514: Serialize request * PW-7514: Query string * PW-7514: Fix version patch * PW-7514: Client generated * PW-7514: Export class by default * PW-7514: Make path and body params required * PW-7514: Dynamic service name * PW-7514: Link all classes into one parent * PW-7514: Dynamic method names * PW-7514: Fix merge issues * PW-7514: Generate using latest specs Co-authored-by: jillingk <93914435+jillingk@users.noreply.github.com> * [PW-7765] add create/disablePermit and simple UT (#1082) * add create/disablePermit and simple UT * Add serializer for Date objects and quick test Co-authored-by: Michael Paul <michael@michaelpaul.com.br> * Update package.json (#1084) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Eoin Falconer <eoin.falconer@hotmail.com> Co-authored-by: Wouter Boereboom <62436079+wboereboom@users.noreply.github.com> Co-authored-by: Jeantwan Teuma <Morerice@users.noreply.github.com> Co-authored-by: Michael Paul <michael@michaelpaul.com.br>
12 KiB
Adyen Node.js API Library
This is the officially supported NodeJS library for using Adyen's APIs.
Supported API versions
The Library supports all APIs under the following services:
| API | Description | Service Name | Supported version |
|---|---|---|---|
| BIN lookup API | The BIN Lookup API provides endpoints for retrieving information based on a given BIN. | BinLookup | v52 |
| Checkout API | Our latest integration for accepting online payments. | CheckoutAPI | v69 |
| Configuration API | 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 | v2 |
| DataProtection API | 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 | v1 |
| Legal Entity Management API | Manage legal entities that contain information required for verification. | LegalEntityManagement | v2 |
| Local/Cloud-based Terminal API | Our point-of-sale integration. | TerminalLocalAPI or TerminalCloudAPI | - |
| Management API | Configure and manage your Adyen company and merchant accounts, stores, and payment terminals. | Management | v1 |
| Payments API | Our classic integration for online payments. | ClassicIntegrationAPI | v68 |
| Payouts API | Endpoints for sending funds to your customers. | Payout | v68 |
| Platforms APIs | Set of APIs when using Adyen for Platforms. This API is used for the classic integration. | Platforms | - |
| Account API | Platforms subclass | Account | v6 |
| Fund API | Platforms subclass | Fund | v6 |
| Hosted onboarding API | Platforms subclass | HostedOnboardingPage | v6 |
| Notification Configuration API | Platforms subclass | NotificationConfiguration | v6 |
| Platforms Notifications Webhooks | Models only | v6 | |
| POS Terminal Management API | Endpoints for managing your point-of-sale payment terminals. | TerminalManagement | v1 |
| Recurring API | Endpoints for managing saved payment details. | Recurring | v68 |
| Stored Value API | Manage both online and point-of-sale gift cards and other stored-value cards. | StoredValue | v46 |
| Transfers API | 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 | v3 |
| Webhooks | Adyen 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 only | v1 |
For more information, refer to our documentation or the API Explorer.
Prerequisites
- Adyen test account. To start using Adyen APIs, you will need a Merchant Account.
- API key. For testing, your API credential needs to have the API PCI Payments role.
- Node 12 or higher
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.
