/// <summary> /// perform additional queries as needed. /// </summary> /// <param name="response"></param> private void ProcessAdditionalTokens(NotificationHistoryResponse response) { NotificationHistoryResponse currentResponse = response; while (string.IsNullOrEmpty(currentResponse.NextPageToken) == false) { NotificationHistoryRequest newRequest = new NotificationHistoryRequest(MerchantID, MerchantKey, Environment.ToString(), response.NextPageToken); try { NotificationHistoryResponse nextResponse = newRequest.Send() as NotificationHistoryResponse; response.AddAdditionalResponse(nextResponse); currentResponse = nextResponse; } catch (Exception ex) { Log.Err("NotificationHistoryRequest ProcessAdditionalTokens:" + ex.Message); throw new NotificationHistoryException(response, response.NextPageToken, ex); } } }
public static void getNotification(string serial) { // get Google Order number from serial string ordernum = serial.Split('-')[0]; // create web client WebClient wc = new WebClient(); wc.Proxy = null; // get merchant info from settings Settings settings = new Settings(); string MerchantID = settings.Get("GoogleMerchantId"); string MerchantKey = settings.Get("GoogleMerchantKey"); GCheckout.EnvironmentType env = GCheckout.EnvironmentType.Production; if (HttpContext.Current.Request.Url.Host.Contains("127.0.0") || HttpContext.Current.Request.Url.Host.Contains("localhost") || settings.Get("GoogleCheckoutEnv") == "override") { MerchantID = settings.Get("GoogleDevMerchantId"); MerchantKey = settings.Get("GoogleDevMerchantKey"); env = GCheckout.EnvironmentType.Sandbox; } NotificationHistoryRequest request = new NotificationHistoryRequest(new List<string> {ordernum}); request.MerchantID = MerchantID; request.MerchantKey = MerchantKey; request.Environment = env; request.RetrieveAllNotifications = true; NotificationHistoryResponse response = (NotificationHistoryResponse)request.Send(); // Iterate through the notification history for this order looking for the notification that exactly matches the given serial number foreach (object notification in response.NotificationResponses) { if (notification.GetType().Equals(typeof(GCheckout.AutoGen.NewOrderNotification))) { GCheckout.AutoGen.NewOrderNotification newOrderNotification = (GCheckout.AutoGen.NewOrderNotification)notification; if (newOrderNotification.serialnumber.Equals(serial)) { HandleNewOrderNotification(newOrderNotification); } } else if (notification.GetType().Equals(typeof(GCheckout.AutoGen.OrderStateChangeNotification))) { GCheckout.AutoGen.OrderStateChangeNotification statechange = (GCheckout.AutoGen.OrderStateChangeNotification)notification; if (statechange.serialnumber.Equals(serial)) { HandleOrderStateChangeNotification(statechange); } } else if (notification.GetType().Equals(typeof(GCheckout.AutoGen.RiskInformationNotification))) { GCheckout.AutoGen.RiskInformationNotification riskInformationNotification = (GCheckout.AutoGen.RiskInformationNotification)notification; if (riskInformationNotification.serialnumber.Equals(serial)) { //HandleRiskInformationNotification(riskInformationNotification); } } else if (notification.GetType().Equals(typeof(GCheckout.AutoGen.AuthorizationAmountNotification))) { GCheckout.AutoGen.AuthorizationAmountNotification authorizationAmountNotification = (GCheckout.AutoGen.AuthorizationAmountNotification)notification; if (authorizationAmountNotification.serialnumber.Equals(serial)) { HandleAuthorizationAmountNotification(authorizationAmountNotification); } } else if (notification.GetType().Equals(typeof(GCheckout.AutoGen.ChargeAmountNotification))) { GCheckout.AutoGen.ChargeAmountNotification chargeAmountNotification = (GCheckout.AutoGen.ChargeAmountNotification)notification; if (chargeAmountNotification.serialnumber.Equals(serial)) { HandleChargeAmountNotification(chargeAmountNotification); } } else { //throw new ArgumentOutOfRangeException("Unhandled Type [" + notification.GetType().ToString() + "]!; serialNumber=[" + serial + "];"); } } }
//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(); }
public void Verify_Serial_Number_Supported() { var sn = "123456"; var request = new NotificationHistoryRequest(new NotificationHistorySerialNumber(sn)); var roundTrip = EncodeHelper.Deserialize(EncodeHelper.Utf8BytesToString(request.GetXml()), typeof(GCheckout.AutoGen.NotificationHistoryRequest)) as GCheckout.AutoGen.NotificationHistoryRequest; Assert.AreEqual(sn, roundTrip.serialnumber); }