From 04f4efbf2aa02000ecc6570d2dbf6d0bba708674 Mon Sep 17 00:00:00 2001 From: skoch Date: Mon, 30 Mar 2020 14:47:12 +0200 Subject: [PATCH] feat: ISREST-1006 adjust payment component structure --- .../payment-method/payment-method.mapper.ts | 27 +++++++++---------- .../checkout-payment-page.module.ts | 6 ++--- .../checkout-payment.component.spec.ts | 5 ++-- ...ayment-concardis-creditcard.component.html | 0 ...ent-concardis-creditcard.component.spec.ts | 0 .../payment-concardis-creditcard.component.ts | 18 +++---------- ...yment-concardis-directdebit.component.html | 0 ...nt-concardis-directdebit.component.spec.ts | 4 +-- ...payment-concardis-directdebit.component.ts | 22 ++++++--------- .../payment-concardis.component.html | 0 .../payment-concardis.component.spec.ts | 7 +++++ .../payment-concardis.component.ts | 20 ++++++++++++-- 12 files changed, 57 insertions(+), 52 deletions(-) rename src/app/pages/checkout-payment/{checkout-payment/payment-concardis => }/payment-concardis-creditcard/payment-concardis-creditcard.component.html (100%) rename src/app/pages/checkout-payment/{checkout-payment/payment-concardis => }/payment-concardis-creditcard/payment-concardis-creditcard.component.spec.ts (100%) rename src/app/pages/checkout-payment/{checkout-payment/payment-concardis => }/payment-concardis-creditcard/payment-concardis-creditcard.component.ts (91%) rename src/app/pages/checkout-payment/{checkout-payment/payment-concardis => }/payment-concardis-directdebit/payment-concardis-directdebit.component.html (100%) rename src/app/pages/checkout-payment/{checkout-payment/payment-concardis => }/payment-concardis-directdebit/payment-concardis-directdebit.component.spec.ts (97%) rename src/app/pages/checkout-payment/{checkout-payment/payment-concardis => }/payment-concardis-directdebit/payment-concardis-directdebit.component.ts (93%) rename src/app/pages/checkout-payment/{checkout-payment => }/payment-concardis/payment-concardis.component.html (100%) rename src/app/pages/checkout-payment/{checkout-payment => }/payment-concardis/payment-concardis.component.spec.ts (83%) rename src/app/pages/checkout-payment/{checkout-payment => }/payment-concardis/payment-concardis.component.ts (91%) 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 6cd552643f1..84f90a162ae 100644 --- a/src/app/core/models/payment-method/payment-method.mapper.ts +++ b/src/app/core/models/payment-method/payment-method.mapper.ts @@ -199,20 +199,19 @@ export class PaymentMethodMapper { private static mapSEPAMandateInformation( hostedPaymentPageParameters: { name: string; value: string }[] ): { name: string; value: string }[] { - hostedPaymentPageParameters - .filter(hppp => hppp.name === 'Concardis_SEPA_Mandate') - .forEach(mandateEntry => { - if (typeof mandateEntry.value !== 'string') { - const sepaMandateArray = mandateEntry.value as { - mandateId: string; - mandateText: string; - directDebitType: string; - }; - hostedPaymentPageParameters.push({ name: 'mandateId', value: sepaMandateArray.mandateId }); - hostedPaymentPageParameters.push({ name: 'mandateText', value: sepaMandateArray.mandateText }); - hostedPaymentPageParameters.push({ name: 'directDebitType', value: sepaMandateArray.directDebitType }); - } - }); + const mandateEntry = hostedPaymentPageParameters.find(hppp => hppp.name === 'Concardis_SEPA_Mandate'); + + if (typeof mandateEntry.value !== 'string') { + const sepaMandateArray = mandateEntry.value as { + mandateId: string; + mandateText: string; + directDebitType: string; + }; + hostedPaymentPageParameters.push({ name: 'mandateId', value: sepaMandateArray.mandateId }); + hostedPaymentPageParameters.push({ name: 'mandateText', value: sepaMandateArray.mandateText }); + hostedPaymentPageParameters.push({ name: 'directDebitType', value: sepaMandateArray.directDebitType }); + } + return hostedPaymentPageParameters; } } diff --git a/src/app/pages/checkout-payment/checkout-payment-page.module.ts b/src/app/pages/checkout-payment/checkout-payment-page.module.ts index b9b9129a60e..c1b50fbb354 100644 --- a/src/app/pages/checkout-payment/checkout-payment-page.module.ts +++ b/src/app/pages/checkout-payment/checkout-payment-page.module.ts @@ -4,9 +4,9 @@ import { SharedModule } from 'ish-shared/shared.module'; import { CheckoutPaymentPageComponent } from './checkout-payment-page.component'; import { CheckoutPaymentComponent } from './checkout-payment/checkout-payment.component'; -import { PaymentConcardisCreditcardComponent } from './checkout-payment/payment-concardis/payment-concardis-creditcard/payment-concardis-creditcard.component'; -import { PaymentConcardisDirectdebitComponent } from './checkout-payment/payment-concardis/payment-concardis-directdebit/payment-concardis-directdebit.component'; -import { PaymentConcardisComponent } from './checkout-payment/payment-concardis/payment-concardis.component'; +import { PaymentConcardisCreditcardComponent } from './payment-concardis-creditcard/payment-concardis-creditcard.component'; +import { PaymentConcardisDirectdebitComponent } from './payment-concardis-directdebit/payment-concardis-directdebit.component'; +import { PaymentConcardisComponent } from './payment-concardis/payment-concardis.component'; @NgModule({ imports: [SharedModule], diff --git a/src/app/pages/checkout-payment/checkout-payment/checkout-payment.component.spec.ts b/src/app/pages/checkout-payment/checkout-payment/checkout-payment.component.spec.ts index 2663fe73439..4ea797f002c 100644 --- a/src/app/pages/checkout-payment/checkout-payment/checkout-payment.component.spec.ts +++ b/src/app/pages/checkout-payment/checkout-payment/checkout-payment.component.spec.ts @@ -21,9 +21,10 @@ import { ErrorMessageComponent } from 'ish-shared/components/common/error-messag import { ModalDialogLinkComponent } from 'ish-shared/components/common/modal-dialog-link/modal-dialog-link.component'; import { CheckboxComponent } from 'ish-shared/forms/components/checkbox/checkbox.component'; +import { PaymentConcardisCreditcardComponent } from '../payment-concardis-creditcard/payment-concardis-creditcard.component'; +import { PaymentConcardisDirectdebitComponent } from '../payment-concardis-directdebit/payment-concardis-directdebit.component'; + import { CheckoutPaymentComponent } from './checkout-payment.component'; -import { PaymentConcardisCreditcardComponent } from './payment-concardis/payment-concardis-creditcard/payment-concardis-creditcard.component'; -import { PaymentConcardisDirectdebitComponent } from './payment-concardis/payment-concardis-directdebit/payment-concardis-directdebit.component'; describe('Checkout Payment Component', () => { let component: CheckoutPaymentComponent; diff --git a/src/app/pages/checkout-payment/checkout-payment/payment-concardis/payment-concardis-creditcard/payment-concardis-creditcard.component.html b/src/app/pages/checkout-payment/payment-concardis-creditcard/payment-concardis-creditcard.component.html similarity index 100% rename from src/app/pages/checkout-payment/checkout-payment/payment-concardis/payment-concardis-creditcard/payment-concardis-creditcard.component.html rename to src/app/pages/checkout-payment/payment-concardis-creditcard/payment-concardis-creditcard.component.html diff --git a/src/app/pages/checkout-payment/checkout-payment/payment-concardis/payment-concardis-creditcard/payment-concardis-creditcard.component.spec.ts b/src/app/pages/checkout-payment/payment-concardis-creditcard/payment-concardis-creditcard.component.spec.ts similarity index 100% rename from src/app/pages/checkout-payment/checkout-payment/payment-concardis/payment-concardis-creditcard/payment-concardis-creditcard.component.spec.ts rename to src/app/pages/checkout-payment/payment-concardis-creditcard/payment-concardis-creditcard.component.spec.ts diff --git a/src/app/pages/checkout-payment/checkout-payment/payment-concardis/payment-concardis-creditcard/payment-concardis-creditcard.component.ts b/src/app/pages/checkout-payment/payment-concardis-creditcard/payment-concardis-creditcard.component.ts similarity index 91% rename from src/app/pages/checkout-payment/checkout-payment/payment-concardis/payment-concardis-creditcard/payment-concardis-creditcard.component.ts rename to src/app/pages/checkout-payment/payment-concardis-creditcard/payment-concardis-creditcard.component.ts index cc79705f415..f80dd9f26e0 100644 --- a/src/app/pages/checkout-payment/checkout-payment/payment-concardis/payment-concardis-creditcard/payment-concardis-creditcard.component.ts +++ b/src/app/pages/checkout-payment/payment-concardis-creditcard/payment-concardis-creditcard.component.ts @@ -1,11 +1,10 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core'; -import { FormControl, FormGroup, Validators } from '@angular/forms'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core'; import { takeUntil } from 'rxjs/operators'; import { ScriptLoaderService } from 'ish-core/utils/script-loader/script-loader.service'; import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils'; -import { PaymentConcardisComponent } from '../payment-concardis.component'; +import { PaymentConcardisComponent } from '../payment-concardis/payment-concardis.component'; // allows access to concardis js functionality // tslint:disable-next-line:no-any @@ -28,7 +27,7 @@ declare var PayEngine: any; changeDetection: ChangeDetectionStrategy.Default, }) // tslint:disable-next-line:ccp-no-intelligence-in-components -export class PaymentConcardisCreditcardComponent extends PaymentConcardisComponent implements OnInit { +export class PaymentConcardisCreditcardComponent extends PaymentConcardisComponent { constructor(protected scriptLoader: ScriptLoaderService, protected cd: ChangeDetectorRef) { super(scriptLoader, cd); } @@ -39,17 +38,6 @@ export class PaymentConcardisCreditcardComponent extends PaymentConcardisCompone verificationIframeName: string; }; - /** - * initialize parameter form on init - */ - ngOnInit() { - this.parameterForm = new FormGroup({ - expirationMonth: new FormControl('', [Validators.required, Validators.pattern('[0-9]{2}')]), - expirationYear: new FormControl('', [Validators.required, Validators.pattern('[0-9]{2}')]), - saveForLater: new FormControl(true), - }); - } - /* ---------------------------------------- load concardis script if component is visible ------------------------------------------- */ loadScript() { // load script only once if component becomes visible diff --git a/src/app/pages/checkout-payment/checkout-payment/payment-concardis/payment-concardis-directdebit/payment-concardis-directdebit.component.html b/src/app/pages/checkout-payment/payment-concardis-directdebit/payment-concardis-directdebit.component.html similarity index 100% rename from src/app/pages/checkout-payment/checkout-payment/payment-concardis/payment-concardis-directdebit/payment-concardis-directdebit.component.html rename to src/app/pages/checkout-payment/payment-concardis-directdebit/payment-concardis-directdebit.component.html diff --git a/src/app/pages/checkout-payment/checkout-payment/payment-concardis/payment-concardis-directdebit/payment-concardis-directdebit.component.spec.ts b/src/app/pages/checkout-payment/payment-concardis-directdebit/payment-concardis-directdebit.component.spec.ts similarity index 97% rename from src/app/pages/checkout-payment/checkout-payment/payment-concardis/payment-concardis-directdebit/payment-concardis-directdebit.component.spec.ts rename to src/app/pages/checkout-payment/payment-concardis-directdebit/payment-concardis-directdebit.component.spec.ts index e65e6570398..a57aaa3955c 100644 --- a/src/app/pages/checkout-payment/checkout-payment/payment-concardis/payment-concardis-directdebit/payment-concardis-directdebit.component.spec.ts +++ b/src/app/pages/checkout-payment/payment-concardis-directdebit/payment-concardis-directdebit.component.spec.ts @@ -79,7 +79,7 @@ describe('Payment Concardis Directdebit Component', () => { verify(emitter.emit(anything())).once(); }); - /**it('should show an error if submit call back returns with an error', () => { + it('should show an error if submit call back returns with an error', () => { const errorMessage = 'field is required'; fixture.detectChanges(); @@ -89,7 +89,7 @@ describe('Payment Concardis Directdebit Component', () => { ); expect(component.errorMessage.iban.message).toEqual(errorMessage); - });**/ + }); it('should emit cancel event when cancelNewPaymentInstrument is triggered', () => { fixture.detectChanges(); diff --git a/src/app/pages/checkout-payment/checkout-payment/payment-concardis/payment-concardis-directdebit/payment-concardis-directdebit.component.ts b/src/app/pages/checkout-payment/payment-concardis-directdebit/payment-concardis-directdebit.component.ts similarity index 93% rename from src/app/pages/checkout-payment/checkout-payment/payment-concardis/payment-concardis-directdebit/payment-concardis-directdebit.component.ts rename to src/app/pages/checkout-payment/payment-concardis-directdebit/payment-concardis-directdebit.component.ts index a19b3da4309..460f47c1109 100644 --- a/src/app/pages/checkout-payment/checkout-payment/payment-concardis/payment-concardis-directdebit/payment-concardis-directdebit.component.ts +++ b/src/app/pages/checkout-payment/payment-concardis-directdebit/payment-concardis-directdebit.component.ts @@ -1,12 +1,12 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core'; -import { FormGroup, Validators } from '@angular/forms'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core'; +import { Validators } from '@angular/forms'; import { FormlyFieldConfig } from '@ngx-formly/core'; import { takeUntil } from 'rxjs/operators'; import { ScriptLoaderService } from 'ish-core/utils/script-loader/script-loader.service'; import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils'; -import { PaymentConcardisComponent } from '../payment-concardis.component'; +import { PaymentConcardisComponent } from '../payment-concardis/payment-concardis.component'; // allows access to concardis js functionality // tslint:disable-next-line:no-any @@ -29,22 +29,16 @@ declare var PayEngine: any; changeDetection: ChangeDetectionStrategy.Default, }) // tslint:disable-next-line:ccp-no-intelligence-in-components -export class PaymentConcardisDirectdebitComponent extends PaymentConcardisComponent implements OnInit { +export class PaymentConcardisDirectdebitComponent extends PaymentConcardisComponent { constructor(protected scriptLoader: ScriptLoaderService, protected cd: ChangeDetectorRef) { super(scriptLoader, cd); } - /** - * initialize parameter form on init - */ - ngOnInit() { - this.parameterForm = new FormGroup({}); - } - handleErrors(controlName: string, message: string) { - this.parameterForm.controls[controlName].markAsDirty(); - this.parameterForm.controls[controlName].markAsTouched(); - this.parameterForm.controls[controlName].setErrors({ customError: message }); + if (this.parameterForm.controls[controlName]) { + this.parameterForm.controls[controlName].markAsDirty(); + this.parameterForm.controls[controlName].setErrors({ customError: message }); + } } /* ---------------------------------------- load concardis script if component is visible ------------------------------------------- */ diff --git a/src/app/pages/checkout-payment/checkout-payment/payment-concardis/payment-concardis.component.html b/src/app/pages/checkout-payment/payment-concardis/payment-concardis.component.html similarity index 100% rename from src/app/pages/checkout-payment/checkout-payment/payment-concardis/payment-concardis.component.html rename to src/app/pages/checkout-payment/payment-concardis/payment-concardis.component.html diff --git a/src/app/pages/checkout-payment/checkout-payment/payment-concardis/payment-concardis.component.spec.ts b/src/app/pages/checkout-payment/payment-concardis/payment-concardis.component.spec.ts similarity index 83% rename from src/app/pages/checkout-payment/checkout-payment/payment-concardis/payment-concardis.component.spec.ts rename to src/app/pages/checkout-payment/payment-concardis/payment-concardis.component.spec.ts index efd29332b1b..a498531ec93 100644 --- a/src/app/pages/checkout-payment/checkout-payment/payment-concardis/payment-concardis.component.spec.ts +++ b/src/app/pages/checkout-payment/payment-concardis/payment-concardis.component.spec.ts @@ -2,6 +2,8 @@ import { ComponentFixture, TestBed, async } from '@angular/core/testing'; import { ReactiveFormsModule } from '@angular/forms'; import { TranslateModule } from '@ngx-translate/core'; +import { PaymentMethod } from 'ish-core/models/payment-method/payment-method.model'; + import { PaymentConcardisComponent } from './payment-concardis.component'; describe('Payment Concardis Component', () => { @@ -20,6 +22,11 @@ describe('Payment Concardis Component', () => { fixture = TestBed.createComponent(PaymentConcardisComponent); component = fixture.componentInstance; element = fixture.nativeElement; + + component.paymentMethod = { + id: 'Concardis_CreditCard', + saveAllowed: false, + } as PaymentMethod; }); it('should be created', () => { diff --git a/src/app/pages/checkout-payment/checkout-payment/payment-concardis/payment-concardis.component.ts b/src/app/pages/checkout-payment/payment-concardis/payment-concardis.component.ts similarity index 91% rename from src/app/pages/checkout-payment/checkout-payment/payment-concardis/payment-concardis.component.ts rename to src/app/pages/checkout-payment/payment-concardis/payment-concardis.component.ts index 5eff1711f1a..25ba13a4edb 100644 --- a/src/app/pages/checkout-payment/checkout-payment/payment-concardis/payment-concardis.component.ts +++ b/src/app/pages/checkout-payment/payment-concardis/payment-concardis.component.ts @@ -6,9 +6,10 @@ import { Input, OnChanges, OnDestroy, + OnInit, Output, } from '@angular/core'; -import { FormGroup } from '@angular/forms'; +import { FormControl, FormGroup, Validators } from '@angular/forms'; import { FormlyFormOptions } from '@ngx-formly/core'; import { Subject } from 'rxjs'; @@ -21,7 +22,7 @@ import { ScriptLoaderService } from 'ish-core/utils/script-loader/script-loader. templateUrl: './payment-concardis.component.html', changeDetection: ChangeDetectionStrategy.Default, }) -export class PaymentConcardisComponent implements OnChanges, OnDestroy { +export class PaymentConcardisComponent implements OnInit, OnChanges, OnDestroy { constructor(protected scriptLoader: ScriptLoaderService, protected cd: ChangeDetectorRef) {} /** * concardis payment method, needed to get configuration parameters @@ -62,6 +63,21 @@ export class PaymentConcardisComponent implements OnChanges, OnDestroy { : 'https://pptest.payengine.de/bridge/1.0/payengine.min.js'; } + /** + * initialize parameter form on init + */ + ngOnInit() { + this.parameterForm = new FormGroup( + this.paymentMethod.id === 'Concardis_CreditCard' + ? { + expirationMonth: new FormControl('', [Validators.required, Validators.pattern('[0-9]{2}')]), + expirationYear: new FormControl('', [Validators.required, Validators.pattern('[0-9]{2}')]), + saveForLater: new FormControl(true), + } + : {} + ); + } + /** * load concardis script if component is shown */