Ejemplo n.º 1
0
        //public TransactionFeeViewModel getTransactionFee(int FROM_SRVC_ID, int TO_SRVC_ID,
        //                                             string FROM_CTRY_CD, string TO_CTRY_CD,
        //                                             string FROM_CRCY_CD, string TO_CRCY_CD,
        //                                             decimal TRANS_AMT, decimal crcyXchgPercent,
        //                                             string SEND_RCPT_CD, string SRVC_TCD)
        //{
        //    try
        //    {
        //        var model = new TransactionFeeViewModel();
        //        var crcyXchgRt = new CurrencyExchangeRate();
        //        decimal adjustXchgRate = 0.0m;
        //        decimal fromXchgRt = 1.0m;
        //        string formatString = CommonLibrary.getExchangeRateDecimalPartByCurrencyCD(FROM_CRCY_CD);

        //        if (FROM_CTRY_CD != TO_CTRY_CD) // DIFFRENT COUNTRIES
        //        {
        //            decimal FROM_TRANS_AMT = 0.0M;
        //            decimal TO_TRANS_AMT = 0.0M;
        //            if (FROM_CRCY_CD != TO_CRCY_CD) // DIFFRENT CURRENCIES
        //            {
        //                //GET the crcy exchange rate
        //                decimal xchgRate = crcyXchgRt.getExchangeRateByCurrency(FROM_CRCY_CD, TO_CRCY_CD);
        //                if (xchgRate == 0.0m)
        //                {
        //                    model.ERROR_TXT = CommonLibrary.displayGenericErrorMessage();
        //                    return model;
        //                }

        //                //GET THE ADJUSTMENT CURRENCY PERCENT RATE
        //                if (crcyXchgPercent == 0.0m)
        //                {
        //                    FROM_TRANS_AMT = TRANS_AMT;
        //                    if (SEND_RCPT_CD == "2")
        //                    {
        //                        FROM_TRANS_AMT = TRANS_AMT / xchgRate;
        //                    }

        //                    //this first query is to get the approximative sent amount, to get the adjustment
        //                    var transFeeObj = getTransactionFee(FROM_TRANS_AMT, FROM_SRVC_ID, TO_SRVC_ID,
        //                                                        FROM_CTRY_CD, TO_CTRY_CD, FROM_CRCY_CD, TO_CRCY_CD);
        //                    if (transFeeObj != null)
        //                    {
        //                        var crcyXchgPercentObj = new CurrencyExchangePercent();
        //                        var getCcrcyXchgPercentObj = crcyXchgPercentObj.getCurrencyExchangePercentByID(transFeeObj.CRCY_XCHG_PRCNT_ID);
        //                        if (crcyXchgPercentObj != null)
        //                        {
        //                            crcyXchgPercent = getCcrcyXchgPercentObj.IVSTR_CRCY_XCHG_PRCNT_RT;
        //                        }
        //                        else
        //                        {
        //                            crcyXchgPercent = 0.980m;
        //                        }
        //                    }
        //                }

        //                //adjust the currency exchange rate
        //                adjustXchgRate = xchgRate;
        //                if (xchgRate == 1.0m)
        //                {
        //                    adjustXchgRate = xchgRate;
        //                }
        //                else if (crcyXchgPercent != 0.0m)
        //                {
        //                    adjustXchgRate = xchgRate * crcyXchgPercent;
        //                }

        //                if (SEND_RCPT_CD == "1")
        //                {
        //                    FROM_TRANS_AMT = TRANS_AMT;
        //                    TO_TRANS_AMT = TRANS_AMT * adjustXchgRate;
        //                }
        //                if (SEND_RCPT_CD == "2")
        //                {
        //                    FROM_TRANS_AMT = TRANS_AMT / adjustXchgRate;
        //                    TO_TRANS_AMT = TRANS_AMT;
        //                }
        //            }
        //            else
        //            {
        //                adjustXchgRate = 1.0m;
        //                FROM_TRANS_AMT = TRANS_AMT;
        //                TO_TRANS_AMT = TRANS_AMT;
        //            }

        //            model.FROM_TRANS_AMT = FROM_TRANS_AMT;
        //            model.TO_TRANS_AMT = TO_TRANS_AMT;

        //            // calculate transaction fee
        //            var transFeeObj1 = getTransactionFee(model.FROM_TRANS_AMT, FROM_SRVC_ID, TO_SRVC_ID,
        //                                                FROM_CTRY_CD, TO_CTRY_CD, FROM_CRCY_CD, TO_CRCY_CD);
        //            if (transFeeObj1 == null)
        //            {
        //                model.ERROR_TXT = "Il se peut que le type de transaction que vous effectuez n'est pas encore autorisé par PayKap. Contactez nous si vous croyez être une erreur.";
        //                return model;
        //            }

        //            if(transFeeObj1.TRANS_FEE_TCD == "1")
        //            {
        //                model.FEE_AMT = transFeeObj1.IVSTR_FIX_FEE_AMT;
        //            }
        //            else
        //            {
        //                model.FEE_AMT = transFeeObj1.IVSTR_PRCNT_FEE_RT * model.FROM_TRANS_AMT;
        //            }

        //            model.CRCY_XCHG_RT_IND = true;
        //            model.CRCY_XCHG_RT_TXT = fromXchgRt.ToString("N2") + " " + FROM_CRCY_CD + " = " + adjustXchgRate.ToString(formatString) + " " + TO_CRCY_CD;
        //            model.CRCY_XCHG_RT = adjustXchgRate;
        //            model.ADJUST_XCHG_RT = crcyXchgPercent;
        //        }
        //        else // SAME COUNTRIES
        //        {
        //            if(FROM_CRCY_CD != TO_CRCY_CD) // DIFFRENT CURRENCIES
        //            {
        //                model.ERROR_TXT = "Les devises des transactions intra nationales ne peuvent pas être differentes";
        //                return model;
        //            }

        //            //when the fromCtry and toCtry are the same contries,
        //            //the fee comes from the BusinessFee class, the class name will be updating in the future
        //            var newBusFee = new BusinessFee();
        //            decimal getBusFee;
        //            if (FROM_CTRY_CD == TO_CTRY_CD)
        //            {
        //                getBusFee = 0.0m;
        //            }
        //            else
        //            {
        //                getBusFee = newBusFee.getClientFeeAmount(TRANS_AMT, FROM_CTRY_CD, FROM_CRCY_CD, SRVC_TCD);

        //                if (getBusFee == 0.0m)
        //                {
        //                    model.ERROR_TXT = "Il se peut que le type de transaction que vous effectuez n'est pas encore autorisé par PayKap. Contactez nous si vous croyez être une erreur.";
        //                    return model;
        //                }
        //            }

        //            model.FEE_AMT = getBusFee;
        //            model.CRCY_XCHG_RT_IND = false;
        //            model.CRCY_XCHG_RT_TXT = "";
        //            model.CRCY_XCHG_RT = 0.0M;
        //            model.ADJUST_XCHG_RT = crcyXchgPercent;
        //            model.FROM_TRANS_AMT = TRANS_AMT;
        //            model.TO_TRANS_AMT = TRANS_AMT;
        //        }

        //        model.TOT_TO_PAY_AMT = model.FROM_TRANS_AMT + model.FEE_AMT;

        //        var newObjCultureInfo = new CountryCurrency();
        //        string cultureInfo = newObjCultureInfo.getCultureInfoByCurrencyCD(FROM_CRCY_CD, "FRA");
        //        string cultureInfo1 = newObjCultureInfo.getCultureInfoByCurrencyCD(TO_CRCY_CD, "FRA");
        //        model.FROM_TRANS_AMT_TXT = CommonLibrary.displayFormattedCurrency(model.FROM_TRANS_AMT, FROM_CRCY_CD, cultureInfo);
        //        model.FEE_AMT_TXT = CommonLibrary.displayFormattedCurrency(model.FEE_AMT, FROM_CRCY_CD, cultureInfo);
        //        model.TOT_TO_PAY_AMT_TXT = CommonLibrary.displayFormattedCurrency(model.TOT_TO_PAY_AMT, FROM_CRCY_CD, cultureInfo);
        //        model.TO_TRANS_AMT_TXT = CommonLibrary.displayFormattedCurrency(model.TO_TRANS_AMT, TO_CRCY_CD, cultureInfo1);

        //        model.SEND_RCPT_CD = SEND_RCPT_CD;
        //        model.FROM_CTRY_CD = FROM_CTRY_CD;
        //        model.TO_CTRY_CD = TO_CTRY_CD;
        //        model.FROM_CRCY_CD = FROM_CRCY_CD;
        //        model.TO_CRCY_CD = TO_CRCY_CD;
        //        model.FROM_SRVC_ID = FROM_SRVC_ID;
        //        model.TO_SRVC_ID = TO_SRVC_ID;

        //        //handle the promo code
        //        if (model.FROM_CTRY_CD == "124") // Canada
        //        {
        //            model.FEE_AMT_PROMO_CD = 0.0m;
        //        }
        //        if (model.FROM_CTRY_CD == "120" && model.TO_CTRY_CD == "120") // Cameroun
        //        {
        //            model.FEE_AMT_PROMO_CD = model.FEE_AMT - 1000;
        //            if (model.FEE_AMT_PROMO_CD < 0.0m)
        //            {
        //                model.FEE_AMT_PROMO_CD = 0.0m;
        //            }
        //        }

        //        model.TOT_TO_PAY_AMT_PROMO_CD = model.FROM_TRANS_AMT + model.FEE_AMT_PROMO_CD;
        //        model.FEE_AMT_TXT_PROMO_CD = CommonLibrary.displayFormattedCurrency(model.FEE_AMT_PROMO_CD, FROM_CRCY_CD, cultureInfo);
        //        model.TOT_TO_PAY_AMT_TXT_PROMO_CD = CommonLibrary.displayFormattedCurrency(model.TOT_TO_PAY_AMT_PROMO_CD, FROM_CRCY_CD, cultureInfo);
        //        model.ERROR_TXT = "ok";
        //        return model;
        //    }
        //    catch
        //    {
        //        return null;
        //    }
        //}

        public TransactionFeeViewModel convertAmount(int FROM_SRVC_ID, int TO_SRVC_ID,
                                                     string FROM_CTRY_CD, string TO_CTRY_CD,
                                                     string FROM_CRCY_CD, string TO_CRCY_CD,
                                                     decimal TRANS_AMT, decimal crcyXchgPercent, string SEND_RCPT_CD)
        {
            try
            {
                var model      = new TransactionFeeViewModel();
                var crcyXchgRt = new CurrencyExchangeRate();

                //GET the crcy exchange rate
                decimal xchgRate = crcyXchgRt.getExchangeRateByCurrency(FROM_CRCY_CD, TO_CRCY_CD);
                if (xchgRate == 0.0m)
                {
                    return(null);
                }

                //GET THE ADJUSTMENT CURRENCY PERCENT RATE
                if (crcyXchgPercent == 0.0m)
                {
                    decimal CONVERT_TRANS_AMT = 0.0m;;
                    if (SEND_RCPT_CD == "1")
                    {
                        CONVERT_TRANS_AMT = xchgRate * TRANS_AMT;
                    }
                    else if (SEND_RCPT_CD == "2")
                    {
                        CONVERT_TRANS_AMT = TRANS_AMT / xchgRate;
                    }

                    var transFeeObj = getTransactionFee(CONVERT_TRANS_AMT, FROM_SRVC_ID, TO_SRVC_ID,
                                                        FROM_CTRY_CD, TO_CTRY_CD, FROM_CRCY_CD, TO_CRCY_CD);
                    if (transFeeObj != null)
                    {
                        var crcyXchgPercentObj     = new CurrencyExchangePercent();
                        var getCcrcyXchgPercentObj = crcyXchgPercentObj.getCurrencyExchangePercentByID(crcyXchgPercentObj.CRCY_XCHG_PRCNT_ID);
                        if (crcyXchgPercentObj != null)
                        {
                            crcyXchgPercent = getCcrcyXchgPercentObj.IVSTR_CRCY_XCHG_PRCNT_RT;
                        }
                    }
                }

                //adjust the currency exchange rate
                decimal adjustXchgRate = xchgRate;
                if (xchgRate == 1.0m)
                {
                    adjustXchgRate = xchgRate;
                }
                else if (crcyXchgPercent != 0.0m)
                {
                    adjustXchgRate = xchgRate * crcyXchgPercent;
                }

                decimal fromXchgRt   = 1.0m;
                string  formatString = CommonLibrary.getExchangeRateDecimalPartByCurrencyCD(FROM_CRCY_CD);

                if (SEND_RCPT_CD == "1")
                {
                    model.TO_TRANS_AMT = adjustXchgRate * TRANS_AMT;
                }
                else if (SEND_RCPT_CD == "2")
                {
                    model.FROM_TRANS_AMT = TRANS_AMT / adjustXchgRate;
                }
                model.CRCY_XCHG_RT_TXT = fromXchgRt.ToString("N2") + " " + FROM_CRCY_CD + " = " + adjustXchgRate.ToString(formatString) + " " + TO_CRCY_CD;
                model.CRCY_XCHG_RT     = adjustXchgRate;
                model.CRCY_XCHG_RT_IND = true;
                model.ADJUST_XCHG_RT   = crcyXchgPercent;
                return(model);
            }
            catch
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        public TransactionFeeViewModel getTransactionFee(int FROM_SRVC_ID, int TO_SRVC_ID,
                                                         string FROM_CTRY_CD, string TO_CTRY_CD,
                                                         string FROM_CRCY_CD, string TO_CRCY_CD,
                                                         decimal TRANS_AMT, decimal crcyXchgPercent,
                                                         string SEND_RCPT_CD, string SRVC_TCD,
                                                         string CLT_ON_CLT_BHLF_TCD)
        {
            try
            {
                var     model          = new TransactionFeeViewModel();
                var     crcyXchgRt     = new CurrencyExchangeRate();
                decimal adjustXchgRate = 0.0m;
                decimal fromXchgRt     = 1.0m;
                string  formatString   = CommonLibrary.getExchangeRateDecimalPartByCurrencyCD(FROM_CRCY_CD);

                if (FROM_CTRY_CD != TO_CTRY_CD) // DIFFRENT COUNTRIES
                {
                    decimal FROM_TRANS_AMT = 0.0M;
                    decimal TO_TRANS_AMT   = 0.0M;
                    if (FROM_CRCY_CD != TO_CRCY_CD) // DIFFRENT CURRENCIES
                    {
                        //GET the crcy exchange rate
                        decimal xchgRate = crcyXchgRt.getExchangeRateByCurrency(FROM_CRCY_CD, TO_CRCY_CD);
                        if (xchgRate == 0.0m)
                        {
                            model.ERROR_TXT = CommonLibrary.displayGenericErrorMessage();
                            return(model);
                        }

                        //GET THE ADJUSTMENT CURRENCY PERCENT RATE
                        if (crcyXchgPercent == 0.0m)
                        {
                            FROM_TRANS_AMT = TRANS_AMT;
                            if (SEND_RCPT_CD == "2")
                            {
                                FROM_TRANS_AMT = TRANS_AMT / xchgRate;
                            }

                            //this first query is to get the approximative sent amount, to get the adjustment
                            var transFeeObj = getTransactionFee(FROM_TRANS_AMT, FROM_SRVC_ID, TO_SRVC_ID,
                                                                FROM_CTRY_CD, TO_CTRY_CD, FROM_CRCY_CD, TO_CRCY_CD);
                            if (transFeeObj != null)
                            {
                                var crcyXchgPercentObj     = new CurrencyExchangePercent();
                                var getCcrcyXchgPercentObj = crcyXchgPercentObj.getCurrencyExchangePercentByID(transFeeObj.CRCY_XCHG_PRCNT_ID);
                                if (crcyXchgPercentObj != null)
                                {
                                    crcyXchgPercent = getCcrcyXchgPercentObj.IVSTR_CRCY_XCHG_PRCNT_RT;
                                }
                                else
                                {
                                    crcyXchgPercent = 0.980m;
                                }
                            }
                        }

                        //adjust the currency exchange rate
                        adjustXchgRate = xchgRate;
                        if (xchgRate == 1.0m)
                        {
                            adjustXchgRate = xchgRate;
                        }
                        else if (crcyXchgPercent != 0.0m)
                        {
                            adjustXchgRate = xchgRate * crcyXchgPercent;
                        }

                        if (SEND_RCPT_CD == "1")
                        {
                            FROM_TRANS_AMT = TRANS_AMT;
                            TO_TRANS_AMT   = TRANS_AMT * adjustXchgRate;
                        }
                        if (SEND_RCPT_CD == "2")
                        {
                            FROM_TRANS_AMT = TRANS_AMT / adjustXchgRate;
                            TO_TRANS_AMT   = TRANS_AMT;
                        }
                    }
                    else
                    {
                        adjustXchgRate = 1.0m;
                        FROM_TRANS_AMT = TRANS_AMT;
                        TO_TRANS_AMT   = TRANS_AMT;
                    }

                    model.FROM_TRANS_AMT = FROM_TRANS_AMT;
                    model.TO_TRANS_AMT   = TO_TRANS_AMT;

                    // calculate transaction fee
                    var transFeeObj1 = getTransactionFee(model.FROM_TRANS_AMT, FROM_SRVC_ID, TO_SRVC_ID,
                                                         FROM_CTRY_CD, TO_CTRY_CD, FROM_CRCY_CD, TO_CRCY_CD);
                    if (transFeeObj1 == null)
                    {
                        model.ERROR_TXT = "Il se peut que le type de transaction que vous effectuez n'est pas encore autorisé par PayKap. Contactez nous si vous croyez être une erreur.";
                        return(model);
                    }

                    if (transFeeObj1.TRANS_FEE_TCD == "1")
                    {
                        model.FEE_AMT = transFeeObj1.IVSTR_FIX_FEE_AMT;
                    }
                    else
                    {
                        model.FEE_AMT = transFeeObj1.IVSTR_PRCNT_FEE_RT * model.FROM_TRANS_AMT;
                    }

                    model.CRCY_XCHG_RT_IND = true;
                    model.CRCY_XCHG_RT_TXT = fromXchgRt.ToString("N2") + " " + FROM_CRCY_CD + " = " + adjustXchgRate.ToString(formatString) + " " + TO_CRCY_CD;
                    model.CRCY_XCHG_RT     = adjustXchgRate;
                    model.ADJUST_XCHG_RT   = crcyXchgPercent;
                }
                else // SAME COUNTRIES
                {
                    if (FROM_CRCY_CD != TO_CRCY_CD) // DIFFRENT CURRENCIES
                    {
                        model.ERROR_TXT = "Les devises des transactions intra nationales ne peuvent pas être differentes";
                        return(model);
                    }

                    //when the fromCtry and toCtry are the same contries,
                    //the fee comes from the BusinessFee class, the class name will be updating in the future
                    var     newBusFee = new BusinessFee();
                    decimal getBusFee;
                    if (FROM_CTRY_CD == TO_CTRY_CD)
                    {
                        //if it is the same country but the transaction on behalf of the client, apply fee
                        if (CLT_ON_CLT_BHLF_TCD == "1")
                        {
                            getBusFee = 0.0m;
                        }
                        else
                        {
                            //getBusFee IS 0.0 because PayKap does not apply the transFee when it is the same country online.

                            //getBusFee = newBusFee.getClientFeeAmount(TRANS_AMT, FROM_CTRY_CD, FROM_CRCY_CD, SRVC_TCD);

                            //if (getBusFee == 0.0m)
                            //{
                            //    model.ERROR_TXT = "Il se peut que le type de transaction que vous effectuez n'est pas encore autorisé par PayKap. Contactez nous si vous croyez être une erreur.";
                            //    return model;
                            //}
                            //decimal getBehalfFeeAmt = getBusFee * 1.3m;
                            //getBusFee = CommonLibrary.roundAmountToCeiling(getBehalfFeeAmt);
                            getBusFee = 0.0m;
                        }
                    }
                    else
                    {
                        getBusFee = newBusFee.getClientFeeAmount(TRANS_AMT, FROM_CTRY_CD, FROM_CRCY_CD, SRVC_TCD);

                        if (getBusFee == 0.0m)
                        {
                            model.ERROR_TXT = "Il se peut que le type de transaction que vous effectuez n'est pas encore autorisé par PayKap. Contactez nous si vous croyez être une erreur.";
                            return(model);
                        }
                    }

                    model.FEE_AMT          = getBusFee;
                    model.CRCY_XCHG_RT_IND = false;
                    model.CRCY_XCHG_RT_TXT = "";
                    model.CRCY_XCHG_RT     = 0.0M;
                    model.ADJUST_XCHG_RT   = crcyXchgPercent;
                    model.FROM_TRANS_AMT   = TRANS_AMT;
                    model.TO_TRANS_AMT     = TRANS_AMT;
                }

                if (CLT_ON_CLT_BHLF_TCD == "1")
                {
                    model.TOT_TO_PAY_AMT = model.FROM_TRANS_AMT + model.FEE_AMT;
                }
                else
                {
                    decimal getBehalfFeeAmt = model.FEE_AMT * 1.3m;
                    model.FEE_AMT        = CommonLibrary.roundAmountToCeiling(getBehalfFeeAmt);
                    model.TOT_TO_PAY_AMT = model.FROM_TRANS_AMT + model.FEE_AMT;
                }

                var    newObjCultureInfo = new CountryCurrency();
                string cultureInfo       = newObjCultureInfo.getCultureInfoByCurrencyCD(FROM_CRCY_CD, "FRA");
                string cultureInfo1      = newObjCultureInfo.getCultureInfoByCurrencyCD(TO_CRCY_CD, "FRA");
                model.FROM_TRANS_AMT_TXT = CommonLibrary.displayFormattedCurrency(model.FROM_TRANS_AMT, FROM_CRCY_CD, cultureInfo);
                model.FEE_AMT_TXT        = CommonLibrary.displayFormattedCurrency(model.FEE_AMT, FROM_CRCY_CD, cultureInfo);
                model.TOT_TO_PAY_AMT_TXT = CommonLibrary.displayFormattedCurrency(model.TOT_TO_PAY_AMT, FROM_CRCY_CD, cultureInfo);
                model.TO_TRANS_AMT_TXT   = CommonLibrary.displayFormattedCurrency(model.TO_TRANS_AMT, TO_CRCY_CD, cultureInfo1);

                model.SEND_RCPT_CD = SEND_RCPT_CD;
                model.FROM_CTRY_CD = FROM_CTRY_CD;
                model.TO_CTRY_CD   = TO_CTRY_CD;
                model.FROM_CRCY_CD = FROM_CRCY_CD;
                model.TO_CRCY_CD   = TO_CRCY_CD;
                model.FROM_SRVC_ID = FROM_SRVC_ID;
                model.TO_SRVC_ID   = TO_SRVC_ID;

                //handle the promo code
                if (model.FROM_CTRY_CD == "124") // Canada
                {
                    model.FEE_AMT_PROMO_CD = 0.0m;
                }
                if (model.FROM_CTRY_CD == "120" && model.TO_CTRY_CD == "120") // Cameroun
                {
                    model.FEE_AMT_PROMO_CD = model.FEE_AMT - 1000;
                    if (model.FEE_AMT_PROMO_CD < 0.0m)
                    {
                        model.FEE_AMT_PROMO_CD = 0.0m;
                    }
                }

                model.TOT_TO_PAY_AMT_PROMO_CD     = model.FROM_TRANS_AMT + model.FEE_AMT_PROMO_CD;
                model.FEE_AMT_TXT_PROMO_CD        = CommonLibrary.displayFormattedCurrency(model.FEE_AMT_PROMO_CD, FROM_CRCY_CD, cultureInfo);
                model.TOT_TO_PAY_AMT_TXT_PROMO_CD = CommonLibrary.displayFormattedCurrency(model.TOT_TO_PAY_AMT_PROMO_CD, FROM_CRCY_CD, cultureInfo);
                model.ERROR_TXT = "ok";
                return(model);
            }
            catch
            {
                return(null);
            }
        }