Skip to content

Commit

Permalink
ISREST-1006: add sepa component
Browse files Browse the repository at this point in the history
  • Loading branch information
skoch-intershop committed Mar 18, 2020
1 parent e8d6e38 commit cdb0045
Show file tree
Hide file tree
Showing 12 changed files with 591 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export class HostedPaymentPageParametersMapper {
static fromData(body: { name: string; value: string }[]): { name: string; value: string }[] {
const hostedPaymentPageParameters: { name: string; value: string }[] = new Array();

if (body !== undefined) {
for (const entry of body) {
if (typeof entry.value !== 'string') {
const sepaMandateArray = entry.value as { name: string; value: string }[];
hostedPaymentPageParameters.push({ name: 'mandateId', value: sepaMandateArray['mandateId'] });
hostedPaymentPageParameters.push({ name: 'mandateText', value: sepaMandateArray['mandateText'] });
hostedPaymentPageParameters.push({ name: 'directDebitType', value: sepaMandateArray['directDebitType'] });
} else {
hostedPaymentPageParameters.push(entry);
}
}
}

return hostedPaymentPageParameters;
}
}
3 changes: 2 additions & 1 deletion src/app/core/models/payment-method/payment-method.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { FormlyFieldConfig } from '@ngx-formly/core';
import { PaymentInstrumentData } from 'ish-core/models/payment-instrument/payment-instrument.interface';
import { PriceMapper } from 'ish-core/models/price/price.mapper';

import { HostedPaymentPageParametersMapper } from './hosted-payment-page-parameters.mapper';
import {
PaymentMethodBaseData,
PaymentMethodData,
Expand Down Expand Up @@ -41,7 +42,7 @@ export class PaymentMethodMapper {
? data.paymentInstruments.map(id => included.paymentInstruments[id])
: undefined,
parameters: data.parameterDefinitions ? PaymentMethodMapper.mapParameter(data.parameterDefinitions) : undefined,
hostedPaymentPageParameters: data.hostedPaymentPageParameters,
hostedPaymentPageParameters: HostedPaymentPageParametersMapper.fromData(data.hostedPaymentPageParameters),
}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ 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 './payment-concardis-creditcard/payment-concardis-creditcard.component';
import { PaymentConcardisDirectdebitComponent } from './payment-concardis-directdebit/payment-concardis-directdebit.component';

@NgModule({
imports: [SharedModule],
declarations: [CheckoutPaymentComponent, CheckoutPaymentPageComponent, PaymentConcardisCreditcardComponent],
declarations: [
CheckoutPaymentComponent,
CheckoutPaymentPageComponent,
PaymentConcardisCreditcardComponent,
PaymentConcardisDirectdebitComponent,
],
})
export class CheckoutPaymentPageModule {
static component = CheckoutPaymentPageComponent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,39 +107,52 @@ <h3>{{ 'checkout.payment.method.select.heading' | translate }}</h3>
<p class="indicates-required">
<span class="required">*</span>{{ 'account.required_field.message' | translate }}
</p>
<ng-container *ngIf="paymentMethod.serviceId !== 'Concardis_CreditCard'; else ConcardisCreditCard">
<formly-form
[form]="parameterForm"
[options]="options"
[model]="model"
[fields]="paymentMethod.parameters"
>
<div class="offset-md-4 col-md-8">
<ng-container *ngIf="paymentMethod.saveAllowed">
<ng-container *ngTemplateOutlet="saveForLaterTemplate"></ng-container>
</ng-container>
<div class="form-group">
<button type="submit" class="btn btn-primary" [disabled]="submitDisabled">
{{ 'checkout.account.submit.button.label' | translate }}
</button>
<button type="button" class="btn btn-secondary" (click)="cancelNewPaymentInstrument()">
{{ 'checkout.cancel.button.label' | translate }}
</button>
<ng-container [ngSwitch]="paymentMethod.serviceId">
<ng-template [ngSwitchCase]="'Concardis_CreditCard'">
<ish-payment-concardis-creditcard
[paymentMethod]="paymentMethod"
[activated]="formIsOpen(i)"
(submit)="createNewPaymentInstrument($event)"
(cancel)="cancelNewPaymentInstrument()"
></ish-payment-concardis-creditcard>
</ng-template>

<ng-template [ngSwitchCase]="'Concardis_DirectDebit'">
<ish-payment-concardis-directdebit
[paymentMethod]="paymentMethod"
[activated]="formIsOpen(i)"
(submit)="createNewPaymentInstrument($event)"
(cancel)="cancelNewPaymentInstrument()"
></ish-payment-concardis-directdebit>
</ng-template>

<ng-template ngSwitchDefault>
<formly-form
[form]="parameterForm"
[options]="options"
[model]="model"
[fields]="paymentMethod.parameters"
>
<div class="offset-md-4 col-md-8">
<ng-container *ngIf="paymentMethod.saveAllowed">
<ng-container *ngTemplateOutlet="saveForLaterTemplate"></ng-container>
</ng-container>
<div class="form-group">
<button type="submit" class="btn btn-primary" [disabled]="submitDisabled">
{{ 'checkout.account.submit.button.label' | translate }}
</button>
<button type="button" class="btn btn-secondary" (click)="cancelNewPaymentInstrument()">
{{ 'checkout.cancel.button.label' | translate }}
</button>
</div>
</div>
</div>
</formly-form>
</formly-form>
</ng-template>
</ng-container>
<ng-template #ConcardisCreditCard>
<ish-payment-concardis-creditcard
[paymentMethod]="paymentMethod"
[activated]="formIsOpen(i)"
(submit)="createNewPaymentInstrument($event)"
(cancel)="cancelNewPaymentInstrument()"
></ish-payment-concardis-creditcard>
</ng-template>
</div>
</div></li
></ng-container>
</div>
</li></ng-container
>
</ul>
<!-- saveForLater checkbox - outlet template -->
<ng-template #saveForLaterTemplate>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<formly-form [form]="parameterForm" [options]="options" [model]="model" [fields]="getFieldConfig()">
<div class="offset-md-4 col-md-8">
<ish-checkbox
*ngIf="paymentMethod && paymentMethod.saveAllowed"
[form]="parameterForm"
controlName="saveForLater"
label="checkout.save_edit.checkbox.label"
data-testing-id="save-for-later-input"
></ish-checkbox>
<div class="form-group">
<button type="submit" class="btn btn-primary" (click)="submitNewPaymentInstrument()">
{{ 'checkout.account.submit.button.label' | translate }}
</button>
<button type="button" class="btn btn-secondary" (click)="cancelNewPaymentInstrument()">
{{ 'checkout.cancel.button.label' | translate }}
</button>
</div>
</div>
</formly-form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { ReactiveFormsModule } from '@angular/forms';
import { FaIconComponent } from '@fortawesome/angular-fontawesome';
import { NgbPopover } from '@ng-bootstrap/ng-bootstrap';
import { FormlyForm } from '@ngx-formly/core';
import { TranslateModule } from '@ngx-translate/core';
import { MockComponent } from 'ng-mocks';

import { PaymentMethod } from 'ish-core/models/payment-method/payment-method.model';
import { CheckboxComponent } from 'ish-shared/forms/components/checkbox/checkbox.component';

import { PaymentConcardisDirectdebitComponent } from './payment-concardis-directdebit.component';

describe('Payment Concardis Directdebit Component', () => {
let component: PaymentConcardisDirectdebitComponent;
let fixture: ComponentFixture<PaymentConcardisDirectdebitComponent>;
let element: HTMLElement;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
MockComponent(CheckboxComponent),
MockComponent(FaIconComponent),
MockComponent(FormlyForm),
MockComponent(NgbPopover),
PaymentConcardisDirectdebitComponent,
],
imports: [ReactiveFormsModule, TranslateModule.forRoot()],
}).compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(PaymentConcardisDirectdebitComponent);
component = fixture.componentInstance;
element = fixture.nativeElement;

component.paymentMethod = {
id: 'Concardis_DirectDebit',
saveAllowed: false,
parameters: [{ key: 'key1', name: 'name', templateOptions: { label: 'input' } }],
} as PaymentMethod;
});

it('should be created', () => {
expect(component).toBeTruthy();
expect(element).toBeTruthy();
expect(() => fixture.detectChanges()).not.toThrow();
});
});
Loading

0 comments on commit cdb0045

Please sign in to comment.