/// <summary>
 /// Create a new Instance of NotificationHistoryRequest used to
 /// obtain more results for a previous request.
 /// </summary>
 /// <param name="serialNumber">The message serial number</param>
 public NotificationHistoryRequest(NotificationHistorySerialNumber serialNumber)
     : base(GCheckoutConfigurationHelper.MerchantID,
            GCheckoutConfigurationHelper.MerchantKey,
            GCheckoutConfigurationHelper.Environment)
 {
     _serialNumber = serialNumber;
 }
 /// <summary>
 /// Create a new Instance of NotificationHistoryRequest
 /// based on a date range.
 /// </summary>
 /// <param name="merchantID">Google Checkout Merchant ID</param>
 /// <param name="merchantKey">Google Checkout Merchant Key</param>
 /// <param name="environment">A String representation of
 /// <see cref="EnvironmentType"/></param>
 /// <param name="serialNumber">The serial number to query</param>
 public NotificationHistoryRequest(string merchantID,
                                   string merchantKey, string environment,
                                   NotificationHistorySerialNumber serialNumber)
     : base(merchantID, merchantKey, environment)
 {
     _serialNumber = serialNumber;
 }
    //private GoogleCheckOutSettingInfo GetSettingGooglePayment()
    //{
    //    GoogleCheckOutSettingInfo setting = new GoogleCheckOutSettingInfo();
    //    GoogleCheckOutWCFService ser = new GoogleCheckOutWCFService();

    //}
    public static void ProcessNotification(string serialNumber)
    {
        GoogleCheckOutWCFService pw = new GoogleCheckOutWCFService();
        List<GoogleCheckOutSettingKeyInfo> sf;
        sf = pw.GoogleCheckOutSettingKey();
        MerchantID = sf[0].GoogleMerchantID;
        MerchantKey = sf[0].GoogleMerchantKey;
        Environment = sf[0].GoogleEnvironmentType;

        GCheckout.OrderProcessing.NotificationHistorySerialNumber sn = new NotificationHistorySerialNumber(serialNumber);
        GCheckout.OrderProcessing.NotificationHistoryRequest oneNotificationHistoryRequest = new NotificationHistoryRequest(MerchantID, MerchantKey, Environment, sn); //newNotificationHistorySerialNumber(serialNumber)
        //Response
        NotificationHistoryResponse oneNotificationHistoryResponse = (NotificationHistoryResponse)oneNotificationHistoryRequest.Send();

//Get type of notification
object notification = GCheckout.Util.EncodeHelper.Deserialize(oneNotificationHistoryResponse.ResponseXml);

//Check for the notification and call functions according to that
if (notification.GetType().Equals(typeof(GCheckout.AutoGen.NewOrderNotification)))

{

GCheckout.AutoGen.NewOrderNotification oneNewOrderNotification = (GCheckout.AutoGen.NewOrderNotification)notification;

if (oneNewOrderNotification.serialnumber.Equals(serialNumber))

{

HandleNewOrderNotification(oneNewOrderNotification);

}

}

else if (notification.GetType().Equals(typeof(GCheckout.AutoGen.OrderStateChangeNotification)))

{

GCheckout.AutoGen.OrderStateChangeNotification oneOrderStateChangeNotification = (GCheckout.AutoGen.OrderStateChangeNotification)notification;

if (oneOrderStateChangeNotification.serialnumber.Equals(serialNumber))

{

HandleOrderStateChangeNotification(oneOrderStateChangeNotification);

}

}

else if (notification.GetType().Equals(typeof(GCheckout.AutoGen.RiskInformationNotification)))

{

GCheckout.AutoGen.RiskInformationNotification oneRiskInformationNotification = (GCheckout.AutoGen.RiskInformationNotification)notification;

if (oneRiskInformationNotification.serialnumber.Equals(serialNumber))

{

HandleRiskInformationNotification(oneRiskInformationNotification);

}

}

else if (notification.GetType().Equals(typeof(GCheckout.AutoGen.AuthorizationAmountNotification)))

{

GCheckout.AutoGen.AuthorizationAmountNotification oneAuthorizationAmountNotification = (GCheckout.AutoGen.AuthorizationAmountNotification)notification;

if (oneAuthorizationAmountNotification.serialnumber.Equals(serialNumber))

{

HandleAuthorizationAmountNotification(oneAuthorizationAmountNotification);

}

}

else if (notification.GetType().Equals(typeof(GCheckout.AutoGen.ChargeAmountNotification)))

{

GCheckout.AutoGen.ChargeAmountNotification oneChargeAmountNotification = (GCheckout.AutoGen.ChargeAmountNotification)notification;

if (oneChargeAmountNotification.serialnumber.Equals(serialNumber))

{

HandleChargeAmountNotification(oneChargeAmountNotification);

}

}

else

{

string exceptionText = "Unhandled Type [" + notification.GetType().ToString() + "]!; serialNumber=[" + serialNumber + "];";

throw new ArgumentOutOfRangeException(exceptionText);

}

}
        protected void Page_Load(object sender, EventArgs e)
        {
            string serial = Request["serial-number"];
            serial = serial.Replace("serial-number=", "");

            GCheckout.OrderProcessing.NotificationHistorySerialNumber ser = new GCheckout.OrderProcessing.NotificationHistorySerialNumber(serial);
            GCheckout.OrderProcessing.NotificationHistoryRequest histroey = new GCheckout.OrderProcessing.NotificationHistoryRequest("417255259260942", "LzWjnZDmrxRiA0UlIUfeSg", GCheckout.EnvironmentType.Sandbox.ToString(), ser);

            GCheckout.Util.GCheckoutResponse responce = histroey.Send();

            XmlDocument xmldoc = new XmlDocument();
            xmldoc.LoadXml(responce.ResponseXml);

            SqlConnection cn = new SqlConnection("Data Source=fbcmsdatabase.db.8886533.hostedresource.com;Initial Catalog=fbcmsdatabase;User ID=fbcmsdatabase;Password=H1v3bu1ld3r");
            cn.Open();
            SqlCommand cmd = new SqlCommand("insertpaypal", cn);
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@date", DateTime.Now.ToString()));
            cmd.Parameters.Add(new SqlParameter("@text", responce.ResponseXml));
            cmd.Parameters.Add(new SqlParameter("@respond", Context.Request.ServerVariables["REMOTE_ADDR"].ToString()));
            cmd.ExecuteNonQuery();
            cn.Close();

            var ack = new GCheckout.AutoGen.NotificationAcknowledgment();
            ack.serialnumber = serial;
            Response.BinaryWrite(GCheckout.Util.EncodeHelper.Serialize(ack));
            Response.StatusCode = 200;
            Response.End();
        }
   /// <summary>
   /// Create a new Instance of NotificationHistoryRequest used to
   /// obtain more results for a previous request.
   /// </summary>
   /// <param name="serialNumber">The message serial number</param>
   public NotificationHistoryRequest(NotificationHistorySerialNumber serialNumber)
       : base(GCheckoutConfigurationHelper.MerchantID,
 GCheckoutConfigurationHelper.MerchantKey,
 GCheckoutConfigurationHelper.Environment)
   {
       _serialNumber = serialNumber;
   }
 /// <summary>
 /// Create a new Instance of NotificationHistoryRequest
 /// based on a date range.
 /// </summary>
 /// <param name="merchantID">Google Checkout Merchant ID</param>
 /// <param name="merchantKey">Google Checkout Merchant Key</param>
 /// <param name="environment">A String representation of 
 /// <see cref="EnvironmentType"/></param>
 /// <param name="serialNumber">The serial number to query</param>
 public NotificationHistoryRequest(string merchantID,
     string merchantKey, string environment,
     NotificationHistorySerialNumber serialNumber)
     : base(merchantID, merchantKey, environment)
 {
     _serialNumber = serialNumber;
 }