示例#1
0
        /// <summary>
        /// Создать счет на оплату в Криптовалюте
        /// </summary>
        /// <param name="order">Заказ</param>
        /// <param name="paymentTypeEnum">Тип платежа. Лайткоин и т.д</param>
        /// <param name="Total">Сумма в фиате.</param>
        /// <param name="LifeTimeDuration">Время жизни счета</param>
        /// <returns></returns>
        private Invoice AddCryptoCurrencyInvoice(Orders order, Services.PaymentTypeEnum paymentTypeEnum, double Total, int LifeTimeDuration = 60)
        {
            double Summa = 0.0;

            var type = db.PaymentType.Where(p => p.Id == PaymentType.GetTypeId(paymentTypeEnum)).FirstOrDefault();

            if (paymentTypeEnum == Services.PaymentTypeEnum.Litecoin) // Лайткоин
            {
                var conf = db.PaymentTypeConfig.Where(p => p.PaymentId == PaymentType.GetTypeId(Services.PaymentTypeEnum.Litecoin) && p.Enable == true).OrderByDescending(p => p.Id).FirstOrDefault();
                if (conf != null)
                {
                    CryptoCurrency = new Services.BitCoinCore.Litecoin(conf.Login, conf.Pass);
                }
            }

            if (type != null && Currency != null) // конвертируем из фиата в крипту
            {
                Summa = MoneyConvert(Total, type.Code, Currency.Code);
            }

            string AccountNumber = CryptoCurrency.GetNewAddress(); // Генерируем адрес куда необходимо перевести деньги

            if (CryptoCurrency != null && AccountNumber != null && AccountNumber != "" && Summa > 0)
            {
                Invoice invoice = new Invoice
                {
                    AccountNumber    = AccountNumber,
                    CreateTimestamp  = DateTime.Now,
                    InvoiceNumber    = GenerateInvoiceNumber(),
                    LifeTimeDuration = System.TimeSpan.FromMinutes(LifeTimeDuration),
                    PaymentTypeId    = PaymentType.GetTypeId(paymentTypeEnum),
                    Value            = Summa,
                    Comment          = "-",
                    Paid             = false
                };

                db.Invoice.Add(invoice);
                db.SaveChanges();
                return(invoice);
            }

            else
            {
                return(null);
            }
        }
示例#2
0
        public static int GetTypeId(Services.PaymentTypeEnum paymentTypeEnum)
        {
            if (paymentTypeEnum == Services.PaymentTypeEnum.PaymentOnReceipt)
            {
                return(1);
            }

            if (paymentTypeEnum == Services.PaymentTypeEnum.Qiwi)
            {
                return(2);
            }

            if (paymentTypeEnum == Services.PaymentTypeEnum.Litecoin)
            {
                return(3);
            }

            else
            {
                return(1);
            }
        }
示例#3
0
 public static async Task <bool> CheckQiwi(string Telephone, string Toke, Services.PaymentTypeEnum typeEnum = Services.PaymentTypeEnum.Qiwi)
 {
     return(await Services.Qiwi.QiwiFunction.TestConnection(Telephone, Toke));
 }