Skip to content

Commit

Permalink
fix: display payment costs according to the configured display type (…
Browse files Browse the repository at this point in the history
…gross/net) (#396)
  • Loading branch information
SGrueber authored Oct 6, 2020
1 parent ea04df6 commit b89c59d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ describe('Payment Method Mapper', () => {

expect(paymentMethod).toBeTruthy();
expect(paymentMethod.id).toEqual('ISH_CreditCard');
expect(paymentMethod.paymentCosts.value).toBePositive();
expect(paymentMethod.paymentCostsThreshold.value).toBePositive();
expect(paymentMethod.paymentCosts.net).toBePositive();
expect(paymentMethod.paymentCostsThreshold.net).toBePositive();
expect(paymentMethod.isRestricted).toBeFalse();
expect(paymentMethod.saveAllowed).toBeFalse();
});
Expand Down
4 changes: 2 additions & 2 deletions src/app/core/models/payment-method/payment-method.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export class PaymentMethodMapper {
isRestricted: data.restricted,
saveAllowed: data.saveAllowed && !!data.parameterDefinitions && !!data.parameterDefinitions.length,
restrictionCauses: data.restrictions,
paymentCosts: PriceItemMapper.fromSpecificPriceItem(data.paymentCosts, 'net'),
paymentCostsThreshold: PriceItemMapper.fromSpecificPriceItem(data.paymentCostsThreshold, 'net'),
paymentCosts: PriceItemMapper.fromPriceItem(data.paymentCosts),
paymentCostsThreshold: PriceItemMapper.fromPriceItem(data.paymentCostsThreshold),
paymentInstruments:
included && included.paymentInstruments && data.paymentInstruments
? data.paymentInstruments.map(id => included.paymentInstruments[id])
Expand Down
6 changes: 3 additions & 3 deletions src/app/core/models/payment-method/payment-method.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FormlyFieldConfig } from '@ngx-formly/core';

import { PaymentInstrument } from 'ish-core/models/payment-instrument/payment-instrument.model';
import { PaymentRestriction } from 'ish-core/models/payment-restriction/payment-restriction.model';
import { Price } from 'ish-core/models/price/price.model';
import { PriceItem } from 'ish-core/models/price-item/price-item.model';

export interface PaymentMethod {
id: string;
Expand All @@ -11,8 +11,8 @@ export interface PaymentMethod {
saveAllowed?: boolean;
description?: string;
capabilities?: string[];
paymentCosts?: Price;
paymentCostsThreshold?: Price;
paymentCosts?: PriceItem;
paymentCostsThreshold?: PriceItem;
isRestricted?: boolean;
restrictionCauses?: PaymentRestriction[];
paymentInstruments?: PaymentInstrument[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ <h3>{{ 'checkout.payment.method.select.heading' | translate }}</h3>
<p *ngIf="paymentMethod.description">{{ paymentMethod.description }}</p>
<p *ngIf="paymentCostThresholdReached(paymentMethod); else displayPaymentCosts">
{{ 'checkout.payment.payment_cost_threshold.amount_reached' | translate }}
&nbsp;
{{ basket.totals.total | ishPrice }}
</p>
<ng-template #displayPaymentCosts>
<div *ngIf="!paymentMethod.isRestricted; else displayRestrictions">
<p *ngIf="paymentMethod.paymentCosts && paymentMethod.paymentCosts.value">
<p *ngIf="paymentMethod.paymentCosts">
{{ 'checkout.payment.method.charges.text' | translate }}&nbsp;{{
paymentMethod.paymentCosts | ishPrice
}}&nbsp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,11 @@ export class CheckoutPaymentComponent implements OnInit, OnChanges, OnDestroy {
*/
paymentCostThresholdReached(paymentMethod: PaymentMethod): boolean {
const basketTotalPrice = PriceItemHelper.selectType(this.basket.totals.total, this.priceType);

if (paymentMethod.paymentCostsThreshold && basketTotalPrice) {
return paymentMethod.paymentCostsThreshold.value <= basketTotalPrice.value;
return (
PriceItemHelper.selectType(paymentMethod.paymentCostsThreshold, this.priceType)?.value <= basketTotalPrice.value
);
}
return false;
}
Expand Down

0 comments on commit b89c59d

Please sign in to comment.