protected bool CreateCharge(out string auth_status,
                                     out string auth_code,
                                     out string auth_message,
                                     out string auth_response_code,
                                     out string auth_transaction_id,
                                     out decimal amt,
                                     decimal deposit,
                                     long transaction_id)
        {
            var apiKey = String.Empty;
            var transKey = String.Empty;

            var isTest = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["IsTestMode"]);

            if (isTest)
            {
                apiKey = System.Configuration.ConfigurationManager.AppSettings["TestAPIkEY"];
                transKey = System.Configuration.ConfigurationManager.AppSettings["TestTransactionKey"];
            }
            else
            {
                apiKey = System.Configuration.ConfigurationManager.AppSettings["APIKey"];
                transKey = System.Configuration.ConfigurationManager.AppSettings["TransactionKey"];
            }

            amt = deposit;

            var request = new AuthorizationRequest(CreditCardNumberTextBox.Text.Trim(),
                                                   MonthTextBox.Text.Trim() + YearTextBox.Text.Trim(),
                                                   amt,
                                                   "Myss.com Product Checkout - $" + amt,
                                                   AddressTextBox.Text.Trim(),
                                                   CityTextBox.Text.Trim(),
                                                   State.SelectedValue,
                                                   ZipTextBox.Text.Trim(),
                                                   CVVTextBox.Text.Trim(),
                                                   FirstNameTextBox.Text,
                                                   LastNameTextBox.Text);

            //Custom values that will be returned with the response
            //request.AddMerchantValue("email", EmailTextBox.Text);

            //order number
            request.AddInvoice(EmailTextBox.Text);

            //Shipping Address
            //request.AddShipping("id", "first", "last", "address", "state", "zip");

            //step 2 - create the gateway, sending in your credentials
            var gate = new Gateway(apiKey, transKey, isTest);

            //step 3 - make some money
            var response = gate.Send(request);

            if (!response.Approved)
            {
                string CardNumber = CreditCardNumberTextBox.Text.Trim();
                var sb = new StringBuilder();
                sb.Append("Name: ").Append(FirstNameTextBox.Text.Trim()).Append(" ").AppendLine(LastNameTextBox.Text.Trim());
                sb.Append("Email: ").AppendLine(EmailTextBox.Text.Trim());
                sb.Append("Card Ending With: ").AppendLine(CardNumber.Substring(CardNumber.Length - 4));
                sb.Append("Card Processor Error Message: ").AppendLine(response.ToString());

                auth_status = "declined";
                auth_code = response.AuthorizationCode;
                auth_message = response.Message;
                auth_response_code = response.ResponseCode;
                auth_transaction_id = response.TransactionID;
                try
                {
                    controller.UpateCMEDShopTransaction(transaction_id,
                                        auth_status,
                                        auth_code,
                                        auth_message,
                                        auth_response_code,
                                        auth_transaction_id);
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                Util.SendMail("*****@*****.**", "*****@*****.**", "Myss.com Purchase Credit Card Not Accepted", sb.ToString(), false);
                throw new CardAuthourize("Failed charging your credit card: error: [" + response.Message + "]  please try a different card");

            }

            auth_status = "approved";
            auth_code = response.AuthorizationCode;
            auth_message = response.Message;
            auth_response_code = response.ResponseCode;
            auth_transaction_id = response.TransactionID;

            return true;
        }
Example #2
0
        private bool CreateCharge(out int amt, int deposit)
        {
            var apiKey = String.Empty;
            var transKey = String.Empty;

            var isTest = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["IsTestMode"]);

            if (isTest)
            {
                apiKey = System.Configuration.ConfigurationManager.AppSettings["TestAPIkEY"];
                transKey = System.Configuration.ConfigurationManager.AppSettings["TestTransactionKey"];
            }
            else
            {
                apiKey = System.Configuration.ConfigurationManager.AppSettings["APIKey"];
                transKey = System.Configuration.ConfigurationManager.AppSettings["TransactionKey"];
            }

            amt = deposit;

            var request = new AuthorizationRequest(CreditCardNumberTextBox.Text.Trim(),
                                                   MonthTextBox.Text.Trim() + YearTextBox.Text.Trim(),
                                                   amt,
                                                   "Myss.com Reflections Classes - " + amt,
                                                   AddressTextBox.Text.Trim(),
                                                   CityTextBox.Text.Trim(),
                                                   State.SelectedValue,
                                                   ZipTextBox.Text.Trim(),
                                                   CVVTextBox.Text.Trim(),
                                                   FirstNameTextBox.Text,
                                                   LastNameTextBox.Text);

            //Custom values that will be returned with the response
            //request.AddMerchantValue("email", EmailTextBox.Text);

            //order number
            request.AddInvoice(EmailTextBox.Text);

            //Shipping Address
            //request.AddShipping("id", "first", "last", "address", "state", "zip");

            //step 2 - create the gateway, sending in your credentials
            var gate = new Gateway(apiKey, transKey, isTest);

            //step 3 - make some money
            var response = gate.Send(request);

            if (!response.Approved)
            {
                string CardNumber = CreditCardNumberTextBox.Text.Trim();
                var sb = new StringBuilder();
                sb.Append("Name: ").Append(FirstNameTextBox.Text.Trim()).Append(" ").AppendLine(LastNameTextBox.Text.Trim());
                sb.Append("Email: ").AppendLine(EmailTextBox.Text.Trim());
                sb.Append("Card Ending With: ").AppendLine(CardNumber.Substring(CardNumber.Length - 4));
                sb.Append("Card Processor Error Message: ").AppendLine(response.ToString());

                Util.SendMail("*****@*****.**", "*****@*****.**", "Myss.com Reflections Classes Credit Card Not Accepted", sb.ToString(), false);
                lblErrorMessage.Text = "Unable to process your credit card. Please verify the information or try another card. ";
                throw new InvalidOperationException("Subscription failed: " + response.ToString());

            }
            return true;
        }