这是后车的方法,我现在用:谷歌结帐的Java API与setMerchantPrivateData()将AnyMultiple时编组的元素,而不是一个字符串
public CheckoutRedirect submit(CreateOrderRequest sku) {
CartPoster cartPoster = context.cartPoster();
CartPoster.CheckoutShoppingCartBuilder cartBuilder = cartPoster.makeCart();
Money unitPrice = new Money();
unitPrice.setCurrency(sku.getCurrency());
unitPrice.setValue(new BigDecimal(sku.getPrice()));
String platformId = sku.getPlatformId().toString();
AnyMultiple merchantPrivateData = new AnyMultiple();
merchantPrivateData.getContent().add(platformId);
MerchantCheckoutFlowSupport merchantCheckoutFlowSupport = new MerchantCheckoutFlowSupport();
merchantCheckoutFlowSupport.setContinueShoppingUrl(sku.getContinueShoppingUrl());
CheckoutShoppingCart.CheckoutFlowSupport checkoutFlowSupport = new CheckoutShoppingCart.CheckoutFlowSupport();
checkoutFlowSupport.setMerchantCheckoutFlowSupport(merchantCheckoutFlowSupport);
DigitalContent digitalcontent = new DigitalContent();
digitalcontent.setDisplayDisposition(sku.getDisplayDisposition());
digitalcontent.setDescription(sku.getDigitalContentDescription());
Item item = new Item();
item.setItemDescription(sku.getDescription());
item.setItemName(sku.getName());
item.setMerchantItemId(sku.getSkuId());
item.setUnitPrice(unitPrice);
item.setDigitalContent(digitalcontent);
item.setQuantity(sku.getQuantity());
cartBuilder.addItem(item);
CheckoutShoppingCart checkoutShoppingCart = cartBuilder.build();
checkoutShoppingCart.setCheckoutFlowSupport(checkoutFlowSupport);
checkoutShoppingCart.getShoppingCart().setMerchantPrivateData(merchantPrivateData);
return cartPoster.postCart(checkoutShoppingCart);
}
这工作正常,将输出XML作为本:
<checkout-shopping-cart xmlns="http://checkout.google.com/schema/2">
<shopping-cart>
<merchant-private-data>1000</merchant-private-data>
<items>
<item>
<digital-content>
<description>Description Goes Here</description>
<display-disposition>OPTIMISTIC</display-disposition>
</digital-content>
<item-name>Product Name</item-name>
<item-description>Product Description Goes Here</item-description>
<unit-price currency="USD">4.95</unit-price>
<quantity>1</quantity>
<merchant-item-id>87</merchant-item-id>
</item>
</items>
</shopping-cart>
<checkout-flow-support>
<merchant-checkout-flow-support>
<continue-shopping-url>http://www.example.com/success</continue-shopping-url>
</merchant-checkout-flow-support>
</checkout-flow-support>
</checkout-shopping-cart>
你会发现<merchant-private-data>1000</merchant-private-data>
如果你看一下这个元素的XML API标签参考:http://code.google.com/apis/checkout/developer/Google_Checkout_XML_API_Tag_Reference.html#tag_merchant-private-data
它指出,这是任何良好的XML序列的容器和示出了具有内这样的一个元件的一个示例:
<merchant-private-data>
<merchant-note>my order number 76543</merchant-note>
</merchant-private-data>
当添加在AnyMultiple的列表构件,其表示将接受String(如在我已经展示的情况下)或元素。我的问题是,我不能为我的生活,添加一个元素到这个列表中,而不会遇到编组错误。
我想创建:
<merchant-private-data>
<platform-id>1000</platform-id>
</merchant-private-data>
另外,我相当新的编写Java代码。有没有人使用这个API成功做到这一点?
在此先感谢。