diff --git a/src/app/core/models/payment-method/payment-method.mapper.ts b/src/app/core/models/payment-method/payment-method.mapper.ts index 99b632b837a..6cd552643f1 100644 --- a/src/app/core/models/payment-method/payment-method.mapper.ts +++ b/src/app/core/models/payment-method/payment-method.mapper.ts @@ -22,7 +22,7 @@ export class PaymentMethodMapper { if (!body.data.length) { return []; } - const paymentMethods = body.data + return body.data .filter(data => PaymentMethodMapper.isPaymentMethodValid(data)) .map(data => ({ id: data.id, @@ -40,14 +40,11 @@ export class PaymentMethodMapper { ? data.paymentInstruments.map(id => included.paymentInstruments[id]) : undefined, parameters: data.parameterDefinitions ? PaymentMethodMapper.mapParameter(data.parameterDefinitions) : undefined, - hostedPaymentPageParameters: data.hostedPaymentPageParameters, + hostedPaymentPageParameters: + data.id === 'Concardis_DirectDebit' + ? PaymentMethodMapper.mapSEPAMandateInformation(data.hostedPaymentPageParameters) + : data.hostedPaymentPageParameters, })); - - // map sepa mandate information only for concardis direct debit - paymentMethods - .filter(pm => pm.id === 'Concardis_DirectDebit') - .forEach(pm => PaymentMethodMapper.mapSEPAMandateInformation(pm)); - return paymentMethods; } // is needed for getting a user's eligible payment methods @@ -199,9 +196,9 @@ export class PaymentMethodMapper { /** * convenience method to restructure concardis sepa mandate hosted payment page parameter */ - private static mapSEPAMandateInformation(pm: PaymentMethod) { - const hostedPaymentPageParameters = pm.hostedPaymentPageParameters; - + private static mapSEPAMandateInformation( + hostedPaymentPageParameters: { name: string; value: string }[] + ): { name: string; value: string }[] { hostedPaymentPageParameters .filter(hppp => hppp.name === 'Concardis_SEPA_Mandate') .forEach(mandateEntry => { @@ -216,5 +213,6 @@ export class PaymentMethodMapper { hostedPaymentPageParameters.push({ name: 'directDebitType', value: sepaMandateArray.directDebitType }); } }); + return hostedPaymentPageParameters; } }