Пример #1
0
        public async Task <IActionResult> Merchant()
        {
            MerchantViewModel model = null;

            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }

            var userMerchant = await _merchantRepository.GetByUser(user.Id);

            if (userMerchant == null)
            {
                return(View("Merchant/Create"));
            }

            var subscriptions = await _subscriptionsRepository.GetByUserId(user.Id);

            if (subscriptions == null ||
                subscriptions.Paid && subscriptions.Expired < DateTime.Now)
            {
                await _subscriptionsRepository.CreatePaymentAddress(user.Id);
            }

            decimal price = Convert.ToDecimal(_configuration["Subscription:" + subscriptions?.WalletType + ":Price"]);

            await Subscriptions(price);

            subscriptions = await _subscriptionsRepository.GetByUserId(user.Id);

            model = new MerchantViewModel
            {
                MerchantId     = userMerchant.MerchantId,
                MerchantSecret = Crypto.GetSha256Hash(userMerchant.MerchantSecret),
                RedirectUri    = userMerchant.RedirectUri,

                XPubKey         = userMerchant.XPubKey,
                EthereumAddress = userMerchant.EthereumAddress,

                Status     = subscriptions.Expired > DateTime.Now && subscriptions.Paid,
                Address    = subscriptions.Address,
                Expired    = subscriptions.Expired,
                WalletType = subscriptions.WalletType,
                Price      = price,

                StatusMessage = StatusMessage
            };

            return(View("Merchant/Index", model));
        }
Пример #2
0
        public async Task <IActionResult> Start(TransactionModel model)
        {
            if (!System.Enum.IsDefined(typeof(WalletType), model.WalletType))
            {
                throw new ApplicationException($"Wrong wallet type with value '{model.WalletType}'.");
            }

            ShopInfoModel result = null;
            string        hash   = string.Empty;

            if (!await _merchantRepository.ValidateMerchant(model.MerchantId, model.MerchantSecret))
            {
                throw new ApplicationException($"Unable to load merchant with ID '{model.MerchantId}'.");
            }

            var merchant = await _merchantRepository.GetByMerchant(model.MerchantId);

            var subscriptions = await _subscriptionsRepository.GetByUserId(merchant.Id);

            if (subscriptions != null && !subscriptions.Paid && subscriptions.Expired < DateTime.Now)
            {
                return(BadRequest("Subscription has expired."));
            }

            if (!string.Equals(merchant.RedirectUri, model.CallbackUrl))
            {
                return(BadRequest("The redirect URI is not the same as in the merchant settings."));
            }

            try
            {
                result = await _requestProvider
                         .PostAsync <CheckPaymentShop, ShopInfoModel>(model.CallbackUrl, new CheckPaymentShop { TrxId = model.TrxId });

                hash = await _transactionRepository.CreateTransactions(result, merchant.Id, model.WalletType);

                var trx = await _transactionRepository.GetByHash(hash);

                await _logRepository.Add(trx.Id, "Transaction created.");
            }
            catch (Exception e)
            {
                _logger.LogError(e, e.Message);
            }

            return(RedirectToAction(nameof(PurchaserController.Index), "Purchaser", new { id = hash }));
        }