Skip to content

Commit

Permalink
Merge pull request #37 from mollie/feature/MOL-268/MOL-282
Browse files Browse the repository at this point in the history
MOL-268/MOL-282: add supported methods check
  • Loading branch information
Tung-Huynh-Shopmacher authored Aug 12, 2024
2 parents 651dd3b + 6ce9441 commit f557963
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
9 changes: 8 additions & 1 deletion processor/src/service/payment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import {
import { getPaymentExtension } from '../commercetools/extensions.commercetools';
import { HttpDestination } from '@commercetools/platform-sdk/dist/declarations/src/generated/models/extension';
import { cancelPaymentRefund, createPaymentRefund, getPaymentRefund } from '../mollie/refund.mollie';
import { ApplePaySessionRequest, CustomPayment } from '../types/mollie.types';
import { ApplePaySessionRequest, CustomPayment, SupportedPaymentMethods } from '../types/mollie.types';
import { parseStringToJsonObject } from '../utils/app.utils';
import ApplePaySession from '@mollie/api-client/dist/types/src/data/applePaySession/ApplePaySession';

Expand All @@ -82,6 +82,13 @@ export const handleListPaymentMethodsByPayment = async (ctPayment: Payment): Pro
);
}

methods.splice(
methods.findIndex((method: Method) => {
return !SupportedPaymentMethods[method.id.toString() as SupportedPaymentMethods];
}),
1,
);

const availableMethods = JSON.stringify({
count: methods.length,
methods: methods.length ? methods : [],
Expand Down
13 changes: 13 additions & 0 deletions processor/src/types/mollie.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,16 @@ export type CustomPayment = Readonly<
method: CustomPaymentMethod;
}
>;

export enum SupportedPaymentMethods {
ideal = 'ideal',
creditcard = 'creditcard',
bancontact = 'bancontact',
banktransfer = 'banktransfer',
przelewy24 = 'przelewy24',
kbc = 'kbc',
blik = 'blik',
applepay = 'applepay',
paypal = 'paypal',
giftcard = 'giftcard',
}
4 changes: 2 additions & 2 deletions processor/src/validators/payment.validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { CTTransactionState, CTTransactionType } from '../types/commercetools.ty
import { parseStringToJsonObject, validateEmail } from '../utils/app.utils';
import { readConfiguration } from '../utils/config.utils';
import { toBoolean } from 'validator';
import { CustomPaymentMethod } from '../types/mollie.types';
import { CustomPaymentMethod, SupportedPaymentMethods } from '../types/mollie.types';

/**
* Checks if the given action is either 'Create' or 'Update'.
Expand Down Expand Up @@ -51,7 +51,7 @@ export const checkPaymentInterface = (ctPayment: CTPayment): true | SkipError =>
* @return {boolean} Returns true if the method is supported by Mollie
*/
export const hasValidPaymentMethod: (method: string | undefined) => boolean = (method: string | undefined): boolean => {
return !!MolliePaymentMethods[method as MolliePaymentMethods] || !!CustomPaymentMethod[method as CustomPaymentMethod];
return !!SupportedPaymentMethods[method as SupportedPaymentMethods];
};

/**
Expand Down
8 changes: 6 additions & 2 deletions processor/tests/validators/payment.validators.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,15 @@ describe('hasValidPaymentMethod', () => {
it('should return true if the payment method is defined and is supported by Mollie', () => {
expect(hasValidPaymentMethod('applepay')).toBe(true);
expect(hasValidPaymentMethod('paypal')).toBe(true);
expect(hasValidPaymentMethod('dummy')).toBe(true);
});

it('should return false if the payment method is defined and is not supported by Mollie', () => {
expect(hasValidPaymentMethod('test')).toBe(false);
expect(hasValidPaymentMethod('dummy')).toBe(false);
expect(hasValidPaymentMethod('eps')).toBe(false);
expect(hasValidPaymentMethod('twint')).toBe(false);
expect(hasValidPaymentMethod('bancomat')).toBe(false);
expect(hasValidPaymentMethod('trustly')).toBe(false);
});
});

Expand Down Expand Up @@ -232,7 +236,7 @@ describe('checkPaymentMethodInput', () => {
transactions: [],
interfaceInteractions: [],
paymentMethodInfo: {
method: 'dummy',
method: 'paypal',
},
};

Expand Down

0 comments on commit f557963

Please sign in to comment.