0

This is the post cart method that I am using:

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);
    }

This works fine and will output xml as this:

<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>

You will notice <merchant-private-data>1000</merchant-private-data> If you look at the XML api tag reference for this element: http://code.google.com/apis/checkout/developer/Google_Checkout_XML_API_Tag_Reference.html#tag_merchant-private-data

It states that this is a container for any well formed xml sequence and shows an example with an element within this:

<merchant-private-data>
   <merchant-note>my order number 76543</merchant-note>
</merchant-private-data>

When adding the the List member in AnyMultiple, its stated that it will accept a String (as in the case I have shown) or an Element. My problem is that I cannot for the life of me, add an Element to this list without encountering marshaling errors.

I want to create:

<merchant-private-data>
   <platform-id>1000</platform-id>
</merchant-private-data> 

Also, I am rather new to writing Java code. Has anyone been successful in doing this using this API?

Thanks in advance.

Brandon G
  • 2,733
  • 3
  • 25
  • 24

1 Answers1

0

Am not a Java dev (am .Net), so forgive my ignorance ~

You'll have to programmatically create an XML element and its value/inner text and insert/add it.

This wouldn't be part of the Google Checkout API, it would be the XML framework that handles the (de)serilialization you are already using - e.g. in .Net Framework this would be System.XML

I know it's not as helpful as can be, so I hope this at least gives you a place to look/start.

EdSF
  • 11,753
  • 6
  • 42
  • 83