Skip to content

Commit

Permalink
Merge bf1e643 into d6b50a3
Browse files Browse the repository at this point in the history
  • Loading branch information
jillingk committed Jan 19, 2023
2 parents d6b50a3 + bf1e643 commit ac955ae
Show file tree
Hide file tree
Showing 117 changed files with 5,059 additions and 1,084 deletions.
14 changes: 0 additions & 14 deletions .github/dependabot.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Expand Up @@ -13,7 +13,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/coveralls.yml
Expand Up @@ -9,10 +9,10 @@ jobs:
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Use Node.js 16.x
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: 16.x

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/nodejs.yml
Expand Up @@ -12,9 +12,9 @@ jobs:
node-version: [12.x, 14.x, 16.x]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: npm install, lint and test
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/npmpublish.yml
Expand Up @@ -9,8 +9,8 @@ jobs:
publish-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14
registry-url: https://registry.npmjs.org/
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sonarcloud.yml
Expand Up @@ -9,7 +9,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
# Disabling shallow clone to improve relevancy of SonarCloud reporting
fetch-depth: 0
Expand Down
13 changes: 9 additions & 4 deletions .npmignore
@@ -1,11 +1,16 @@
src/
.babelrc
.eslintignore
.eslintrc.json
.eslintrc.js
.gitignore
.travis.yml
.release-it.json
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Makefile
config.ts
renovate.json
tsconfig.json
jest.config.js
tslint.json
webpack.config.js
.github
/**/__mocks__/
/**/__tests__/
42 changes: 34 additions & 8 deletions Makefile
@@ -1,18 +1,24 @@
generator:=typescript-node
openapi-generator-cli:=docker run --user $(shell id -u):$(shell id -g) --rm -v ${PWD}:/local -w /local openapitools/openapi-generator-cli:v5.4.0
services:=binlookup checkout storedValue terminalManagement payments recurring payouts management legalEntityManagement balancePlatform platformsAccount platformsFund platformsNotificationConfiguration platformsHostedOnboardingPage transfer
openapi-generator-version:=5.4.0
openapi-generator-url:=https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/$(openapi-generator-version)/openapi-generator-cli-$(openapi-generator-version).jar
openapi-generator-jar:=build/openapi-generator-cli.jar
openapi-generator-cli:=java -jar $(openapi-generator-jar)
services:=balancePlatform binlookup checkout dataProtection legalEntityManagement management payments payouts platformsAccount platformsFund platformsHostedOnboardingPage platformsNotificationConfiguration recurring storedValue terminalManagement transfer

# Generate models (for each service)
models: $(services)

binlookup: spec=BinLookupService-v52
checkout: spec=CheckoutService-v69
dataProtection: spec=DataProtectionService-v1
storedValue: spec=StoredValueService-v46
terminalManagement: spec=TfmAPIService-v1
payments: spec=PaymentService-v68
recurring: spec=RecurringService-v68
payouts: spec=PayoutService-v68
management: spec=ManagementService-v1
managementapi: spec=ManagementService-v1
managementapi: service=management
legalEntityManagement: spec=LegalEntityService-v2
balancePlatform: spec=BalancePlatformService-v2
platformsAccount: spec=AccountService-v6
Expand All @@ -21,28 +27,48 @@ platformsNotificationConfiguration: spec=NotificationConfigurationService-v6
platformsHostedOnboardingPage: spec=HopService-v6
transfer: spec=TransferService-v3

$(services): build/spec
$(services): build/spec $(openapi-generator-jar)
rm -rf src/typings/$@ build/model
$(openapi-generator-cli) generate \
-i build/spec/json/$(spec).json \
-g $(generator) \
-t templates/typescript \
-o build \
--global-property models,supportingFiles
--global-property models,supportingFiles \
--additional-properties=serviceName=$@
mv build/model src/typings/$@

# Service
managementapi: build/spec $(openapi-generator-jar)
$(openapi-generator-cli) generate \
-i build/spec/json/$(spec).json \
-g $(generator) \
-t templates/typescript \
-o build \
--api-package $(service) \
--model-package typings/$(service) \
--global-property apis \
--additional-properties=serviceName=$(service)
cp build/$(service)/* src/services/$(service)
sed -i.bak '/RestServiceError/d' src/services/$(service)/*
rm src/services/$(service)/*.bak

# Checkout spec (and patch version)
build/spec:
git clone https://github.com/Adyen/adyen-openapi.git build/spec
sed -i 's/"openapi" : "3.[0-9].[0-9]"/"openapi" : "3.0.0"/' build/spec/json/*.json
perl -i -pe's/"openapi" : "3.[0-9].[0-9]"/"openapi" : "3.0.0"/' build/spec/json/*.json

# Extract templates (copy them for modifications)
templates:
templates: $(openapi-generator-jar)
$(openapi-generator-cli) author template -g $(generator) -o build/templates/typescript

# Download the generator
$(openapi-generator-jar):
wget --quiet -o /dev/null $(openapi-generator-url) -O $(openapi-generator-jar)

# Discard generated artifacts and changed models
clean:
git checkout src/typings
git clean -f -d src/typings
git checkout src/typings src/services/management
git clean -f -d src/typings src/services/management

.PHONY: templates models $(services)
136 changes: 105 additions & 31 deletions README.md
@@ -1,43 +1,45 @@

![Node js](https://user-images.githubusercontent.com/62436079/207373079-9cf9377f-f530-4b02-a515-9b64ef7b06e7.png)

# Adyen Node.js API Library
![Node.js CI](https://github.com/Adyen/adyen-node-api-library/workflows/Node.js%20CI/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/Adyen/adyen-node-api-library/badge.svg?branch=main)](https://coveralls.io/github/Adyen/adyen-node-api-library?branch=main)
[![Downloads](https://img.shields.io/npm/dm/@adyen/api-library.svg)](https://www.npmjs.com/package/@adyen/api-library)
![npm bundle size (scoped)](https://img.shields.io/bundlephobia/minzip/@adyen/api-library.svg)
[![Version](https://img.shields.io/npm/v/@adyen/api-library.svg)](https://www.npmjs.com/package/@adyen/api-library)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=Adyen_adyen-node-api-library&metric=alert_status)](https://sonarcloud.io/dashboard?id=Adyen_adyen-node-api-library)
[![Total alerts](https://img.shields.io/lgtm/alerts/g/Adyen/adyen-node-api-library.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Adyen/adyen-node-api-library/alerts/)
[![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/Adyen/adyen-node-api-library.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Adyen/adyen-node-api-library/context:javascript)

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

## Integration
## Supported API versions
The Library supports all APIs under the following services:

* [BIN lookup API](https://docs.adyen.com/api-explorer/#/BinLookup/v52/overview): The BIN Lookup API provides endpoints for retrieving information based on a given BIN. Current supported version: **v52**
* [Checkout API](https://docs.adyen.com/api-explorer/#/CheckoutService/v69/overview): Our latest integration for accepting online payments. Current supported version: **v69**
* [Configuration API](https://docs.adyen.com/api-explorer/#/balanceplatform/v2/overview): 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. Current supported verison: **v2**
* [Legal Entity Management API](https://docs.adyen.com/api-explorer/#/legalentity/v2/overview): Manage legal entities that contain information required for verification. Current supported version: **v2**
* [Local/Cloud-based Terminal API](https://docs.adyen.com/point-of-sale/terminal-api-reference): Our point-of-sale integration.
* [Management API](https://docs.adyen.com/api-explorer/#/ManagementService/v1/overview): Configure and manage your Adyen company and merchant accounts, stores, and payment terminals. Current supported version **v1**
* [Payments API](https://docs.adyen.com/api-explorer/#/Payment/v68/overview): Our classic integration for online payments. Current supported version: **v68**
* [Payouts API](https://docs.adyen.com/api-explorer/#/Payout/v68/overview): Endpoints for sending funds to your customers. Current supported version: **v68**
* [Platforms APIs](https://docs.adyen.com/platforms/api): Set of APIs when using Adyen for Platforms. This API is used for the classic integration.
* [Account API](https://docs.adyen.com/api-explorer/#/Account/v6/overview) Current supported version: **v6**
* [Fund API](https://docs.adyen.com/api-explorer/#/Fund/v6/overview) Current supported version: **v6**
* [Hosted onboarding API](https://docs.adyen.com/api-explorer/#/Hop/v6/overview): Current supported version: **v6**
* [Notification Configuration API](https://docs.adyen.com/api-explorer/#/NotificationConfigurationService/v6/overview) Current supported version: **v6**
* [Platforms Notifications Webhooks](https://docs.adyen.com/api-explorer/#/NotificationService/v6/overview) Current supported version: **v6**
* [POS Terminal Management API](https://docs.adyen.com/api-explorer/#/postfmapi/v1/overview): Endpoints for managing your point-of-sale payment terminals. Current supported version **v1**
* [Recurring API](https://docs.adyen.com/api-explorer/#/Recurring/v68/overview): Endpoints for managing saved payment details. Current supported version: **v68**
* [Stored Value API](https://docs.adyen.com/payment-methods/gift-cards/stored-value-api): Manage both online and point-of-sale gift cards and other stored-value cards. Current supported version: **v46**
* [Transfers API](https://docs.adyen.com/api-explorer/transfers/3/overview) The Transfers API provides endpoints that you can use to get information about all your transactions, move funds within your balance platform or send funds from your balance platform to a transfer instrument. **v3**


| API | Description | Service Name | Supported version |
| --- | ----------- | ------------ | ----------------- |
|[BIN lookup API](https://docs.adyen.com/api-explorer/#/BinLookup/v52/overview) | The BIN Lookup API provides endpoints for retrieving information based on a given BIN. | BinLookup | **v52** |
| [Checkout API](https://docs.adyen.com/api-explorer/#/CheckoutService/v69/overview)| Our latest integration for accepting online payments. | CheckoutAPI | **v69** |
| [Configuration API](https://docs.adyen.com/api-explorer/#/balanceplatform/v2/overview)| 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](https://docs.adyen.com/development-resources/data-protection-api) | Adyen Data Protection API provides a way for you to process [Subject Erasure Requests](https://gdpr-info.eu/art-17-gdpr/) 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](https://docs.adyen.com/api-explorer/#/legalentity/v2/overview)| Manage legal entities that contain information required for verification. | LegalEntityManagement | **v2** |
| [Local/Cloud-based Terminal API](https://docs.adyen.com/point-of-sale/terminal-api-reference)| Our point-of-sale integration. | TerminalLocalAPI or TerminalCloudAPI | - |
| [Management API](https://docs.adyen.com/api-explorer/#/ManagementService/v1/overview)| Configure and manage your Adyen company and merchant accounts, stores, and payment terminals. | Management | **v1** |
| [Payments API](https://docs.adyen.com/api-explorer/#/Payment/v68/overview)| Our classic integration for online payments. | ClassicIntegrationAPI | **v68** |
| [Payouts API](https://docs.adyen.com/api-explorer/#/Payout/v68/overview)| Endpoints for sending funds to your customers. | Payout | **v68** |
| [Platforms APIs](https://docs.adyen.com/platforms/api)| Set of APIs when using Adyen for Platforms. This API is used for the classic integration. | Platforms | - |
| [Account API](https://docs.adyen.com/api-explorer/#/Account/v6/overview) | *Platforms subclass* | Account | **v6** |
| [Fund API](https://docs.adyen.com/api-explorer/#/Fund/v6/overview) | *Platforms subclass* | Fund | **v6** |
| [Hosted onboarding API](https://docs.adyen.com/api-explorer/#/Hop/v6/overview)| *Platforms subclass* | HostedOnboardingPage | **v6** |
| [Notification Configuration API](https://docs.adyen.com/api-explorer/#/NotificationConfigurationService/v6/overview) | *Platforms subclass* | NotificationConfiguration | **v6** |
| [Platforms Notifications Webhooks](https://docs.adyen.com/api-explorer/#/NotificationService/v6/overview) || *Models only* | **v6** |
| [POS Terminal Management API](https://docs.adyen.com/api-explorer/#/postfmapi/v1/overview)| Endpoints for managing your point-of-sale payment terminals. | TerminalManagement | **v1** |
| [Recurring API](https://docs.adyen.com/api-explorer/#/Recurring/v68/overview)| Endpoints for managing saved payment details. | Recurring | **v68** |
| [Stored Value API](https://docs.adyen.com/payment-methods/gift-cards/stored-value-api) | Manage both online and point-of-sale gift cards and other stored-value cards. | StoredValue | **v46** |
| [Transfers API](https://docs.adyen.com/api-explorer/transfers/3/overview) | 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](https://docs.adyen.com/api-explorer/Webhooks/1/overview) | 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](https://docs.adyen.com/development-resources/webhooks). | *Models only* | **v1** |

For more information, refer to our [documentation](https://docs.adyen.com/) or the [API Explorer](https://docs.adyen.com/api-explorer/).

## Prerequisites
- [Adyen test account](https://docs.adyen.com/get-started-with-adyen)
- [Adyen test account](https://docs.adyen.com/get-started-with-adyen). To start using Adyen APIs, you will need a Merchant Account.
- [API key](https://docs.adyen.com/development-resources/api-credentials#generate-api-key). For testing, your API credential needs to have the [API PCI Payments role](https://docs.adyen.com/development-resources/api-credentials#roles).
- Node 12 or higher

Expand All @@ -56,21 +58,93 @@ Alternatively, you can download the [release on GitHub](https://github.com/Adyen

## Using the library

### General use with API key
### 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:

```typescript
const client = new Client({apiKey: "YOUR_API_KEY", environment: "TEST"});
const { Client } = require('@adyen/api-library');
const client = new Client({apiKey: "YOUR_API_KEY", environment: "TEST"});
```
### General use with API key for live environment
#### General use with API key for live environment
```typescript
const client = new Client({apiKey: "YOUR_API_KEY", environment: "LIVE"});
const { Client } = require('@adyen/api-library');
const client = new Client({apiKey: "YOUR_API_KEY", environment: "LIVE"});
```
### General use with basic auth
#### General use with basic auth
```typescript
const client = new Client({username: "YOUR_USERNAME", password: "YOUR_PASSWORD", environment: "TEST"});
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](#supported-api-versions) section of this document.
```javascript
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:
```typescript
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](https://nodejs.org/api/https.html) 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`:
Expand Down

0 comments on commit ac955ae

Please sign in to comment.