src/app/providers/services/payment-status.service.ts
Methods |
|
constructor()
|
getState | ||||||
getState(payment: Payment)
|
||||||
Parameters :
Returns :
PaymentState
|
Private statusIsValid | ||||||
statusIsValid(payment: Payment)
|
||||||
Parameters :
Returns :
boolean
|
import { Injectable } from '@angular/core';
import { PaymentState } from '../../enums/payment-state.enum';
import { Payment } from '../../models/payment.model';
const states = PaymentState;
@Injectable()
export class PaymentStatusService {
constructor() {}
getState(payment: Payment): PaymentState {
const status = this.statusIsValid(payment) ? payment.status.toUpperCase() : 'ERROR';
switch (status) {
case 'INFLIGHT':
return states.INFLIGHT;
case 'DONE':
return states.DONE;
case 'PENDING':
case 'SCHEDULED':
return states.WAITING;
case 'REJECTED':
case 'REVERSED':
case 'RETURNED':
return states.EXPIRED;
case 'RESENT':
case 'REISSUED':
case 'RESCHEDULED':
case 'REVERSING':
return states.NOTAPPLICABLE;
case 'HOLD':
case 'CREDITHOLD':
case 'BANKHOLD':
case 'ALLIEDHOLD':
case 'PROCESSING':
return states.PROCESSING;
case 'STOPPED':
case 'CANCELLED':
return states.CANCELLED;
case 'ERROR':
return states.ERROR;
}
}
private statusIsValid(payment: Payment): boolean {
return (
payment !== null &&
payment !== undefined &&
payment.status !== null &&
payment.status !== null &&
payment.status !== undefined &&
payment.status.length > 0
);
}
}