googlecheckout网上支付 代码

<%!
	public static void callBack(String CallBackUrl,String msg) throws Exception
	{
		try {
			URL url = new URL(CallBackUrl);
			HttpURLConnection connection = (HttpURLConnection)url.openConnection();
			connection.setRequestMethod("POST");
			connection.setDoOutput(true);
			connection.setDoInput(true);
			connection.setUseCaches(false);
			connection.setInstanceFollowRedirects(true);
			connection.setRequestProperty("Authorization", "Basic NTA0MzUyNjI2NjE5MjcxOlNFVnJzTzlsYmVLaHFaZ3lMMjh6b3c=");
			connection.setRequestProperty("Host", connection.getURL().getHost());
			connection.setRequestProperty("content-type","application/xml; charset=UTF-8");
			connection.setRequestProperty("accept", "application/xml");
			PrintWriter pw = new PrintWriter(new OutputStreamWriter(connection.getOutputStream(),"UTF8"));
			pw.print(msg);
			pw.flush();
			pw.close();
			int responseCode = connection.getResponseCode();
			InputStream inputStream;
		      if (responseCode == HttpURLConnection.HTTP_OK) 
		      {
		    	  inputStream = connection.getInputStream();
		      } 
		      else 
		      {
		    	  inputStream = connection.getErrorStream();
		    	  LoggingKit.writePayLog("Unknown status: " + inputStream);
		      }
			}catch (MalformedURLException ex) 
			{
				LoggingKit.writePayLog("Unknown status: " + ex);
		    } catch (IOException ex) 
		    {
		    	LoggingKit.writePayLog("Unknown status: " + ex);
		    }
	}

	public static boolean checkData(String cartNo,String tatol) throws Exception
	{
		boolean result = false;
		BoRegShoppingCart aoBoRegShoppingCart = new BoRegShoppingCart();
		aoBoRegShoppingCart.cartno = Integer.parseInt(cartNo);
		Qwhere aoQwhere = new Qwhere("cartno",Qwhere.Operator.EQ,Integer.parseInt(cartNo));
		if(aoBoRegShoppingCart.restore(aoQwhere))
		{
			if(aoBoRegShoppingCart.total==Double.parseDouble(tatol))
			{
				result = true;
			}
			else
			{
				LoggingKit.writePayLog("checkData unSuccess" );
			}
		}
		else
		{
			LoggingKit.writePayLog("checkData unSuccess" );
		}
		return result;
		
	}
	
	public static void ipn_update(int aiCartNo,String asPayFee)
	{
		  try
	        {
	            BoRegShoppingCart oBoRegShoppingCart = new BoRegShoppingCart();
	            oBoRegShoppingCart.cartno = aiCartNo;
	            if (!oBoRegShoppingCart.restore())
	            {
	                LoggingKit.writePayLog(aiCartNo + " fail to find invoice at save_paypal_ipn\n");
	                return;
	            }
	            oBoRegShoppingCart.ipn_time = new Date();
	            oBoRegShoppingCart.pay_method = "google checkout";
	            oBoRegShoppingCart.update();
	        }
	        catch (Exception ex)
	        {
	            Global.reportError(ex.getMessage(), "save_paypal_ipn error");
	        }
	    }

%>

<%
	final String url = "https://checkout.google.com/api/checkout/v2/checkoutForm/Merchant/504352626619271"; 
	String callBack = "";
	String type = ToolKit.getParameter(request, "_type", "");
	String serial_number = ToolKit.getParameter(request,"serial-number","");
	String orderNumber =ToolKit.getParameter(request,"google-order-number","");
	String amount = ToolKit.getParameter(request,"order-total","");
	String currency = ToolKit.getParameter(request,"order-total.currency",""); 
	String asCartNo = ToolKit.getParameter(request,"shopping-cart.items.item-1.item-name","");
		if(type.equalsIgnoreCase("new-order-notification"))
		{
			//our system check data,if success post data to goole
			boolean checkSucess = checkData(asCartNo,amount);
			if(checkSucess==true)
			{
				callBack = "_type=charge-order&serial-number="+serial_number+"&amount="+amount+"&currency="+currency;
				ipn_update(Integer.parseInt(asCartNo),amount);
			}
			else
			{
				String reason = "checkDate unSuccess";
				String comment = "total error";
				callBack = "_type=cancel-order&google-order-number="+serial_number+"&reason="+reason+"&comment="+comment;
			}
			//post data to google
			callBack(url,callBack);
		}
		if(type.equalsIgnoreCase("risk-information-notification"))
		{
			String reason = "risk";
			String comment = "users cread card money can't payfor this goods";
			callBack = "_type=cancel-order&google-order-number="+serial_number+"&reason="+reason+"&comment="+comment;
			//post data to google
			callBack(url,callBack);
			//if need order google email this customer
		}
		if(type.equalsIgnoreCase("charge-amount-notification"))
		{
			// chargeable then give user things
			StaticDnsTools.paidCartWrapper( Integer.parseInt(asCartNo), null);
			//if need order google bak this order
			callBack = "_type=archive-order&google-order-number="+orderNumber;
			callBack(url,callBack);
		}
	
%>

 啥都不用说了,有点基础的人应该都看得懂

猜你喜欢

转载自hefeidaxia.iteye.com/blog/700608