Skip to content

Commit

Permalink
Merge branch 'main' of github.com:mollie/commercetools-connector
Browse files Browse the repository at this point in the history
  • Loading branch information
Tung-Huynh-Shopmacher committed Oct 2, 2024
2 parents 6a12153 + fc677d6 commit a4061bd
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 29 deletions.
14 changes: 10 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 5 additions & 3 deletions processor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ WORKDIR /app

COPY ./package*.json ./

RUN npm install --production --frozen-lockfile
RUN npm install --frozen-lockfile

COPY . .

RUN npm run build
RUN npm run build

RUN npm prune --production

FROM node:18-alpine AS runner

Expand All @@ -27,4 +29,4 @@ CMD ["npm", "run", "start"]

# Metadata
LABEL org.opencontainers.image.authors="Mollie B.V. <[email protected]>" \
copyright="Copyright (c) 2024 Mollie B.V. All rights reserved."
copyright="Copyright (c) 2024 Mollie B.V. All rights reserved."
4 changes: 2 additions & 2 deletions processor/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions processor/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down Expand Up @@ -33,12 +33,12 @@
"node": ">=18.0.0 <=20.9.0"
},
"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",
"@tsconfig/recommended": "^1.0.7",
"@types/node": "^18.19.39",
"@typescript-eslint/eslint-plugin": "7.13.1",
"@typescript-eslint/parser": "7.13.1",
"concurrently": "^8.2.2",
Expand Down
7 changes: 6 additions & 1 deletion processor/src/utils/map.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<MethodsListParams> => {
Expand Down
8 changes: 5 additions & 3 deletions processor/src/validators/payment.validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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,
);
};
Expand Down
16 changes: 8 additions & 8 deletions processor/tests/service/payment.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions processor/tests/utils/map.utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down
87 changes: 86 additions & 1 deletion processor/tests/validators/payment.validators.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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);
});
});

0 comments on commit a4061bd

Please sign in to comment.