From baa39d1afa94d9ab807324d9466921d1bcf56538 Mon Sep 17 00:00:00 2001 From: Blackfaded Date: Mon, 12 Aug 2024 11:51:48 +0200 Subject: [PATCH 01/11] docs: update readme --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index 92b458f..1872f1e 100644 --- a/README.md +++ b/README.md @@ -9,10 +9,6 @@ Welcome to the Node SDK for the PAYONE Commerce Platform! This repository contains a powerful, easy-to-use software development kit (SDK) designed to simplify the integration of online payment processing into your applications. -### TODOS - -- [ ] Write more tests - ## Table of Contents - [Features](#features) From c9fcf9b57839c7425c8044f5cf4ebe8e78ce1a84 Mon Sep 17 00:00:00 2001 From: Blackfaded Date: Mon, 12 Aug 2024 11:53:38 +0200 Subject: [PATCH 02/11] chore: update coverage script in workflow --- .github/workflows/lint_test_sonar.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint_test_sonar.yml b/.github/workflows/lint_test_sonar.yml index 80272ca..46873a2 100644 --- a/.github/workflows/lint_test_sonar.yml +++ b/.github/workflows/lint_test_sonar.yml @@ -27,7 +27,7 @@ jobs: - name: Run Linting run: npm run lint - name: Run Tests - run: npm run coverage + run: npm run test:coverage - name: Run SonarCloud Scan uses: SonarSource/sonarcloud-github-action@master env: From c539427e8d49c25758a62a04dfbdd84c92367f86 Mon Sep 17 00:00:00 2001 From: Blackfaded Date: Mon, 12 Aug 2024 12:18:25 +0200 Subject: [PATCH 03/11] refactor: use correct enum values --- src/endpoints/CheckoutApiClient.test.ts | 2 +- src/endpoints/PaymentInformationApiClient.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/endpoints/CheckoutApiClient.test.ts b/src/endpoints/CheckoutApiClient.test.ts index 7d15627..3efdfea 100644 --- a/src/endpoints/CheckoutApiClient.test.ts +++ b/src/endpoints/CheckoutApiClient.test.ts @@ -89,7 +89,7 @@ describe('CheckoutApiClient', () => { merchantCustomerId: 'cust-1234', references: { merchantReference: 'com-12345' }, amountOfMoney: { currencyCode: 'YEN', amount: 1000 }, - checkoutStatus: StatusCheckout.Open, + checkoutStatus: StatusCheckout.OPEN, }; mockedFetch.mockResolvedValueOnce(createResponseMock(200, expectedResponse)); diff --git a/src/endpoints/PaymentInformationApiClient.test.ts b/src/endpoints/PaymentInformationApiClient.test.ts index 0131a87..b89200f 100644 --- a/src/endpoints/PaymentInformationApiClient.test.ts +++ b/src/endpoints/PaymentInformationApiClient.test.ts @@ -39,12 +39,12 @@ describe('PaymentInformationApiClient', () => { }, type: PaymentType.Sale, paymentProductId: 1331, - paymentChannel: PaymentChannel.Ecommerce, + paymentChannel: PaymentChannel.ECOMMERCE, }; test('given request was successful, should return response', async () => { const expectedResponse: PaymentInformationResponse = { - paymentChannel: PaymentChannel.Pos, + paymentChannel: PaymentChannel.POS, terminalId: 'terminalId', cardPaymentDetails: { maskedCardNumber: '672559XXXXXX1108', From ea27f0a9fa90b5fd29c2ef7042b9f5d136fa488d Mon Sep 17 00:00:00 2001 From: Blackfaded Date: Mon, 12 Aug 2024 12:18:56 +0200 Subject: [PATCH 04/11] chore: add versioning script --- package.json | 3 ++- version.sh | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100755 version.sh diff --git a/package.json b/package.json index 5401f8a..703f465 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,8 @@ "format:write": "prettier --write \"src/**/!(*.d).ts\"", "test": "vitest", "test:coverage": "vitest run --coverage", - "changelog": "conventional-changelog -i CHANGELOG.md -s -r 0 --config ./changelog.config.cjs" + "changelog": "conventional-changelog -i CHANGELOG.md -s -r 0 --config ./changelog.config.cjs", + "version": "./version.sh" }, "keywords": [ "payone", diff --git a/version.sh b/version.sh new file mode 100755 index 0000000..b73de6c --- /dev/null +++ b/version.sh @@ -0,0 +1,16 @@ +SERVER_META_INFO_PATH='./src/utils/ServerMetaInfo.ts' +NEW_VERSION=$npm_package_version + +if [ -n "$NEW_VERSION" ]; then + if [ -f $SERVER_META_INFO_PATH ]; then + sed -i '' "s/JavaServerSDK\/v[0-9]*\.[0-9]*\.[0-9]*/JavaServerSDK\/v$NEW_VERSION/g" ${SERVER_META_INFO_PATH} + git add $SERVER_META_INFO_PATH + echo "Updated $SERVER_META_INFO_PATH with version $NEW_VERSION" + else + echo "Could not find $SERVER_META_INFO_PATH" + exit 1 + fi + +else + echo "Script can only be run as npm version hook" +fi From 487c39f4b99a7426a52c7e45471f87503986925a Mon Sep 17 00:00:00 2001 From: Blackfaded Date: Mon, 12 Aug 2024 12:32:46 +0200 Subject: [PATCH 05/11] docs: update readme --- README.md | 66 ++++++++++++++++++++++++++++---- src/transformer/applepay.test.ts | 6 +-- src/transformer/applepay.ts | 2 +- 3 files changed, 63 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 1872f1e..aea8b70 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,9 @@ Welcome to the Node SDK for the PAYONE Commerce Platform! This repository contai - [Features](#features) - [Installation](#installation) - [Usage](#usage) - - [Configuration](#configuration) +- [Error Handling](#error-handling) +- [Client Side](#client-side) +- [Apple Pay](#apple-pay) - [Contributing](#contributing) - [Build the library](#build-the-library) - [Run tests](#run-tests) @@ -33,16 +35,66 @@ Welcome to the Node SDK for the PAYONE Commerce Platform! This repository contai ## Installation +```sh +# npm +npm i pcp-server-nodejs-sdk +# yarn +yarn add pcp-server-nodejs-sdk +``` + ## Usage -### Configuration +To use this SDK you need to construct a `CommunicatorConfiguration` which encapsulate everything needed to connect to the PAYONE Commerce Platform. + +```ts +const apiKey = process.env.API_KEY; +const apiSecret = process.env.API_SECRET; + +const config = new CommunicatorConfiguration(apiKey, apiSecret, "preprod.commerce-api.payone.com"); +``` + +With the configuration you can create an API client for each reource you want to interact with. For example to create a commerce case you can use the `CommerceCaseApiClient`. + + +```ts +const commerceCaseClient = new CommerceCaseApiClient(config); +``` + +All payloads and reponses are availabe as ts interfaces exported from this library. +For example, to create an empty commerce case you can pass an object with the `CreateCommerceCaseRequest` interface: + + +```ts +const createCommerceCaseRequest: CreateCommerceCaseRequest = {}; + +const createCommerceCaseResponse: CreateCommerceCaseResponse = commerceCaseClient.createCommerceCaseRequest('merchant_id', createCommerceCaseRequest); +``` + +The models directly map to the API as described in [PAYONE Commerce Platform API Reference](https://docs.payone.com/pcp/commerce-platform-api). + + +### Error Handling + +When making a request any client may throw a `ApiException`. There two subtypes of this exception: + +- `ApiErrorReponseException`: This exception is thrown when the API returns an well-formed error response. The given errors are deserialized into `APIError` objects which are availble via the `getErrors()` method on the exception. They usually contain useful information about what is wrong in your request or the state of the resource. +- `ApiResponseRetrievalException`: This exception is a catch-all exception for any error that cannot be turned into a helpful error response. This includes malformed responses or unknown responses. + + +### Client Side + +For most [payment methods](https://docs.payone.com/pcp/commerce-platform-payment-methods) some information from the client is needed, e.g. payment information given by Apple when a payment via ApplePay suceeds. PAYONE provides client side SDKs which helps you interact the third party payment providers. You can find the SDKs under the [PAYONE GitHub organization](https://github.com/PAYONE-GmbH). Either way ensure to never store or even send credit card information to your server. The PAYONE Commerce Platform never needs access to the credit card information. The client side is responsible for safely retrieving a credit card token. This token must be used with this SDK. + +### Apple Pay + +When a client is successfully made a payment via ApplePay it receives a [ApplePayPayment](https://developer.apple.com/documentation/apple_pay_on_the_web/applepaypayment). This structure is accessible as the `ApplePayPayment` class. You can use the `ApplePayTransformer` to map an `ApplePayPayment` to a `MobilePaymentMethodSpecificInput` which can be used for payment executions or order requests. The transformer has a static method `transformApplePayPaymentToMobilePaymentMethodSpecificInput()` which takes an `ApplePayPayment` and returns a `MobilePaymentMethodSpecificInput`. The transformer does not check if the response is complete, if anything is missing the field will be set to `undefined`. ### Run the example app ```sh cd example-app -yarn -API_KEY=api_key API_SECRET=api_secret MERCHANT_ID=123 COMMERCE_CASE_ID=234 CHECKOUT_ID=345 yarn dev +npm i +API_KEY=api_key API_SECRET=api_secret MERCHANT_ID=123 COMMERCE_CASE_ID=234 CHECKOUT_ID=345 npm run dev ``` ## Contributing @@ -82,15 +134,15 @@ npm run coverage git checkout -b release/0.1.0 ``` -- Run prepare-release.sh script to set correct version +- Apply versioning ```sh -./prepare-release.sh +npm version major|minor|patch ``` #### Changelog Generation with Conventional Changelog -After calling the `prepare_release.sh` script, it is recommended to manually trigger the changelog generation script (which uses [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog)). +After versioning, it is recommended to manually trigger the changelog generation script (which uses [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog)). 1. **Conventional Commit Messages**: diff --git a/src/transformer/applepay.test.ts b/src/transformer/applepay.test.ts index ee7360c..d6aa629 100644 --- a/src/transformer/applepay.test.ts +++ b/src/transformer/applepay.test.ts @@ -3,10 +3,10 @@ import type { ApplePayPayment } from '../models/applepay/ApplePayPayment.js'; import type { MobilePaymentMethodSpecificInput } from '../models/MobilePaymentMethodSpecificInput.js'; import { ApplePayPaymentMethodType } from '../models/applepay/ApplePayPaymentMethodType.js'; import { Network } from '../models/Network.js'; -import { applePayPaymentToMobilePaymentMethodSpecificInput } from '../transformer/applepay.js'; +import { transformApplePayPaymentToMobilePaymentMethodSpecificInput } from '../transformer/applepay.js'; describe('applepay transformer', () => { - describe('applePayPaymentToMobilePaymentMethodSpecificInput', () => { + describe('transformApplePayPaymentToMobilePaymentMethodSpecificInput', () => { test('converts a full ApplePayPayment correctly', () => { const payment: ApplePayPayment = { token: { @@ -60,7 +60,7 @@ describe('applepay transformer', () => { }, }; - expect(applePayPaymentToMobilePaymentMethodSpecificInput(payment)).toEqual(expected); + expect(transformApplePayPaymentToMobilePaymentMethodSpecificInput(payment)).toEqual(expected); }); }); }); diff --git a/src/transformer/applepay.ts b/src/transformer/applepay.ts index 67baa54..7dfa86f 100644 --- a/src/transformer/applepay.ts +++ b/src/transformer/applepay.ts @@ -31,7 +31,7 @@ function versionFromString(value: string): ApplePaymentTokenVersion { } } -export function applePayPaymentToMobilePaymentMethodSpecificInput( +export function transformApplePayPaymentToMobilePaymentMethodSpecificInput( payment: ApplePayPayment, ): MobilePaymentMethodSpecificInput { return { From b45ab1e3d0e78dc8151cf52fb9509a182ebefa27 Mon Sep 17 00:00:00 2001 From: Blackfaded Date: Mon, 12 Aug 2024 14:13:25 +0200 Subject: [PATCH 06/11] chore: update npmignore file --- .npmignore | 36 ++++++++---------------------------- README.md | 10 +--------- 2 files changed, 9 insertions(+), 37 deletions(-) diff --git a/.npmignore b/.npmignore index 86236eb..6e8ae59 100644 --- a/.npmignore +++ b/.npmignore @@ -1,28 +1,8 @@ -src -node_modules -coverage -example-app - -temp -images - -.github -.vscode -.idea -*.iml - -.DS_Store -Thumbs.db - -vitest.config.ts -tsconfig.json -sonar-project.properties -prepare_release.sh -lefthook.yml -eslint.config.mjs -.prettierrc -commitlint.config.js -.husky - -*.tar.gz -*.tgz +# Exclude everything +* + +# But include these files and directories +!package.json +!README.md +!dist/ +!dist/** diff --git a/README.md b/README.md index aea8b70..7a6ddd9 100644 --- a/README.md +++ b/README.md @@ -99,15 +99,7 @@ API_KEY=api_key API_SECRET=api_secret MERCHANT_ID=123 COMMERCE_CASE_ID=234 CHECK ## Contributing -We welcome contributions from the community. If you want to contribute, please follow these steps: - -Fork the repository. -Create a new branch (`git checkout -b feature-branch`). -Make your changes. -Commit your changes (`git commit -am 'Add new feature'`). -Push to the branch (`git push origin feature-branch`). -Create a new Pull Request. -Please make sure to follow the coding standards and write appropriate tests for your changes. +See [Contributing](./CONTRIBUTING.md) ### Build the library From 838de357b1cc97f3cae5f007b3d124765df1a1b2 Mon Sep 17 00:00:00 2001 From: Blackfaded Date: Mon, 12 Aug 2024 14:15:02 +0200 Subject: [PATCH 07/11] build: update workflows --- .github/workflows/lint_test_sonar.yml | 4 +++- .github/workflows/publish.yml | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint_test_sonar.yml b/.github/workflows/lint_test_sonar.yml index 46873a2..2b5d77b 100644 --- a/.github/workflows/lint_test_sonar.yml +++ b/.github/workflows/lint_test_sonar.yml @@ -1,4 +1,4 @@ -name: Quality Check (Lint, Test, Sonarcloud) +name: Quality Check (Build, Lint, Test, Sonarcloud) on: push: branches: @@ -24,6 +24,8 @@ jobs: node-version: '20.x' - name: Install dependencies run: npm ci + - name: Run Build + run: npm run build - name: Run Linting run: npm run lint - name: Run Tests diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 3455388..4e5c523 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,9 +1,10 @@ name: Publish package to npm on: workflow_dispatch: + jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 permissions: contents: read packages: write @@ -15,6 +16,7 @@ jobs: registry-url: 'https://registry.npmjs.org' scope: '@payone' - run: npm ci + - run: npm run build - run: npm publish --access public env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} From 4e1e02c949d2ead23c38a7cbf4b1122e3ae1d577 Mon Sep 17 00:00:00 2001 From: Blackfaded Date: Mon, 12 Aug 2024 14:17:42 +0200 Subject: [PATCH 08/11] chore: export transformer in main file --- src/index.ts | 1 + src/transformer/index.ts | 1 + 2 files changed, 2 insertions(+) create mode 100644 src/transformer/index.ts diff --git a/src/index.ts b/src/index.ts index 88e6561..8368790 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,4 +2,5 @@ export * from './endpoints/index.js'; export * from './errors/index.js'; export * from './queries/index.js'; export * from './models/index.js'; +export * from './transformer/index.js'; export { CommunicatorConfiguration } from './CommunicatorConfiguration.js'; diff --git a/src/transformer/index.ts b/src/transformer/index.ts new file mode 100644 index 0000000..fa16c75 --- /dev/null +++ b/src/transformer/index.ts @@ -0,0 +1 @@ +export { transformApplePayPaymentToMobilePaymentMethodSpecificInput } from './applepay.js'; From 4040144231a326943a62a78f2988a6d6702f9deb Mon Sep 17 00:00:00 2001 From: Blackfaded Date: Mon, 12 Aug 2024 14:19:07 +0200 Subject: [PATCH 09/11] chore: add format check in pipeline --- .github/workflows/lint_test_sonar.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint_test_sonar.yml b/.github/workflows/lint_test_sonar.yml index 2b5d77b..4457347 100644 --- a/.github/workflows/lint_test_sonar.yml +++ b/.github/workflows/lint_test_sonar.yml @@ -1,4 +1,4 @@ -name: Quality Check (Build, Lint, Test, Sonarcloud) +name: Quality Check (Build, Lint, Format, Test, Sonarcloud) on: push: branches: @@ -28,6 +28,8 @@ jobs: run: npm run build - name: Run Linting run: npm run lint + - name: Run Format Check + run: npm run format:check - name: Run Tests run: npm run test:coverage - name: Run SonarCloud Scan From 2e22daa3a1875d775b9a1796d09846d92985942b Mon Sep 17 00:00:00 2001 From: Blackfaded Date: Mon, 12 Aug 2024 14:44:00 +0200 Subject: [PATCH 10/11] refactor: change Java to Node sdk --- src/utils/ServerMetaInfo.test.ts | 2 +- src/utils/ServerMetaInfo.ts | 2 +- version.sh | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/utils/ServerMetaInfo.test.ts b/src/utils/ServerMetaInfo.test.ts index dd7022b..74dd7a6 100644 --- a/src/utils/ServerMetaInfo.test.ts +++ b/src/utils/ServerMetaInfo.test.ts @@ -10,7 +10,7 @@ describe('ServerMetaInfo', () => { test('initializes with correct values', () => { const serverMetaInfo = new ServerMetaInfo(); expect(serverMetaInfo.platformIdentifier).toBe(`${os.platform()}, node version is: ${process.version}`); - expect(serverMetaInfo.sdkIdentifier).toBe('JavaServerSDK/v0.0.2'); + expect(serverMetaInfo.sdkIdentifier).toBe('NodeServerSDK/v0.0.2'); expect(serverMetaInfo.sdkCreator).toBe('PAYONE GmbH'); }); }); diff --git a/src/utils/ServerMetaInfo.ts b/src/utils/ServerMetaInfo.ts index c5bc8a1..1709d6b 100644 --- a/src/utils/ServerMetaInfo.ts +++ b/src/utils/ServerMetaInfo.ts @@ -8,7 +8,7 @@ export class ServerMetaInfo { constructor(integrator?: string) { this.platformIdentifier = `${os.platform()}, node version is: ${process.version}`; - this.sdkIdentifier = 'JavaServerSDK/v0.0.2'; // version gets updated with the prepare-release.sh script + this.sdkIdentifier = 'NodeServerSDK/v0.0.2'; // version gets updated with the prepare-release.sh script this.sdkCreator = 'PAYONE GmbH'; this.integrator = integrator || ''; } diff --git a/version.sh b/version.sh index b73de6c..6bcc680 100755 --- a/version.sh +++ b/version.sh @@ -1,9 +1,11 @@ SERVER_META_INFO_PATH='./src/utils/ServerMetaInfo.ts' +SERVER_META_INFO_TEST_PATH='./src/utils/ServerMetaInfo.test.ts' NEW_VERSION=$npm_package_version if [ -n "$NEW_VERSION" ]; then if [ -f $SERVER_META_INFO_PATH ]; then - sed -i '' "s/JavaServerSDK\/v[0-9]*\.[0-9]*\.[0-9]*/JavaServerSDK\/v$NEW_VERSION/g" ${SERVER_META_INFO_PATH} + sed -i '' "s/NodeServerSDK\/v[0-9]*\.[0-9]*\.[0-9]*/NodeServerSDK\/v$NEW_VERSION/g" ${SERVER_META_INFO_PATH} + sed -i '' "s/NodeServerSDK\/v[0-9]*\.[0-9]*\.[0-9]*/NodeServerSDK\/v$NEW_VERSION/g" ${SERVER_META_INFO_TEST_PATH} git add $SERVER_META_INFO_PATH echo "Updated $SERVER_META_INFO_PATH with version $NEW_VERSION" else From eaae5c17e0728f13b33c9038e92678f54301048e Mon Sep 17 00:00:00 2001 From: Blackfaded Date: Mon, 12 Aug 2024 15:03:02 +0200 Subject: [PATCH 11/11] 0.0.2 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5f90bd3..4ffa7a4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pcp-server-nodejs-sdk", - "version": "0.0.1", + "version": "0.0.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "pcp-server-nodejs-sdk", - "version": "0.0.1", + "version": "0.0.2", "license": "MIT", "dependencies": { "node-fetch": "3.3.2" diff --git a/package.json b/package.json index 703f465..6be480c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pcp-server-nodejs-sdk", - "version": "0.0.1", + "version": "0.0.2", "description": "", "main": "dist/index.js", "types": "dist/index.d.ts",