简体   繁体   English

将Checkout请求发布到Google Checkout API时400响应

[英]400 response when posting Checkout request to Google Checkout API

While I've integrated several payment processors and shopping carts in the past, this Google Checkout API integration is not going well for me. 虽然过去我已经集成了多个付款处理程序和购物车,但是这种Google Checkout API集成对我来说并不理想。 I get a 400 response from Google, even when I use the diagnostic link. 即使使用诊断链接,我也会收到Google的400条回复。 I'm sure something's wrong in my URL, but I can't seem to figure out what. 我确定我的网址有问题,但似乎无法弄清楚。 I'm using a sandbox Merchant ID and Key. 我正在使用沙盒商户ID和密钥。

Can someone help me see what I'm doing to get this 400 response, please? 有人可以帮我看看我正在做什么以获得这400条回复吗?

I am using Java and posting from a server thus I'm calling the server to server API link: 我正在使用Java并从服务器中进行发布,因此我在调用服务器到服务器的API链接:

https://sandbox.google.com/checkout/api/checkout/v2/merchantCheckout/Merchant/%SANDBOXID%

<?xml version="1.0" encoding="UTF-8"?>
<checkout-shopping-cart xmlns="http://checkout.google.com/schema/2">
    <shopping-cart>
        <merchant-private-data>
            <merchant-note>8Ra8fw4tBaOdP4v3lseykKO6crR0dFqhzWV0EmqKuVuQaN1w0mcScAAR71pbexXlVnrwpP8wNzehuc7wz3KO9JM6xfedW8106olarCZcZBs=</merchant-note>
        </merchant-private-data>
        <items>
            <item-name>MyName : MySubname</item-name>
            <item-description>Weigh in on this year's...</item-description>
            <unit-price currency="USD">100</unit-price>
            <quantity>1</quantity>
         </items>
     </shopping-cart>
</checkout-shopping-cart>

I am using Java to post this data. 我正在使用Java发布此数据。 In the code below, the url above is sandboxLink in the code and checkReq is the XML post... 在下面的代码中,上面的网址是代码中的sandboxLink,而checkReq是XML帖子...

    public static String postCheckoutReqData(String userID, String gameName, boolean test) {

    String checkRequest = GoogleCheckoutXML.getCheckoutRequestXML(userID, gameName);

    if(checkRequest.indexOf("error,") != -1) return checkRequest;

    URL url = null;
    try {           
        String baseCodeString;          
        if(test) {
            url = new URL(GoogleCheckoutXML.sandboxLink + GoogleCheckoutXML.sandboxMerchID);
            baseCodeString = GoogleCheckoutXML.sandboxMerchID + ":" + GoogleCheckoutXML.sandboxMerchKey;
        }
        else {
            url = new URL(GoogleCheckoutXML.productionLink + GoogleCheckoutXML.merchantID);
            baseCodeString = GoogleCheckoutXML.merchantID + ":" + GoogleCheckoutXML.merchantKey;
        }
        //url = new URL(GoogleCheckoutXML.diagnose);
        byte[] bytes = (baseCodeString.getBytes());
        baseCodeString = new Base64().encodeAsString(bytes);
        URLConnection conn = url.openConnection();          
        conn.setDoOutput(true);
        conn.setRequestProperty("Authorization", "Basic " + baseCodeString);
        conn.setRequestProperty("Content-Type", "application/xml; charset=UTF-8");
        conn.setRequestProperty("Accept", "application/xml; charset=UTF-8");

        OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
        wr.write(checkRequest);
        wr.flush();

        // Get the response
        BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line;
        while ((line = rd.readLine()) != null) {
            line = line + rd.readLine();
        }

        wr.close();
        rd.close();
        return line;
    } 
    catch (Exception e) {   
        e.printStackTrace();
        return "error,Purchase Error posting communcation failed";
    }

The actual stack trace in Tomcat is: Tomcat中的实际堆栈跟踪为:

java.io.IOException: Server returned HTTP response code: 400 for URL: https://sandbox.google.com/checkout/api/checkout/v2/merchantCheckout/Merchant/[withheld]
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1612)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
at com.[withheld]..GoogleCheckoutXML.postCheckoutReqData(GoogleCheckoutXML.java:194)
at com.[withheld]...l.getCheckoutLink(DubQueryImpl.java:270)
at com.[withheld]....GenerateCheckoutLinkServlet.doGet(GenerateCheckoutLinkServlet.java:56)
at com.[withheld]...doPost(GenerateCheckoutLinkServlet.java:73)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)

I think I've solved a similar issue - it may, or may not, be yours ... 我认为我已经解决了类似的问题-可能是,也可能不是您的...

  1. Check the return code: 检查返回码:

    int code = conn.getResponseCode(); 整数代码= conn.getResponseCode(); // Integer (would be 400 in the case you give above) \\String msg = conn.getResponseMessage(); //整数(在上面的情况下为400)\\ String msg = conn.getResponseMessage(); // String (would be "Bad Request" in the case you give above //字符串(在上面的情况下为“错误请求”

  2. Check for further details 检查更多细节

    InputStream in = new BufferedInputStream(conn.getErrorStream()); InputStream in = new BufferedInputStream(conn.getErrorStream());

    Read in to see what further information is being provided - I have found it to be quite helpful! 阅读以查看提供了哪些进一步的信息-我发现它非常有帮助!

  3. In my case, my carefully prepared xml was losing the quotation marks somewhere along the way, trashing the <xml version="1.0" ... > right at the start and wreaking havoc from then onwards ... 就我而言,我精心准备的xml一直丢失引号,一开始就把<xml version="1.0" ... >丢掉了,从那以后就造成了严重破坏...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM