public async Task <ActionResult> Payment(PaymentInput input) { var paymentViewModel = new PaymentViewModel() { PaymentInput = input, }; if (!ModelState.IsValid) { return(View("Index", paymentViewModel)); } var gateCheckRequest = new GateCheckRequest() { Number = input.Number, Amount = double.Parse(input.Amount, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture), }; try { paymentViewModel.GatePayResponse = await m_Gate.CheckAndPay(gateCheckRequest).ConfigureAwait(false); } catch (Exception e) { m_Logger.Error(e.Message, e); paymentViewModel.ExceptionMessage = e.Message; } return(View("Index", paymentViewModel)); }
public async Task <SubmitOrderCommandViewModel> Handle(SubmitOrderCommand request, CancellationToken cancellationToken) { var order = _dbContext.Orders.FirstOrDefault(o => o.Id.Equals(request.Id)); var paymentType = Domain.EnumObjects.PaymentType.Parse <PaymentType>(request.Type); var paymentInput = new PaymentInput() { Amount = order.Price, OrderId = order.Id, Type = paymentType }; var output = _paymentProcessor.Process(paymentInput); order.PaymentInformation = new PaymentInformation() { Details = output.Details, Type = paymentInput.Type }; _dbContext.Orders.Update(order); await _dbContext.SaveChangesAsync(cancellationToken); await _mediator.Publish(new OrderSubmitted() { OrderId = order.Id }, cancellationToken); return(new SubmitOrderCommandViewModel() { Order = _mapper.Map <OrderDto>(order) }); }
public async Task InsertAsync(SaleInput input) { var itens = new List <Item>(); var total = 0.00M; if (input.Itens.Count <= 0) { throw new Exception("Para a venda, é necessário pelo menos informar um item"); } foreach (var itemId in input.Itens) { var item = await _itemRepository .GetByIdAsync(itemId) .ConfigureAwait(false); var stock = await _stockGateway .PutAsync(urlStock, itemId) .ConfigureAwait(false); if (!stock.Success) { throw new Exception(stock.ErrorMessage); } itens.Add(item); total += item.Price; } var payment = new PaymentInput() { CardNumber = input.Payment.CardNumber, SubDivision = input.Payment.SubDivision, Total = total }; var response = await _paymentGateway .PostAsync(urlPayment, payment) .ConfigureAwait(false); if (!response.Success) { throw new Exception(response.ErrorMessage); } var sale = new Sale(new Payment(response.ReadToObject.Id, response.ReadToObject.CardNumber, response.ReadToObject.SubDivision, response.ReadToObject.Total, response.ReadToObject.TotalSubDivision)); sale.AddItems(itens); await _saleRepository .InsertAsync(sale) .ConfigureAwait(false); }
public async Task <ActionResult <OrderPaymentIntent> > PaymentAsync(PaymentInput paymentInput) { var order = service.GetDetail(paymentInput.OrderId); if (order == null) { return(BadRequest()); } return(await service.CreatePaymentIntentAsync(order)); }
public PaymentOutput Handle(PaymentInput paymentInput) { return(new PaymentOutput() { Details = new WireTransferPaymentDetails() { AccountNumber = "1234567890", Reference = "1234567890" } }); }
public void Pay(PaymentInput input) { CheckInputMessage(input, MessageTypePayment); repositoryService.AddPaymentInput(input); decimal commission = CalculateCommission(input.Origin, input.Amount); decimal currentAmount = repositoryService.GetAmount(input.AccountId); decimal newAmount = currentAmount - input.Amount - commission; repositoryService.UpdateAccount(input.AccountId, newAmount); }
public PaymentOutput Process(PaymentInput paymentInput) { foreach (var handler in _handlers) { if (handler.CanHandle(paymentInput)) { return(handler.Handle(paymentInput)); } } throw new Exception("No payment handler found"); }
public async Task <IActionResult> Post([FromBody] PaymentInput input) { try { var pay = await _paymentAppService.InsertAsync(input); return(Created("", pay)); } catch (ArgumentException ex) { return(BadRequest($"Payment => {ex.Message}")); } }
private void CheckInputMessage(PaymentInput input, string messageType) { if (!CheckMessageType(messageType, input.MessageType)) { throw new Exception("Message Type is not valid"); } List <Account> accounts = repositoryService.GetAccounts(); if (accounts.Find(item => item.AccountId == input.AccountId) == null) { throw new Exception("Account not found"); } }
public PaymentGatewayFixture() { var mapperConfig = MapperConfigurationFactory.MapperConfiguration; Mapper = mapperConfig.CreateMapper(); PaymentInput = new PaymentInput() { Amount = 10.50m, CardNumber = "4532517464958844", CurrencyCode = "EUR", CVV = "078", ExpiryMonth = 10, ExpiryYear = 23 }; }
public async Task <Payment> InsertAsync(PaymentInput input) { var payment = new Payment(input.CardNumber, input.SubDivision, input.Total); if (!payment.ValidateCreditCard()) { throw new ArgumentException("Cartão de crédito inválido"); } payment.CalculatedSubDivision(); await _paymentRepository .InsertAsync(payment) .ConfigureAwait(false); return(payment); }
//Assumption: A transaction for an account can be corrected only once. public void Adjust(PaymentInput input) { CheckInputMessage(input, MessageTypeAdjustment); List <PaymentInput> paymentInputs = repositoryService.GetPaymentInputsByAccountIdAndTransactionId(input.AccountId, input.TransactionId); if (paymentInputs.Count == 0) { throw new Exception("Transaction not found"); } decimal currentAmount = repositoryService.GetAmount(input.AccountId); decimal oldAmount = paymentInputs[0].Amount; decimal correctedAmount = currentAmount + oldAmount - input.Amount; repositoryService.UpdateAccount(input.AccountId, correctedAmount); }
public async Task <IActionResult> Post([FromBody] PaymentInput input) { var dto = _mapper.Map <PaymentDto>(input); dto.UserId = new Guid(User.Identity.Name); try { var paymentId = await _paymentService.ProcessPaymentAsync(dto); dto.Id = paymentId; _logger.LogInformation($"Payment {paymentId} succesfully created for user {User.Identity.Name}"); return(Accepted(dto)); } catch (Exception e) { _logger.LogError(e, $"Error while trying to issue payment for user {User.Identity.Name}", dto); return(BadRequest(dto)); } }
public IRestResponse <PaymentResponse> PaymentInquery(PaymentInput input) { try { var req = new RestRequest("payment/inquery", Method.POST); req.AddParameter("chat_id", input.ChatId); req.AddParameter("ref_id", input.RefId); var response = RestApi.Execute <PaymentResponse>(req); LogOutput(response, new { hasData = response.Data != null, method = "PaymentInquery", input.RefId }); return(response); } catch (Exception ex) { Logger.Log("PaymentInquery", LogErrorLevel.Error, ex); return(null); } }
public Task <PaymentOutput> MakePaymentAsync(PaymentInput input, CancellationToken token = default) { var result = new MockPaymentOutput { IsSuccessful = true, CardType = "Visa" }; var random = new Random(); var randomIndex = 0; switch (input) { case MonerisCreditCardPaymentInput i: randomIndex = random.Next(0, this.monerisTokens.Length); result.SetAuth(this.monerisTokens[randomIndex]); result.TransactionResult = "APPROVED"; break; case IatsCreditCardPaymentInput i: randomIndex = random.Next(0, this.iatsTokens.Length); result.SetAuth(this.iatsTokens[randomIndex]); result.TransactionResult = "OK"; break; case StripeCreditCardPaymentInput i: randomIndex = random.Next(0, this.stripeTokens.Length); var tokenItem = this.stripeTokens[randomIndex]; result.SetAuth(tokenItem.AuthToken); result.StripeCustomerId = tokenItem.StripeCustomerId; result.TransactionResult = "succeeded"; break; default: break; } return(Task.FromResult((PaymentOutput)result)); }
public async Task <PaymentOutput> MakePaymentAsync(PaymentInput input, CancellationToken token = default) { switch (input) { case IatsCreditCardPaymentInput i: var iats = this.serviceProvider.GetRequiredService <IPaymentClient <IatsCreditCardPaymentInput, PaymentOutput> >(); return(await iats.MakePaymentAsync(i, token)); case MonerisCreditCardPaymentInput i: var moneris = this.serviceProvider.GetRequiredService <IPaymentClient <MonerisCreditCardPaymentInput, PaymentOutput> >(); return(await moneris.MakePaymentAsync(i, token)); case StripeCreditCardPaymentInput i: var stripe = this.serviceProvider.GetRequiredService <IPaymentClient <StripeCreditCardPaymentInput, PaymentOutput> >(); return(await stripe.MakePaymentAsync(i, token)); case WorldPayCreditCardPaymentInput i: var worldPay = this.serviceProvider.GetRequiredService <IPaymentClient <WorldPayCreditCardPaymentInput, PaymentOutput> >(); return(await worldPay.MakePaymentAsync(i, token)); } throw new NotSupportedException($"Input of type '{input.GetType().Name}' is not supported."); }
private void btnEdit_Click(object sender, EventArgs e) { Int64 currentPay = Int64.Parse(txtPayed.Text); if (txtPayed.Text != string.Empty && txtPayed.Text != "0" && currentPay <= MaxPay()) { string Type = txtMSHD.Text.Trim().Substring(0, 2); if (Type == "NH") { PaymentInputBO paymentInputBO = new PaymentInputBO(); PaymentInput payment = new PaymentInput(); payment.ID = int.Parse(txtMSTT.Text.Substring(2)); payment.Date = DateTime.Parse(txtDate.Text); payment.MSDH = int.Parse(txtMSHD.Text.Trim().Substring(2)); payment.isDelete = false; payment.Payment = int.Parse(txtPayed.Text); paymentInputBO.Update(payment); } else { PaymentOutputBO paymentOutputBO = new PaymentOutputBO(); PaymentOutput payment = new PaymentOutput(); payment.ID = int.Parse(txtMSTT.Text.Substring(2)); payment.Date = DateTime.Parse(txtDate.Text); payment.MSDH = int.Parse(txtMSHD.Text.Trim().Substring(2)); payment.isDelete = false; payment.Payment = int.Parse(txtPayed.Text); paymentOutputBO.Update(payment); } this.Close(); } else { MessageBox.Show("Không hợp lệ .Vui lòng kiểm tra lại"); txtPayed.Text = MaxPay().ToString(); } }
public bool CanHandle(PaymentInput paymentInput) { return(paymentInput.Type == PaymentType.WireTransfer); }
//ToDo: AddPermission //[AbpAuthorize(AppPermissions.Pages_Administration_Users_Create)] public async Task CreatePaymentManually(PaymentInput input) { try { long?transactionId = null; //get latestUnpaidTransaction if (input.TransactionId != null) { //Demo step transactionId = (long)input.TransactionId; } else { //maybe also partially paid var transactionByWaletId = await _transactionRepository.FirstOrDefaultAsync(x => x.WalletId == input.WalletId && x.TransactionStatus == TransactionStatusEnum.Commited); if (transactionByWaletId != null) { transactionId = transactionByWaletId.Id; } } if (transactionId == null) { throw new UserFriendlyException("We are working on that feature"); // todo in case you have a user //transactionId = _transactionRepository.InsertAndGetIdAsync(new Transaction() { }) } var transaction = await _transactionRepository.GetAsync((long)transactionId); //create payment var payment = new Payments.Payment() { AmountOfFunds = input.AmountOfFunds, CreationTime = DateTime.UtcNow, //TODO: old CurrencyType = (CurrentTypeEnum)(Enum.Parse(typeof(CurrentTypeEnum), input.CurrencyType)), CurrencyId = input.CurrencyId, PaymentReceivedTime = input.PaymentReceivedTime, WalletId = transaction.WalletId, TrackingNumber = input.TrackingNumber, TenantId = AbpSession.TenantId }; payment.PaymentTransaction.Add(new PaymentTransaction.PaymentTransaction() { PaymentId = payment.Id, TransactionId = transaction.Id }); await _paymentRepository.InsertAsync(payment); //Convert currency and calculate Tokens Amount if (transaction.UserId == null) { throw new UserFriendlyException("There is no user in found transaction!"); } var currencies = await _walletAppService.GetBtcEthValue(); var currentCurency = new Wallet.Dto.ExchageRateDto(); var currency = await _currenciesRepository.FirstOrDefaultAsync(input.CurrencyId); if (currency == null) { throw new UserFriendlyException(L("CurrencyNotFound")); } if (!currency.IsCrypto) { currentCurency.Price = 1; } else { currentCurency = currencies.Find(x => x.Currency.Id == input.CurrencyId); } decimal amountTokens = (decimal)(((decimal)currentCurency.Price * input.AmountOfFunds) / 0.25M); var user = await _userRepository.GetAsync((long)transaction.UserId); user.AmountTokens += amountTokens; user.DcntTokensBalance += amountTokens; await _userRepository.UpdateAsync(user); if (amountTokens > transaction.TokensIssued) { //pay for current transaction transaction.TransactionStatus = TransactionStatusEnum.Paid; transaction.TokensIssued = (long)amountTokens; //search new unpaid transaction or create one } else if (amountTokens == transaction.TokensIssued) { //Demo step transaction.TransactionStatus = TransactionStatusEnum.Paid; transaction.TokensIssued = (long)amountTokens; } else if (amountTokens < transaction.TokensIssued) { transaction.TransactionStatus = TransactionStatusEnum.PartiallyPaid; } }catch (Exception ex) { throw new UserFriendlyException(ex.Message); } }
public PaymentOutput Payment(PaymentInput Input) { throw new NotImplementedException(); }
public async Task <OperationResult> AddPaymentInPortfolio([CurrentUserIdGlobalState] int userId, [Service] IPortfolioService portfolioService, PaymentInput paymentInput) { var result = await portfolioService.AddPaymentInPortfolio(paymentInput.PortfolioId, userId, paymentInput.Ticket, paymentInput.Amount, paymentInput.PaymentValue, paymentInput.Date); return(result); }
public IEnumerable <Account> Adjust(PaymentInput input) { paymentService.Adjust(input); return(paymentService.GetAccounts()); }
public void AddPaymentInput(PaymentInput paymentInput) { RepositoryService.PaymentInputs.Add(paymentInput); }
public async Task <BXJG.WeChat.Payment.WeChatPaymentUnifyOrderResultForMiniProgram> PaymentAsync(PaymentInput intput) { //做一堆业务判断 //金额 订单 优惠 ... 你的业务 var order = weChatPaymentService.Create("商品描述", "本地订单号", 3.5m); order.product_id = "aaa"; //继续配置微信需要的消息参数 var rt = await weChatPaymentService.PayAsync(order, base.HttpContext.RequestAborted); //你的业务再判断 return(rt.CreateMiniProgramResult()); }