Esempio n. 1
0
        public async Task <IResponse <string> > Verify(Payment payment, object[] args)
        {
            var findGateway = await _gatewayFactory.GetInsance(payment.PaymentGatewayId);

            if (!findGateway.IsSuccessful)
            {
                return new Response <string> {
                           Message = ServiceMessage.RecordNotExist
                }
            }
            ;
            var verify = await findGateway.Result.Service.VerifyTransaction(new VerifyRequest
            {
                OrderId       = payment.OrderId,
                TransactionId = payment.TransactionId,
                ApiKey        = findGateway.Result.Gateway.MerchantId,
                Url           = findGateway.Result.Gateway.VerifyUrl
            }, args);

            if (!verify.IsSuccessful)
            {
                return new Response <string> {
                           IsSuccessful = false, Result = payment.TransactionId
                }
            }
            ;
            var order = await _orderRepo.FindAsync(payment.OrderId);

            if (order == null)
            {
                return new Response <string> {
                           Message = ServiceMessage.RecordNotExist
                }
            }
            ;
            order.OrderStatus     = OrderStatus.InProcessing;
            payment.PaymentStatus = PaymentStatus.Success;
            _appUow.OrderRepo.Update(order);
            _appUow.PaymentRepo.Update(payment);
            var update = await _appUow.ElkSaveChangesAsync();

            return(new Response <string>
            {
                IsSuccessful = update.IsSuccessful,
                Result = payment.TransactionId,
                Message = update.Message
            });
        }
Esempio n. 2
0
        public async Task <IActionResult> Add([FromBody] OrderDTO order)
        {
            var findUser = await _userService.FindAsync(order.UserToken);

            if (!findUser.IsSuccessful)
            {
                return(Json(new Response <string> {
                    Message = Strings.InvalidToken
                }));
            }
            var addOrder = await _orderService.Add(order);

            if (!addOrder.IsSuccessful)
            {
                return(Json(new Response <AddOrderReponse> {
                    Message = addOrder.Message
                }));
            }
            var fatcory = await _gatewayFectory.GetInsance(int.Parse(_configuration["DefaultGatewayId"]));

            var transModel = new CreateTransactionRequest
            {
                OrderId      = addOrder.Result.Order.OrderId,
                Amount       = addOrder.Result.Order.TotalPriceAfterDiscount,
                MobileNumber = findUser.Result.MobileNumber.ToString(),
                ApiKey       = fatcory.Result.Gateway.MerchantId,
                CallbackUrl  = fatcory.Result.Gateway.PostBackUrl,
                Url          = fatcory.Result.Gateway.Url
            };
            var createTrans = await fatcory.Result.Service.CreateTrasaction(transModel, null);

            if (!createTrans.IsSuccessful)
            {
                return(Json(new Response <AddOrderReponse> {
                    Message = createTrans.Message, Result = new AddOrderReponse {
                        OrderId = addOrder.Result.Order.OrderId
                    }
                }));
            }
            var addPayment = await _paymentService.Add(transModel, createTrans.Result.TransactionId, fatcory.Result.Gateway.PaymentGatewayId);

            if (!addPayment.IsSuccessful)
            {
                return(Json(new Response <AddOrderReponse> {
                    Message = addPayment.Message, Result = new AddOrderReponse {
                        OrderId = addOrder.Result.Order.OrderId
                    }
                }));
            }
            return(Json(new Response <AddOrderReponse>
            {
                IsSuccessful = true,
                Result = new AddOrderReponse
                {
                    OrderId = addOrder.Result.Order.OrderId,
                    Url = createTrans.Result.GatewayUrl,
                    BasketChanged = addOrder.Result.IsChanged,
                    ChangedProducts = addOrder.Result.Order.OrderDetails.Select(x => new ProductDTO
                    {
                        Id = x.ProductId,
                        Discount = x.DiscountPercent ?? 0,
                        Price = x.Price,
                        Count = x.Count
                    })
                }
            }));
        }