public static CCProcTran findCCLastSuccessfulTran(PXSelectBase <CCProcTran> ccProcTran)
        {
            CCProcTran lastTran = null;
            CCProcTranOrderComparer ascComparer = new CCProcTranOrderComparer();

            foreach (CCProcTran iTran in ccProcTran.Select())
            {
                if (iTran.ProcStatus != CCProcStatus.Finalized)
                {
                    continue;
                }
                if (iTran.TranStatus == CCTranStatusCode.Approved)
                {
                    if (lastTran == null || (ascComparer.Compare(iTran, lastTran) > 0))
                    {
                        lastTran = iTran;
                    }
                }
            }
            return(lastTran);
        }
Exemplo n.º 2
0
        public static ICCPaymentTransaction FindCCLastSuccessfulTran(IEnumerable <ICCPaymentTransaction> ccProcTran)
        {
            IEnumerable <ICCPaymentTransaction> filtered = FilterDeclinedTrans(ccProcTran);
            ICCPaymentTransaction   lastTran             = null;
            CCProcTranOrderComparer ascComparer          = new CCProcTranOrderComparer();

            foreach (ICCPaymentTransaction iTran in filtered)
            {
                if (iTran.ProcStatus != CCProcStatus.Finalized)
                {
                    continue;
                }
                if (iTran.TranStatus == CCTranStatusCode.Approved || iTran.TranStatus == CCTranStatusCode.HeldForReview)
                {
                    if (lastTran == null || (ascComparer.Compare(iTran, lastTran) > 0))
                    {
                        lastTran = iTran;
                    }
                }
            }
            return(lastTran);
        }
        public static CCPaymentState ResolveCCPaymentState(IEnumerable <PXResult <CCProcTran> > ccProcTrans, out CCProcTran aLastTran)
        {
            CCPaymentState          result        = CCPaymentState.None;
            CCProcTran              lastTran      = null;
            CCProcTran              lastSSTran    = null; //Last successful tran
            CCProcTran              preLastSSTran = null;
            CCProcTranOrderComparer ascComparer   = new CCProcTranOrderComparer();

            aLastTran = null;
            foreach (CCProcTran iTran in ccProcTrans)
            {
                if (iTran.ProcStatus != CCProcStatus.Finalized && iTran.ProcStatus != CCProcStatus.Error)
                {
                    continue;
                }
                if (lastTran == null)
                {
                    lastTran = iTran;
                }
                else
                {
                    if (ascComparer.Compare(iTran, lastTran) > 0)
                    {
                        lastTran = iTran;
                    }
                }

                if (iTran.TranStatus == CCTranStatusCode.Approved)
                {
                    if (lastSSTran == null)
                    {
                        lastSSTran = iTran;
                    }
                    else if (ascComparer.Compare(iTran, lastSSTran) > 0)
                    {
                        lastSSTran = iTran;
                    }

                    if (lastSSTran != null && (ascComparer.Compare(iTran, lastSSTran) < 0))
                    {
                        if (preLastSSTran == null)
                        {
                            preLastSSTran = iTran;
                        }
                        else if (ascComparer.Compare(iTran, preLastSSTran) > 0)
                        {
                            preLastSSTran = iTran;
                        }
                    }
                }
            }

            if (lastTran != null)
            {
                if (lastSSTran != null)
                {
                    switch (lastSSTran.TranType)
                    {
                    case CCTranTypeCode.Authorize:
                        if (!IsExpired(lastSSTran))
                        {
                            result = CCPaymentState.PreAuthorized;
                        }
                        else
                        {
                            result = CCPaymentState.PreAuthorizationExpired;
                        }
                        break;

                    case CCTranTypeCode.AuthorizeAndCapture:
                    case CCTranTypeCode.PriorAuthorizedCapture:
                    case CCTranTypeCode.CaptureOnly:
                        result = CCPaymentState.Captured;
                        break;

                    case CCTranTypeCode.VoidTran:
                        if (preLastSSTran != null)
                        {
                            result                   = (preLastSSTran.TranType == CCTranTypeCode.Authorize) ?
                                              result = CCPaymentState.None : result = CCPaymentState.Voided;                                           //Voidin of credit currenly is not allowed
                        }
                        break;

                    case CCTranTypeCode.Credit:
                        result = CCPaymentState.Refunded;
                        break;
                    }
                }

                if (lastSSTran == null || lastSSTran.TranNbr != lastTran.TranNbr)                 //this means that lastOp failed
                {
                    switch (lastTran.TranType)
                    {
                    case CCTranTypeCode.Authorize:
                        result |= CCPaymentState.PreAuthorizationFailed;
                        break;

                    case CCTranTypeCode.AuthorizeAndCapture:
                    case CCTranTypeCode.PriorAuthorizedCapture:
                    case CCTranTypeCode.CaptureOnly:
                        result |= CCPaymentState.CaptureFailed;
                        break;

                    case CCTranTypeCode.VoidTran:
                        result |= CCPaymentState.VoidFailed;
                        break;

                    case CCTranTypeCode.Credit:
                        result |= CCPaymentState.RefundFailed;
                        break;
                    }
                }
            }
            aLastTran = lastTran;
            return(result);
        }