Exemplo n.º 1
0
        public async Task InsertWalletHistory(WalletHistoryDto WalletHistoryDto)
        {
            // Guid transactionId = Guid.NewGuid();
            var getCustomerID = await _UsersService.getCustomerID(WalletHistoryDto.CustomerID);

            if (string.IsNullOrEmpty(WalletHistoryDto.TransactionDescription))
            {
                WalletHistoryDto.TransactionDescription = "****";
            }

            await Repository.InsertAsync(new WalletHistory
            {
                CustomerID             = Convert.ToInt32(getCustomerID),
                Type                   = 21,
                Transaction            = WalletHistoryDto.Transaction, //transactionId.ToString(),
                TransactionDate        = DateTime.Now,
                TransactionAmount      = WalletHistoryDto.TransactionAmount,
                TransactionDescription = WalletHistoryDto.TransactionDescription,
                Status                 = 1
            });


            await _WalletService.InsertWallet(getCustomerID);

            var _getWalletHistorysum = await GetWalletHistorysum(getCustomerID);

            WalletHistoryDto.TransactionAmount = _getWalletHistorysum + WalletHistoryDto.TransactionAmount;
            WalletHistoryDto.CustomerID        = getCustomerID.ToString();
            await _WalletService.UpdateWalletAmount(WalletHistoryDto);
        }
Exemplo n.º 2
0
        public async Task <List <WalletHistoryDto> > GetAll(int CustomerID)
        {
            var getWalletHistory = (from s in this.Repository.Where(m => m.CustomerID == CustomerID)
                                    select new
            {
                s.LookupTypeValues.Description,
                s.Transaction,
                s.TransactionDate,
                s.TransactionAmount,
                s.TransactionDescription,
                s.Status,
            }).OrderByDescending(s => s.TransactionDate).ToList();

            List <WalletHistoryDto> walletHistoryList = new List <WalletHistoryDto>();

            foreach (var WalletHistory in getWalletHistory)
            {
                WalletHistoryDto WalletHistoryDto = new WalletHistoryDto();
                WalletHistoryDto.Type            = WalletHistory.Description;
                WalletHistoryDto.Transaction     = WalletHistory.Transaction;
                WalletHistoryDto.TransactionDate = WalletHistory.TransactionDate;
                if (WalletHistory.TransactionAmount < 0)
                {
                    WalletHistoryDto.TransactionAmount = Decimal.Negate(WalletHistory.TransactionAmount);
                }
                else
                {
                    WalletHistoryDto.TransactionAmount = WalletHistory.TransactionAmount;
                }
                WalletHistoryDto.TransactionDescription = WalletHistory.TransactionDescription;
                WalletHistoryDto.Status = WalletHistory.Status;
                walletHistoryList.Add(WalletHistoryDto);
            }
            return(walletHistoryList);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> InsertWalletHistory([FromBody] WalletHistoryDto walletHistoryDto)
        {
            try
            {
                if (walletHistoryDto.isExistingCard.Value)
                {
                    Checkout.Payments.PaymentResponse paymentResponse = walletHistoryDto.PaymentResponseSource;
                    walletHistoryDto.Transaction            = paymentResponse.Payment.Id;
                    walletHistoryDto.TransactionDescription = ((Checkout.Payments.CardSourceResponse)paymentResponse.Payment.Source).Scheme
                                                              + "****" + ((Checkout.Payments.CardSourceResponse)paymentResponse.Payment.Source).Last4;
                }
                else
                {
                    if (walletHistoryDto.SourceId != null)
                    {
                        Checkout.Payments.GetPaymentResponse payment = walletHistoryDto.SourceId;
                        if (walletHistoryDto.SaveCard)
                        {
                            var customerID = await _UsersService.getCustomerID(walletHistoryDto.CustomerID);

                            List <GetPaymentCardsDto> paymentCards = _paymentCardsService.GetPaymentByCustomer(walletHistoryDto.CustomerID);
                            var itemExists = paymentCards.Find(p => p.CardType == ((Checkout.Payments.CardSourceResponse)payment.Source).Scheme &&
                                                               p.Expyear == Convert.ToInt32(((Checkout.Payments.CardSourceResponse)payment.Source).ExpiryYear) &&
                                                               p.Expmonth == Convert.ToInt32(((Checkout.Payments.CardSourceResponse)payment.Source).ExpiryMonth) &&
                                                               p.last4digits == Convert.ToInt32(((Checkout.Payments.CardSourceResponse)payment.Source).Last4)
                                                               );
                            if (itemExists == null)
                            {
                                await _paymentCardsService.InsertPaymentCards(
                                    new PaymentCardsDto
                                {
                                    CardCustomerId = ((Checkout.Payments.CustomerResponse)payment.Customer).Id,
                                    CardSourceId   = ((Checkout.Payments.CardSourceResponse)payment.Source).Id,
                                    CardType       = ((Checkout.Payments.CardSourceResponse)payment.Source).Scheme,
                                    CustomerId     = customerID,
                                    Expyear        = Convert.ToInt32(((Checkout.Payments.CardSourceResponse)payment.Source).ExpiryYear),
                                    Expmonth       = Convert.ToInt32(((Checkout.Payments.CardSourceResponse)payment.Source).ExpiryMonth),
                                    last4digits    = Convert.ToInt32(((Checkout.Payments.CardSourceResponse)payment.Source).Last4)
                                }
                                    );
                            }
                        }
                        walletHistoryDto.Transaction            = payment.Id;
                        walletHistoryDto.TransactionDescription = ((Checkout.Payments.CardSourceResponse)payment.Source).Scheme
                                                                  + "****" + ((Checkout.Payments.CardSourceResponse)payment.Source).Last4;
                    }
                }
                await _WalletHistoryService.InsertWalletHistory(walletHistoryDto);
            }

            catch (Exception err)
            {
                return(BadRequest(new GenericResultDto <string> {
                    Result = err.Message
                }));
            }
            return(Ok(new GenericResultDto <string> {
                Result = "Insert successfully"
            }));
        }
        public async Task UpdateWalletAmount(WalletHistoryDto WalletHistoryDto)
        {
            var isvalid = Repository.SingleOrDefault(x => x.CustomerID == Convert.ToInt32(WalletHistoryDto.CustomerID));

            isvalid.Amount = WalletHistoryDto.TransactionAmount;
            await Repository.UpdateAsync(isvalid);
        }
Exemplo n.º 5
0
        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");
            }
        }
Exemplo n.º 6
0
        public async Task <IActionResult> PayOrder([FromBody] WalletHistoryDto walletHistoryDto)
        {
            try
            {
                var customerID = await _UsersService.getCustomerID(walletHistoryDto.CustomerID);

                if (walletHistoryDto.isExistingCard.Value)
                {
                    Checkout.Payments.PaymentResponse paymentResponse = walletHistoryDto.PaymentResponseSource;
                    string TrasnsactionId         = paymentResponse.Payment.Id;
                    string TransactionDescription = ((Checkout.Payments.CardSourceResponse)paymentResponse.Payment.Source).Scheme
                                                    + "****" + ((Checkout.Payments.CardSourceResponse)paymentResponse.Payment.Source).Last4;


                    await _PaymentResponseService.InsertPaymentDetails(new PaymentResponseDto
                    {
                        Amount            = Convert.ToDecimal(paymentResponse.Payment.Amount),
                        Cardscheme        = ((Checkout.Payments.CardSourceResponse)paymentResponse.Payment.Source).Scheme,
                        Currency          = paymentResponse.Payment.Currency,
                        CardType          = ((Checkout.Payments.CardSourceResponse)paymentResponse.Payment.Source).CardType,
                        PaymentCustomerId = ((Checkout.Payments.CustomerResponse)paymentResponse.Payment.Customer).Id,
                        PaymentSourceId   = ((Checkout.Payments.CardSourceResponse)paymentResponse.Payment.Source).Id,
                        TransactionId     = paymentResponse.Payment.Id,
                        PaymentDate       = paymentResponse.Payment.ProcessedOn,
                        PaymentStatus     = "Approved",
                        CustomerId        = customerID,
                        Card            = Convert.ToInt32(((Checkout.Payments.CardSourceResponse)paymentResponse.Payment.Source).Last4),
                        TransactionType = ((Checkout.Payments.CardSourceResponse)paymentResponse.Payment.Source).Type,
                        OrderId         = walletHistoryDto.OrderID.Value
                    });
                }
                else
                {
                    if (walletHistoryDto.SourceId != null)
                    {
                        Checkout.Payments.GetPaymentResponse payment = walletHistoryDto.SourceId;

                        if (walletHistoryDto.SaveCard)
                        {
                            List <GetPaymentCardsDto> paymentCards = _paymentCardsService.GetPaymentByCustomer(walletHistoryDto.CustomerID);
                            var itemExists = paymentCards.Find(p => p.CardType == ((Checkout.Payments.CardSourceResponse)payment.Source).Scheme &&
                                                               p.Expyear == Convert.ToInt32(((Checkout.Payments.CardSourceResponse)payment.Source).ExpiryYear) &&
                                                               p.Expmonth == Convert.ToInt32(((Checkout.Payments.CardSourceResponse)payment.Source).ExpiryMonth) &&
                                                               p.last4digits == Convert.ToInt32(((Checkout.Payments.CardSourceResponse)payment.Source).Last4)
                                                               );
                            if (itemExists == null)
                            {
                                await _paymentCardsService.InsertPaymentCards(
                                    new PaymentCardsDto
                                {
                                    CardCustomerId = ((Checkout.Payments.CustomerResponse)payment.Customer).Id,
                                    CardSourceId   = ((Checkout.Payments.CardSourceResponse)payment.Source).Id,
                                    CardType       = ((Checkout.Payments.CardSourceResponse)payment.Source).Scheme,
                                    CustomerId     = customerID,
                                    Expyear        = Convert.ToInt32(((Checkout.Payments.CardSourceResponse)payment.Source).ExpiryYear),
                                    Expmonth       = Convert.ToInt32(((Checkout.Payments.CardSourceResponse)payment.Source).ExpiryMonth),
                                    last4digits    = Convert.ToInt32(((Checkout.Payments.CardSourceResponse)payment.Source).Last4)
                                }
                                    );
                            }
                        }
                        string TrasnsactionId         = payment.Id;
                        string TransactionDescription = ((Checkout.Payments.CardSourceResponse)payment.Source).Scheme
                                                        + "****" + ((Checkout.Payments.CardSourceResponse)payment.Source).Last4;

                        await _PaymentResponseService.InsertPaymentDetails(new PaymentResponseDto
                        {
                            Amount            = Convert.ToDecimal(payment.Amount),
                            Cardscheme        = ((Checkout.Payments.CardSourceResponse)payment.Source).Scheme,
                            Currency          = payment.Currency,
                            CardType          = ((Checkout.Payments.CardSourceResponse)payment.Source).CardType,
                            PaymentCustomerId = ((Checkout.Payments.CustomerResponse)payment.Customer).Id,
                            PaymentSourceId   = ((Checkout.Payments.CardSourceResponse)payment.Source).Id,
                            TransactionId     = payment.Id,
                            PaymentDate       = payment.RequestedOn,
                            PaymentStatus     = "Approved",
                            CustomerId        = customerID,
                            Card            = Convert.ToInt32(((Checkout.Payments.CardSourceResponse)payment.Source).Last4),
                            TransactionType = ((Checkout.Payments.CardSourceResponse)payment.Source).Type,
                            OrderId         = walletHistoryDto.OrderID.Value
                        });
                    }
                }
                if (walletHistoryDto.OrderWalletPaymentAmount > 0)
                {
                    OrderPaymentDto OrderPaymentDto = new OrderPaymentDto
                    {
                        CustomerId  = walletHistoryDto.CustomerID,
                        OrderAmount = walletHistoryDto.OrderWalletPaymentAmount.ToString(),
                        OrderId     = walletHistoryDto.OrderID.Value.ToString()
                    };
                    await _WalletHistoryService.OrderWalletPayment(OrderPaymentDto);
                }
                await _OrdersService.UpdatePaymentStatus(Convert.ToInt32(walletHistoryDto.OrderID));
            }

            catch (Exception err)
            {
                return(BadRequest(new GenericResultDto <string> {
                    Result = err.Message
                }));
            }
            return(Ok(new GenericResultDto <string> {
                Result = "Insert successfully"
            }));
        }