2

まず、私の質問は「ASP.NET MVC3 と Google チェックアウトの開始: テイク 2」に似ていますが、これが完全に回答されているとは感じず、私の質問は MVC3 とは何の関係もありません。

わかりました。サンドボックス サーバーを使用して、Google Checkout / Wallet を ASP.NET アプリケーションにうまく統合することができました。これでライブの準備が整いました。アクション URL、マーチャント ID、マーチャント キーなどのパラメータを変更しただけで、機能しなくなりました。

問題の原因を突き止めようと単純な Web プロジェクトをセットアップしましたが、少し途方に暮れています。すべてが正常に機能しているようです。400 の不正なリクエスト エラーを受信して​​います。フィドラーを使用してキャプチャした送信内容は次のとおりです。

POST https://checkout.google.com/api/checkout/v2/checkoutForm/Merchant/XXXXXXXXXXXXXXX         HTTP/1.1
Authorization: Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Content-Type: application/xml;charset=UTF-8
Host: checkout.google.com
Content-Length: 679
Expect: 100-continue
Connection: Keep-Alive

<?xml version="1.0" encoding="UTF-8"?>
<checkout-shopping-cart xmlns="http://checkout.google.com/schema/2">
    <shopping-cart>
        <merchant-private-data>2390</merchant-private-data>
        <items>
            <item>
                <item-name>Business Cards 107 - White 350gsm Silk</item-name>
                <unit-price currency="GBP">20.40</unit-price>
                <quantity>1</quantity>
                <item-description>25 x1 One sided - Standard Business Cards</item-description>
                <merchant-item-id>2956</merchant-item-id>
            </item>
        </items>
    </shopping-cart>
    <checkout-flow-support>
        <merchant-checkout-flow-support />
    </checkout-flow-support>
</checkout-shopping-cart>

そして、これが C# コードです。これは、冒頭で言及した質問とほとんど同じです。

#define LIVE

      string url = string.Format(SandboxMerchantCheckoutUrl, SandboxMerchantId);

#if LIVE
      url = string.Format(ProductionMerchantCheckoutUrl, ProductionMerchantId);
#endif

      string path = HttpContext.Current.Server.MapPath("~/SampleXML/") + "order.xml";
      string xml = File.ReadAllText(path);
      byte[] bytes = Encoding.UTF8.GetBytes(xml);
      string xmlstr = string.Empty;

      HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;

      string authInfo = SandboxMerchantId + ":" + SandboxMerchantKey;

#if LIVE
      authInfo = ProductionMerchantId + ":" + ProductionMerchantKey;
#endif

      authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));

      request.Headers["Authorization"] = "Basic " + authInfo;
      request.Method = "POST";
      request.ContentLength = bytes.Length;
      request.ContentType = "text/xml";
      request.ContentType = "application/xml;charset=UTF-8";

      using (Stream requestStream = request.GetRequestStream())
      {
        requestStream.Write(bytes, 0, bytes.Length);
      }

      using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
      {

        if (response.StatusCode == HttpStatusCode.OK)
        {

          StreamReader reader = new StreamReader(response.GetResponseStream());

          xmlstr = reader.ReadToEnd();

        }
        else
        {

          string message = string.Format("POST failed. Received HTTP {0}", response.StatusCode);

          throw new ApplicationException(message);

        }

      }

      XmlDocument xmldoc = new XmlDocument();
      XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmldoc.NameTable);

      nsmgr.AddNamespace("g", "http://checkout.google.com/schema/2");
      xmldoc.LoadXml(xmlstr);

      string serialNumber = xmldoc.SelectSingleNode("/g:checkout-redirect", nsmgr).Attributes["serial-number"].Value;

      string redirectUrl = xmldoc.SelectSingleNode("/g:checkout-redirect/g:redirect-url", nsmgr).InnerText;

よし、ここで更新。上記で問題ないと思います。Google 販売者アカウントにログインし、統合コンソールを確認したところ、次のものが正常に受信されていることがわかりました。

<?xml version="1.0" encoding="UTF-8"?>
<checkout-shopping-cart xmlns="http://checkout.google.com/schema/2">
  <shopping-cart>
    <merchant-private-data>2390</merchant-private-data>
    <items>
      <item>
        <item-name>Business Cards 107 - White 350gsm Silk</item-name>
        <unit-price currency="GBP">20.40</unit-price>
        <quantity>1</quantity>
        <item-description>25 x1 One sided - Standard Business Cards</item-description>
        <merchant-item-id>2956</merchant-item-id>
      </item>
    </items>
  </shopping-cart>
  <checkout-flow-support>
    <merchant-checkout-flow-support />
  </checkout-flow-support>
</checkout-shopping-cart>

ただし、「カートには少なくとも 1 つのアイテムが含まれている必要があります」というエラーが Google から送信されます。ショッピング カートにアイテムがない場合、または数量がゼロに設定されている場合にこのエラーが発生するという Google ドキュメントへのリンクがあります。これらのいずれもここには当てはまらないため、このリクエストが拒否された理由はまだわかりません。

4

0 に答える 0