public static void AuthorizeCCPayment <TNode>(TNode doc, PXSelectBase <CCProcTran> ccProcTran, UpdateDocStateDelegate aDocStateUpdater)
            where TNode : class, IBqlTable, ICCPayment, new()
        {
            if (doc != null && doc.PMInstanceID != null && doc.CuryDocBal != null)
            {
                if (CCPaymentEntry.HasOpenCCTran(ccProcTran))
                {
                    throw new PXException(Messages.ERR_CCTransactionCurrentlyInProgress);
                }

                CCPaymentState paymentState = CCPaymentEntry.ResolveCCPaymentState(ccProcTran.Select());
                if ((paymentState & (CCPaymentState.Captured | CCPaymentState.PreAuthorized)) > 0)
                {
                    throw new PXException(Messages.ERR_CCPaymentAlreadyAuthorized);
                }

                ccProcTran.View.Graph.Actions.PressSave();

                TNode toProc = PXCache <TNode> .CreateCopy(doc);

                PXLongOperation.StartOperation(ccProcTran.View.Graph, delegate() {
                    try
                    {
                        CCPaymentEntry.ProcessCCTransaction(toProc, null, CCTranType.AuthorizeOnly);
                    }
                    finally
                    {
                        if (aDocStateUpdater != null)
                        {
                            aDocStateUpdater(doc, CCTranType.AuthorizeOnly);
                        }
                    }
                });
            }
        }
        public static string FormatCCPaymentState(CCPaymentState aState)
        {
            Dictionary <CCPaymentState, string> stateDict = new Dictionary <CCPaymentState, string>();

            stateDict[CCPaymentState.None]                    = PXMessages.LocalizeNoPrefix(Messages.CCNone);
            stateDict[CCPaymentState.PreAuthorized]           = PXMessages.LocalizeNoPrefix(Messages.CCPreAuthorized);
            stateDict[CCPaymentState.PreAuthorizationFailed]  = PXMessages.LocalizeNoPrefix(Messages.CCPreAuthorizationFailed);
            stateDict[CCPaymentState.PreAuthorizationExpired] = PXMessages.LocalizeNoPrefix(Messages.CCPreAuthorizationExpired);
            stateDict[CCPaymentState.Captured]                = PXMessages.LocalizeNoPrefix(Messages.CCCaptured);
            stateDict[CCPaymentState.CaptureFailed]           = PXMessages.LocalizeNoPrefix(Messages.CCCaptureFailed);
            stateDict[CCPaymentState.Voided]                  = PXMessages.LocalizeNoPrefix(Messages.CCVoided);
            stateDict[CCPaymentState.VoidFailed]              = PXMessages.LocalizeNoPrefix(Messages.CCVoidFailed);
            stateDict[CCPaymentState.Refunded]                = PXMessages.LocalizeNoPrefix(Messages.CCRefunded);
            stateDict[CCPaymentState.RefundFailed]            = PXMessages.LocalizeNoPrefix(Messages.CCRefundFailed);
            stateDict[CCPaymentState.VoidFailed]              = PXMessages.LocalizeNoPrefix(Messages.CCRefundFailed);
            StringBuilder result = new StringBuilder();

            foreach (KeyValuePair <CCPaymentState, string> it in stateDict)
            {
                if ((aState & it.Key) != 0)
                {
                    if (result.Length > 0)
                    {
                        result.Append(",");
                    }
                    result.Append(it.Value);
                }
            }
            return(result.ToString());
        }
        protected virtual IEnumerable ardocumentlist()
        {
            DateTime now = DateTime.Now.Date;
            PXSelectBase <CCProcTran> tranSelect = new PXSelect <CCProcTran, Where <CCProcTran.docType, Equal <Optional <CCProcTran.docType> >, And <CCProcTran.refNbr, Equal <Optional <CCProcTran.refNbr> > > >, OrderBy <Desc <CCProcTran.tranNbr> > >(this);

            foreach (PXResult <ARPaymentInfo, Customer, CustomerPaymentMethod, PaymentMethod, CCProcessingCenterPmntMethod> it
                     in PXSelectJoin <ARPaymentInfo,
                                      InnerJoin <Customer, On <Customer.bAccountID, Equal <ARPaymentInfo.customerID> >,
                                                 InnerJoin <CustomerPaymentMethod, On <CustomerPaymentMethod.pMInstanceID, Equal <ARPaymentInfo.pMInstanceID> >,
                                                            InnerJoin <PaymentMethod, On <PaymentMethod.paymentMethodID, Equal <ARPaymentInfo.paymentMethodID>,
                                                                                          And <PaymentMethod.paymentType, Equal <PaymentMethodType.creditCard>,
                                                                                               And <PaymentMethod.aRIsProcessingRequired, Equal <True> > > >,
                                                                       LeftJoin <CCProcessingCenterPmntMethod, On <CCProcessingCenterPmntMethod.paymentMethodID, Equal <PaymentMethod.paymentMethodID>,
                                                                                                                   And <CCProcessingCenterPmntMethod.isDefault, Equal <True>,
                                                                                                                        And <CCProcessingCenterPmntMethod.isActive, Equal <True> > > > > > > >,
                                      Where <ARPaymentInfo.released, Equal <False>,
                                             And <ARPaymentInfo.hold, Equal <False>,
                                                  And <ARPaymentInfo.voided, Equal <False>,
                                                       And <ARPaymentInfo.docType, Equal <ARPaymentType.payment>,
                                                            And <ARPaymentInfo.docDate, LessEqual <Current <PaymentFilter.payDate> >,
                                                                 And <ARPaymentInfo.isMigratedRecord, NotEqual <True>,
                                                                      And2 <Where <Customer.statementCycleId, Equal <Current <PaymentFilter.statementCycleId> >,
                                                                                   Or <Current <PaymentFilter.statementCycleId>, IsNull> >,
                                                                            And2 <Where <PaymentMethod.paymentMethodID, Equal <Current <PaymentFilter.paymentMethodID> >,
                                                                                         Or <Current <PaymentFilter.paymentMethodID>, IsNull> >,
                                                                                  And <Match <Customer, Current <AccessInfo.userName> > > > > > > > > > >,
                                      OrderBy <Asc <ARPaymentInfo.refNbr> > > .Select(this))
            {
                ARPaymentInfo                doc  = (ARPaymentInfo)it;
                CustomerPaymentMethod        cpm  = (CustomerPaymentMethod)it;
                CCProcessingCenterPmntMethod pcpm = (CCProcessingCenterPmntMethod)it;
                if (!String.IsNullOrEmpty(this.Filter.Current.ProcessingCenterID) && (this.Filter.Current.ProcessingCenterID != pcpm.ProcessingCenterID))
                {
                    continue;
                }
                ARDocKey key = new ARDocKey(doc);
                if (Filter.Current == null || Filter.Current.CustomerID == null || object.Equals(Filter.Current.CustomerID, doc.CustomerID))
                {
                    doc.PMInstanceDescr    = cpm.Descr;
                    doc.PaymentMethodID    = cpm.PaymentMethodID;
                    doc.IsCCExpired        = (cpm.ExpirationDate < now);
                    doc.ProcessingCenterID = (pcpm != null) ? pcpm.ProcessingCenterID: string.Empty;
                    CCProcTran     lastTran;
                    CCPaymentState ccPaymentState = CCProcTranHelper.ResolveCCPaymentState(tranSelect.Select(doc.DocType, doc.RefNbr), out lastTran);
                    doc.CCPaymentStateDescr = CCProcTranHelper.FormatCCPaymentState(ccPaymentState);
                    doc.CCTranDescr         = (lastTran != null) ? (string.IsNullOrEmpty(lastTran.PCResponseReasonText)?lastTran.PCResponseReasonText: lastTran.ErrorText): String.Empty;
                    if (doc.IsCCExpired == true && String.IsNullOrEmpty(doc.CCTranDescr))
                    {
                        doc.CCTranDescr = Messages.CreditCardIsExpired;
                    }
                    if ((ccPaymentState & CCPaymentState.Captured) == 0)
                    {
                        yield return(doc);
                    }
                }
            }
        }
Exemplo n.º 4
0
        public static void CaptureCCPayment <TNode>(TNode doc, PXSelectBase <CCProcTran> ccProcTran,
                                                    CCPaymentEntry.ReleaseDelegate aReleaseDelegate,
                                                    UpdateDocStateDelegate aDocStateUpdater,
                                                    ICCTransactionsProcessor processor = null)
            where TNode : class, IBqlTable, ICCPayment, new()
        {
            if (processor == null)
            {
                processor = CCTransactionsProcessor.GetCCTransactionsProcessor();
            }
            if (doc != null && doc.PMInstanceID != null && doc.CuryDocBal != null)
            {
                if (CCProcTranHelper.HasOpenCCTran(ccProcTran))
                {
                    throw new PXException(Messages.ERR_CCTransactionCurrentlyInProgress);
                }

                CCPaymentState paymentState = CCProcTranHelper.ResolveCCPaymentState(ccProcTran.Select());
                if ((paymentState & (CCPaymentState.Captured)) > 0)
                {
                    throw new PXException(Messages.ERR_CCAuthorizedPaymentAlreadyCaptured);
                }
                if (doc.Released == false)
                {
                    ccProcTran.View.Graph.Actions.PressSave();
                }
                CCProcTran authTran = CCProcTranHelper.FindCCPreAthorizing(ccProcTran.Select());
                TNode      toProc   = PXCache <TNode> .CreateCopy(doc);

                CCProcTran authTranCopy = null;
                if (authTran != null && !CCProcTranHelper.IsExpired(authTran))
                {
                    authTranCopy = PXCache <CCProcTran> .CreateCopy(authTran);
                }
                CCTranType operation = (authTranCopy) != null ? CCTranType.PriorAuthorizedCapture : CCTranType.AuthorizeAndCapture;
                PXLongOperation.StartOperation(ccProcTran.View.Graph, delegate()
                {
                    try
                    {
                        processor.ProcessCCTransaction(toProc, authTranCopy, operation);
                    }
                    finally
                    {
                        //Update doc state in any case
                        if (aDocStateUpdater != null)
                        {
                            aDocStateUpdater(doc, operation);
                        }
                    }
                    if (aReleaseDelegate != null)
                    {
                        aReleaseDelegate(toProc);                               //On Success Only
                    }
                });
            }
        }
Exemplo n.º 5
0
        public static void RecordCCPayment <TNode>(TNode doc, string aExtPCTranNbr, string aPCAuthNbr, PXSelectBase <CCProcTran> ccProcTran, CCPaymentEntry.ReleaseDelegate aReleaseDelegate, UpdateDocStateDelegate aDocStateUpdater)
            where TNode : class, IBqlTable, ICCPayment, new()
        {
            if (doc != null && doc.PMInstanceID != null && doc.CuryDocBal != null)
            {
                if (CCProcTranHelper.HasOpenCCTran(ccProcTran))
                {
                    throw new PXException(Messages.ERR_CCTransactionCurrentlyInProgress);
                }

                if (string.IsNullOrEmpty(aExtPCTranNbr))
                {
                    throw new PXException(Messages.ERR_PCTransactionNumberOfTheOriginalPaymentIsRequired);
                }


                CCPaymentState paymentState = CCProcTranHelper.ResolveCCPaymentState(ccProcTran.Select());
                if ((paymentState & (CCPaymentState.Captured)) > 0)
                {
                    throw new PXException(Messages.ERR_CCAuthorizedPaymentAlreadyCaptured);
                }

                if (doc.Released == false)
                {
                    ccProcTran.View.Graph.Actions.PressSave();
                }

                TNode toProc = PXCache <TNode> .CreateCopy(doc);

                CCProcTran authTran  = CCProcTranHelper.FindCCPreAthorizing(ccProcTran.Select());
                CCTranType operation = CCTranType.AuthorizeAndCapture;
                PXLongOperation.StartOperation(ccProcTran.View.Graph, delegate()
                {
                    try
                    {
                        var graph        = PXGraph.CreateInstance <CCPaymentProcessingGraph>();
                        int?tranID       = 0;
                        string extTranID = aExtPCTranNbr;
                        graph.RecordCapture(doc, extTranID, aPCAuthNbr, null, ref tranID);
                    }
                    finally
                    {
                        //Update doc state in any case
                        if (aDocStateUpdater != null)
                        {
                            aDocStateUpdater(doc, operation);
                        }
                    }
                    if (aReleaseDelegate != null)
                    {
                        aReleaseDelegate(toProc);                               //On Success Only
                    }
                });
            }
        }
        public static void RecordCCCredit <TNode>(TNode doc, string aRefPCTranNbr, string aExtPCTranNbr, string aPCAuthNbr, PXSelectBase <CCProcTran> ccProcTran, CCPaymentEntry.ReleaseDelegate aReleaseDelegate, UpdateDocStateDelegate aDocStateUpdater)
            where TNode : class, IBqlTable, ICCPayment, new()
        {
            if (doc != null && doc.PMInstanceID != null && doc.CuryDocBal != null)
            {
                if (CCPaymentEntry.HasOpenCCTran(ccProcTran))
                {
                    throw new PXException(Messages.ERR_CCTransactionCurrentlyInProgress);
                }

                if (string.IsNullOrEmpty(aExtPCTranNbr))
                {
                    throw new PXException(Messages.ERR_PCTransactionNumberOfTheOriginalPaymentIsRequired);
                }


                CCPaymentState paymentState = CCPaymentEntry.ResolveCCPaymentState(ccProcTran.Select());
                if ((paymentState & (CCPaymentState.Refunded)) > 0)
                {
                    throw new PXException(Messages.ERR_CCPaymentIsAlreadyRefunded);
                }


                ccProcTran.View.Graph.Actions.PressSave();
                TNode toProc = PXCache <TNode> .CreateCopy(doc);

                CCTranType operation = CCTranType.Credit;
                PXLongOperation.StartOperation(ccProcTran.View.Graph, delegate()
                {
                    try
                    {
                        CCPaymentProcessing ccProcGraph = PXGraph.CreateInstance <CCPaymentProcessing>();
                        int?tranID;
                        if (ccProcGraph.RecordCredit(doc, aRefPCTranNbr, aExtPCTranNbr, aPCAuthNbr, out tranID))
                        {
                        }
                    }
                    finally
                    {
                        //Update doc state in any case
                        if (aDocStateUpdater != null)
                        {
                            aDocStateUpdater(doc, operation);
                        }
                    }
                    if (aReleaseDelegate != null)
                    {
                        aReleaseDelegate(toProc);                               //On Success Only
                    }
                });
            }
        }
        public static bool UpdateCapturedState <T>(T doc, IEnumerable <PXResult <CCProcTran> > ccProcTrans)
            where T : class, IBqlTable, ICCCapturePayment
        {
            CCProcTran     lastTran;
            CCPaymentState ccPaymentState       = CCPaymentEntry.ResolveCCPaymentState(ccProcTrans, out lastTran);
            bool           isCCVoided           = (ccPaymentState & CCPaymentState.Voided) != 0;
            bool           isCCCaptured         = (ccPaymentState & CCPaymentState.Captured) != 0;
            bool           isCCPreAuthorized    = (ccPaymentState & CCPaymentState.PreAuthorized) != 0;
            bool           isCCRefunded         = (ccPaymentState & CCPaymentState.Refunded) != 0;
            bool           isCCVoidingAttempted = (ccPaymentState & CCPaymentState.VoidFailed) != 0;
            bool           needUpdate           = false;

            if (doc.IsCCCaptured != isCCCaptured)
            {
                doc.IsCCCaptured = isCCCaptured;
                needUpdate       = true;
            }

            if (lastTran != null &&
                (lastTran.TranType == CCTranTypeCode.PriorAuthorizedCapture ||
                 lastTran.TranType == CCTranTypeCode.AuthorizeAndCapture ||
                 lastTran.TranType == CCTranTypeCode.CaptureOnly))
            {
                if (isCCCaptured)
                {
                    doc.CuryCCCapturedAmt = lastTran.Amount;
                    doc.IsCCCaptureFailed = false;
                    needUpdate            = true;
                }
                else
                {
                    doc.IsCCCaptureFailed = true;
                    needUpdate            = true;
                }
            }

            if (doc.IsCCCaptured == false && (doc.CuryCCCapturedAmt != Decimal.Zero))
            {
                doc.CuryCCCapturedAmt = Decimal.Zero;
                needUpdate            = true;
            }

            return(needUpdate);
        }
        public static bool HasUnfinishedCCTrans(PXGraph aGraph, CustomerPaymentMethod aCPM)
        {
            if (aCPM.PMInstanceID < 0)
            {
                return(false);
            }

            Dictionary <string, List <PXResult <CCProcTran> > > TranDictionary = new Dictionary <string, List <PXResult <CCProcTran> > >();
            PXResultset <CCProcTran> ccTrans = PXSelect <CCProcTran, Where <CCProcTran.pMInstanceID, Equal <Required <CCProcTran.pMInstanceID> >,
                                                                            And <CCProcTran.pCTranNumber, IsNotNull> >, OrderBy <Asc <CCProcTran.pCTranNumber> > > .Select(aGraph, aCPM.PMInstanceID);

            foreach (var row in ccTrans)
            {
                CCProcTran tran = (CCProcTran)row;
                if (tran.PCTranNumber != "0")
                {
                    if (!TranDictionary.ContainsKey(tran.PCTranNumber))
                    {
                        TranDictionary[tran.PCTranNumber] = new List <PXResult <CCProcTran> >();
                    }
                    TranDictionary[tran.PCTranNumber].Add(row);
                }
            }

            bool hasUnfinishedTrans = false;

            foreach (var kvp in TranDictionary)
            {
                List <PXResult <CCProcTran> > tranList = kvp.Value;
                CCProcTran     lastTran;
                CCPaymentState ccPaymentState    = CCPaymentEntry.ResolveCCPaymentState(tranList, out lastTran);
                bool           isCCPreAuthorized = (ccPaymentState & CCPaymentState.PreAuthorized) != 0;
                if (isCCPreAuthorized && lastTran != null && (lastTran.ExpirationDate == null || lastTran.ExpirationDate > DateTime.Now))
                {
                    hasUnfinishedTrans = true;
                    break;
                }
            }
            return(hasUnfinishedTrans);
        }
        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);
        }
        public static CCTransState UpdateCCPaymentState <T>(T doc, IEnumerable <PXResult <CCProcTran> > ccProcTrans)
            where T : class, ICCAuthorizePayment, ICCCapturePayment
        {
            CCProcTran     lastTran;
            CCPaymentState ccPaymentState       = CCPaymentEntry.ResolveCCPaymentState(ccProcTrans, out lastTran);
            bool           isCCVoided           = (ccPaymentState & CCPaymentState.Voided) != 0;
            bool           isCCCaptured         = (ccPaymentState & CCPaymentState.Captured) != 0;
            bool           isCCPreAuthorized    = (ccPaymentState & CCPaymentState.PreAuthorized) != 0;
            bool           isCCRefunded         = (ccPaymentState & CCPaymentState.Refunded) != 0;
            bool           isCCVoidingAttempted = (ccPaymentState & CCPaymentState.VoidFailed) != 0 || (ccPaymentState & CCPaymentState.RefundFailed) != 0;
            bool           needUpdate           = false;

            if (doc.IsCCAuthorized != isCCPreAuthorized || doc.IsCCCaptured != isCCCaptured)
            {
                if (!isCCVoidingAttempted)
                {
                    doc.IsCCAuthorized = isCCPreAuthorized;
                    doc.IsCCCaptured   = isCCCaptured;
                    needUpdate         = true;
                }
                else
                {
                    doc.IsCCAuthorized = false;
                    doc.IsCCCaptured   = false;
                    needUpdate         = false;
                }
            }


            if (lastTran != null && isCCPreAuthorized && lastTran.TranType == CCTranTypeCode.Authorize)
            {
                doc.CCAuthExpirationDate = lastTran.ExpirationDate;
                doc.CuryCCPreAuthAmount  = lastTran.Amount;
                needUpdate = true;
            }

            if (doc.IsCCAuthorized == false && (doc.CCAuthExpirationDate != null || doc.CuryCCPreAuthAmount > Decimal.Zero))
            {
                doc.CCAuthExpirationDate = null;
                doc.CuryCCPreAuthAmount  = Decimal.Zero;

                needUpdate = true;
            }

            if (lastTran != null &&
                (lastTran.TranType == CCTranTypeCode.PriorAuthorizedCapture ||
                 lastTran.TranType == CCTranTypeCode.AuthorizeAndCapture ||
                 lastTran.TranType == CCTranTypeCode.CaptureOnly))
            {
                if (isCCCaptured)
                {
                    doc.CuryCCCapturedAmt = lastTran.Amount;
                    doc.IsCCCaptureFailed = false;
                    needUpdate            = true;
                }
                else
                {
                    doc.IsCCCaptureFailed = true;
                    needUpdate            = true;
                }
            }

            if (doc.IsCCCaptured == false && (doc.CuryCCCapturedAmt != Decimal.Zero))
            {
                doc.CuryCCCapturedAmt = Decimal.Zero;
                needUpdate            = true;
            }

            return(new CCTransState {
                NeedUpdate = needUpdate, CCState = ccPaymentState, LastTran = lastTran
            });
        }