Exemplo n.º 1
0
        public async Task <PaymentDomain> CreateAsync(PaymentUpdateModel model)
        {
            var result = await Context.Payments.AddAsync(Mapper.Map <PaymentEntity>(model));

            await Context.SaveChangesAsync();

            return(Mapper.Map <PaymentDomain>(result.Entity));
        }
Exemplo n.º 2
0
        public async Task <CommandResult <PaymentUpdateModel> > RemitanceAsync(PaymentUpdateModel model)
        {
            try
            {
                if (Validate(model))
                {
                    using (var transaction = transactionScope.BeginTransaction())
                    {
                        var now             = DateTime.Now;
                        var productContract = await query.Get <ProductEntity>().Where(x => x.Id == model.Product.Id).SelectProductContract().SingleAsync();

                        var customerEntity = await _customerService.CreateAsync(model.Customer);

                        // Create order
                        var orderEntity = new OrderEntity
                        {
                            Id            = Guid.NewGuid(),
                            CustomerId    = customerEntity.Id,
                            ProductId     = model.Product.Id,
                            Start         = now,
                            OrderStatusId = (int)OrderStatusEnum.PENDING,
                            Token         = Tokenizer.Token(),
                            OrderTypeId   = (int)OrderTypeEnum.REMITANCE,
                            Quantity      = 1,
                        };
                        await store.CreateAsync(orderEntity);

                        // Create pro forma invoice
                        var lastNumber     = query.Get <ProFormaEntity>().Min(x => (int?)x.Number) ?? 0;
                        var proFormaEntity = new ProFormaEntity
                        {
                            OrderId      = orderEntity.Id,
                            ExposureDate = now,
                            Number       = lastNumber + 1,
                            FullNumber   = InvoiceNumberBuilder.Build(lastNumber + 1, now),
                        };
                        await store.CreateAsync(proFormaEntity);

                        // Send mail with pro forma
                        await _mailService.SendProFormaAsync(orderEntity.Id);

                        transaction.Commit();
                        return(new CommandResult <PaymentUpdateModel>(model));
                    }
                }
                return(new CommandResult <PaymentUpdateModel>(model, Localization.Resource.Validation_Summary_Error));
            }
            catch (Exception e)
            {
                log.Error(nameof(RemitanceAsync), model, e);
                return(new CommandResult <PaymentUpdateModel>(model, e));
            }
        }
Exemplo n.º 3
0
        public async Task <PaymentDomain> UpdateAsync(PaymentUpdateModel model)
        {
            var existing = await Get(model);

            Context.Entry(existing).State = EntityState.Modified;
            var result = Mapper.Map(model, existing);

            Context.Update(result);
            await Context.SaveChangesAsync();

            return(Mapper.Map <PaymentDomain>(result));
        }
Exemplo n.º 4
0
        public async Task <ActionResult> AddOrUpdateCartPayment(PaymentUpdateModel payment)
        {
            EnsureThatCartExist();

            //Need lock to prevent concurrent access to same cart
            using (var lockObject = await AsyncLock.GetLockByKey(GetAsyncLockCartKey(WorkContext.CurrentCart.Id)).LockAsync())
            {
                await _cartBuilder.AddOrUpdatePaymentAsync(payment);

                await _cartBuilder.SaveAsync();
            }
            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
Exemplo n.º 5
0
        public virtual async Task <ICartBuilder> AddOrUpdatePaymentAsync(PaymentUpdateModel updateModel)
        {
            Payment payment;

            if (!string.IsNullOrEmpty(updateModel.Id))
            {
                payment = _cart.Payments.FirstOrDefault(s => s.Id == updateModel.Id);
                if (payment == null)
                {
                    throw new StorefrontException(string.Format("Payment with {0} not found", updateModel.Id));
                }
            }
            else
            {
                payment = new Payment(_cart.Currency);
                _cart.Payments.Add(payment);
            }

            if (updateModel.BillingAddress != null)
            {
                payment.BillingAddress = updateModel.BillingAddress;
            }

            if (!string.IsNullOrEmpty(updateModel.PaymentGatewayCode))
            {
                var availablePaymentMethods = await GetAvailablePaymentMethodsAsync();

                var paymentMethod = availablePaymentMethods.FirstOrDefault(pm => string.Equals(pm.GatewayCode, updateModel.PaymentGatewayCode, StringComparison.InvariantCultureIgnoreCase));
                if (paymentMethod == null)
                {
                    throw new StorefrontException("Unknown payment method " + updateModel.PaymentGatewayCode);
                }
                payment.PaymentGatewayCode = paymentMethod.GatewayCode;
            }

            payment.OuterId = updateModel.OuterId;
            payment.Amount  = _cart.Total;

            return(this);
        }
        public async Task <Response> Update(PaymentUpdateModel model, ClaimsPrincipal claimsPrincipal)
        {
            using (var context = _applicationDbContextFactory.Create())
            {
                var Entity = context.Payments.Where(i => i.Id == model.Id).FirstOrDefault();
                if (Entity == null)
                {
                    return new Response {
                               Status = 500, Message = "Студент еще внес оплату за этот месяц"
                    }
                }
                ;
                Entity.Sum     += model.Sum;
                Entity.DateTime = model.DateTime;
                var User = await _userManager.FindByNameAsync(claimsPrincipal.Identity.Name);

                Entity.UserId = User.Id;
                var Group = context.GetGroupStudentId(model.StudentId, model.GroupId);
                if (Entity.Sum > Group.OneMounthSum)
                {
                    return(new Response {
                        Status = 500, Message = "Сумма взноса больше суммы контракта"
                    });
                }
                if (context.StudentGroups.Any(i => i.GroupId == model.GroupId && i.StudentId == model.GroupId))
                {
                    return new Response {
                               Status = 500, Message = "Студент не зарегистрирован в данной группе"
                    }
                }
                ;
                context.Update(Entity);
                context.SaveChanges();
                return(new Response {
                    Status = 100, Message = "Запрос прошел успешно"
                });
            }
        }
Exemplo n.º 7
0
 public Task <PaymentDetailsViewModel> UpdatePaymentAsync(Guid id, PaymentUpdateModel update, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(PutAsync <PaymentUpdateModel, PaymentDetailsViewModel>($"competitions/registration/payments/{id}", update, cancellationToken));
 }
Exemplo n.º 8
0
 public async Task <CommandResult <PaymentUpdateModel> > Remitance([FromBody] PaymentUpdateModel model) => await _paymentService.RemitanceAsync(model);
Exemplo n.º 9
0
 public async Task <CommandResult <PaymentUpdateModel> > Start([FromBody] PaymentUpdateModel model) => await _paymentService.StartOrderAsync(model);
 public async Task <ActionResult <Response> > Edit(PaymentUpdateModel model)
 {
     return(await paymentService.Update(model, User));
 }
Exemplo n.º 11
0
        public async Task <CommandResult <PaymentUpdateModel> > StartOrderAsync(PaymentUpdateModel model)
        {
            try
            {
                if (Validate(model))
                {
                    using (var transaction = transactionScope.BeginTransaction())
                    {
                        var productContract = query.Get <ProductEntity>().Where(x => x.Id == model.Product.Id).SelectProductContract().Single();
                        var customerEntity  = await _customerService.CreateAsync(model.Customer);

                        var orderEntity = new OrderEntity
                        {
                            Id            = Guid.NewGuid(),
                            CustomerId    = customerEntity.Id,
                            ProductId     = model.Product.Id,
                            Start         = DateTime.Now,
                            OrderStatusId = (int)OrderStatusEnum.PENDING,
                            Token         = Tokenizer.Token(),
                            OrderTypeId   = (int)OrderTypeEnum.PAYU,
                            Quantity      = 1,
                        };
                        store.Create(orderEntity);
                        // Send request to PayU
                        var payuProduct = new PayuProductContract
                        {
                            Name      = productContract.FullName,
                            Quantity  = 1,
                            UnitPrice = (int)(productContract.GrossPrice * 100),
                        };
                        var payuBuyer = new PayuBuyerContract
                        {
                            FirstName = customerEntity.FirstName,
                            LastName  = customerEntity.LastName,
                            Email     = customerEntity.Email,
                            Phone     = customerEntity.Phone,
                            Language  = PayuConsts.Language,
                        };
                        var payuResult = await _payuManager.CreateOrderAsync(orderEntity.Token, payuProduct, payuBuyer);

                        if (payuResult.Succeeded)
                        {
                            var payuOutput = payuResult.Value;
                            model.RedirectUrl = payuOutput.RedirectUri;
                        }
                        else
                        {
                            orderEntity.OrderStatusId = (int)OrderStatusEnum.PENDING;
                            store.Update(orderEntity);
                            // cancel order
                        }
                        transaction.Commit();
                        return(new CommandResult <PaymentUpdateModel>(model));
                    }
                }
                return(new CommandResult <PaymentUpdateModel>(model, Localization.Resource.Validation_Summary_Error));
            }
            catch (Exception e)
            {
                log.Error(nameof(StartOrderAsync), model, e);
                return(new CommandResult <PaymentUpdateModel>(model, e));
            }
        }
Exemplo n.º 12
0
 public bool Validate(PaymentUpdateModel model)
 {
     DataValidator.Validate(model);
     _customerService.Validate(model.Customer);
     return(DataValidator.IsValid(model) && DataValidator.IsValid(model.Customer));
 }