public string GetTokens([FromBody] BCClientModel content)
        {
            BCClientModel bCClient = new BCClientModel();
            string        json     = "";
            string        query    = "select ID from MobilePayOnBoarding where BCTenantId='" + content.BCTenantId + "'";

            DBManager.VerifyTenantID(query, status =>
            {
                if (status.Equals("S"))
                {
                    DBManager.GetTokens(content.BCTenantId, callback =>
                    {
                        var results = new
                        {
                            AccessToken  = callback.accessToken,
                            RefreshToken = callback.refreshToken
                        };

                        json = JsonConvert.SerializeObject(results);
                    });
                }
                else
                {
                    json = "Invalide tenantId !";
                }
            });
            return(json);
        }
Exemplo n.º 2
0
 public static void InsertRecord(BCClientModel data)
 {
     WithConnection(conn =>
     {
         InsertRecord(data, conn);
     });
 }
Exemplo n.º 3
0
        public static void VerifyTenantID(string query, SqlConnection conn, Action <string> status)
        {
            SqlCommand     sqlCommand;
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
            BCClientModel  bCClient       = new BCClientModel();
            int            id             = 0;

            sqlCommand = new SqlCommand(query, conn);
            using (SqlDataReader reader = sqlCommand.ExecuteReader())
            {
                while (reader.Read())
                {
                    id = reader.GetInt32(0);
                }
            }

            sqlCommand.Dispose();

            if (id > 0)
            {
                status("S");
            }
            else
            {
                status("E");
            }
            //return codeverified;
        }
Exemplo n.º 4
0
        public void PostAgreement(BCClientModel clientModel, AgreementModel agreement)
        {
            string         Cred            = clientModel.userName + ":" + clientModel.password;
            HttpWebRequest request         = Common.CreateWebRequest(clientModel.BCTenantId, Cred, null);
            XmlDocument    soapEnvelopeXml = new XmlDocument();

            soapEnvelopeXml.LoadXml(@"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:mer='urn:microsoft-dynamics-schemas/codeunit/MerchantTokens'> <soapenv:Body> <mer:AgreementStatus> <mer:agreementId>" + agreement.Agreement_Id + "</mer:agreementId> <mer:status>" + agreement.Status + "</mer:status> <mer:statusText>" + agreement.Status_Text + "</mer:statusText> <mer:statusCode>" + agreement.Status_Code + "</mer:statusCode> <mer:callBackTime>" + agreement.Timestamp + "</mer:callBackTime> </mer:AgreementStatus> </soapenv:Body> </soapenv:Envelope>");

            using (Stream stream = request.GetRequestStream())
            {
                soapEnvelopeXml.Save(stream);
            }
            try
            {
                using (WebResponse response = request.GetResponse())
                {
                    using (StreamReader rd = new StreamReader(response.GetResponseStream()))
                    {
                        string soapResult = rd.ReadToEnd();
                        Console.WriteLine(soapResult);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 5
0
        public void PostInvoice(BCClientModel clientModel, InvoiceModel invoice, string responsebody)
        {
            string Cred = clientModel.userName + ":" + clientModel.password;

            responsebody = new JavaScriptSerializer().Serialize(invoice);
            string         invoiceSoapAction = "urn:microsoft-dynamics-schemas/codeunit/Invoice_CallBack:InvoiceCallBack";
            HttpWebRequest request           = Common.CreateWebRequest(invoice.InvoiceCallBackSoapURL, Cred, invoiceSoapAction);
            XmlDocument    soapEnvelopeXml   = new XmlDocument();

            soapEnvelopeXml.LoadXml(@"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:inv='urn:microsoft-dynamics-schemas/codeunit/Invoice_CallBack'> <soapenv:Body> <inv:InvoiceCallBack> <inv:invoiceId>" + invoice.InvoiceId + "</inv:invoiceId> <inv:status>" + invoice.Status + "</inv:status> <inv:errorCode>" + invoice.ErrorCode + "</inv:errorCode> <inv:errorMessage>" + invoice.ErrorMessage + "</inv:errorMessage> <inv:date>" + invoice.Date + "</inv:date> <inv:response_Body>" + responsebody + "</inv:response_Body> </inv:InvoiceCallBack> </soapenv:Body> </soapenv:Envelope>");
            using (Stream stream = request.GetRequestStream())
            {
                soapEnvelopeXml.Save(stream);
            }
            try
            {
                using (WebResponse response = request.GetResponse())
                {
                    using (StreamReader rd = new StreamReader(response.GetResponseStream()))
                    {
                        string soapResult = rd.ReadToEnd();
                        Console.WriteLine(soapResult);
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 6
0
        public static void InsertRecord(BCClientModel data, SqlConnection conn)
        {
            SqlCommand     sqlCommand;
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
            string         query          = "if exists(select 1 from MobilePayOnBoarding   where  [TenantIdFormatted] = '" + data.extractedTenantId + "' and [BCTenantId] = '" + data.BCTenantId + "') begin UPDATE MobilePayOnBoarding SET UserName = '******', Password = '******' ,BCTenantId = '" + data.BCTenantId + "', State = '" + data.state + "' , CodeVerifier = '" + data.code_verifier + "', CodeChallenge = '" + data.code_challenge + "', Premium='" + data.enableCallback + "' where TenantIdFormatted = '" + data.extractedTenantId + "' and [BCTenantId] = '" + data.BCTenantId + "' end else begin  insert into MobilePayOnBoarding (UserName,Password,BCTenantId,State,CodeVerifier,CodeChallenge,TenantIdFormatted,Premium) values('" + data.userName + "','" + data.password + "','" + data.BCTenantId + "','" + data.state + "','" + data.code_verifier + "','" + data.code_challenge + "','" + data.extractedTenantId + "','" + data.enableCallback + "') end";

            sqlCommand = new SqlCommand(query, conn);
            sqlDataAdapter.InsertCommand = new SqlCommand(query, conn);
            sqlDataAdapter.InsertCommand.ExecuteNonQuery();
            sqlCommand.Dispose();
        }
Exemplo n.º 7
0
        public static void GetAccessTokenAsync(BCClientModel model, Action <BCClientModel> callback)
        {
            var    codeVerifier = CryptoRandom.CreateUniqueId(32);
            string codeChallenge;

            using (var sha256 = SHA256.Create())
            {
                var challengeBytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(codeVerifier));
                codeChallenge = Base64Url.Encode(challengeBytes);
            }
            model.nonce          = CryptoRandom.CreateUniqueId(32);
            model.state          = CryptoRandom.CreateUniqueId(32);
            model.code_challenge = codeChallenge;
            model.code_verifier  = codeVerifier;
            callback(model);
        }
Exemplo n.º 8
0
        public string SendLogingRequest(BCClientModel clientModel, Action <BCClientModel> callback)
        {
            string HtmlResult = "";

            AuthCodeMethod.GetAccessTokenAsync(clientModel, model =>
            {
                Url        = new Uri(clientModel.url);
                parameters = model.url + "?response_type=" + model.response_type + "&client_id=" + model.client_id + "&redirect_uri=" + model.redirect_uri + "&scope=openid" + model.scope + "offline_access&state=" + clientModel.state +
                             "&code_challenge=" + model.code_challenge + "&code_challenge_method=" + model.code_challenge_method + "&nonce=" + model.nonce + "&response_mode=form_post";

                using (WebClient wc = new WebClient())
                {
                    HtmlResult = wc.DownloadString(parameters);
                }
                callback(model);
            });
            return(parameters);
        }
Exemplo n.º 9
0
        private static void GetMerchantData(string tenantId, SqlConnection conn, Action <BCClientModel> BcClientModel)
        {
            SqlCommand     sqlCommand;
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
            BCClientModel  bCClient       = new BCClientModel();
            string         query          = "select CodeVerifier,UserName,Password,BCTenantId,AccessToken,RefreshToken,Premium from MobilePayOnBoarding where BCTenantId='" + tenantId + "'";

            sqlCommand = new SqlCommand(query, conn);
            using (SqlDataReader reader = sqlCommand.ExecuteReader())
            {
                while (reader.Read())
                {
                    bCClient.userName       = reader.GetString(1);
                    bCClient.password       = reader.GetString(2);
                    bCClient.BCTenantId     = reader.GetString(3);
                    bCClient.accessToken    = string.IsNullOrEmpty(reader.GetString(4)) ? "" : reader.GetString(4);
                    bCClient.refreshToken   = string.IsNullOrEmpty(reader.GetString(5)) ? "" : reader.GetString(5);
                    bCClient.enableCallback = string.IsNullOrEmpty(reader.GetString(6)) ? "" : reader.GetString(6);
                }
            }
            sqlCommand.Dispose();
            BcClientModel(bCClient);
        }
        public ActionResult MobilePay([FromBody] BCClientModel content)
        {
            int    insertedId  = 0;
            string baseURL     = GetBaseUrl();
            string returnedURL = GenerateAuthURL(content);

            Server.Start(REDIRECT_URL);
            Thread.Sleep(2);
            try
            {
                SessionUrl su = new SessionUrl();
                su.url        = returnedURL;
                su.bcTenantId = content.password;
                insertedId    = DBManager.InsertRecordSession(su);
            }
            catch (Exception eexx)
            {
                throw eexx;
            }
            string dataToPassWithUrl = baseURL + "/MobilePayIndex" + "/?sessionId=" + insertedId;

            return(Content(dataToPassWithUrl));
        }
Exemplo n.º 11
0
        public static string GetCodeVerified(string state, SqlConnection conn, Action <BCClientModel> callback)
        {
            SqlCommand     sqlCommand;
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
            BCClientModel  bCClient       = new BCClientModel();
            string         query          = "select CodeVerifier,UserName,Password,BCTenantId,Premium from MobilePayOnBoarding where state='" + state + "'";
            string         codeverified   = "";

            sqlCommand = new SqlCommand(query, conn);
            using (SqlDataReader reader = sqlCommand.ExecuteReader())
            {
                while (reader.Read())
                {
                    codeverified            = reader.GetString(0);
                    bCClient.userName       = reader.GetString(1);
                    bCClient.password       = reader.GetString(2);
                    bCClient.BCTenantId     = reader.GetString(3);
                    bCClient.enableCallback = reader.GetString(4);
                }
            }
            sqlCommand.Dispose();
            callback(bCClient);
            return(codeverified);
        }
        private string GenerateAuthURL(BCClientModel content)
        {
            string        url      = "";
            BCClientModel bcClient = new BCClientModel();

            bcClient.userName       = content.userName;
            bcClient.password       = content.password;
            bcClient.BCTenantId     = content.BCTenantId;
            bcClient.enableCallback = string.IsNullOrEmpty(content.enableCallback) ? "false" : content.enableCallback;
            bcClient.scope          = content.scope;
            proxy = new HttpProxyServer();
            try
            {
                url = proxy.SendLogingRequest(bcClient, model =>
                {
                    DBManager.InsertRecord(model);
                });
            }
            catch (Exception eexx)
            {
                throw eexx;
            }
            return(url);
        }
Exemplo n.º 13
0
        protected override void ProcessRequest(HttpListenerContext Context)
        {
            HttpListenerRequest  request  = Context.Request;
            HttpListenerResponse response = Context.Response;
            string formData = GetRequestPostData(request);

            AccessTokenModel accessToken = new AccessTokenModel();
            BCClientModel    clientModel = new BCClientModel();
            Regex            rx          = new Regex(@"=(.*?)&|=.*");
            int count = 0;

            foreach (Match mech in rx.Matches(formData))
            {
                if (count == 0)
                {
                    accessToken.code = mech.Groups[1].Value;
                }

                if (count == 1)
                {
                    accessToken.id_token = mech.Groups[1].Value;
                }

                if (count == 3)
                {
                    accessToken.state = mech.Groups[0].Value.ToString().Replace('=', ' ').Trim();
                }

                count++;
            }

            try
            {
                accessToken.code_verifier = DBManager.GetCodeVerifier(accessToken.state, callback =>
                {
                    clientModel = callback;
                });

                getRefereshToken(accessToken, model =>
                {
                    DBManager.AddTokens(model);
                    if (clientModel.enableCallback.Equals("true"))
                    {
                        string merchantId = "";
                        PostToClient(clientModel.userName, clientModel.password, clientModel.BCTenantId, model.access_token, model.refresh_token);

                        if (!string.IsNullOrEmpty(model.access_token))
                        {
                            merchantId = GetMerchantId(model.access_token);
                        }

                        if (!string.IsNullOrEmpty(merchantId) && !string.IsNullOrEmpty(model.access_token))
                        {
                            DBManager.AddMerchantID(merchantId, model);
                        }
                    }
                });
            }
            catch (Exception eexx)
            {
                throw eexx;
            }
            finally
            {
                string responseString = "<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <div style=\"position:fixed;top:0;left:0;min-width:100%; min-height:50px;background-color:#222;border-color:#080808;\"> <p>&nbsp;</p> </div>  <div style=\"padding-left: 25%; margin-right: auto; margin-left: auto; margin-top: 4%;\">   <h2 style=\"font-family: Helvetica Neue,Helvetica,Arial,sans-serif; font-weight: 500; line-height: 1.1;font-size: 30px;\">Congratulations !</h2> <h3 style=\"font-family: Helvetica Neue,Helvetica,Arial,sans-serif; font-weight: 500; line-height: 1.1;font-size: 24px;\">To continue Go back to your application</h3>    <hr style=\"margin-top: 20px; margin-bottom: 20px; border: 0; border-top: 1px solid #eee;\"/> <footer> <p style=\"font-family: Helvetica Neue,Helvetica,Arial,sans-serif; font-size: 14px; line-height: 1.428571429; color: #333;\"> &copy; <script>document.write(new Date().getFullYear())</script> - Merchant On-Boarding</p> </footer> </div>  </body> </html>";
                byte[] buffer         = Encoding.UTF8.GetBytes(responseString);

                response.ContentLength64 = buffer.Length;
                Stream output = response.OutputStream;
                output.Write(buffer, 0, buffer.Length);

                output.Close();
                // HttpServer.Stop();
                //Listener.Stop();
            }
        }