/// <summary> /// Create a new instance of the Response parser /// </summary> /// <param name="responseXml"></param> public GCheckoutResponse(string responseXml) { //to cut down on the number or exceptions, we are going to try to //predetermine the type of message being returned this will allow for //a greater experience on the dev side. If you are not using debug //symbols, it is very difficult to determine if the error is real //or not if you are breaking on all thrown exceptions. _responseXml = responseXml; if (ResponseXml.IndexOf("<request-received") > -1) { _GoodResponse = (AutoGen.RequestReceivedResponse) EncodeHelper.Deserialize(ResponseXml, typeof(AutoGen.RequestReceivedResponse)); Log.Xml(_GoodResponse.serialnumber, ResponseXml); //_parsed = true; } else if (ResponseXml.IndexOf("<error") > -1) { _ErrorResponse = (AutoGen.ErrorResponse) EncodeHelper.Deserialize(ResponseXml, typeof(AutoGen.ErrorResponse)); Log.Xml(_ErrorResponse.serialnumber, ResponseXml); //_parsed = true; } else if (ParseMessage()) { //_parsed = true; } else { //What we want to do is determine if there is a type so we //can report it to the user so they can report the error string messageTypeFound = string.Empty; try { var theType = EncodeHelper.Deserialize(ResponseXml); if (theType != null) { messageTypeFound = theType.GetType().Name; } else { messageTypeFound = "Unknown Message Type"; } Log.Xml(Guid.NewGuid().ToString(), ResponseXml); } catch (Exception ex) { Log.Xml(Guid.NewGuid().ToString(), ResponseXml); Log.Err("GCheckoutResponse else check failed:" + ex.Message); } _ErrorResponse = new GCheckout.AutoGen.ErrorResponse(); _ErrorResponse.errormessage = string.Format("Couldn't parse ResponseXml. " + "Message type found was {0}. Please See ResponseXml", messageTypeFound); } }
/// <summary> /// The Type is Bye so we need to look for that /// </summary> /// <returns></returns> protected override bool ParseMessage() { try { if (ResponseXml.IndexOf("<bye") > -1) { _response = (AutoGen.Bye) EncodeHelper.Deserialize(ResponseXml, typeof(AutoGen.Bye)); Log.Xml(_response.serialnumber, ResponseXml); return(true); } } catch (Exception ex) { Log.Err("HelloCheckoutResponse ParseResponse:" + ex.Message); } return(false); }
/// <summary> /// Creates a new instance of the <see cref="GCheckoutResponse"/> class. /// </summary> /// <param name="ResponseXml">The XML returned from Google.</param> public GCheckoutResponse(string ResponseXml) { _Xml = ResponseXml; try { _GoodResponse = (AutoGen.RequestReceivedResponse) EncodeHelper.Deserialize(ResponseXml, typeof(AutoGen.RequestReceivedResponse)); } catch { try { _ErrorResponse = (AutoGen.ErrorResponse) EncodeHelper.Deserialize(ResponseXml, typeof(AutoGen.ErrorResponse)); } catch { _CheckoutRedirectResponse = (AutoGen.CheckoutRedirect) EncodeHelper.Deserialize(ResponseXml, typeof(AutoGen.CheckoutRedirect)); } } }
/// <summary> /// Parse the message for a checkout-redirect /// </summary> /// <returns></returns> protected override bool ParseMessage() { //to cut down on the number or exceptions, we are going to try to //predetermine the type of message being returned this will allow for //a greater experience on the dev side. If you are not using debug //symbols, it is very difficult to determine if the error is real //or not if you are breaking on all thrown exceptions. try { if (ResponseXml.IndexOf("<checkout-redirect") > -1) { _CheckoutRedirectResponse = (AutoGen.CheckoutRedirect) EncodeHelper.Deserialize(ResponseXml, typeof(AutoGen.CheckoutRedirect)); Log.Xml(_CheckoutRedirectResponse.serialnumber, ResponseXml); return(true); } } catch (Exception ex) { Log.Err("GCheckoutShoppingCartResponse ParseResponse:" + ex.Message); } return(false); }
private static string GetAuthorization(string User, string Password) { return(Convert.ToBase64String(EncodeHelper.StringToUtf8Bytes( string.Format("{0}:{1}", User, Password)))); }