public void AddAddress(UserAccount account, BillerAddAddressIM im) { var count = new BillerAddressDAC().GetAllAddresses(account.Id).Count; if (count >= 500) { throw new CommonException(ReasonCode.BillerOverMaxAddressCount, Resources.BillerOverAddressMaxCount); } if (new BillerAddressDAC().GetAllAddresses(account.Id).Any(item => item.BillerCode == im.BillerCode && im.ReferenceNumber == item.ReferenceNumber)) { throw new CommonException(ReasonCode.BillerAddressExisted, Resources.BillerAddressExisted); } var address = new BillerAddress() { BillerCode = im.BillerCode, IconIndex = im.IconIndex, ReferenceNumber = im.ReferenceNumber, Tag = im.Tag, AccountId = account.Id, Timestamp = DateTime.UtcNow }; new BillerAddressDAC().Insert(address); }
public BillerPayOM Pay(UserAccount account, BillerPayIM im, ref int errorCode) { var coin = new CryptocurrencyDAC().GetById(im.CryptoId); if (!coin.Status.HasFlag(CryptoStatus.Biller) || coin.Enable == 0) { throw new CommonException(ReasonCode.CURRENCY_FORBIDDEN, MessageResources.CurrencyForbidden); } var result = PrePay(new BillerPrePayIM() { CountryId = im.CountryId, CryptoAmount = im.CryptoAmount, CryptoCode = im.CryptoCode, CryptoId = im.CryptoId, FiatAmount = im.FiatAmount, FiatCurrency = im.FiatCurrency }).Status; if (result != 0) { errorCode = 10400 + result; return(null); } new SecurityComponent().VerifyPin(account, im.Pin); var cryptoCurrency = new CryptocurrencyDAC().GetById(im.CryptoId); if (cryptoCurrency?.Id == null) { throw new CommonException(ReasonCode.CRYPTO_NOT_EXISTS, "Error: Invalid Cryptocurrency"); } var uwComponent = new UserWalletComponent(); var userWallet = uwComponent.GetUserWallet(account.Id, im.CryptoId); if (userWallet == null) { throw new CommonException(ReasonCode.INSUFFICIENT_BALANCE, MessageResources.InsufficientBalance); } if (userWallet.Balance < im.CryptoAmount) { throw new CommonException(ReasonCode.INSUFFICIENT_BALANCE, MessageResources.InsufficientBalance); } var uwDAC = new UserWalletDAC(); var uwsDAC = new UserWalletStatementDAC(); var boDAC = new BillerOrderDAC(); var billerOrder = new BillerOrder() { Id = Guid.NewGuid(), BillerCode = im.BillerCode, CryptoAmount = im.CryptoAmount, CryptoCode = im.CryptoCode, CryptoId = im.CryptoId, Discount = im.CryptoCode.Equals("Fiii", StringComparison.InvariantCultureIgnoreCase) ? decimal.Parse(new MasterSettingDAC().SelectByGroup("BillerMaxAmount").First(item => item.Name.Equals("DiscountRate", StringComparison.CurrentCultureIgnoreCase)).Value) : 0, ExchangeRate = im.ExchangeRate, FiatAmount = im.FiatAmount, FiatCurrency = im.FiatCurrency, ReferenceNumber = im.ReferenceNumber, Tag = im.Tag, Status = BillerOrderStatus.Pending, Timestamp = DateTime.UtcNow, AccountId = account.Id, OrderNo = IdentityHelper.OrderNo(), PayTime = DateTime.UtcNow, CountryId = im.CountryId }; var address = new BillerAddressDAC().GetAllAddresses(account.Id).FirstOrDefault(item => item.BillerCode == im.BillerCode && im.ReferenceNumber == item.ReferenceNumber); billerOrder.Tag = address?.Tag; using (var scope = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required, new TimeSpan(0, 0, 1, 30))) { uwDAC.Decrease(userWallet.Id, billerOrder.CryptoAmount); uwsDAC.Insert(new UserWalletStatement { WalletId = userWallet.Id, Action = UserWalletStatementAction.Consume, Amount = -billerOrder.CryptoAmount, Balance = userWallet.Balance - billerOrder.CryptoAmount, FrozenAmount = 0, FrozenBalance = userWallet.FrozenBalance, Timestamp = DateTime.UtcNow }); boDAC.Insert(billerOrder); new UserTransactionDAC().Insert(new UserTransaction { Id = Guid.NewGuid(), AccountId = billerOrder.AccountId, CryptoId = cryptoCurrency.Id, CryptoCode = cryptoCurrency.Code, Type = UserTransactionType.BillOrder, DetailId = billerOrder.Id.ToString(), Status = (byte)billerOrder.Status, Timestamp = billerOrder.Timestamp, Amount = billerOrder.CryptoAmount, OrderNo = billerOrder.OrderNo }); scope.Complete(); } return(new BillerPayOM() { CryptoAmount = billerOrder.CryptoAmount.ToString(), OrderNo = billerOrder.OrderNo, CryptoCode = billerOrder.CryptoCode, OrderId = billerOrder.Id, Timestamp = billerOrder.PayTime.ToUnixTime().ToString(), SaveAddress = address != null }); }