Allow worldwide shipping with Google Checkout/Wallet java SDK

Google’s java SDK for interacting with the checkout API is not a fun experience. It’s generated from the WSDL using JAXB which has a unique ability to generate client interfaces that no human could ever “design”.

It’s not actually that hard to write code with, you just have to think like a deranged machine.

By default, the only allowed shipping destination will be your country. If you wish to allow worldwide shipping, you have to do something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
ApiContext apiContext = new ApiContext(environment, "yourMerchantId", "yourMerchantKey", "GBP");
CheckoutShoppingCartBuilder cartBuilder = apiContext.cartPoster().makeCart();
CheckoutShoppingCart cart = cartBuilder.build();
FlatRateShipping frs = new FlatRateShipping();
frs.setName("flat rate");
 
ShippingRestrictions shippingRestrictions = new ShippingRestrictions();
AllowedAreas allowedAreas = new AllowedAreas();
allowedAreas.getUsStateAreaOrUsZipAreaOrUsCountryArea().add(new WorldArea());
shippingRestrictions.setAllowedAreas(allowedAreas);
frs.setShippingRestrictions(shippingRestrictions);
 
...
ApiContext apiContext = new ApiContext(environment, "yourMerchantId", "yourMerchantKey", "GBP");
CheckoutShoppingCartBuilder cartBuilder = apiContext.cartPoster().makeCart();
CheckoutShoppingCart cart = cartBuilder.build();
FlatRateShipping frs = new FlatRateShipping();
frs.setName("flat rate");

ShippingRestrictions shippingRestrictions = new ShippingRestrictions();
AllowedAreas allowedAreas = new AllowedAreas();
allowedAreas.getUsStateAreaOrUsZipAreaOrUsCountryArea().add(new WorldArea());
shippingRestrictions.setAllowedAreas(allowedAreas);
frs.setShippingRestrictions(shippingRestrictions);

...

I just posted this because I could not find one example on the internet. Crazy I know, but now there is one.