Google Checkout HTTP Post with ASP.net

I have 2 pages that I created in ASP.net (C #). The first of them (the so-called shoppingcart.asp) has a Buy Now button. The second (called processpay.asp) just waits for google verification to send an HTTP request for payment processing. What I would like to do is send a post message to google checkout using a couple of variables that I want to pass to the pay.asp process (i.e. clientid = 3 & itemid = 10), but I don't know how to format HTTP POST or what I have to change the settings in google checkout to make it work.

We will be very grateful for any ideas.

0
source share
3 answers

Google Checkout .NET-:

" -.


, POST , , HTTP :

using System.Net;

string HttpPost (string parameters)
{ 
   WebRequest webRequest = WebRequest.Create("http://checkout.google.com/buttons/checkout.gif?merchant_id=1234567890");
   webRequest.ContentType = "application/x-www-form-urlencoded";
   webRequest.Method = "POST";

   byte[] bytes = Encoding.ASCII.GetBytes(parameters);

   Stream os = null;

   try
   { 
      webRequest.ContentLength = bytes.Length;
      os = webRequest.GetRequestStream();
      os.Write(bytes, 0, bytes.Length);      
   }
   catch (WebException e)
   {
      // handle e.Message
   }
   finally
   {
      if (os != null)
      {
         os.Close();
      }
   }

   try
   { 
      // get the response

      WebResponse webResponse = webRequest.GetResponse();

      if (webResponse == null) 
      { 
          return null; 
      }

      StreamReader sr = new StreamReader(webResponse.GetResponseStream());

      return sr.ReadToEnd().Trim();
   }
   catch (WebException e)
   {
      // handle e.Message
   }

   return null;
} 

: name1=value1&name2=value2

+2

, , :

GCheckout.Checkout.CheckoutShoppingCartRequest oneCheckoutShoppingCartRequest =
  GCheckoutButton1.CreateRequest();

oneCheckoutShoppingCartRequest.MerchantPrivateData = "clientid=3";

GCheckout.Checkout.ShoppingCartItem oneShoppingCartItem =
  new GCheckout.Checkout.ShoppingCartItem();
oneShoppingCartItem.Name = "YourProductDisplayName";
oneShoppingCartItem.MerchantItemID = "10";

oneCheckoutShoppingCartRequest.AddItem(oneShoppingCartItem);
0

Source: https://habr.com/ru/post/1727015/


All Articles