예제 #1
0
        internal static void ProcessTransferSettlement(E_TRANSACTION item)
        {
            List <E_TRANSFER_COMMISSION_SPLIT> splitFormular         = CachingProvider.GetCachedData <List <E_TRANSFER_COMMISSION_SPLIT> >("Transfer");
            List <E_FUNDGATE_COMMISSION_SPLIT> fundGatesplitFormular = CachingProvider.GetCachedData <List <E_FUNDGATE_COMMISSION_SPLIT> >("FundGate");

            List <CommissionMapViewModel> commission         = AutoMapper.Mapper.Map <List <CommissionMapViewModel> >(splitFormular);
            List <CommissionMapViewModel> fundGatecommission = AutoMapper.Mapper.Map <List <CommissionMapViewModel> >(fundGatesplitFormular);

            using (EtzbkDataContext etzbk = new EtzbkDataContext())
            {
                try
                {
                    List <E_FEE_DETAIL_BK> feeDetailList = new List <E_FEE_DETAIL_BK>();
                    if (item.CHANNELID == "09")
                    {
                        feeDetailList = FeeProcessing.ProcessCardloadSplit(item, fundGatecommission);
                    }
                    else
                    {
                        feeDetailList = FeeProcessing.ProcessCardloadSplit(item, commission);
                    }

                    var e_Fee_detail = RemoveSettledFeeDetails(feeDetailList);
                    etzbk.E_FEE_DETAIL_BK.AddRange(e_Fee_detail);

                    E_SETTLEMENT_DOWNLOAD_BK e_settlement = AutoMapper.Mapper.Map <E_SETTLEMENT_DOWNLOAD_BK>(item);
                    decimal bankFee = feeDetailList.Where(fee => fee.MERCHANT_CODE.EndsWith("9999")).Select(FEE => FEE.FEE).FirstOrDefault();
                    e_settlement.BANK_FEE = bankFee;

                    if (!CheckSettledFee(e_settlement))
                    {
                        etzbk.E_SETTLEMENT_DOWNLOAD_BK.Add(e_settlement);
                    }

                    item.PROCESS_STATUS = "1";
                    etzbk.E_TRANSACTION.Add(item);
                    etzbk.Entry(item).State = System.Data.Entity.EntityState.Modified;

                    etzbk.SaveChanges();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception from " + System.Reflection.MethodBase.GetCurrentMethod().Name + " " + nameof(Settlement) + " " + ExceptionExtensions.GetFullMessage(ex));
                    logger.LogInfoMessage("Exception from Run " + nameof(Settlement) + " " + System.Reflection.MethodBase.GetCurrentMethod().Name + " " + ExceptionExtensions.GetFullMessage(ex));
                }
            }
        }
예제 #2
0
 public void SplitCardLoad_D_Transaction(E_TRANSACTION entity)
 {
     //var
 }
예제 #3
0
        public static List <E_FEE_DETAIL_BK> ProcessCardloadSplit(E_TRANSACTION e_transaction, List <CommissionMapViewModel> splitFormular)
        {
            List <E_FEE_DETAIL_BK> feeDetailList = new List <E_FEE_DETAIL_BK>();

            if (e_transaction == null)
            {
                throw new ArgumentNullException(nameof(e_transaction));
            }
            else
            {
                int    i = 1;
                string bankCode;
                if (e_transaction.CHANNELID == "09")
                {
                    bankCode = e_transaction.CARD_NUM.Substring(0, 6);
                }
                else
                {
                    bankCode = e_transaction.CARD_NUM.Substring(0, 3);
                }

                var items = from card in splitFormular
                            where card.BANK_CODE.StartsWith(bankCode)
                            orderby card.MAIN_FLAG
                            select card;
                //Cehck Split is not configured for the Card, Pick the Defaul split
                if (items.Count() == 0)
                {
                    items = splitFormular.Where(def => def.BANK_CODE == "000" || def.BANK_CODE == "000000").ToList().OrderBy(a => a.MAIN_FLAG);
                }
                foreach (var item in items)
                {
                    decimal fee = 0;
                    if (item.RATIO == 0)
                    {
                        fee = e_transaction.TRANS_AMOUNT;
                    }
                    else
                    {
                        fee = CalculateFeeBeneficiary(item.RATIO, e_transaction.FEE);
                    }

                    //if (item.MAIN_FLAG == 0)
                    //    //
                    //else if (item.MAIN_FLAG == 1)
                    //    //

                    var card_num      = item.COMM_SUSPENCE == null || item.COMM_SUSPENCE.Trim() == "" ? bankCode + TransactionAlias.GetSuspenseAlias(e_transaction.TRANS_CODE) : item.COMM_SUSPENCE;
                    var GFLAG         = item.MAIN_FLAG.ToString();
                    var MERCHANT_CODE = item.SPLIT_CARD.Contains("%") ? e_transaction.CARD_NUM.Substring(0, 3) + TransactionAlias.GetChannelAlias(e_transaction.CHANNELID.ToString()) + item.SPLIT_CARD.Substring(item.SPLIT_CARD.IndexOf("%") + 1) : item.SPLIT_CARD;

                    E_FEE_DETAIL_BK feeDetail = new E_FEE_DETAIL_BK()
                    {
                        CARD_NUM         = item.COMM_SUSPENCE == null || item.COMM_SUSPENCE.Trim() == "" ? bankCode + TransactionAlias.GetSuspenseAlias(e_transaction.TRANS_CODE) : item.COMM_SUSPENCE,
                        CHANNELID        = e_transaction.CHANNELID,
                        CLOSED           = "1",
                        CURRENCY         = e_transaction.CURRENCY,
                        EXTERNAL_TRANSID = e_transaction.UNIQUE_TRANSID,
                        UNIQUE_TRANSID   = "C" + i.ToString() + e_transaction.UNIQUE_TRANSID,
                        FEE            = 0,
                        FEE_BATCH      = e_transaction.FEE_BATCH,
                        GFLAG          = item.MAIN_FLAG.ToString(),
                        INTSTATUS      = "2",
                        ISSUER_CODE    = e_transaction.CARD_NUM.Substring(0, 3),
                        MERCHANT_CODE  = item.SPLIT_CARD.Contains("%") ? e_transaction.CARD_NUM.Substring(0, 3) + TransactionAlias.GetChannelAlias(e_transaction.CHANNELID.ToString()) + item.SPLIT_CARD.Substring(item.SPLIT_CARD.IndexOf("%") + 1) : item.SPLIT_CARD,
                        PROCESS_STATUS = "1",
                        SUB_CODE       = e_transaction.CARD_NUM.Substring(3, 3),
                        SERVICEID      = e_transaction.CARD_NUM.Substring(0, 6),
                        SETTLE_BATCH   = e_transaction.SETTLE_BATCH,
                        TRANSID        = e_transaction.TRANSID,
                        TRANS_AMOUNT   = fee,
                        TRANS_CODE     = "C",
                        TRANS_DATE     = DateTime.Now,
                        TRANS_DESCR    = "SETTLEMENT:;" + item.SPLIT_DESCR,
                        TRANS_NO       = e_transaction.TRANS_NO,
                        TRANS_REF      = e_transaction.MERCHANT_CODE,
                        TRANS_TYPE     = "1"
                    };

                    Console.WriteLine("Split transaction Trans_Code=" + e_transaction.TRANS_CODE + "  Merchant_Code : " + feeDetail.MERCHANT_CODE + " Card_num: " + feeDetail.CARD_NUM + " Descr " + feeDetail.TRANS_DESCR + " isssuer" + feeDetail.ISSUER_CODE + " unique_trans: " + feeDetail.UNIQUE_TRANSID + " Value: " + feeDetail.TRANS_AMOUNT);
                    i++;
                    feeDetailList.Add(feeDetail);
                }

                return(feeDetailList);
            }
        }
예제 #4
0
        public static ResponseViewModel ProcessPaymentSettlement(E_TRANSACTION item)
        {
            ResponseViewModel response = new ResponseViewModel();


            using (EtzbkDataContext etzbk = new EtzbkDataContext())
            {
                //item = etzbk.E_TRANSACTION.Where(a => a.UNIQUE_TRANSID == "0327002364000289256353").FirstOrDefault();
                if (item.UNIQUE_TRANSID.Contains("#"))
                {
                    item.UNIQUE_TRANSID = item.UNIQUE_TRANSID.Substring(0, item.UNIQUE_TRANSID.IndexOf("#"));
                }
                try
                {
                    var merchantIntercept = etzbk.E_MERCHANT_CODE_INTERCEPT.Where(a => a.INITIATOR_CODE == item.CARD_NUM.Substring(0, 3) && a.MERCHANT_CODE == item.MERCHANT_CODE && a.CHANNELID == item.CHANNELID && a.TRANS_CODE == item.TRANS_CODE && a.INTERCEPT_STATUS == "1").FirstOrDefault();

                    if (merchantIntercept != null)
                    {
                        if (merchantIntercept.INTERCEPT_MERCHANT_CODE != null || merchantIntercept.INTERCEPT_MERCHANT_CODE.Trim() != "")
                        {
                            item.MERCHANT_CODE = merchantIntercept.INTERCEPT_MERCHANT_CODE;
                        }
                        if (merchantIntercept.CARD_NUM != null || merchantIntercept.CARD_NUM.Trim() != "")
                        {
                            item.CARD_NUM = merchantIntercept.CARD_NUM;
                        }
                    }

                    if (item.CHANNELID == "09")
                    {
                        using (FundGateDataContext fundGate = new FundGateDataContext())
                        {
                            var fundGateQuery = from A in fundGate.FUNDGATE_RESPONSE
                                                join B in fundGate.FUNDGATE_REQUEST
                                                on new { X = A.clientRef, Y = A.terminal } equals new { X = B.clientRef, Y = B.terminal } into jointData
                            from joinRecord in jointData.DefaultIfEmpty()
                            where (joinRecord.action == "VT" && A.etzRef == item.UNIQUE_TRANSID)
                            select new
                            {
                                joinRecord.lineType
                            };

                            var fundGateTrx = fundGateQuery.FirstOrDefault();
                            if (fundGateTrx != null)
                            {
                                var swicthData = etzbk.E_SWITCHIT_TRANSFORMER.Where(a => a.CARD_NUM == item.CARD_NUM && a.PROVIDER_ID == fundGateTrx.lineType).FirstOrDefault();
                                if (swicthData != null)
                                {
                                    item.CARD_NUM      = swicthData.TRANSFORM_CARD;
                                    item.MERCHANT_CODE = swicthData.MERCHANT_CODE;
                                }
                            }
                        }
                    }
                    string merchantCode = item.MERCHANT_CODE;
                    List <E_FEE_DETAIL_BK>   feeDetailList = new List <E_FEE_DETAIL_BK>();
                    E_SETTLEMENT_DOWNLOAD_BK e_settlement  = AutoMapper.Mapper.Map <E_SETTLEMENT_DOWNLOAD_BK>(item);

                    var merchantScaleQuery = from A in etzbk.E_MERCHANT
                                             join B in etzbk.E_CATSCALE
                                             on new { X = A.CAT_ID } equals new { X = B.CAT_ID } into jointData
                    from joinRecord in jointData.DefaultIfEmpty()
                    where (A.MERCHANT_CODE == merchantCode)
                    select new
                    {
                        A.FEE_STATUS,
                        A.SPECIAL_SPLIT,
                        A.MERCHANT_NAME,
                        joinRecord.SCALE_VALUE,
                        joinRecord.SCALE_TYPE,
                        joinRecord.CAT_ID
                    };

                    var merchantScale = merchantScaleQuery.FirstOrDefault();
                    if (merchantScale == null)
                    {
                        response = new ResponseViewModel()
                        {
                            ErrorType = ErrorType.NoMerchantCode, MerchantCode = merchantCode, Response = false
                        };

                        //return response;

                        ///Write Code to handle No Merchant Code or Split category configured
                    }
                    else
                    {
                        List <CommissionMapViewModel> commission = new List <CommissionMapViewModel>();
                        if (merchantScale.SPECIAL_SPLIT == "0")
                        {
                            // Check If Fee is Charged if not, ignore and comparee value
                            if (merchantScale.SCALE_TYPE == "1" & item.FEE == 0)
                            {
                                item.FEE = FeeProcessing.CalculateFeeBeneficiary(merchantScale.SCALE_VALUE, item.TRANS_AMOUNT);
                            }
                            var query = from A in etzbk.E_MERCHANT_COMMISSION_SPLIT
                                        where (A.MERCHANT_CODE == item.MERCHANT_CODE)
                                        select new CommissionMapViewModel
                            {
                                AGENT         = "",
                                MAIN_FLAG     = A.MAIN_FLAG,
                                SPLIT_CARD    = A.SPLIT_CARD,
                                RATIO         = A.RATIO,
                                SPLIT_DESCR   = A.SPLIT_DESCR,
                                COMM_SUSPENCE = item.MERCHANT_CODE
                            };
                            commission = AutoMapper.Mapper.Map <List <CommissionMapViewModel> >(query.ToList());
                        }
                        else if (merchantScale.SPECIAL_SPLIT == "1")
                        {
                            var query = from A in etzbk.E_MERCHANT_SPECIAL_SPLIT
                                        where (A.MERCHANT_CODE == item.MERCHANT_CODE)
                                        select new CommissionMapViewModel
                            {
                                AGENT         = "",
                                MAIN_FLAG     = A.MAIN_FLAG,
                                SPLIT_CARD    = A.SPLIT_CARD,
                                RATIO         = A.SVALUE,
                                SPLIT_DESCR   = A.SPLIT_DESCR,
                                COMM_SUSPENCE = item.MERCHANT_CODE
                            };
                            commission = AutoMapper.Mapper.Map <List <CommissionMapViewModel> >(query.ToList());
                        }
                        else
                        {
                            response = new ResponseViewModel()
                            {
                                ErrorType = ErrorType.InvalidSplitType, MerchantCode = merchantCode, Response = false
                            };
                            // return response;
                        }

                        if (merchantScale.SPECIAL_SPLIT == "1" || merchantScale.SPECIAL_SPLIT == "0")
                        {
                            feeDetailList = FeeProcessing.ProcessRatioPaymentSplit(item, commission);

                            var e_Fee_detail = RemoveSettledFeeDetails(feeDetailList);
                            etzbk.E_FEE_DETAIL_BK.AddRange(e_Fee_detail);

                            decimal bankFee = feeDetailList.Where(fee => fee.MERCHANT_CODE.EndsWith("9999")).Select(FEE => FEE.FEE).FirstOrDefault();
                            e_settlement.BANK_FEE = bankFee;
                        }
                    }


                    if (!CheckSettledFee(e_settlement))
                    {
                        etzbk.E_SETTLEMENT_DOWNLOAD_BK.Add(e_settlement);
                    }

                    item.PROCESS_STATUS = "1";
                    etzbk.E_TRANSACTION.Add(item);
                    etzbk.Entry(item).State = System.Data.Entity.EntityState.Modified;


                    etzbk.SaveChanges();
                    // Console.WriteLine(nameof(PaymentProducer) + " Final round saved to database ");
                    return(new ResponseViewModel()
                    {
                        ErrorType = ErrorType.Valid, MerchantCode = merchantCode, Response = true
                    });
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception from " + System.Reflection.MethodBase.GetCurrentMethod().Name + " " + nameof(Settlement) + " " + ExceptionExtensions.GetFullMessage(ex) + item.UNIQUE_TRANSID);
                    logger.LogInfoMessage("Exception from Run " + nameof(Settlement) + " " + System.Reflection.MethodBase.GetCurrentMethod().Name + " " + ExceptionExtensions.GetFullMessage(ex) + item.UNIQUE_TRANSID);
                    return(new ResponseViewModel()
                    {
                        ErrorType = ErrorType.Exception, MerchantCode = item.UNIQUE_TRANSID, Message = ex.Message, Response = false
                    });
                }
            }
        }
예제 #5
0
        public static List <E_FEE_DETAIL_BK> ProcessRatioPaymentSplit(E_TRANSACTION e_transaction, List <CommissionMapViewModel> splitFormular)
        {
            List <E_FEE_DETAIL_BK> feeDetailList = new List <E_FEE_DETAIL_BK>();

            if (e_transaction == null)
            {
                throw new ArgumentNullException(nameof(e_transaction));
                //return feeDetailList;
            }
            else
            {
                int i = 1;
                //string bankCode = e_transaction.CARD_NUM.Substring(0, 3);
                decimal trans_amount = e_transaction.TRANS_AMOUNT;

                foreach (var item in splitFormular.OrderBy(a => a.MAIN_FLAG))
                {
                    decimal fee = 0;
                    try
                    {
                        if (e_transaction.FEE > 0)
                        {
                            fee = CalculateFeeBeneficiary(item.RATIO, e_transaction.FEE);
                        }
                        else
                        {
                            fee = item.RATIO;
                        }

                        if (trans_amount < 0)
                        {
                            return(new List <E_FEE_DETAIL_BK>());
                        }

                        trans_amount = trans_amount - fee;
                        if (fee == 0)
                        {
                            fee = trans_amount;
                        }

                        E_FEE_DETAIL_BK feeDetail = new E_FEE_DETAIL_BK()
                        {
                            CARD_NUM         = item.COMM_SUSPENCE,
                            CHANNELID        = e_transaction.CHANNELID,
                            CLOSED           = "1",
                            CURRENCY         = e_transaction.CURRENCY,
                            EXTERNAL_TRANSID = e_transaction.UNIQUE_TRANSID,
                            UNIQUE_TRANSID   = "C" + i.ToString() + e_transaction.UNIQUE_TRANSID,
                            FEE            = 0,
                            FEE_BATCH      = e_transaction.FEE_BATCH,
                            GFLAG          = item.MAIN_FLAG.ToString(),
                            INTSTATUS      = "2",
                            ISSUER_CODE    = e_transaction.CARD_NUM.Substring(0, 3),
                            MERCHANT_CODE  = item.SPLIT_CARD.Contains("%") ? e_transaction.CARD_NUM.Substring(0, 3) + TransactionAlias.GetChannelAlias(e_transaction.CHANNELID.ToString()) + item.SPLIT_CARD.Substring(item.SPLIT_CARD.IndexOf("%") + 1) : item.SPLIT_CARD,
                            PROCESS_STATUS = "1",
                            SUB_CODE       = e_transaction.CARD_NUM.Substring(3, 3),
                            SERVICEID      = e_transaction.CARD_NUM.Substring(0, 6),
                            SETTLE_BATCH   = e_transaction.SETTLE_BATCH,
                            TRANSID        = e_transaction.TRANSID,
                            TRANS_AMOUNT   = fee,
                            TRANS_CODE     = "C",
                            TRANS_DATE     = DateTime.Now,
                            TRANS_DESCR    = "SETTLEMENT:;" + item.SPLIT_DESCR,
                            TRANS_NO       = e_transaction.TRANS_NO,
                            TRANS_REF      = e_transaction.MERCHANT_CODE,
                            TRANS_TYPE     = "1"
                        };

                        Console.WriteLine("Split transaction Trans_Code=" + e_transaction.TRANS_CODE + "  Merchant_Code : " + feeDetail.MERCHANT_CODE + " Card_num: " + feeDetail.CARD_NUM + " Descr " + feeDetail.TRANS_DESCR + " isssuer" + feeDetail.ISSUER_CODE + " unique_trans: " + feeDetail.UNIQUE_TRANSID + " Value: " + feeDetail.TRANS_AMOUNT);
                        i++;

                        feeDetailList.Add(feeDetail);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Exception from " + System.Reflection.MethodBase.GetCurrentMethod().Name + " " + nameof(Settlement) + " " + ExceptionExtensions.GetFullMessage(ex));
                        //logger.LogInfoMessage("Exception from Run " + nameof(Settlement) + " " + System.Reflection.MethodBase.GetCurrentMethod().Name + " " + ExceptionExtensions.GetFullMessage(ex) + item.UNIQUE_TRANSID);
                        return(feeDetailList);
                    }
                }


                return(feeDetailList);
            }
        }