File

src/app/services/payment-status.service.ts

Index

Methods

Constructor

constructor()

Methods

getState
getState(payment: Payment)
Parameters :
Name Type Optional
payment Payment no
Returns : PaymentState
getStateBySubStatus
getStateBySubStatus(payment: Payment)
Parameters :
Name Type Optional
payment Payment no
Returns : PaymentState
Private statusIsValid
statusIsValid(payment: Payment)
Parameters :
Name Type Optional
payment Payment no
Returns : boolean
Private subStatusIsValid
subStatusIsValid(payment: Payment)
Parameters :
Name Type Optional
payment Payment no
Returns : boolean
import { Payment } from '../models';
import { PaymentState } from '../enums';
import { Injectable } from '@angular/core';

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 'PROCESSING':
        return this.getStateBySubStatus(payment);
      case 'PENDING':
      case 'SCHEDULED':
        return this.getStateBySubStatus(payment);
      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':
        return states.PROCESSING;
      case 'STOPPED':
      case 'CANCELLED':
        return states.CANCELLED;
      case 'ERROR':
        return states.ERROR;
    }
  }

  getStateBySubStatus(payment: Payment): PaymentState {
    const status = this.subStatusIsValid(payment) ? payment.p2PStatus.toUpperCase() : 'ERROR';
    switch (status) {
      case 'ACCEPTED':
        return states.DONE;
      case 'TIMEDOUT':
      case 'ALLIEDTIMEDOUT': // N/A for 2.0
      case 'ACH_RETURNED': // N/A for 2.0
        return states.EXPIRED;
      case 'FAILED_MAX_ATTEMPTS': // new for 2.0
        return states.FAILED_MAX_ATTEMPTS;
      case 'RETURNED':
      case 'PENDING':
        return states.PROCESSING;
      case 'SENT':
      case 'CARD_DENIED': // new for 2.0
      case 'CARD_ERROR': // new for 2.0
        return states.WAITING;
      case 'INFLIGHT':
        return states.INFLIGHT;
      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
    );
  }

  private subStatusIsValid(payment: Payment): boolean {
    return (
      payment !== null &&
      payment !== undefined &&
      payment.p2PStatus !== null &&
      payment.p2PStatus !== null &&
      payment.p2PStatus !== undefined &&
      payment.p2PStatus.length > 0
    );
  }
}

results matching ""

    No results matching ""