Пример #1
0
        public int InsertTransactionFail(TransactionFailAddRequest model)
        {
            int returnValue = 0;

            DataProvider.ExecuteNonQuery("dbo.PlanTransactionsFailed_Insert",
                                         inputParamMapper: (SqlParameterCollection inputs) =>
            {
                inputs.Add(SqlDbParameter.Instance.BuildParameter("@UserBaseId", model.UserBaseId, SqlDbType.Int));
                inputs.Add(SqlDbParameter.Instance.BuildParameter("@CustomerId", model.CustomerId, SqlDbType.NVarChar, 50));
                inputs.Add(SqlDbParameter.Instance.BuildParameter("@Name", model.Name, SqlDbType.NVarChar, 50));
                inputs.Add(SqlDbParameter.Instance.BuildParameter("@Email", model.Email, SqlDbType.NVarChar, 50));
                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("@AmountAttempted", model.Amount, SqlDbType.Int));
                inputs.Add(SqlDbParameter.Instance.BuildParameter("@Currency", model.Currency, SqlDbType.NVarChar, 10));
                inputs.Add(SqlDbParameter.Instance.BuildParameter("@DiscountPercent", model.DiscountPercent, SqlDbType.Decimal));
                inputs.Add(SqlDbParameter.Instance.BuildParameter("@ErrorMessage", model.ErrorMessage, SqlDbType.NVarChar, 100));

                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);
        }
Пример #2
0
 //Deactivate user
 public void UpdateUserIsActive(TransactionFailAddRequest model)
 {
     DataProvider.ExecuteNonQuery("dbo.UserSubscriptions_UpdateUserIsActive",
                                  inputParamMapper: (SqlParameterCollection inputs) =>
     {
         inputs.Add(SqlDbParameter.Instance.BuildParameter("@CustomerId", model.CustomerId, SqlDbType.NVarChar, 50));
         inputs.Add(SqlDbParameter.Instance.BuildParameter("@IsActive", false, SqlDbType.Bit));
     });
 }
Пример #3
0
        public string CreateTokenForFailedTransactions(TransactionFailAddRequest model)
        {
            string GUID = null;

            DataProvider.ExecuteNonQuery("dbo.AppToken_InsertFailedTransaction",
                                         inputParamMapper: (SqlParameterCollection inputs) =>
            {
                inputs.Add(SqlDbParameter.Instance.BuildParameter("@UserBaseId", model.UserBaseId, SqlDbType.Int));

                SqlParameter guidOut = new SqlParameter("@Token", SqlDbType.NVarChar, 128);
                guidOut.Direction    = ParameterDirection.Output;

                inputs.Add(guidOut);
            },
                                         returnParameters: (SqlParameterCollection inputs) =>
            {
                GUID = inputs["@Token"].Value.ToString();
            });

            return(GUID);
        }
Пример #4
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);
        }