Ejemplo n.º 1
0
        public PaymentType AddPaymentType(CreatePaymentTypeRequest newPaymentTypeObj)
        {
            using (var db = new SqlConnection(ConnectionString))
            {
                var newPaymentQuery = db.QueryFirstOrDefault <PaymentType>(@"
                    Insert into PaymentType (userId, name, accountNumber, type, CVV, expDate, isDeleted)
                    Output inserted.*
                    Values(@userId,@name,@accountNumber,@type,@CVV,@expDate,0)",
                                                                           new
                {
                    newPaymentTypeObj.UserId,
                    newPaymentTypeObj.Name,
                    newPaymentTypeObj.AccountNumber,
                    newPaymentTypeObj.Type,
                    newPaymentTypeObj.CVV,
                    newPaymentTypeObj.ExpDate,
                    newPaymentTypeObj.IsDeleted
                });
                if (newPaymentQuery != null)
                {
                    return(newPaymentQuery);
                }

                throw new Exception("No Payment Found");
            }
        }
 public bool Validate(CreatePaymentTypeRequest requestToValidate)
 {
     return(!(string.IsNullOrEmpty(requestToValidate.Name) ||
              string.IsNullOrEmpty(requestToValidate.UserId.ToString()) ||
              string.IsNullOrEmpty(requestToValidate.AccountNumber.ToString()) ||
              string.IsNullOrEmpty(requestToValidate.CVV.ToString()) ||
              string.IsNullOrEmpty(requestToValidate.ExpDate.ToString()) ||
              string.IsNullOrEmpty(requestToValidate.Type)));
 }
Ejemplo n.º 3
0
        /// <inheritdoc />
        public async Task CreatePaymentType(CreatePaymentTypeRequest request)
        {
            // Loading project
            var project = await ProjectRepository.GetProjectForFinanceSetup(request.ProjectId);

            // Checking access rights of the current user
            if (!IsCurrentUserAdmin)
            {
                project.RequestMasterAccess(CurrentUserId, acl => acl.CanManageMoney);
            }

            // Preparing master Id and checking if the same payment type already created
            int masterId;

            if (request.TypeKind != PaymentTypeKind.Online)
            {
                if (request.TargetMasterId == null)
                {
                    throw new ArgumentNullException(nameof(request.TargetMasterId), @"Target master must be specified");
                }
                project.RequestMasterAccess(request.TargetMasterId);
                // Cash payment could be only one
                if (request.TypeKind == PaymentTypeKind.Cash && project.PaymentTypes.FirstOrDefault(pt => pt.UserId == request.TargetMasterId) != null)
                {
                    throw new JoinRpgInvalidUserException($@"Payment of type ${request.TypeKind.GetDisplayName()} is already created for the user ${request.TargetMasterId}");
                }
                masterId = request.TargetMasterId.Value;
            }
            else
            {
                if (project.PaymentTypes.Any(pt => pt.TypeKind == PaymentTypeKind.Online))
                {
                    throw new DataException("Can't create more than one online payment type");
                }
                masterId = _vpu.PaymentsUser.UserId;
            }

            // Checking custom payment type name
            if (request.TypeKind == PaymentTypeKind.Custom && string.IsNullOrWhiteSpace(request.Name))
            {
                throw new ArgumentNullException(nameof(request.Name), "Custom payment type name must be specified");
            }

            // Creating payment type
            var result = new PaymentType(request.TypeKind, request.ProjectId, masterId);

            // Configuring payment type
            if (result.TypeKind == PaymentTypeKind.Custom)
            {
                result.Name = request.Name.Trim();
            }

            // Saving
            project.PaymentTypes.Add(result);
            await UnitOfWork.SaveChangesAsync();
        }
        public ActionResult AddPaymentType(CreatePaymentTypeRequest createRequest)
        {
            var newPaymentType = _paymentTypeRepository.AddNewPaymentType(
                createRequest.Name,
                createRequest.AccountNumber,
                createRequest.UserId,
                createRequest.IsActive);

            return(Created($"/api/paymenttype/{newPaymentType.Id}", newPaymentType));
        }
Ejemplo n.º 5
0
        public ActionResult AddPaymentType(CreatePaymentTypeRequest createPaymentType)
        {
            if (!_validator.Validate(createPaymentType))
            {
                return(BadRequest(new { error = "Payment Information is either not valid or not complete." }));
            }
            var newPaymentType = _paymentRepository.AddPaymentType(createPaymentType);

            return(Created($"api/paymentTypes/{newPaymentType.Id}", newPaymentType));
        }
Ejemplo n.º 6
0
        public PaymentType AddPayment(CreatePaymentTypeRequest newPaymentObject)
        {
            using (var db = new SqlConnection(ConnectionString))
            {
                var insertQuery = @"
                    INSERT INTO PaymentTypes
                               ([PaymentName],
                               [CardName],
                               [AcctNumber],
                               [ExpDate],
                               [CVV],
                               [CustomerId],
                               [IsActive])
                    OUTPUT inserted.*
                         VALUES
                               (@paymentName,
                               @cardName,
                               @acctNumber,
                               @expDate,
                               @cvv,
                               @customerId,
                               @isActive)";

                var parameters = new
                {
                    PaymentName = newPaymentObject.PaymentName,
                    CardName    = newPaymentObject.CardName,
                    AcctNumber  = newPaymentObject.AcctNumber,
                    ExpDate     = newPaymentObject.ExpDate,
                    CVV         = newPaymentObject.CVV,
                    CustomerId  = newPaymentObject.CustomerId,
                    IsActive    = newPaymentObject.IsActive,
                };

                var newPaymentType = db.QueryFirstOrDefault <PaymentType>(insertQuery, parameters);

                if (newPaymentType != null)
                {
                    return(newPaymentType);
                }
            }
            throw new Exception("Payment type was not created");
        }
        public ActionResult AddNewPaymentType(CreatePaymentTypeRequest newPaymentObject)
        {
            var newPaymentType = _paymentRepository.AddPayment(newPaymentObject);

            return(Created($"api/payments/{newPaymentType.PaymentTypeId}", newPaymentType));
        }