Skip to content

Commit

Permalink
feat: calculate payment cost threshold according to ICM pricing setti…
Browse files Browse the repository at this point in the history
…ngs (#179)
  • Loading branch information
dhhyi committed Apr 8, 2020
1 parent 9e0f518 commit eb981ec
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 19 deletions.
3 changes: 2 additions & 1 deletion src/app/core/facades/checkout.facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ import {
isBasketInvoiceAndShippingAddressEqual,
} from 'ish-core/store/checkout/basket';
import { getCheckoutStep } from 'ish-core/store/checkout/viewconf';
import { getServerConfigParameter } from 'ish-core/store/configuration';
import { CreateOrder, getOrdersError, getSelectedOrder } from 'ish-core/store/orders';
import { getLoggedInUser } from 'ish-core/store/user';
import { whenTruthy } from 'ish-core/utils/operators';

// tslint:disable:member-ordering
@Injectable({ providedIn: 'root' })
export class CheckoutFacade {
Expand Down Expand Up @@ -105,6 +105,7 @@ export class CheckoutFacade {
switchMap(() => this.store.pipe(select(getBasketEligiblePaymentMethods)))
);
}
priceType$ = this.store.pipe(select(getServerConfigParameter<'gross' | 'net'>('pricing.priceType')));

setBasketPayment(paymentName: string) {
this.store.dispatch(new SetBasketPayment({ id: paymentName }));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ <h1>{{ 'checkout.payment.pagetitle' | translate }}</h1>
<ish-checkout-payment
[basket]="basket$ | async"
[paymentMethods]="paymentMethods$ | async"
[priceType]="priceType$ | async"
[error]="basketError$ | async"
(updatePaymentMethod)="updateBasketPaymentMethod($event)"
(createPaymentInstrument)="createPaymentInstrument($event)"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { combineReducers } from '@ngrx/store';
import { TranslateModule } from '@ngx-translate/core';
import { MockComponent } from 'ng-mocks';
import { instance, mock } from 'ts-mockito';

import { checkoutReducers } from 'ish-core/store/checkout/checkout-store.module';
import { shoppingReducers } from 'ish-core/store/shopping/shopping-store.module';
import { ngrxTesting } from 'ish-core/utils/dev/ngrx-testing';
import { CheckoutFacade } from 'ish-core/facades/checkout.facade';
import { LoadingComponent } from 'ish-shared/components/common/loading/loading.component';

import { CheckoutPaymentPageComponent } from './checkout-payment-page.component';
Expand All @@ -24,15 +22,8 @@ describe('Checkout Payment Page Component', () => {
MockComponent(LoadingComponent),
],

imports: [
TranslateModule.forRoot(),
ngrxTesting({
reducers: {
checkout: combineReducers(checkoutReducers),
shopping: combineReducers(shoppingReducers),
},
}),
],
imports: [TranslateModule.forRoot()],
providers: [{ provide: CheckoutFacade, useFactory: () => instance(mock(CheckoutFacade)) }],
}).compileComponents();
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class CheckoutPaymentPageComponent implements OnInit {
basketError$: Observable<HttpError>;
loading$: Observable<boolean>;
paymentMethods$: Observable<PaymentMethod[]>;
priceType$: Observable<'gross' | 'net'>;

constructor(private checkoutFacade: CheckoutFacade) {}

Expand All @@ -25,6 +26,7 @@ export class CheckoutPaymentPageComponent implements OnInit {
this.basketError$ = this.checkoutFacade.basketError$;
this.loading$ = this.checkoutFacade.basketLoading$;
this.paymentMethods$ = this.checkoutFacade.eligiblePaymentMethods$();
this.priceType$ = this.checkoutFacade.priceType$;
}

updateBasketPaymentMethod(paymentName: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Basket } from 'ish-core/models/basket/basket.model';
import { HttpError } from 'ish-core/models/http-error/http-error.model';
import { PaymentInstrument } from 'ish-core/models/payment-instrument/payment-instrument.model';
import { PaymentMethod } from 'ish-core/models/payment-method/payment-method.model';
import { PriceItemHelper } from 'ish-core/models/price-item/price-item.helper';
import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';

/**
Expand All @@ -33,6 +34,7 @@ import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
export class CheckoutPaymentComponent implements OnInit, OnChanges, OnDestroy {
@Input() basket: Basket;
@Input() paymentMethods: PaymentMethod[];
@Input() priceType: 'gross' | 'net';
@Input() error: HttpError;

@Output() updatePaymentMethod = new EventEmitter<string>();
Expand Down Expand Up @@ -133,11 +135,12 @@ export class CheckoutPaymentComponent implements OnInit, OnChanges, OnDestroy {
* Determine whether payment cost threshold has been reached
* for usage in template
*/
paymentCostThresholdReached(paymentMethod: PaymentMethod) {
return (
// TODO: check if 'gross' is correct here
paymentMethod.paymentCostsThreshold && paymentMethod.paymentCostsThreshold.value <= this.basket.totals.total.gross
);
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 false;
}

/**
Expand Down

0 comments on commit eb981ec

Please sign in to comment.