Ejemplo n.º 1
0
        protected void Play_Click(object sender, EventArgs e)
        {
            if ( txtbxAmount.Text == "" )
            {
                string l_strMessageToUser = "******";
                string l_strGoBackUrl = "~/Play.aspx";
                Response.Redirect("~/MessageToUser.aspx?message_to_user="******"&go_back_url=" + l_strGoBackUrl, true);
                return;
            }
            // take the amount
            decimal l_amountRequested = decimal.Parse(txtbxAmount.Text);
            // find the current wallet amount
            string l_strUsername = Context.User.Identity.Name;
            Account l_accountFound = Account.FindByUsername(l_strUsername);
            if ( l_accountFound == null )
            {
                string l_strMessageToUser = "******";
                string l_strGoBackUrl = "~/Play.aspx";
                Response.Redirect("~/MessageToUser.aspx?message_to_user="******"&go_back_url=" + l_strGoBackUrl, true);
                return;
            }

            Wallet l_wallet = Wallet.FindByAccountId(l_accountFound.Id);
            if ( l_wallet.Amount<l_amountRequested)
            {
                string l_strMessageToUser = "******";
                string l_strGoBackUrl = "~/Play.aspx";
                Response.Redirect("~/MessageToUser.aspx?message_to_user="******"&go_back_url=" + l_strGoBackUrl, true);
                return;                
            }

            // ok. Enough Money.

            // Let us win or loose now
            Random l_random = new Random(DateTime.Now.Second);
            bool l_boolWin = l_random.Next() % 2 == 1;

            Transaction l_transaction = new Transaction();
            l_transaction.AccountId = l_accountFound.Id;
            l_transaction.Amount = l_amountRequested;
            if ( !l_boolWin )
            {
                l_transaction.Amount = -l_transaction.Amount;
            }
            l_transaction.DateOfTransaction = DateTime.Now;
            l_transaction.TypeOfTransaction = "play";
            l_transaction = Transaction.Create(l_transaction);
            
            if ( l_transaction != null && l_transaction.Id >= 1 )
            {
                string l_strLooseOrWinMessage = "You won!";
                if (!l_boolWin)
                {
                    l_strLooseOrWinMessage = "Sorry. You missed that one. Why don't you try again?";
                }                    
                string l_strMessageToUser = "******" + l_transaction.Id + ", " + l_strLooseOrWinMessage;
                string l_strGoBackUrl = "~/Play.aspx";
                Response.Redirect("~/MessageToUser.aspx?message_to_user="******"&go_back_url=" + l_strGoBackUrl, true);
                return;                                
            }
            else
            {
                string l_strMessageToUser = "******";
                string l_strGoBackUrl = "~/Play.aspx";
                Response.Redirect("~/MessageToUser.aspx?message_to_user="******"&go_back_url=" + l_strGoBackUrl, true);
                return;                                                
            }

        } // Play_Click
Ejemplo n.º 2
0
        } // GetOrderNumber ()
        //-------------------------

        protected void Purchase_Click(Object o, EventArgs e)
        {
            StoreDataInSession();

            // Find Account
            string l_strUsername = Context.User.Identity.Name;
            Account l_accountFound = Account.FindByUsername(l_strUsername);
            if (l_accountFound == null)
            {
                String l_messageToUser = "******";
                String l_strGoBackUrl = "Default.aspx";

                Response.Redirect("~/MessageToUser.aspx?message_to_user="******"&go_back_url=" + HttpUtility.UrlEncode(l_strGoBackUrl), true);

                return;
            }

            if ( hdnfldPaymentMethod.Value == "bank")
            {
                // create the transaction
                Transaction l_transaction = new Transaction();
                l_transaction.Amount = decimal.Parse(txtbxAmount.Text);
                l_transaction.DateOfTransaction = new DateTime(int.Parse(lstbxDateOfDepositYear.SelectedValue),
                                                               int.Parse(lstbxDateOfDepositMonth.SelectedValue),
                                                               int.Parse(lstbxDateOfDepositDayOfMonth.SelectedValue),
                                                               DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second,
                                                               DateTimeKind.Local);
                l_transaction.AccountId = l_accountFound.Id;
                l_transaction.TypeOfTransaction = "deposit";
                l_transaction.BankDeposit = 1;
                l_transaction = Transaction.Create(l_transaction);
                //--------------------------------------------------

                ResetSessionVars();

                String l_messageToUser = "******";
                String l_strGoBackUrl = "Default.aspx";

                Response.Redirect("~/MessageToUser.aspx?message_to_user="******"&go_back_url=" + HttpUtility.UrlEncode(l_strGoBackUrl), true);

                return;
            }

            // Create Checkout Event and send it over to FraudPointer Server
            Event l_eventCreated = CreateAndSendCheckoutEvent(l_accountFound);

            // ask for Interim Fraud Assessment

            FraudAssessment l_fa = _client.CreateFraudAssessment(GetOrCreateAssessmentSession(), true);

            if (l_fa.Result == "Accept" || l_fa.Result == "Review" && _reviewMapping == "Accept")
            {
                // We will try to charge customers credit card

                bool l_chargeResult = chckbxSuccessCharging.Checked; 
                
                if (l_chargeResult)
                {
                    // create the transaction
                    Transaction l_transaction = new Transaction();
                    l_transaction.Amount = decimal.Parse(txtbxAmount.Text);
                    l_transaction.DateOfTransaction = new DateTime(int.Parse(lstbxDateOfDepositYear.SelectedValue),
                                                                   int.Parse(lstbxDateOfDepositMonth.SelectedValue),
                                                                   int.Parse(lstbxDateOfDepositDayOfMonth.SelectedValue),
                                                                   DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second,
                                                                   DateTimeKind.Local);                    
                    l_transaction.AccountId = l_accountFound.Id;
                    l_transaction.TypeOfTransaction = "deposit";
                    l_transaction = Transaction.Create(l_transaction);
                    //--------------------------------------------------

                    // success charging credit card
                    CreateAndSendSuccessfulPaymentEvent();

                    l_fa = _client.CreateFraudAssessment(GetOrCreateAssessmentSession(), false);

                    ResetSessionVars();

                    String l_messageToUser = "******";
                    String l_strGoBackUrl = "Default.aspx";

                    Response.Redirect("~/MessageToUser.aspx?message_to_user="******"&go_back_url=" + HttpUtility.UrlEncode(l_strGoBackUrl), true);

                    return;

                }
                else
                {
                    // charging the card failed.

                    CreateAndSendFailedPaymentEvent();

                    // increase the number of failed payments
                    int l_numberOfFailedPaymentAttempts = GetNumberOfFailedPaymentAttempts();
                    l_numberOfFailedPaymentAttempts = l_numberOfFailedPaymentAttempts + 1;
                    Context.Session["number_of_failed_payment_attempts"] = l_numberOfFailedPaymentAttempts;

                    if (l_numberOfFailedPaymentAttempts > 3)
                    {
                        ResetSessionVars();
                        Response.Redirect("~/Default.aspx", true);
                        return;
                    }
                    else
                    {
                        Response.Redirect("~/Checkout.aspx?payment_method=" + hdnfldPaymentMethod.Value, true);
                        return;
                    }

                }

            }
            else if (l_fa.Result == "Review" && _reviewMapping == "Review")
            {
                _client.CreateFraudAssessment(GetOrCreateAssessmentSession(), false);
                ResetSessionVars();
                string l_strMessageToUser =
                    "******";
                string l_strGoBackUrl = "Default.aspx";
                Response.Redirect("~/MessageToUser.aspx?message_to_user="******"&go_back_url=" + HttpUtility.UrlEncode(l_strGoBackUrl), true);
                return;
            }
            else
            {
                // this is a Reject case
                _client.CreateFraudAssessment(GetOrCreateAssessmentSession(), false);
                ResetSessionVars();
                string l_strMessageToUser =
                    "******";
                Response.Redirect("~/MessageToUser.aspx?message_to_user=" + HttpUtility.UrlEncode(l_strMessageToUser), true);
                return;

            }

        } // Purchase_Click ()
Ejemplo n.º 3
0
        public int BankDeposit { get; set; } // 0 means CC, 1 means Bank, -1 means nothing

        public static Transaction Create (Transaction i_transaction)
        {
            SqlConnection l_sqlConnection = null;
            SqlCommand l_sqlCommand = null;
            string l_strSqlForInsert = "insert into transactions (AccountId, Amount, DateOfTransaction, TypeOfTransaction, BankDeposit) " +
                                       " values ( @AccountId, @Amount, @DateOfTransaction, @TypeOfTransaction, @BankDeposit)";
            SqlDataReader l_sqlDataReader = null;
            try
            {
                l_sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings[Common.DbName].ConnectionString);
                l_sqlConnection.Open();

                l_sqlCommand = new SqlCommand(l_strSqlForInsert, l_sqlConnection);

                SqlParameter l_paramAccountId = new SqlParameter("AccountId", SqlDbType.Int);
                l_paramAccountId.Value = i_transaction.AccountId;
                l_sqlCommand.Parameters.Add(l_paramAccountId);

                SqlParameter l_paramAmount = new SqlParameter("Amount", SqlDbType.Decimal);
                l_paramAmount.Value = i_transaction.Amount;
                l_sqlCommand.Parameters.Add(l_paramAmount);

                SqlParameter l_paramDateOfTransaction = new SqlParameter("DateOfTransaction", SqlDbType.DateTime);
                l_paramDateOfTransaction.Value = i_transaction.DateOfTransaction;
                l_sqlCommand.Parameters.Add(l_paramDateOfTransaction);

                SqlParameter l_paramTypeOfTransaction = new SqlParameter("TypeOfTransaction", SqlDbType.VarChar);
                l_paramTypeOfTransaction.Value = i_transaction.TypeOfTransaction;
                l_sqlCommand.Parameters.Add(l_paramTypeOfTransaction);

                SqlParameter l_paramBankDeposit = new SqlParameter("BankDeposit", SqlDbType.Int);
                l_paramBankDeposit.Value = i_transaction.BankDeposit;
                l_sqlCommand.Parameters.Add(l_paramBankDeposit);

                l_sqlCommand.ExecuteNonQuery();

                l_sqlCommand.Dispose();

                // let us get the last id inserted
                string l_strScopeIdentity = "select max(id) as new_id from transactions where AccountId = " +
                                            i_transaction.AccountId;
                
                l_sqlCommand = new SqlCommand(l_strScopeIdentity, l_sqlConnection);

                int l_iNewId = 0;

                l_sqlDataReader = l_sqlCommand.ExecuteReader();
                if ( l_sqlDataReader.Read() )
                {
                    l_iNewId = (int) l_sqlDataReader["new_id"];
                }
                
                i_transaction.Id = l_iNewId;
                return i_transaction;

            }
            catch (Exception ex)
            {
                throw new Exception("Cannot create account, ex: " + ex);
            }
            finally
            {
                if ( l_sqlDataReader != null )
                {
                    l_sqlDataReader.Close();
                }
                if (l_sqlCommand != null)
                {
                    l_sqlCommand.Dispose();
                }
                if (l_sqlConnection != null)
                {
                    if (l_sqlConnection.State == ConnectionState.Open)
                    {
                        l_sqlConnection.Close();
                    }
                    l_sqlConnection.Dispose();
                }
            }
    
        } // Create ()