C# and Google Checkout - getting the reply back from the server? -


are there tutorials out there on how responses google checkout transaction when using c# , gcheckout api. of examples find previous versions of api , not current 1 (2.5). more specifically, i'd see example reply of google post me without , https connection. know it's minimal data, i'd still see example of , see how others parsing it.

google sends notification internally
create notification page this:

<%@ import namespace="system.io" %> <%@ import namespace="gcheckout" %> <%@ import namespace="gcheckout.autogen" %> <%@ import namespace="gcheckout.util" %> <%@ import namespace="system.data.sqlclient" %> <%@ import namespace="system.text" %>  <script runat="server" language="c#">  string serialnum = string.empty; void page_load(object sender, eventargs e) {     // extract xml request.     stream requeststream = request.inputstream;     streamreader requeststreamreader = new streamreader(requeststream);     string requestxml = requeststreamreader.readtoend();     requeststream.close();     // act on xml.     switch (encodehelper.gettopelement(requestxml))     {         case "new-order-notification":             newordernotification n1 = (newordernotification)encodehelper.deserialize(requestxml, typeof(newordernotification));                  string ordernumber1 = n1.googleordernumber;                 string shiptoname = n1.buyershippingaddress.contactname;                 string shiptoaddress1 = n1.buyershippingaddress.address1;                 string shiptoaddress2 = n1.buyershippingaddress.address2;                 string shiptocity = n1.buyershippingaddress.city;                 string shiptostate = n1.buyershippingaddress.region;                 string shiptozip = n1.buyershippingaddress.postalcode;                 system.xml.xmlnode[] arr = n1.shoppingcart.merchantprivatedata.any;                 string pdata = string.empty;                 try                 {                     pdata = arr[0].innertext;                 }                 catch { pdata = "error"; }                 decimal totalprice = 0.0m;                 foreach (item thisitem in n1.shoppingcart.items)                 {                     string name = thisitem.itemname;                     int quantity = thisitem.quantity;                     decimal price = thisitem.unitprice.value;                     totalprice += price * quantity;                 }                 serialnum = n1.serialnumber;                 string message = "order no : " + ordernumber1 + " total price = $" + totalprice + "\r\np. data:" + pdata;               logtransaction(ordernumber1, serialnum, message, pdata);             sendgoogleacknowledgement();             break;         case "risk-information-notification":             riskinformationnotification n2 = (riskinformationnotification)encodehelper.deserialize(requestxml, typeof(riskinformationnotification));             // notification tells google has authorized order , has passed fraud check.             // use data below determine if want accept order, start processing it.             string ordernumber2 = n2.googleordernumber;             string avs = n2.riskinformation.avsresponse;             string cvn = n2.riskinformation.cvnresponse;             bool sellerprotection = n2.riskinformation.eligibleforprotection;             serialnum = n2.serialnumber;             break;         case "order-state-change-notification":             orderstatechangenotification n3 = (orderstatechangenotification)encodehelper.deserialize(requestxml, typeof(orderstatechangenotification));             // order has changed either financial or fulfillment state in google's system.             string ordernumber3 = n3.googleordernumber;             string newfinancestate = n3.newfinancialorderstate.tostring();             string newfulfillmentstate = n3.newfulfillmentorderstate.tostring();             string prevfinancestate = n3.previousfinancialorderstate.tostring();             string prevfulfillmentstate = n3.previousfulfillmentorderstate.tostring();             serialnum = n3.serialnumber;             break;         case "charge-amount-notification":             chargeamountnotification n4 = (chargeamountnotification)encodehelper.deserialize(requestxml, typeof(chargeamountnotification));             // google has charged customer's credit card.             string ordernumber4 = n4.googleordernumber;             decimal chargedamount = n4.latestchargeamount.value;             serialnum = n4.serialnumber;             break;         case "refund-amount-notification":             refundamountnotification n5 = (refundamountnotification)encodehelper.deserialize(requestxml, typeof(refundamountnotification));             // google has refunded customer's credit card.             string ordernumber5 = n5.googleordernumber;             decimal refundedamount = n5.latestrefundamount.value;             serialnum = n5.serialnumber;             break;         case "chargeback-amount-notification":             chargebackamountnotification n6 = (chargebackamountnotification)encodehelper.deserialize(requestxml, typeof(chargebackamountnotification));             // customer initiated chargeback credit card company money back.             string ordernumber6 = n6.googleordernumber;             decimal chargebackamount = n6.latestchargebackamount.value;             serialnum = n6.serialnumber;             break;         default:             break;     } }  private void sendgoogleacknowledgement() {     stringbuilder responsexml = new stringbuilder();     responsexml.append("<?xml version='1.0' encoding='utf-8'?>");     responsexml.append("<notifiation-acknowledgment xmlns='http://checkout.google.com/schema/2' />");     httpresponse response =     system.web.httpcontext.current.response;     response.statuscode = 200;     response.contenttype = "text/xml";     response.write(responsexml.tostring());     response.end();  }  protected virtual void logtransaction(string orderno, string serialno, string message, string pdata) {     try     {         //insert record in database         string sql = "update googleorder set googleordernumber = @googleordernumber privatedata = @pdata";         using (sqlconnection conn = new sqlconnection(configurationmanager.connectionstrings["incommandconnectionstring"].connectionstring))         {             conn.open();             sqlcommand cmd = new sqlcommand(sql, conn);             cmd.parameters.addwithvalue("@googleordernumber", orderno);             cmd.parameters.addwithvalue("@pdata", pdata);             cmd.executenonquery();             conn.close();          }     }     catch (exception ex)     {         logerror("error save order no" + orderno);     }     //insert record in text file      logerror(message); } private void logerror(string message) {     string logfile = configurationmanager.appsettings.get("linkpointlogfile");     if (logfile != "")     {         byte[] binlogstring = encoding.default.getbytes(message);          try         {             filestream lofile = new filestream(logfile, filemode.openorcreate, fileaccess.write, fileshare.write);             lofile.seek(0, seekorigin.end);             lofile.write(binlogstring, 0, binlogstring.length);             lofile.close();         }         catch { ; }     } } 

`

on google checkout setting page set notification page name , path , response on page. test whether notification page working or not, try log transaction txt file , once every thing working smooth can remove code.

in example pdata number send google checkout , same number in notification, used match transaction particular order.

hope code you;


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -