Esempio n. 1
0
        public async Task <IHttpActionResult> SchoolAuthNetSubmit(AuthNetBindingModel model)
        {
            var processingResult = new ServiceProcessingResult <string> {
                IsSuccessful = true
            };
            var authNetService = new AuthNetService();
            var result         = await authNetService.SubmittAsync(model);

            if (!result.IsSuccessful)
            {
                processingResult.IsSuccessful = false;
                processingResult.Error        = new ProcessingError("Error submiting payment to Authorzie.net", "Error submiting payment to Authorzie.net", true, false);
                ExceptionlessClient.Default.SubmitLog(typeof(OrderController).FullName, result.Error.UserHelp, "Error");
                return(Ok(processingResult));
            }
            AuthNetResponse AuthNetData = new AuthNetResponse();

            AuthNetData = result.Data;
            if (!AuthNetData.Approved)
            {
                processingResult.IsSuccessful = false;
                processingResult.Error        = new ProcessingError("Your payment to Authorized.net failed for the following reason:" + AuthNetData.Message, "Your payment to Authorized.net failed for the following reason:" + AuthNetData.Message, true, false);
                return(Ok(processingResult));
            }
            var    sqlQuery = "INSERT INTO Payment (schcode,schname,custemail,ddate,poamt,paytype,ccnum,invno,parentpay,payerfname,payerlname,transid,authcode) VALUES(@schcode,@schname,@custemail,@ddate,@poamt,@paytype,@ccnum,@invno,@parentpay,@payerfname,@payerlname,@transid,@authcode)";
            string fname    = "";
            string lname    = "";

            if (!String.IsNullOrEmpty(model.BankAccName))
            {
                fname = model.BankAccName.Substring(0, model.BankAccName.IndexOf(" ") - 1);
                lname = model.BankAccName.Substring(model.BankAccName.IndexOf(" ") + 1);
            }
            else
            {
                fname = model.FirstName;
                lname = model.LastName;
            }
            MySqlParameter[] parameters = new MySqlParameter[] {
                new MySqlParameter("@custemail", model.EmailAddress),
                new MySqlParameter("@ddate", DateTime.Now),
                new MySqlParameter("@poamt", model.Amount),
                new MySqlParameter("@payerfname", fname),
                new MySqlParameter("@payerlname", lname),
                new MySqlParameter("@paytype", model.Method),
                new MySqlParameter("@transid", AuthNetData.TransId),
                new MySqlParameter("@authcode", AuthNetData.AuthCode),
                new MySqlParameter("@ccnum", model.Cardnum == null?"":model.Cardnum.Substring(model.Cardnum.Length - 3)),
                new MySqlParameter("@invno", model.InvoiceNumber),
                new MySqlParameter("@schcode", AuthNetData.Custid),
                new MySqlParameter("@schname", model.Schname),
                new MySqlParameter("@parentpay", "0"),
            };
            var sqlQueryService = new SQLQuery();
            var payResult       = await sqlQueryService.ExecuteNonQueryAsync(CommandType.Text, sqlQuery, parameters);

            if (!payResult.IsSuccessful)
            {
                processingResult.IsSuccessful = false;
                processingResult.Error        = new ProcessingError("Your payment was made but an error occurred creating your receipt. To obtain a receipt contact Memory Book with this tranasaction id:" + AuthNetData.TransId, "Your payment was made but an error occurred creating your receipt. To obtain a receipt contact Memory Book with this tranasaction id:" + AuthNetData.TransId, true, false);
                ExceptionlessClient.Default.CreateLog(typeof(OrderController).FullName, "Error inserting school payment.", "Error").AddObject(model).AddObject(AuthNetData);
                return(Ok(processingResult));
            }
            EmailSchoolReceipt(AuthNetData.TransId);


            processingResult.Data = AuthNetData.TransId;
            return(Ok(processingResult));
        }
Esempio n. 2
0
        public async Task <IHttpActionResult> AuthNetSubmit(AuthNetBindingModel model)
        {
            var processingResult = new ServiceProcessingResult <List <OrderBindingModel> > {
                IsSuccessful = true
            };
            //Get the order first thing to make sure we have it.
            List <OrderBindingModel> Orders = new List <OrderBindingModel>();

            try
            {
                var sqlQuery = "SELECT Id,OrderId,PayType,Grade,BookType,Teacher,PersText1,Studentfname,Studentlname,Emailaddress,Schcode,ItemAmount,Itemqty,Schinvoicenumber,Orddate,ItemTotal,Schname,Yr,Icon1,Icon2,Icon3,Icon4,Josicon1,Josicon2,Josicon3,Josicon4 FROM temporders where orderid=@OrderId";

                MySqlParameter[] parameters = new MySqlParameter[] { new MySqlParameter("@OrderId", model.InvoiceNumber) };
                var sqlQueryService         = new SQLQuery();
                var orderResult             = await sqlQueryService.ExecuteReaderAsync <OrderBindingModel>(CommandType.Text, sqlQuery, parameters);

                if (!orderResult.IsSuccessful)
                {
                    processingResult.IsSuccessful = false;
                    processingResult.Error        = new ProcessingError("Error retrieving order.", "Error retrieving order.", true, false);
                    ExceptionlessClient.Default.SubmitLog(typeof(TempOrderController).FullName, orderResult.Error.UserMessage, "Error");
                    return(Ok(processingResult));
                }
                if (orderResult.Data == null)
                {
                    processingResult.IsSuccessful = false;
                    processingResult.Error        = new ProcessingError("Error retrieving order.", "Error retrieving order.", true, false);
                    ExceptionlessClient.Default.SubmitLog(typeof(TempOrderController).FullName, orderResult.Error.UserMessage, "Error");
                    return(Ok(processingResult));
                }


                Orders = (List <OrderBindingModel>)orderResult.Data;
            }
            catch (Exception ex)
            {
                ex.ToExceptionless().Submit();
                processingResult.IsSuccessful = false;
                processingResult.Error        = new ProcessingError("Error retrieving order.", "Error retrieving order.", true, false);

                return(Ok(processingResult));
            }

            //----------------------------------------------------------------------

            var authNetService = new AuthNetService();
            var result         = await authNetService.SubmittAsync(model);

            if (!result.IsSuccessful)
            {
                processingResult.IsSuccessful = false;
                processingResult.Error        = new ProcessingError("Error submiting payment to Authorzie.net", "Error submiting payment to Authorzie.net", true, false);
                ExceptionlessClient.Default.SubmitLog(typeof(OrderController).FullName, result.Error.UserHelp, "Error");
                return(Ok(processingResult));
            }
            AuthNetResponse AuthNetData = new AuthNetResponse();

            AuthNetData = result.Data;
            if (!AuthNetData.Approved)
            {
                processingResult.IsSuccessful = false;
                processingResult.Error        = new ProcessingError("Your payment to Authorized.net failed for the following reason:" + AuthNetData.Message, "Your payment to Authorized.net failed for the following reason:" + AuthNetData.Message, true, false);
                return(Ok(processingResult));
            }    //not approved
            else //Is Approved
            {
                foreach (var order in Orders)
                {
                    var sqlQuery1 = "INSERT INTO Orders (grade,booktype,teacher,perstext1,studentfname,studentlname,emailaddress,schcode,itemamount,itemqty,schinvoicenumber,orderid,orddate,paytype,itemtotal,schname,parentpayment,yr,icon1,icon2,icon3,icon4,josicon1,josicon2,josicon3,josicon4) VALUES(@grade,@booktype,@teacher,@perstext1,@studentfname,@studentlname,@emailaddress,@schcode,@itemamount,@itemqty,@schinvoicenumber,@orderid,@orddate,@paytype,@itemtotal,@schname,@parentpayment,@yr,@icon1,@icon2,@icon3,@icon4,@josicon1,@josicon2,@josicon3,@josicon4)";

                    MySqlParameter[] parameters = new MySqlParameter[] {
                        new MySqlParameter("@grade", order.Grade),
                        new MySqlParameter("@booktype", order.BookType),
                        new MySqlParameter("@teacher", order.Teacher),
                        new MySqlParameter("@perstext1", order.PersText1),
                        new MySqlParameter("@studentfname", order.Studentfname),
                        new MySqlParameter("@studentlname", order.Studentlname),
                        new MySqlParameter("@emailaddress", order.Emailaddress),
                        new MySqlParameter("@schcode", order.Schcode),
                        new MySqlParameter("@itemamount", order.ItemAmount),
                        new MySqlParameter("@itemqty", order.Itemqty),
                        new MySqlParameter("@schinvoicenumber", order.Schinvoicenumber),
                        new MySqlParameter("@orderid", order.OrderId),
                        new MySqlParameter("@orddate", order.Orddate),
                        new MySqlParameter("@paytype", order.PayType),
                        new MySqlParameter("@itemtotal", order.ItemTotal),
                        new MySqlParameter("@schname", order.Schname),
                        new MySqlParameter("@parentpayment", 1),
                        new MySqlParameter("@yr", order.Yr),
                        new MySqlParameter("@icon1", order.Icon1),
                        new MySqlParameter("@icon2", order.Icon2),
                        new MySqlParameter("@icon3", order.Icon3),
                        new MySqlParameter("@icon4", order.Icon4),
                        new MySqlParameter("@josicon1", order.Josicon1),
                        new MySqlParameter("@josicon2", order.Josicon2),
                        new MySqlParameter("@josicon3", order.Josicon3),
                        new MySqlParameter("@josicon4", order.Josicon4),
                    };
                    try
                    {
                        var sqlQueryService = new SQLQuery();
                        var orderResult     = await sqlQueryService.ExecuteNonQueryAsync(CommandType.Text, sqlQuery1, parameters);

                        if (!orderResult.IsSuccessful)
                        {
                            ExceptionlessClient.Default.SubmitLog(typeof(TempOrderController).FullName, orderResult.Error.UserMessage, "Error");
                            //create the mail message

                            MailMessage mail = new MailMessage();
                            //set the addresses
                            mail.From = new MailAddress(ConfigurationManager.AppSettings["FromAddr"]);
                            mail.To.Add("*****@*****.**");
                            //set the content
                            mail.Subject = "Mysql Error:Inserting Order " + order.Schname.ToString() + "(" + order.Schcode.ToString() + ")";
                            mail.Body    = "An error occured inserting a order record into the Mysql database server. The following data was not recorded in the order table.<br/>School Name:" + order.Schname +
                                           "<br/>Student Name:" + order.Studentfname + " " + order.Studentlname +
                                           "<br/>School Code:" + order.Schcode +
                                           "<br/>Order Id:" + model.InvoiceNumber +
                                           "<br/>Grade:" + order.Grade +
                                           "<br/>Teacher:" + order.Teacher +
                                           "<br/>Book Type:" + order.BookType +
                                           "<br/>EmailAddress:" + order.Emailaddress +
                                           "<br/>Perstext1:" + order.PersText1 +
                                           "<br/>Item Amount:" + order.ItemAmount +
                                           "<br/>Item Total:" + order.ItemTotal +
                                           "<br/>Item Qty:" + order.Itemqty +
                                           "<br/>icon1:" + order.Icon1 +
                                           "<br/>icon2:" + order.Icon2 +
                                           "<br/>icon3:" + order.Icon3 +
                                           "<br/>icon4:" + order.Icon4 +
                                           "<br/>Year:" + order.Yr +
                                           "<br/><br/>Mysql Exception Code:" + orderResult.Error.UserMessage;
                            mail.IsBodyHtml = true;
                            //send the message
                            SmtpClient smtp = new System.Net.Mail.SmtpClient(ConfigurationManager.AppSettings["SmtpServer"]);
                            smtp.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["smtpuser"], ConfigurationManager.AppSettings["smtppassword"]);
                            //smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis 'only works on some serves
                            try
                            {
                                smtp.Send(mail);
                            }
                            catch (Exception ex)
                            {
                                //go on don't stop because email cant be sent.
                            }
                        }
                        if (orderResult.Data == 0)
                        {
                            ExceptionlessClient.Default.SubmitLog(typeof(TempOrderController).FullName, "Failed to insert an order", "Error");

                            MailMessage mail = new MailMessage();
                            //set the addresses
                            mail.From = new MailAddress(ConfigurationManager.AppSettings["FromAddr"]);
                            mail.To.Add("*****@*****.**");
                            //set the content
                            mail.Subject = "Mysql Error:Inserting Order " + order.Schname.ToString() + "(" + order.Schcode.ToString() + ")";
                            mail.Body    = "An error occured inserting a order record into the Mysql database server. The following data was not recorded in the order table.<br/>School Name:" + order.Schname +
                                           "<br/>Student Name:" + order.Studentfname + " " + order.Studentlname +
                                           "<br/>Order Id:" + model.InvoiceNumber +
                                           "<br/>School Code:" + order.Schcode +
                                           "<br/>Grade:" + order.Grade +
                                           "<br/>Teacher:" + order.Teacher +
                                           "<br/>Book Type:" + order.BookType +
                                           "<br/>EmailAddress:" + order.Emailaddress +
                                           "<br/>Perstext1:" + order.PersText1 +
                                           "<br/>Item Amount:" + order.ItemAmount +
                                           "<br/>Item Total:" + order.ItemTotal +
                                           "<br/>Item Qty:" + order.Itemqty +
                                           "<br/>icon1:" + order.Icon1 +
                                           "<br/>icon2:" + order.Icon2 +
                                           "<br/>icon3:" + order.Icon3 +
                                           "<br/>icon4:" + order.Icon4 +
                                           "<br/>Year:" + order.Yr +
                                           "<br/><br/>Mysql Exception Code:" + orderResult.Error.UserMessage;
                            mail.IsBodyHtml = true;
                            //send the message
                            SmtpClient smtp = new System.Net.Mail.SmtpClient(ConfigurationManager.AppSettings["SmtpServer"]);
                            smtp.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["smtpuser"], ConfigurationManager.AppSettings["smtppassword"]);
                            //smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis 'only works on some serves
                            try
                            {
                                smtp.Send(mail);
                            }
                            catch (Exception ex)
                            {
                                //go on don't stop because email cant be sent.
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ex.ToExceptionless().Submit();
                    }
                }//endforeach
                 //,
                 //insert payment even if order failed
                try {
                    var sqlQuery = "INSERT INTO Payment (orderid,schname,schcode,custemail,ddate,poamt,paytype,ccnum,invno,parentpay,payerfname,payerlname,addr,city,state,zip,transid,authcode) VALUES(@orderid,@schname,@schcode,@custemail,@ddate,@poamt,@paytype,@ccnum,@invno,@parentpay,@payerfname,@payerlname,@addr,@city,@state,@zip,@transid,@authcode)";
                    MySqlParameter[] parameters1 = new MySqlParameter[] {
                        new MySqlParameter("@orderid", model.InvoiceNumber),
                        new MySqlParameter("@custemail", model.EmailAddress),
                        new MySqlParameter("@ddate", DateTime.Now),
                        new MySqlParameter("@poamt", model.Amount),
                        new MySqlParameter("@paytype", model.Method),
                        new MySqlParameter("@transid", AuthNetData.TransId),
                        new MySqlParameter("@authcode", AuthNetData.AuthCode),
                        new MySqlParameter("@ccnum", model.Cardnum == null?"":model.Cardnum.Substring(model.Cardnum.Length - 3)),
                        new MySqlParameter("@invno", Orders[0].Schinvoicenumber),
                        new MySqlParameter("@schname", Orders[0].Schname),
                        new MySqlParameter("@schcode", AuthNetData.Custid),
                        new MySqlParameter("@parentpay", 1),
                        new MySqlParameter("@payerfname", model.FirstName),
                        new MySqlParameter("@payerlname", model.LastName),
                        new MySqlParameter("@addr", model.Address),
                        new MySqlParameter("@city", model.City),
                        new MySqlParameter("@state", model.State.TrimEnd()),
                        new MySqlParameter("@zip", model.Zip)
                    };
                    var sqlQueryService1 = new SQLQuery();
                    var payResult        = await sqlQueryService1.ExecuteNonQueryAsync(CommandType.Text, sqlQuery, parameters1);

                    if (!payResult.IsSuccessful)
                    {
                        //fail it because we don't have the payment to create a receipt.
                        processingResult.IsSuccessful = false;
                        processingResult.Error        = new ProcessingError("Your payment was made but an error occurred creating your receipt. To obtain a receipt contact your school adviser with this tranasaction id:" + AuthNetData.TransId, "Your payment was made but an error occurred creating your receipt. To obtain a receipt contact your school adviser with this tranasaction id:" + AuthNetData.TransId, true, false);
                        ExceptionlessClient.Default.CreateLog(typeof(OrderController).FullName, "Error inserting  parent payment.", "Error").AddObject(model).AddObject(AuthNetData);
                        return(Ok(processingResult));
                    }
                    EmailReceipt(model.InvoiceNumber);
                }
                catch (Exception ex)
                {
                    ex.ToExceptionless()
                    .SetMessage("Error inserting payment.")
                    .AddTags("Insert Payment Error")
                    .AddObject(model)
                    .AddObject(AuthNetData)
                    .Submit();
                    processingResult.IsSuccessful = false;
                    processingResult.Error        = new ProcessingError("Your payment was made but an error occurred creating your receipt. To obtain a receipt contact your school adviser with this tranasaction id:" + AuthNetData.TransId, "Your payment was made but an error occurred creating your receipt. To obtain a receipt contact your school adviser with this tranasaction id:" + AuthNetData.TransId, true, false);

                    return(Ok(processingResult));
                }
            }// End Approved
            return(Ok(processingResult));
        }
Esempio n. 3
0
        public async Task <ServiceProcessingResult <AuthNetResponse> > SubmittAsync(AuthNetBindingModel model)


        {
            var result = new ServiceProcessingResult <AuthNetResponse> {
                IsSuccessful = true
            };
            //  ' By default, this sample code is designed to post to our test server for
            //  ' developer accounts: https://test.authorize.net/gateway/transact.dll
            //  ' for real accounts (even in test mode), please make sure that you are
            //  'posting to: https://secure.authorize.net/gateway/transact.dll
            //' post_url = "https://secure.authorize.net/gateway/transact.dll"
            string post_url = ConfigurationManager.AppSettings["AuthUrl"].ToString();
            Dictionary <string, string> post_values = new Dictionary <string, string>();
            string login = ConfigurationManager.AppSettings["mbc" + "ApiLogin"].ToString();//need variable to tell what site to use. should come in post
            string Key   = ConfigurationManager.AppSettings["mbc" + "TransactionKey"].ToString();
            string test  = ConfigurationManager.AppSettings["GatewayTest"].ToString();


            //post_values.Add("x_test_request", ConfigurationManager.AppSettings("GatewayTest")) /*use this for submissions to live site only-----------------------------------------------------------------------------------------------------------------*/
            post_values.Add("x_test_request", test);
            post_values.Add("x_version", "3.1");
            post_values.Add("x_login", login);
            post_values.Add("x_tran_key", Key);
            post_values.Add("x_delim_data", "TRUE");
            post_values.Add("x_delim_char", "|");
            post_values.Add("x_relay_response_array", "FALSE");
            post_values.Add("x_type", "AUTH_CAPTURE"); /*' request.TransType AUTH_CAPTURE,AUTH_ONLY,PRIOR_AUTH_CAPTURE,CREDIT,VOID ect.*/
            post_values.Add("x_method", model.Method); /* 'CC,ECHECK*/
            post_values.Add("x_echeck_type", "WEB");   /* 'web*/
            post_values.Add("x_card_num", model.Cardnum);
            post_values.Add("x_exp_date", model.ExpirationDate);
            post_values.Add("x_card_code", model.CardCode);
            post_values.Add("x_recurring_billing", "FALSE");        /*' we don't use this so is always false*/
            post_values.Add("x_bank_acct_name", model.BankAccName); //customer name
            post_values.Add("x_bank_name", model.BankName);
            post_values.Add("x_bank_acct_type", model.BankAccType); /*'savings,checking,businesschecking*/
            post_values.Add("x_bank_aba_code", model.BankAbaCode);
            post_values.Add("x_bank_acct_num", model.BankAccountNumber);
            post_values.Add("x_amount", model.Amount);
            post_values.Add("x_description", "");
            post_values.Add("x_cust_id", model.CustId);
            post_values.Add("x_first_name", model.FirstName);
            post_values.Add("x_last_name", model.LastName);
            post_values.Add("x_address", model.Address);
            post_values.Add("x_state", model.State);
            post_values.Add("x_ city", model.City);
            post_values.Add("x_zip", model.Zip);
            post_values.Add("x_invoice_num", model.InvoiceNumber);
            post_values.Add("x_email", model.EmailAddress);
            post_values.Add("x_duplicate_window", "420");/* '7 minutes*/

            //    ' Additional fields can be added here as outlined in the AIM integration
            //' guide at: http://developer.authorize.net

            //' This section takes the input fields and converts them to the proper format
            //' for an http post.  For example: "x_login=username&x_tran_key=a1B2c3D4"
            string post_string = "";

            foreach (KeyValuePair <string, string> field in post_values)
            {
                post_string += field.Key + "=" + HttpUtility.UrlEncode(field.Value) + "&";
            }

            post_string = post_string.Substring(0, post_string.Length - 1);
            //' create an HttpWebRequest object to communicate with Authorize.net
            HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(post_url);

            objRequest.Method        = "POST";
            objRequest.ContentLength = post_string.Length;
            objRequest.ContentType   = "application/x-www-form-urlencoded";
            //' post data is sent as a stream
            StreamWriter myWriter = new StreamWriter(objRequest.GetRequestStream());

            myWriter.Write(post_string);
            myWriter.Close();
            // returned values are returned as a stream, then read into a string


            HttpWebResponse objResponse    = (HttpWebResponse)objRequest.GetResponse();
            StreamReader    responseStream = new StreamReader(objResponse.GetResponseStream());
            string          post_response  = responseStream.ReadToEnd();

            responseStream.Close();


            // the response_array string is broken into an array


            String[] response_array = post_response.Split('|');


            AuthNetResponse Returnresponse_array = new AuthNetResponse();

            try
            {
                //Returnresponse_array.Approved = Returnresponse_array.GetText(response_array(1)) '1,2,3,4 approved,declined,error,held for review
                bool approvedret = false;
                switch (response_array[0])
                {
                case "1":
                    approvedret = true;
                    break;

                default:
                    approvedret = false;
                    break;
                }
                Returnresponse_array.Approved = approvedret;
                Returnresponse_array.Message  = response_array[3];
                Returnresponse_array.AuthCode = response_array[4];
                Returnresponse_array.TransId  = response_array[6];
                string r  = response_array[7];
                string rr = response_array[5];
                Returnresponse_array.Amount          = response_array[9];
                Returnresponse_array.Method          = response_array[10];
                Returnresponse_array.TransActionType = response_array[11];
                Returnresponse_array.Custid          = response_array[12];
                Returnresponse_array.Email           = response_array[23];
                Returnresponse_array.CardNum         = response_array[50];
                Returnresponse_array.CardType        = response_array[51];
                //will fail if submission faisl and there are not enough elements
            }
            catch (Exception ex)
            {
                ex.ToExceptionless().Submit();
                result.IsSuccessful = false;
                result.Error        = new ProcessingError(ex.Message, ex.Message, true, false);
                return(result);
            }

            result.IsSuccessful = true;
            result.Data         = Returnresponse_array;
            return(result);
        }