예제 #1
0
        /// <summary>
        /// Exchanges from currecny passed as parameter to Main currency
        /// </summary>
        /// <param name="currencyCode"></param>
        /// <returns></returns>
        public Money ExchangeFrom(string currencyCode)
        {
            Money output = Money.Zero;

            if (AppSettings.Payments.CurrencyMode == CurrencyMode.Fiat)
            {
                output = CurrencyExchangeHelper.FromCalculate(this, currencyCode);
            }
            else if (AppSettings.Payments.CurrencyMode == CurrencyMode.Cryptocurrency)
            {
                var cryptocurrencyExchange = CryptocurrencyFactory.Get(AppSettings.Site.CurrencyCode);
                output = new Money(cryptocurrencyExchange.ConvertFromMoney(this, currencyCode));
            }

            return(output);
        }
예제 #2
0
        public override void ProcessRequest()
        {
            var request = context.Request.QueryString;

            //Set variables
            TransactionID = HttpUtility.UrlDecode(request["proxy_trans_id"]);

            Amount   = HttpUtility.UrlDecode(request["trans_amount"]);
            Merchant = HttpUtility.UrlDecode(request["location_id"]);

            PhoneNumber = HttpUtility.UrlDecode(request["phone"]);
            Code        = HttpUtility.UrlDecode(request["trans_id"]);

            try
            {
                //Check IPs
                CheckIP("192.241.213.216");

                //Check duplicated transactions
                CheckIfNotDoneYet(TransactionID);

                //Check if we are the merchant
                CheckMerchant(MPesaSapamaAccountDetails.Exists(Convert.ToInt32(Merchant)));

                //Amount from KES to USD
                Money money          = Money.Parse(Amount); //in KES
                var   ConvertedMoney = CurrencyExchangeHelper.FromCalculate(money, "KES");

                //All OK, let's proceed
                MPesaSapamaCode.Create(ConvertedMoney, Code, PhoneNumber);

                context.Response.Write("OK");
            }
            catch (Exception ex)
            {
                ErrorLogger.Log(ex);
                context.Response.Write("ERROR");
            }
        }