From 448017dbbd70d067c593b1871956d2a3cc78db71 Mon Sep 17 00:00:00 2001 From: Win Date: Thu, 12 Sep 2024 10:59:13 +0700 Subject: [PATCH 1/5] MOL-431: update dockerfile + packages --- processor/Dockerfile | 2 +- processor/package.json | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/processor/Dockerfile b/processor/Dockerfile index 76c1d8f..2a9a82c 100644 --- a/processor/Dockerfile +++ b/processor/Dockerfile @@ -4,7 +4,7 @@ WORKDIR /app COPY ./package*.json ./ -RUN npm install --production --frozen-lockfile +RUN npm install -g typescript && npm install --production --frozen-lockfile COPY . . diff --git a/processor/package.json b/processor/package.json index 7a8e33f..5afaa22 100644 --- a/processor/package.json +++ b/processor/package.json @@ -8,7 +8,7 @@ "start": "node dist/index.js", "gcp-build": "tsc", "start:dev": "concurrently -k \"tsc --watch\" \"nodemon -q dist/index.js\"", - "build": "rimraf ./dist && tsc", + "build": "rm -rf ./dist && tsc", "watch": "nodemon -q --ignore '**/*.spec.ts' src/index.ts", "lint": "eslint . --ext .ts", "prettier:check": "prettier --check '**/*.{js,ts}'", @@ -34,11 +34,7 @@ }, "devDependencies": { "@tsconfig/recommended": "^1.0.7", - "@types/express": "^4.17.21", - "@types/jest": "^29.5.12", "@types/node": "^18.19.39", - "@types/node-fetch": "^2.6.11", - "@types/validator": "^13.12.0", "@typescript-eslint/eslint-plugin": "7.13.1", "@typescript-eslint/parser": "7.13.1", "concurrently": "^8.2.2", @@ -60,6 +56,10 @@ "typescript": "^5.5.3" }, "dependencies": { + "@types/express": "^4.17.21", + "@types/jest": "^29.5.12", + "@types/node-fetch": "^2.6.11", + "@types/validator": "^13.12.0", "@commercetools-backend/loggers": "^21.25.2", "@commercetools/platform-sdk": "^4.11.0", "@commercetools/sdk-client-v2": "^2.5.0", From c324f46ee50fe6a637d2865b475c4c563afa40de Mon Sep 17 00:00:00 2001 From: Win Date: Thu, 12 Sep 2024 11:55:00 +0700 Subject: [PATCH 2/5] MOL-431: update dockerfile + packages --- processor/Dockerfile | 4 ++-- processor/package.json | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/processor/Dockerfile b/processor/Dockerfile index 2a9a82c..5a0f3bb 100644 --- a/processor/Dockerfile +++ b/processor/Dockerfile @@ -4,11 +4,11 @@ WORKDIR /app COPY ./package*.json ./ -RUN npm install -g typescript && npm install --production --frozen-lockfile +RUN npm install --frozen-lockfile COPY . . -RUN npm run build +RUN npm run build && npm prune --production FROM node:18-alpine AS runner diff --git a/processor/package.json b/processor/package.json index 5afaa22..2ba675b 100644 --- a/processor/package.json +++ b/processor/package.json @@ -8,7 +8,7 @@ "start": "node dist/index.js", "gcp-build": "tsc", "start:dev": "concurrently -k \"tsc --watch\" \"nodemon -q dist/index.js\"", - "build": "rm -rf ./dist && tsc", + "build": "rimraf ./dist && tsc", "watch": "nodemon -q --ignore '**/*.spec.ts' src/index.ts", "lint": "eslint . --ext .ts", "prettier:check": "prettier --check '**/*.{js,ts}'", @@ -33,6 +33,10 @@ "node": ">=18.0.0 <=20.9.0" }, "devDependencies": { + "@types/express": "^4.17.21", + "@types/jest": "^29.5.12", + "@types/node-fetch": "^2.6.11", + "@types/validator": "^13.12.0", "@tsconfig/recommended": "^1.0.7", "@types/node": "^18.19.39", "@typescript-eslint/eslint-plugin": "7.13.1", @@ -56,10 +60,6 @@ "typescript": "^5.5.3" }, "dependencies": { - "@types/express": "^4.17.21", - "@types/jest": "^29.5.12", - "@types/node-fetch": "^2.6.11", - "@types/validator": "^13.12.0", "@commercetools-backend/loggers": "^21.25.2", "@commercetools/platform-sdk": "^4.11.0", "@commercetools/sdk-client-v2": "^2.5.0", From 325afdf5d851f16f60c9cce7a684f26362b09faa Mon Sep 17 00:00:00 2001 From: Tung Huynh <84435886+Tung-Huynh-Shopmacher@users.noreply.github.com> Date: Thu, 12 Sep 2024 12:41:56 +0700 Subject: [PATCH 3/5] Update Dockerfile --- processor/Dockerfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/processor/Dockerfile b/processor/Dockerfile index 5a0f3bb..1d010e2 100644 --- a/processor/Dockerfile +++ b/processor/Dockerfile @@ -8,7 +8,9 @@ RUN npm install --frozen-lockfile COPY . . -RUN npm run build && npm prune --production +RUN npm run build + +RUN npm prune --production FROM node:18-alpine AS runner @@ -27,4 +29,4 @@ CMD ["npm", "run", "start"] # Metadata LABEL org.opencontainers.image.authors="Mollie B.V. " \ - copyright="Copyright (c) 2024 Mollie B.V. All rights reserved." \ No newline at end of file + copyright="Copyright (c) 2024 Mollie B.V. All rights reserved." From 98efe1d8a7dee812144ddf4cc91d94f8e6f79180 Mon Sep 17 00:00:00 2001 From: Win Date: Thu, 19 Sep 2024 11:14:30 +0700 Subject: [PATCH 4/5] MOL-471: fixing get payment methods --- CHANGELOG.md | 14 ++++++++++---- processor/package-lock.json | 4 ++-- processor/package.json | 2 +- processor/src/utils/map.utils.ts | 7 ++++++- processor/tests/service/payment.service.spec.ts | 16 ++++++++-------- processor/tests/utils/map.utils.spec.ts | 8 ++++---- 6 files changed, 31 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a6aaa26..f4355b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,20 +4,26 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## v1.0.2 + +Fixes + +- Fix the issue that the payment method is not correctly set in some cases + ## v1.0.1 -### Added +Added - Changelog -### Updated +Updated - Postman collection - Interface interaction field naming to differentiate the connector itself to others ## v1.0.0 -### Added +Added - General configurations for Commercetools, Mollie and connector related - Package version for requests @@ -32,7 +38,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p - [KBC/CBC](https://docs.mollie.com/docs/kbc) - [Paypal](https://docs.mollie.com/docs/paypal) - [Przelewy24](https://docs.mollie.com/docs/przelewy24) -- Supporting for [Apply pay direct](https://docs.mollie.com/docs/direct-integration-of-apple-pay) & [Mollie card component](https://docs.mollie.com/docs/mollie-components) +- Supporting for [Apply pay direct](https://docs.mollie.com/docs/direct-integration-of-apple-pay) & [Mollie card component](https://docs.mollie.com/docs/mollie-components) - Filter options for listing payment methods - Create/cancel payment via Payment API - Refund/cancel refund payment via Refund API diff --git a/processor/package-lock.json b/processor/package-lock.json index fd7e99a..8b01a13 100644 --- a/processor/package-lock.json +++ b/processor/package-lock.json @@ -1,12 +1,12 @@ { "name": "shopmacher-mollie-processor", - "version": "1.0.0", + "version": "1.0.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "shopmacher-mollie-processor", - "version": "1.0.0", + "version": "1.0.2", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/processor/package.json b/processor/package.json index 2ba675b..98e4a1d 100644 --- a/processor/package.json +++ b/processor/package.json @@ -1,7 +1,7 @@ { "name": "shopmacher-mollie-processor", "description": "Integration between commercetools and mollie payment service provider", - "version": "1.0.0", + "version": "1.0.2", "main": "index.js", "private": true, "scripts": { diff --git a/processor/src/utils/map.utils.ts b/processor/src/utils/map.utils.ts index ad95dcb..f7f3570 100644 --- a/processor/src/utils/map.utils.ts +++ b/processor/src/utils/map.utils.ts @@ -9,7 +9,12 @@ import { parseStringToJsonObject, removeEmptyProperties } from './app.utils'; import { readConfiguration } from './config.utils'; const extractMethodsRequest = (ctPayment: Payment): ParsedMethodsRequestType | undefined => { - return ctPayment?.custom?.fields?.[CustomFields.payment.request]; + return parseStringToJsonObject( + ctPayment?.custom?.fields?.[CustomFields.payment.request], + CustomFields.payment.request, + 'SCTM - extractMethodsRequest', + ctPayment.id, + ); }; const buildMethodsListParams = (parsedMethodsRequest: ParsedMethodsRequestType): Partial => { diff --git a/processor/tests/service/payment.service.spec.ts b/processor/tests/service/payment.service.spec.ts index 371c94b..43dc30a 100644 --- a/processor/tests/service/payment.service.spec.ts +++ b/processor/tests/service/payment.service.spec.ts @@ -160,9 +160,9 @@ describe('Test listPaymentMethodsByPayment', () => { }, custom: { fields: { - sctm_payment_methods_request: { + sctm_payment_methods_request: JSON.stringify({ locale: 'de_DE', - }, + }), }, } as unknown as CustomFields, } as unknown as Payment; @@ -214,9 +214,9 @@ describe('Test listPaymentMethodsByPayment', () => { }, custom: { fields: { - sctm_payment_methods_request: { + sctm_payment_methods_request: JSON.stringify({ locale: 'de_DE', - }, + }), }, } as unknown as CustomFields, } as unknown as Payment; @@ -286,9 +286,9 @@ describe('Test listPaymentMethodsByPayment', () => { }, custom: { fields: { - sctm_payment_methods_request: { + sctm_payment_methods_request: JSON.stringify({ locale: 'de_DE', - }, + }), }, } as unknown as CustomFields, } as unknown as Payment; @@ -362,9 +362,9 @@ describe('Test listPaymentMethodsByPayment', () => { }, custom: { fields: { - sctm_payment_methods_request: { + sctm_payment_methods_request: JSON.stringify({ locale: 'de_DE', - }, + }), }, } as unknown as CustomFields, } as unknown as Payment; diff --git a/processor/tests/utils/map.utils.spec.ts b/processor/tests/utils/map.utils.spec.ts index be3c7bd..5d2b17a 100644 --- a/processor/tests/utils/map.utils.spec.ts +++ b/processor/tests/utils/map.utils.spec.ts @@ -28,14 +28,14 @@ describe('Test map.utils.ts', () => { }, custom: { fields: { - sctm_payment_methods_request: { + sctm_payment_methods_request: JSON.stringify({ sequenceType: 'oneoff', locale: 'de_DE', billingCountry: 'DE', resouce: 'payments', - includeWallets: 'momo', + includeWallets: 'applepay', orderLineCategories: 'demo,test,sandbox', - }, + }), }, }, } as unknown as Payment; @@ -49,7 +49,7 @@ describe('Test map.utils.ts', () => { sequenceType: 'oneoff', locale: 'de_DE', billingCountry: 'DE', - includeWallets: 'momo', + includeWallets: 'applepay', orderLineCategories: 'demo,test,sandbox', } as unknown as MethodsListParams; From eb018242f1e0d0d06ffbcb651ef35596630c2393 Mon Sep 17 00:00:00 2001 From: Nghia Tran Date: Tue, 1 Oct 2024 11:49:05 +0700 Subject: [PATCH 5/5] MOL-475: Connector should verify if mailaddress for banktransfer is set, as it is mandatory --- .../src/validators/payment.validators.ts | 8 +- .../validators/payment.validators.spec.ts | 87 ++++++++++++++++++- 2 files changed, 91 insertions(+), 4 deletions(-) diff --git a/processor/src/validators/payment.validators.ts b/processor/src/validators/payment.validators.ts index aeada37..9cad0df 100644 --- a/processor/src/validators/payment.validators.ts +++ b/processor/src/validators/payment.validators.ts @@ -38,7 +38,7 @@ const validateCardToken = (cardToken: string | undefined, ctPayment: CTPayment): } }; -const validateBanktransfer = (paymentCustomFields: any, ctPayment: CTPayment): void => { +export const validateBanktransfer = (paymentCustomFields: any, ctPayment: CTPayment): void => { if (!paymentCustomFields?.billingAddress || !paymentCustomFields?.billingAddress?.email) { throwError( 'validateBanktransfer', @@ -66,8 +66,10 @@ const validateBlik = (paymentCustomFields: any, ctPayment: CTPayment): void => { } }; -const paymentMethodRequiredExtraParameters = (method: string): method is MolliePaymentMethods | CustomPaymentMethod => { - return [MolliePaymentMethods.creditcard, CustomPaymentMethod.blik].includes( +export const paymentMethodRequiredExtraParameters = ( + method: string, +): method is MolliePaymentMethods | CustomPaymentMethod => { + return [MolliePaymentMethods.creditcard, CustomPaymentMethod.blik, MolliePaymentMethods.banktransfer].includes( method as MolliePaymentMethods | CustomPaymentMethod, ); }; diff --git a/processor/tests/validators/payment.validators.spec.ts b/processor/tests/validators/payment.validators.spec.ts index 55366c0..4bfaf56 100644 --- a/processor/tests/validators/payment.validators.spec.ts +++ b/processor/tests/validators/payment.validators.spec.ts @@ -12,8 +12,10 @@ import { checkValidRefundTransactionForCreate, checkValidRefundTransactionForCancel, checkValidSuccessAuthorizationTransaction, + validateBanktransfer, + paymentMethodRequiredExtraParameters, } from './../../src/validators/payment.validators'; -import { describe, it, expect, jest, afterEach } from '@jest/globals'; +import { describe, it, expect, jest, afterEach, test } from '@jest/globals'; import CustomError from '../../src/errors/custom.error'; import SkipError from '../../src/errors/skip.error'; import { logger } from '../../src/utils/logger.utils'; @@ -281,6 +283,62 @@ describe('checkPaymentMethodInput', () => { expect(checkPaymentMethodSpecificParameters).toBeCalledTimes(1); }); + + it('should validate the billing email for banktransfer method', () => { + const paymentValidators = require('../../src/validators/payment.validators'); + + jest.spyOn(paymentValidators, 'checkPaymentMethodSpecificParameters'); + jest.spyOn(paymentValidators, 'validateBanktransfer'); + + const CTPayment: Payment = { + id: '5c8b0375-305a-4f19-ae8e-07806b101999', + version: 1, + createdAt: '2024-07-04T14:07:35.625Z', + lastModifiedAt: '2024-07-04T14:07:35.625Z', + amountPlanned: { + type: 'centPrecision', + currencyCode: 'EUR', + centAmount: 1000, + fractionDigits: 2, + }, + paymentStatus: {}, + transactions: [], + interfaceInteractions: [], + paymentMethodInfo: { + method: 'banktransfer', + }, + custom: { + type: { + typeId: 'type', + id: 'sctm-payment-custom-fields', + }, + fields: { + sctm_create_payment_request: + '{"description":"Test","locale":"en_GB","redirectUrl":"https://www.google.com/","cardToken":"token_12345"}', + }, + }, + }; + + try { + checkPaymentMethodInput(ConnectorActions.CreatePayment, CTPayment); + } catch (error) { + expect(checkPaymentMethodSpecificParameters).toBeCalledTimes(1); + expect(checkPaymentMethodSpecificParameters).toBeCalledWith( + CTPayment, + CTPayment.paymentMethodInfo.method as string, + ); + + expect(validateBanktransfer).toBeCalledTimes(1); + + expect(logger.error).toBeCalledTimes(1); + expect(logger.error).toBeCalledWith( + 'SCTM - validateBanktransfer - email is required for payment method banktransfer. Please make sure you have sent it in billingAddress.email of the custom field.', + { + commerceToolsPayment: CTPayment, + }, + ); + } + }); }); describe('checkPaymentMethodSpecificParameters', () => { @@ -1354,3 +1412,30 @@ describe('validateCommerceToolsPaymentPayload', () => { expect(checkValidSuccessAuthorizationTransaction).toReturnWith(true); }); }); + +describe('paymentMethodRequiredExtraParameters', () => { + test.each([ + { + method: 'creditcard', + result: true, + }, + { + method: 'banktransfer', + result: true, + }, + { + method: 'blik', + result: true, + }, + { + method: 'applepay', + result: false, + }, + { + method: 'ideal', + result: false, + }, + ])('should return $result for method $method', ({ method, result }) => { + expect(paymentMethodRequiredExtraParameters(method)).toBe(result); + }); +});