public ActionResult Add(TransactionsAddRequest request)
        {
            var userId = UserId;

            if (request.ContragentId == userId)
            {
                return(BadRequest(new { message = "Контрагент является текущим пользователем" }));
            }
            try {
                _transactionService.Add(userId, request.ContragentId, request.Amount);
            } catch (UserNotFoundException e) {
                switch (e.Name)
                {
                case "Payee": return(Unauthorized());

                case "Recepient": return(BadRequest(new { message = "Контрагент не найден" }));
                }
            } catch (ArgumentException e) {
                switch (e.ParamName)
                {
                case "amount":
                    return(BadRequest(new { message = "Недостаточно средств" }));
                }
                throw;
            }

            _unitOfWork.Complete();

            return(Ok());
        }
Beispiel #2
0
        public int InsertTransaction(TransactionsAddRequest model)
        {
            int returnValue = 0;

            DataProvider.ExecuteNonQuery("dbo.PlanTransactions_Insert",
                                         inputParamMapper: (SqlParameterCollection inputs) =>
            {
                inputs.Add(SqlDbParameter.Instance.BuildParameter("@UserBaseId", model.UserBaseId, SqlDbType.Int));
                inputs.Add(SqlDbParameter.Instance.BuildParameter("@PlanId", model.PlanId, SqlDbType.Int));
                inputs.Add(SqlDbParameter.Instance.BuildParameter("@DurationTypeId", model.DurationTypeId, SqlDbType.Int));
                inputs.Add(SqlDbParameter.Instance.BuildParameter("@ChargeId", model.ChargeId, SqlDbType.NVarChar, 50));
                inputs.Add(SqlDbParameter.Instance.BuildParameter("@AmountPaid", model.AmountPaid, SqlDbType.Int));
                inputs.Add(SqlDbParameter.Instance.BuildParameter("@Currency", model.Currency, SqlDbType.NVarChar, 10));
                inputs.Add(SqlDbParameter.Instance.BuildParameter("@NetworkStatus", model.NetworkStatus, SqlDbType.NVarChar, 50));
                inputs.Add(SqlDbParameter.Instance.BuildParameter("@Type", model.Type, SqlDbType.NVarChar, 50));
                inputs.Add(SqlDbParameter.Instance.BuildParameter("@CreatedDate", model.CreatedDate, SqlDbType.DateTime));
                inputs.Add(SqlDbParameter.Instance.BuildParameter("@isPaid", model.isPaid, SqlDbType.Bit));
                inputs.Add(SqlDbParameter.Instance.BuildParameter("@CardId", model.CardId, SqlDbType.NVarChar, 50));
                inputs.Add(SqlDbParameter.Instance.BuildParameter("@ExpMonth", model.ExpMonth, SqlDbType.Int));
                inputs.Add(SqlDbParameter.Instance.BuildParameter("@ExpYear", model.ExpYear, SqlDbType.Int));
                inputs.Add(SqlDbParameter.Instance.BuildParameter("@CardLast4", model.CardLast4, SqlDbType.VarChar, 4));
                inputs.Add(SqlDbParameter.Instance.BuildParameter("@DiscountPercent", model.DiscountPercent, SqlDbType.Decimal));

                SqlParameter idOut = new SqlParameter("@Id", 0);
                idOut.Direction    = ParameterDirection.Output;

                inputs.Add(idOut);
            },
                                         returnParameters: (SqlParameterCollection inputs) =>
            {
                int.TryParse(inputs["@Id"].Value.ToString(), out returnValue);
            });

            return(returnValue);
        }
        public int Insert(TransactionsAddRequest model)
        {
            string UserId = UserService.GetCurrentUserId();
            int    Id     = 0;

            DataProvider.ExecuteNonQuery(GetConnection, "dbo.Transactions_Insert"
                                         , inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@CaseId", model.CaseId);
                paramCollection.AddWithValue("@ListingId", model.ListingId);
                paramCollection.AddWithValue("@ParcelNumber", model.ParcelNumber);
                paramCollection.AddWithValue("@EscrowNumber", model.EscrowNumber);
                paramCollection.AddWithValue("@BuyerId", model.BuyerId);
                paramCollection.AddWithValue("@BuyerAgentId", model.BuyerAgentId);
                paramCollection.AddWithValue("@SalePrice", model.SalePrice);
                paramCollection.AddWithValue("@UserId", UserId);
                SqlParameter p = new SqlParameter("@id", System.Data.SqlDbType.Int);
                p.Direction    = System.Data.ParameterDirection.Output;

                paramCollection.Add(p);
            }, returnParameters : delegate(SqlParameterCollection param)
            {
                int.TryParse(param["@id"].Value.ToString(), out Id);
            }
                                         );
            return(Id);
        }
Beispiel #4
0
        public void RenewalCustomerCharge(ChargeExistingUser model)
        {
            StripeConfiguration.SetApiKey("");

            double _convertAmountToPennies = model.Price * 100;
            int    _convertToIntAmount     = Convert.ToInt32(_convertAmountToPennies);
            //Charge the customer
            var chargeOptions = new StripeChargeCreateOptions
            {
                Amount     = _convertToIntAmount,
                Currency   = model.Currency,
                CustomerId = model.CustomerId
                             //model.CustomerId
            };

            var          chargeService = new StripeChargeService();
            StripeCharge charge        = chargeService.Create(chargeOptions);

            //insert into transaction table
            TransactionsAddRequest transaction = new TransactionsAddRequest
            {
                UserBaseId      = model.UserBaseId,
                PlanId          = model.PlanId,
                DurationTypeId  = model.DurationTypeId,
                ChargeId        = charge.Id,
                AmountPaid      = _convertToIntAmount / 100,
                Currency        = model.Currency,
                CardId          = charge.Source.Card.Id,
                ExpMonth        = charge.Source.Card.ExpirationMonth,
                ExpYear         = charge.Source.Card.ExpirationYear,
                CardLast4       = charge.Source.Card.Last4,
                NetworkStatus   = charge.Outcome.NetworkStatus,
                Type            = charge.Outcome.Type,
                isPaid          = charge.Paid,
                CreatedDate     = charge.Created,
                DiscountPercent = model.DiscountPercent
            };

            InsertTransaction(transaction);

            ChargeExistingUser customer = model;

            DateTime _newBillDate = charge.Created.AddMonths(customer.DurationMonths);

            customer.NextBillingDate = _newBillDate;

            UpdateNextBillingDate(customer);

            _userBaseService.UpdateAccoutUnlocked(model.UserBaseId);
        }
Beispiel #5
0
        public TransactionsAddRequest ChargeExistingCustomer(ChargeExistingUser model)
        {
            StripeConfiguration.SetApiKey("");

            double _convertAmountToPennies = model.Price * 100;
            int    _convertToIntAmount     = Convert.ToInt32(_convertAmountToPennies);
            //Charge the customer
            var chargeOptions = new StripeChargeCreateOptions
            {
                Amount     = _convertToIntAmount,
                Currency   = model.Currency,
                CustomerId = model.CustomerId
            };

            var          chargeService = new StripeChargeService();
            StripeCharge charge        = chargeService.Create(chargeOptions);

            //insert into transaction table
            TransactionsAddRequest transaction = new TransactionsAddRequest
            {
                UserBaseId      = model.UserBaseId,
                PlanId          = model.PlanId,
                DurationTypeId  = model.DurationTypeId,
                ChargeId        = charge.Id,
                AmountPaid      = _convertToIntAmount / 100,
                Currency        = model.Currency,
                CardId          = charge.Source.Card.Id,
                ExpMonth        = charge.Source.Card.ExpirationMonth,
                ExpYear         = charge.Source.Card.ExpirationYear,
                CardLast4       = charge.Source.Card.Last4,
                NetworkStatus   = charge.Outcome.NetworkStatus,
                Type            = charge.Outcome.Type,
                isPaid          = charge.Paid,
                CreatedDate     = charge.Created,
                DiscountPercent = model.DiscountPercent
            };

            return(transaction);
        }
Beispiel #6
0
        //ONE-TIME CHARGE
        public void Charge(ChargeRequest model)
        {
            StripeConfiguration.SetApiKey("");

            var options = new StripeChargeCreateOptions
            {
                Amount   = (int)(model.Amount * 100), //Stripe arg in units of cents (usd)
                Currency = model.Currency,
                SourceTokenOrExistingSourceId = model.SourceTokenOrExistingSourceId,
                ReceiptEmail = model.Email
            };
            var          service = new StripeChargeService();
            StripeCharge charge  = service.Create(options);

            //insert into transaction table
            TransactionsAddRequest transactionModel = new TransactionsAddRequest
            {
                UserBaseId      = model.UserBaseId,
                PlanId          = model.PlanId,
                DurationTypeId  = model.DurationTypeId,
                DiscountPercent = model.DiscountPercent,
                ChargeId        = charge.Id,
                AmountPaid      = model.Amount,
                Currency        = model.Currency,
                CardId          = charge.Source.Card.Id,
                ExpMonth        = charge.Source.Card.ExpirationMonth,
                ExpYear         = charge.Source.Card.ExpirationYear,
                CardLast4       = charge.Source.Card.Last4,
                NetworkStatus   = charge.Outcome.NetworkStatus,
                Type            = charge.Outcome.Type,
                isPaid          = charge.Paid,
                CreatedDate     = charge.Created
            };

            InsertTransaction(transactionModel);
        }
Beispiel #7
0
        //CHARGE CUSTOMER (recurring)
        public void ChargeCustomer(ChargeRequest model)
        {
            StripeConfiguration.SetApiKey("");

            //Create customer for recurring charges
            var customerOptions = new StripeCustomerCreateOptions
            {
                SourceToken = model.SourceTokenOrExistingSourceId,
                Email       = model.Email
            };
            var            customerService = new StripeCustomerService();
            StripeCustomer customer        = customerService.Create(customerOptions);

            //Charge the customer
            var chargeOptions = new StripeChargeCreateOptions
            {
                Amount     = (int)(model.Amount * 100), //Stripe arg in units of cents (usd)
                Currency   = model.Currency,
                CustomerId = customer.Id
            };

            var          chargeService = new StripeChargeService();
            StripeCharge charge        = chargeService.Create(chargeOptions);

            //insert into transaction table
            TransactionsAddRequest transactionModel = new TransactionsAddRequest
            {
                UserBaseId      = model.UserBaseId,
                PlanId          = model.PlanId,
                DurationTypeId  = model.DurationTypeId,
                DiscountPercent = model.DiscountPercent,
                ChargeId        = charge.Id,
                AmountPaid      = model.Amount,
                Currency        = model.Currency,
                CardId          = charge.Source.Card.Id,
                ExpMonth        = charge.Source.Card.ExpirationMonth,
                ExpYear         = charge.Source.Card.ExpirationYear,
                CardLast4       = charge.Source.Card.Last4,
                NetworkStatus   = charge.Outcome.NetworkStatus,
                Type            = charge.Outcome.Type,
                isPaid          = charge.Paid,
                CreatedDate     = charge.Created
            };

            InsertTransaction(transactionModel);

            //insert into customer subscription table
            DateTime _nextBillingDate = (customer.Created).AddMonths(model.DurationMonths);

            UserSubscriptionsAddRequest usersubModel = new UserSubscriptionsAddRequest
            {
                CustomerId      = customer.Id,
                CustomerName    = model.Name,
                CustomerEmail   = model.Email,
                PlanName        = model.PlanName,
                DurationName    = model.DurationName,
                DiscountPercent = model.DiscountPercent,
                Price           = model.Amount,
                Currency        = model.Currency,
                StartDate       = customer.Created,
                NextBillingDate = _nextBillingDate,
                UserBaseId      = model.UserBaseId,
                PlanId          = model.PlanId,
                DurationTypeId  = model.DurationTypeId,
                DurationMonths  = model.DurationMonths,
                IsActive        = true,
                CurrentCard     = charge.Source.Card.Last4,
                CardExpMonth    = charge.Source.Card.ExpirationMonth,
                CardExpYear     = charge.Source.Card.ExpirationYear
            };

            InsertCustomerSubscription(usersubModel);
        }
Beispiel #8
0
        //CHARGE EXISTING CUSTOMERS
        public List <ChargeExistingUser> GetUsersToCharge()
        {
            List <ChargeExistingUser> existingUserList = null;

            DataProvider.ExecuteCmd("dbo.UserSubscriptions_SelectCustomersToBill",
                                    inputParamMapper: null,
                                    singleRecordMapper: (IDataReader reader, short resultSet) =>
            {
                if (existingUserList == null)
                {
                    existingUserList = new List <ChargeExistingUser>();
                }

                existingUserList.Add(DataMapper <ChargeExistingUser> .Instance.MapToObject(reader));
            });

            if (existingUserList != null)
            {
                ChargeExistingUser model = null;

                foreach (ChargeExistingUser existingUser in existingUserList.ToList())
                {
                    try
                    {
                        model = existingUser;
                        TransactionsAddRequest transaction = ChargeExistingCustomer(existingUser);
                        InsertTransaction(transaction);
                        DateTime _newBillDate = existingUser.NextBillingDate.AddMonths(existingUser.DurationMonths);
                        existingUser.NextBillingDate = _newBillDate;
                    }
                    catch (Exception ex)
                    {
                        TransactionFailAddRequest failedTransaction = new TransactionFailAddRequest
                        {
                            UserBaseId      = model.UserBaseId,
                            CustomerId      = model.CustomerId,
                            Amount          = model.Price,
                            Currency        = model.Currency,
                            Name            = model.CustomerName,
                            Email           = model.CustomerEmail,
                            PlanId          = model.PlanId,
                            DurationTypeId  = model.DurationTypeId,
                            DiscountPercent = model.DiscountPercent,
                            ErrorMessage    = ex.Message
                        };

                        //will lock UserBaseId when transaction failure is inserted
                        this.InsertTransactionFail(failedTransaction);
                        //will deactivate user once transaction fails
                        //this.UpdateUserIsActive(failedTransaction);

                        //create Token/GUID on AppToken table with the UserBaseId
                        ItemResponse <string> Token = new ItemResponse <string> {
                            Item = this.CreateTokenForFailedTransactions(failedTransaction)
                        };

                        Email eml = new Email();

                        MessageAddress msgAdd = new MessageAddress
                        {
                            Email = "*****@*****.**",
                            Name  = model.CustomerName
                        };

                        List <MessageAddress> list = new List <MessageAddress>
                        {
                            msgAdd
                        };

                        eml.To          = list;
                        eml.FromAddress = "*****@*****.**";
                        eml.FromName    = "Eleveight";
                        eml.Subject     = "Subscription Charge Failure";
                        eml.HtmlBody    = _emailTemplateService.CreateFailedPayments(new EmailPaymentFailTemplateInput
                        {
                            CustomerName = msgAdd.Name,
                            Token        = Token.Item,
                            ExtraInfo    = "Your subscription has been deactivated due to failed recurring charges. " +
                                           "Please call Eleveight customer service to reactivate your subscription"
                        });

                        _emailMessenger.SendMail(eml);

                        //remove from list if transaction failed
                        existingUserList.Remove(existingUser);
                    }
                }
                if (existingUserList.Count != 0)
                {
                    UpdateMultipleCustomerSubscription(existingUserList);
                }
            }

            return(existingUserList);
        }