private static void CaptureConsoleCmdOutputWin(string pExeName, string pArgs, out RequestClass pRes) { string result = ""; ProcessStartInfo start = new ProcessStartInfo(); start.FileName = pExeName; start.Arguments = pArgs; start.UseShellExecute = false; start.RedirectStandardOutput = true; start.CreateNoWindow = true; try { Process process = Process.Start(start); using (StreamReader sr = process.StandardOutput) { // Read the stream to a string, and write the string to the console. result = sr.ReadToEnd(); } process.WaitForExit(); pRes = new RequestClass(result, pArgs, false, ""); } catch (Exception e) { Logger.Log(e.Message); pRes = new RequestClass("", pArgs, true, e.Message.ToString()); } }
// Method to get http tls request public IEnumerator Request(string pUrl, Dictionary<string, object> pDataDic, Action<RequestClass> onReturnRes) { Logger.isLogRequired = true; RequestClass res = new RequestClass(); string urldata = ""; string args = ""; // Get data paremetrs foreach(KeyValuePair<string, object> dicItem in pDataDic) { urldata += dicItem.Key + "=" + Uri.EscapeDataString((dicItem.Value==null)?"":dicItem.Value.ToString()) + "&"; } urldata = "?" + urldata.Substring(0, urldata.Length - 1); args = pUrl + urldata; Logger.Log(this.GetType().Name + " -> " + args); // Platform switcher Logger.Log("ApplicationPlatform -> " + Application.platform); Logger.Log("ApplicationDataPath -> " + Application.dataPath); switch (Application.platform) { case RuntimePlatform.OSXEditor: case RuntimePlatform.OSXPlayer: case RuntimePlatform.OSXWebPlayer: case RuntimePlatform.LinuxPlayer: { CaptureConsoleCmdOutput("curl", args , out res); break; } case RuntimePlatform.WindowsEditor: case RuntimePlatform.WindowsPlayer: case RuntimePlatform.WindowsWebPlayer: { CaptureConsoleCmdOutputWin(@"" + Application.dataPath +"/Plugins/" + "ExecConnectWin.dll", args, out res); break; } case RuntimePlatform.Android: //{ //CaptureConsoleCmdOutput(@"ExecConnect.dll", args, out exitcode, out res); //break; //} case RuntimePlatform.WebGLPlayer: case RuntimePlatform.IPhonePlayer: { Logger.Log("StartCoroutine"); // Coroutine request only for Iphone StartCoroutine(GetWWWFormRequest(pUrl, pDataDic, (value) => onReturnRes(value))); break; } default: { break; } } yield return res; onReturnRes(res); }
private static void CaptureConsoleCmdOutput(string pExeName, string pArgs, out RequestClass pRes) { ProcessStartInfo start = new ProcessStartInfo(); start.FileName = pExeName; start.Arguments = "--globoff --output " + outputFileName + " " + pArgs; start.UseShellExecute = false; start.RedirectStandardOutput = true; start.CreateNoWindow = true; try { string result = ""; Process process = Process.Start(start); process.WaitForExit(); StreamReader reader = process.StandardOutput; //result = reader.ReadToEnd(); try { // Open the text file using a stream reader. using (StreamReader sr = new StreamReader(outputFileName)) { // Read the stream to a string, and write the string to the console. result = sr.ReadToEnd(); } } catch (Exception e) { Console.WriteLine("The file could not be read:"); Console.WriteLine(e.Message); } pRes = new RequestClass(result, pArgs, false, ""); } catch (Exception e) { Logger.Log(e.Message); pRes = new RequestClass("", pArgs, true, e.Message.ToString()); } }
private static void CaptureConsoleCmdOutput(string pExeName, string pArgs, out RequestClass pRes) { ProcessStartInfo start = new ProcessStartInfo(); start.FileName = pExeName; start.Arguments = "--globoff --output " + outputFileName + " " + pArgs; start.UseShellExecute = false; start.RedirectStandardOutput = true; start.CreateNoWindow = true; try { string result = ""; Process process = Process.Start(start); process.WaitForExit(); StreamReader reader = process.StandardOutput; //result = reader.ReadToEnd(); try { // Open the text file using a stream reader. using (StreamReader sr = new StreamReader(outputFileName)) { // Read the stream to a string, and write the string to the console. result = sr.ReadToEnd(); } } catch (Exception e) { Console.WriteLine("The file could not be read:"); Console.WriteLine(e.Message); } pRes = new RequestClass(result, pArgs, false, ""); } catch (Exception e) { Logger.Log(e.Message); pRes = new RequestClass("",pArgs,true,e.Message.ToString()); } }
// Method to get http tls request public IEnumerator Request(string pUrl, Dictionary <string, object> pDataDic, Action <RequestClass> onReturnRes) { Logger.isLogRequired = true; RequestClass res = new RequestClass(); string urldata = ""; string args = ""; // Get data paremetrs foreach (KeyValuePair <string, object> dicItem in pDataDic) { urldata += dicItem.Key + "=" + Uri.EscapeDataString((dicItem.Value == null)?"":dicItem.Value.ToString()) + "&"; } urldata = "?" + urldata.Substring(0, urldata.Length - 1); args = pUrl + urldata; Logger.Log(this.GetType().Name + " -> " + args); // Platform switcher Logger.Log("ApplicationPlatform -> " + Application.platform); Logger.Log("ApplicationDataPath -> " + Application.dataPath); switch (Application.platform) { case RuntimePlatform.OSXEditor: case RuntimePlatform.OSXPlayer: //case RuntimePlatform.OSXWebPlayer: case RuntimePlatform.LinuxPlayer: { CaptureConsoleCmdOutput("curl", args, out res); break; } case RuntimePlatform.WindowsEditor: case RuntimePlatform.WindowsPlayer: //case RuntimePlatform.WindowsWebPlayer: { CaptureConsoleCmdOutputWin(@"" + Application.dataPath + "/Plugins/" + "ExecConnectWin.dll", args, out res); break; } case RuntimePlatform.Android: //{ //CaptureConsoleCmdOutput(@"ExecConnect.dll", args, out exitcode, out res); //break; //} case RuntimePlatform.WebGLPlayer: case RuntimePlatform.IPhonePlayer: { Logger.Log("StartCoroutine"); // Coroutine request only for Iphone StartCoroutine(GetWWWFormRequest(pUrl, pDataDic, (value) => onReturnRes(value))); break; } default: { break; } } yield return(res); onReturnRes(res); }
private void ProcessingRequestResult(int pType, RequestClass pRequestResult, Dictionary <string, object> pDataArgs) { if (!pRequestResult.HasError) { // Start Processing Debug.Log("Type -> " + pType); Debug.Log("WWW_request -> " + pRequestResult.TextRequest); JSONNode rootNode = JSON.Parse(pRequestResult.TextRequest); if (rootNode != null && rootNode.Count > 2 || rootNode["error"] == null) { switch (pType) { case TRANSLATIONS: { if (rootNode.Count > 2) { XsollaUtils utils = new XsollaUtils().Parse(rootNode) as XsollaUtils; projectId = utils.GetProject().id.ToString(); OnUtilsRecieved(utils); // if base param not containKey access token, then add token from util if (!baseParams.ContainsKey(XsollaApiConst.ACCESS_TOKEN)) { _accessToken = utils.GetAcceessToken(); } OnTranslationRecieved(utils.GetTranslations()); } else { XsollaError error = new XsollaError(); error.Parse(rootNode); OnErrorReceived(error); } } break; case DIRECTPAYMENT_FORM: { if (rootNode.Count > 8) { XsollaForm form = new XsollaForm(); form.Parse(rootNode); switch (form.GetCurrentCommand()) { case XsollaForm.CurrentCommand.STATUS: GetStatus(form.GetXpsMap()); break; case XsollaForm.CurrentCommand.CHECKOUT: case XsollaForm.CurrentCommand.CHECK: case XsollaForm.CurrentCommand.FORM: case XsollaForm.CurrentCommand.CREATE: case XsollaForm.CurrentCommand.ACCOUNT: OnFormReceived(form); break; case XsollaForm.CurrentCommand.UNKNOWN: if (rootNode.Count > 10) { OnFormReceived(form); } else { XsollaError error = new XsollaError(); error.Parse(rootNode); OnErrorReceived(error); } break; default: break; } } else { XsollaStatusPing statusPing = new XsollaStatusPing(); statusPing.Parse(rootNode); OnStatusChecked(statusPing); } } break; case DIRECTPAYMENT_STATUS: { XsollaForm form = new XsollaForm(); form.Parse(rootNode); XsollaStatus status = new XsollaStatus(); status.Parse(rootNode); OnStatusReceived(status, form); } break; case PRICEPOINTS: { XsollaPricepointsManager pricepoints = new XsollaPricepointsManager(); pricepoints.Parse(rootNode); OnPricepointsRecieved(pricepoints); } break; case GOODS: { XsollaGoodsManager goods = new XsollaGoodsManager(); goods.Parse(rootNode); OnGoodsRecieved(goods); } break; case GOODS_GROUPS: { XsollaGroupsManager groups = new XsollaGroupsManager(); groups.Parse(rootNode); OnGoodsGroupsRecieved(groups); } break; case GOODS_ITEMS: { XsollaGoodsManager goods = new XsollaGoodsManager(); goods.Parse(rootNode); OnGoodsRecieved(goods); } break; case PAYMENT_LIST: { XsollaPaymentMethods paymentMethods = new XsollaPaymentMethods(); paymentMethods.Parse(rootNode); OnPaymentMethodsRecieved(paymentMethods); } break; case SAVED_PAYMENT_LIST: { XsollaSavedPaymentMethods savedPaymentsMethods = new XsollaSavedPaymentMethods(); savedPaymentsMethods.Parse(rootNode); OnSavedPaymentMethodsRecieved(savedPaymentsMethods); } break; case QUICK_PAYMENT_LIST: { XsollaQuickPayments quickPayments = new XsollaQuickPayments(); quickPayments.Parse(rootNode); OnQuickPaymentMethodsRecieved(quickPayments); } break; case COUNTRIES: { XsollaCountries countries = new XsollaCountries(); countries.Parse(rootNode); OnCountriesRecieved(countries); } break; case VIRTUAL_PAYMENT_SUMMARY: { XVirtualPaymentSummary summary = new XVirtualPaymentSummary(); summary.Parse(rootNode); Logger.Log("VIRTUAL_PAYMENT_SUMMARY " + summary.ToString()); if (summary.IsSkipConfirmation) { Logger.Log("IsSkipConfirmation true"); pDataArgs.Add("dont_ask_again", 0); ProceedVPayment(pDataArgs); } else { Logger.Log("IsSkipConfirmation false"); OnVPSummaryRecieved(summary); } } break; case VIRTUAL_PROCEED: { XProceed proceed = new XProceed(); proceed.Parse(rootNode); Logger.Log("VIRTUAL_PROCEED " + proceed.ToString()); if (proceed.IsInvoiceCreated) { Logger.Log("VIRTUAL_PROCEED 1"); long operationId = proceed.OperationId; pDataArgs.Add("operation_id", operationId); VPaymentStatus(pDataArgs); } else { Logger.Log("VIRTUAL_PROCEED 0 "); OnVPProceedError(proceed.Error); } } break; case VIRTUAL_STATUS: { XVPStatus vpStatus = new XVPStatus(); vpStatus.Parse(rootNode); //{"errors":[ {"message":"Insufficient balance to complete operation"} ], "api":{"ver":"1.0.1"}, "invoice_created":"false", "operation_id":"0", "code":"0"} Logger.Log("VIRTUAL_STATUS" + vpStatus.ToString()); OnVPStatusRecieved(vpStatus); } break; case APPLY_PROMO_COUPONE: { XsollaForm form = new XsollaForm(); form.Parse(rootNode); OnApplyCouponeReceived(form); } break; case COUPON_PROCEED: { XsollaCouponProceedResult couponProceed = new XsollaCouponProceedResult(); couponProceed.Parse(rootNode); if (couponProceed._error != null) { Logger.Log("COUPON_PROCEED ERROR: " + couponProceed._error); OnCouponProceedErrorRecived(couponProceed); } else { long operationId = couponProceed._operationId; if (pDataArgs.ContainsKey("coupon_code")) { pDataArgs.Remove("coupon_code"); } pDataArgs.Add("operation_id", operationId); VPaymentStatus(pDataArgs); } } break; case HISTORY: { XsollaHistoryList history = new XsollaHistoryList().Parse(rootNode["operations"]) as XsollaHistoryList; OnHistoryRecieved(history); } break; case CALCULATE_CUSTOM_AMOUNT: { //TODO: fill method CustomVirtCurrAmountController.CustomAmountCalcRes res = new CustomVirtCurrAmountController.CustomAmountCalcRes().Parse(rootNode["calculation"]) as CustomVirtCurrAmountController.CustomAmountCalcRes; OnCustomAmountResRecieved(res); } break; default: break; } } else { XsollaError error = new XsollaError(); error.Parse(rootNode); OnErrorReceived(error); } } else { JSONNode errorNode = JSON.Parse(pRequestResult.TextRequest); string errorMsg = errorNode["errors"].AsArray[0]["message"].Value + ". Support code " + errorNode["errors"].AsArray[0]["support_code"].Value; int errorCode = 0; if (pRequestResult.ErrorText.Length > 3) { errorCode = int.Parse(pRequestResult.ErrorText.Substring(0, 3)); } else { errorCode = int.Parse(pRequestResult.ErrorText); } OnErrorReceived(new XsollaError(errorCode, errorMsg)); } if (projectId != null && !"".Equals(projectId)) { LogEvent("UNITY " + SDK_VERSION + " REQUEST", projectId, pRequestResult.Url); } else { LogEvent("UNITY " + SDK_VERSION + " REQUEST", "undefined", pRequestResult.Url); } }
private void ProcessingRequestResult(int pType, RequestClass pRequestResult, Dictionary<string, object> pDataArgs) { if (!pRequestResult.HasError) { // Start Processing Debug.Log("Type -> " + pType); Debug.Log("WWW_request -> " + pRequestResult.TextRequest); JSONNode rootNode = JSON.Parse(pRequestResult.TextRequest); if(rootNode != null && rootNode.Count > 2 || rootNode["error"] == null) { switch(pType) { case TRANSLATIONS: { if(rootNode.Count > 2){ XsollaUtils utils = new XsollaUtils().Parse(rootNode) as XsollaUtils; projectId = utils.GetProject().id.ToString(); OnUtilsRecieved(utils); // if base param not containKey access token, then add token from util if (!baseParams.ContainsKey(XsollaApiConst.ACCESS_TOKEN)) _accessToken = utils.GetAcceessToken(); OnTranslationRecieved(utils.GetTranslations()); } else { XsollaError error = new XsollaError(); error.Parse(rootNode); OnErrorReceived(error); } } break; case DIRECTPAYMENT_FORM: { if(rootNode.Count > 8) { XsollaForm form = new XsollaForm(); form.Parse(rootNode); switch (form.GetCurrentCommand()) { case XsollaForm.CurrentCommand.STATUS: GetStatus(form.GetXpsMap()); break; case XsollaForm.CurrentCommand.CHECKOUT: case XsollaForm.CurrentCommand.CHECK: case XsollaForm.CurrentCommand.FORM: case XsollaForm.CurrentCommand.CREATE: case XsollaForm.CurrentCommand.ACCOUNT: OnFormReceived(form); break; case XsollaForm.CurrentCommand.UNKNOWN: if(rootNode.Count > 10) { OnFormReceived(form); } else { XsollaError error = new XsollaError(); error.Parse(rootNode); OnErrorReceived(error); } break; default: break; } } else { XsollaStatusPing statusPing = new XsollaStatusPing(); statusPing.Parse(rootNode); OnStatusChecked(statusPing); } } break; case DIRECTPAYMENT_STATUS: { XsollaForm form = new XsollaForm(); form.Parse(rootNode); XsollaStatus status = new XsollaStatus(); status.Parse(rootNode); OnStatusReceived(status, form); } break; case PRICEPOINTS: { XsollaPricepointsManager pricepoints = new XsollaPricepointsManager(); pricepoints.Parse(rootNode); OnPricepointsRecieved(pricepoints); } break; case GOODS: { XsollaGoodsManager goods = new XsollaGoodsManager(); goods.Parse(rootNode); OnGoodsRecieved(goods); } break; case GOODS_GROUPS: { XsollaGroupsManager groups = new XsollaGroupsManager(); groups.Parse(rootNode); OnGoodsGroupsRecieved(groups); } break; case GOODS_ITEMS: { XsollaGoodsManager goods = new XsollaGoodsManager(); goods.Parse(rootNode); OnGoodsRecieved(goods); } break; case PAYMENT_LIST: { XsollaPaymentMethods paymentMethods = new XsollaPaymentMethods(); paymentMethods.Parse(rootNode); OnPaymentMethodsRecieved(paymentMethods); } break; case SAVED_PAYMENT_LIST: { XsollaSavedPaymentMethods savedPaymentsMethods = new XsollaSavedPaymentMethods(); savedPaymentsMethods.Parse(rootNode); OnSavedPaymentMethodsRecieved(savedPaymentsMethods); } break; case QUICK_PAYMENT_LIST: { XsollaQuickPayments quickPayments = new XsollaQuickPayments(); quickPayments.Parse(rootNode); OnQuickPaymentMethodsRecieved(quickPayments); } break; case COUNTRIES: { XsollaCountries countries = new XsollaCountries(); countries.Parse(rootNode); OnCountriesRecieved(countries); } break; case VIRTUAL_PAYMENT_SUMMARY: { XVirtualPaymentSummary summary = new XVirtualPaymentSummary(); summary.Parse(rootNode); Logger.Log("VIRTUAL_PAYMENT_SUMMARY " + summary.ToString()); if(summary.IsSkipConfirmation) { Logger.Log("IsSkipConfirmation true"); pDataArgs.Add("dont_ask_again", 0); ProceedVPayment(pDataArgs); } else { Logger.Log("IsSkipConfirmation false"); OnVPSummaryRecieved(summary); } } break; case VIRTUAL_PROCEED: { XProceed proceed = new XProceed(); proceed.Parse(rootNode); Logger.Log ("VIRTUAL_PROCEED " + proceed.ToString()); if(proceed.IsInvoiceCreated) { Logger.Log ("VIRTUAL_PROCEED 1"); long operationId = proceed.OperationId; pDataArgs.Add("operation_id", operationId); VPaymentStatus(pDataArgs); } else { Logger.Log ("VIRTUAL_PROCEED 0 "); OnVPProceedError(proceed.Error); } } break; case VIRTUAL_STATUS: { XVPStatus vpStatus = new XVPStatus(); vpStatus.Parse(rootNode); //{"errors":[ {"message":"Insufficient balance to complete operation"} ], "api":{"ver":"1.0.1"}, "invoice_created":"false", "operation_id":"0", "code":"0"} Logger.Log ("VIRTUAL_STATUS" + vpStatus.ToString()); OnVPStatusRecieved(vpStatus); } break; case APPLY_PROMO_COUPONE: { XsollaForm form = new XsollaForm(); form.Parse(rootNode); OnApplyCouponeReceived(form); } break; case COUPON_PROCEED: { XsollaCouponProceedResult couponProceed = new XsollaCouponProceedResult(); couponProceed.Parse(rootNode); if (couponProceed._error != null) { Logger.Log("COUPON_PROCEED ERROR: " + couponProceed._error); OnCouponProceedErrorRecived(couponProceed); } else { long operationId = couponProceed._operationId; if (pDataArgs.ContainsKey("coupon_code")) pDataArgs.Remove("coupon_code"); pDataArgs.Add("operation_id", operationId); VPaymentStatus(pDataArgs); } } break; case HISTORY: { XsollaHistoryList history = new XsollaHistoryList().Parse(rootNode["operations"]) as XsollaHistoryList; OnHistoryRecieved(history); } break; case CALCULATE_CUSTOM_AMOUNT: { //TODO: fill method CustomVirtCurrAmountController.CustomAmountCalcRes res = new CustomVirtCurrAmountController.CustomAmountCalcRes().Parse(rootNode["calculation"]) as CustomVirtCurrAmountController.CustomAmountCalcRes; OnCustomAmountResRecieved(res); } break; default: break; } } else { XsollaError error = new XsollaError(); error.Parse(rootNode); OnErrorReceived(error); } } else { JSONNode errorNode = JSON.Parse(pRequestResult.TextRequest); string errorMsg = errorNode["errors"].AsArray[0]["message"].Value + ". Support code " + errorNode["errors"].AsArray[0]["support_code"].Value; int errorCode = 0; if(pRequestResult.ErrorText.Length > 3) errorCode = int.Parse(pRequestResult.ErrorText.Substring(0, 3)); else errorCode = int.Parse(pRequestResult.ErrorText); OnErrorReceived(new XsollaError(errorCode, errorMsg)); } if(projectId != null && !"".Equals(projectId)) LogEvent ("UNITY " + SDK_VERSION + " REQUEST", projectId, pRequestResult.Url); else LogEvent ("UNITY " + SDK_VERSION + " REQUEST", "undefined", pRequestResult.Url); }
private static void CaptureConsoleCmdOutputWin(string pExeName, string pArgs, out RequestClass pRes) { string result = ""; ProcessStartInfo start = new ProcessStartInfo(); start.FileName = pExeName; start.Arguments = pArgs; start.UseShellExecute = false; start.RedirectStandardOutput = true; start.CreateNoWindow = true; try { Process process = Process.Start(start); using (StreamReader sr = process.StandardOutput) { // Read the stream to a string, and write the string to the console. result = sr.ReadToEnd(); } process.WaitForExit(); pRes = new RequestClass(result, pArgs, false, ""); } catch (Exception e) { Logger.Log(e.Message); pRes = new RequestClass("",pArgs,true,e.Message.ToString()); } }