public async Task <IActionResult> OrderPayment([FromBody] OrderPaymentDto orderPaymeentDto) { string returnmessage = string.Empty; try { if (!string.IsNullOrEmpty(orderPaymeentDto.OrderAmount)) { if (Convert.ToDecimal(orderPaymeentDto.OrderAmount) > 0) { returnmessage = await _WalletHistoryService.OrderWalletPayment(orderPaymeentDto); } } } catch (Exception err) { return(BadRequest(new GenericResultDto <string> { Result = err.Message })); } return(Ok(new GenericResultDto <string> { Result = returnmessage })); }
public async Task <string> OrderWalletPayment(OrderPaymentDto orderPaymeentDto) { try { Guid transactionId = Guid.NewGuid(); var getCustomerID = await _UsersService.getCustomerID(orderPaymeentDto.CustomerId); decimal CustomerWallet = await _WalletService.getWalletAmount(Convert.ToInt32(getCustomerID)); await Repository.InsertAsync(new WalletHistory { CustomerID = Convert.ToInt32(getCustomerID), Type = 31, Transaction = transactionId.ToString(), TransactionDate = DateTime.Now, TransactionAmount = -Convert.ToDecimal(orderPaymeentDto.OrderAmount), TransactionDescription = "Order Wallet Payment", Status = 1, OrderID = Convert.ToInt32(orderPaymeentDto.OrderId) }); var _getWalletHistorysum = await GetWalletHistorysum(getCustomerID); WalletHistoryDto WalletHistoryDto = new WalletHistoryDto(); WalletHistoryDto.TransactionAmount = _getWalletHistorysum - Convert.ToDecimal(orderPaymeentDto.OrderAmount); WalletHistoryDto.CustomerID = getCustomerID.ToString(); await _WalletService.UpdateWalletAmount(WalletHistoryDto); await _OrdersService.UpdatePaymentStatus(Convert.ToInt32(orderPaymeentDto.OrderId)); return("Order Payment Success"); } catch (Exception ex) { return("Order Payment Failed"); } }
public async Task <PaymentTransaction> PayTheOrder(OrderPaymentDto orderPaymentDto) { var order = CreateOrder(orderPaymentDto); var payment = CreatePayment(orderPaymentDto); var paymentTransaction = PayTheOrder(order, payment); if (paymentTransaction.IsPaid()) { PersistPaymentAdded(payment); PersistPaymentTransactionAdded(paymentTransaction); await CommitChanges(); payment.AddEvent(new PaidOrderEvent(orderPaymentDto.CustomerId, orderPaymentDto.OrderId, payment.Id, paymentTransaction.Id, orderPaymentDto.TotalPrice)); await PublishPaymentEvents(payment); } else { await PublishTransactionDeclinedNotification(); await PublichOrderPaymentDeclinedEvent(orderPaymentDto, payment, paymentTransaction); } return(paymentTransaction); }
private async Task PublichOrderPaymentDeclinedEvent(OrderPaymentDto orderPaymentDto, Payment payment, PaymentTransaction paymentTransaction) { await _mediatrHandler.PublishEvent(new OrderPaymentDeclinedEvent(orderPaymentDto.CustomerId, orderPaymentDto.OrderId, payment.Id, paymentTransaction.Id, orderPaymentDto.TotalPrice)); }
private Payment CreatePayment(OrderPaymentDto orderPaymentDto) { return(new Payment(orderPaymentDto.OrderId, orderPaymentDto.TotalPrice, orderPaymentDto.CardName, orderPaymentDto.CardName, orderPaymentDto.CardExpirationDate, orderPaymentDto.CardCvv)); }
private Order CreateOrder(OrderPaymentDto orderPaymentDto) { return(new Order(orderPaymentDto.OrderId, orderPaymentDto.TotalPrice)); }
public async Task <IActionResult> MobilePayOrder([FromBody] MobileWalletHistoryDto MobilewalletHistoryDto) { try { var customerID = await _UsersService.getCustomerID(MobilewalletHistoryDto.CustomerID); if (MobilewalletHistoryDto.isExistingCard.Value) { Checkout.Payments.PaymentResponse paymentResponse = MobilewalletHistoryDto.PaymentResponseSource; string TrasnsactionId = paymentResponse.Payment.Id; string TransactionDescription = ((Checkout.Payments.MobileCardSourceResponse)paymentResponse.Payment.Source).Scheme + "****" + ((Checkout.Payments.MobileCardSourceResponse)paymentResponse.Payment.Source).Last4; await _PaymentResponseService.InsertPaymentDetails(new PaymentResponseDto { Amount = Convert.ToDecimal(paymentResponse.Payment.Amount), Cardscheme = ((Checkout.Payments.MobileCardSourceResponse)paymentResponse.Payment.Source).Scheme, Currency = paymentResponse.Payment.Currency, CardType = ((Checkout.Payments.MobileCardSourceResponse)paymentResponse.Payment.Source).Card_Type, PaymentCustomerId = ((Checkout.Payments.CustomerResponse)paymentResponse.Payment.Customer).Id, PaymentSourceId = ((Checkout.Payments.MobileCardSourceResponse)paymentResponse.Payment.Source).Id, TransactionId = paymentResponse.Payment.Id, PaymentDate = paymentResponse.Payment.ProcessedOn, PaymentStatus = "Approved", CustomerId = customerID, Card = Convert.ToInt32(((Checkout.Payments.MobileCardSourceResponse)paymentResponse.Payment.Source).Last4), TransactionType = ((Checkout.Payments.MobileCardSourceResponse)paymentResponse.Payment.Source).Type, OrderId = MobilewalletHistoryDto.OrderID.Value }); } else { if (MobilewalletHistoryDto.SourceId != null) { Checkout.Payments.GetMobilePaymentResponse payment = MobilewalletHistoryDto.SourceId; if (MobilewalletHistoryDto.SaveCard) { List <GetPaymentCardsDto> paymentCards = _paymentCardsService.GetPaymentByCustomer(MobilewalletHistoryDto.CustomerID); var itemExists = paymentCards.Find(p => p.CardType == ((Checkout.Payments.MobileCardSourceResponse)payment.Source).Scheme && p.Expyear == Convert.ToInt32(((Checkout.Payments.MobileCardSourceResponse)payment.Source).Expiry_Year) && p.Expmonth == Convert.ToInt32(((Checkout.Payments.MobileCardSourceResponse)payment.Source).Expiry_Month) && p.last4digits == Convert.ToInt32(((Checkout.Payments.MobileCardSourceResponse)payment.Source).Last4) ); if (itemExists == null) { await _paymentCardsService.InsertPaymentCards( new PaymentCardsDto { CardCustomerId = ((Checkout.Payments.CustomerResponse)payment.Customer).Id, CardSourceId = ((Checkout.Payments.MobileCardSourceResponse)payment.Source).Id, CardType = ((Checkout.Payments.MobileCardSourceResponse)payment.Source).Scheme, CustomerId = customerID, Expyear = Convert.ToInt32(((Checkout.Payments.MobileCardSourceResponse)payment.Source).Expiry_Year), Expmonth = Convert.ToInt32(((Checkout.Payments.MobileCardSourceResponse)payment.Source).Expiry_Month), last4digits = Convert.ToInt32(((Checkout.Payments.MobileCardSourceResponse)payment.Source).Last4) } ); } } string TrasnsactionId = payment.Id; string TransactionDescription = ((Checkout.Payments.MobileCardSourceResponse)payment.Source).Scheme + "****" + ((Checkout.Payments.MobileCardSourceResponse)payment.Source).Last4; await _PaymentResponseService.InsertPaymentDetails(new PaymentResponseDto { Amount = Convert.ToDecimal(payment.Amount), Cardscheme = ((Checkout.Payments.MobileCardSourceResponse)payment.Source).Scheme, Currency = payment.Currency, CardType = ((Checkout.Payments.MobileCardSourceResponse)payment.Source).Card_Type, PaymentCustomerId = ((Checkout.Payments.CustomerResponse)payment.Customer).Id, PaymentSourceId = ((Checkout.Payments.MobileCardSourceResponse)payment.Source).Id, TransactionId = payment.Id, PaymentDate = payment.Requested_On, PaymentStatus = "Approved", CustomerId = customerID, Card = Convert.ToInt32(((Checkout.Payments.MobileCardSourceResponse)payment.Source).Last4), TransactionType = ((Checkout.Payments.MobileCardSourceResponse)payment.Source).Type, OrderId = MobilewalletHistoryDto.OrderID.Value }); } } if (MobilewalletHistoryDto.OrderWalletPaymentAmount > 0) { OrderPaymentDto OrderPaymentDto = new OrderPaymentDto { CustomerId = MobilewalletHistoryDto.CustomerID, OrderAmount = MobilewalletHistoryDto.OrderWalletPaymentAmount.ToString(), OrderId = MobilewalletHistoryDto.OrderID.Value.ToString() }; await _WalletHistoryService.OrderWalletPayment(OrderPaymentDto); } await _OrdersService.UpdatePaymentStatus(Convert.ToInt32(MobilewalletHistoryDto.OrderID)); } catch (Exception err) { return(BadRequest(new GenericResultDto <string> { Result = err.Message })); } return(Ok(new GenericResultDto <string> { Result = "Insert successfully" })); }