Java examples for AWS:Payment
retrieve the address selected by the buyer for amazon payments
package com.amazon.samples; /******************************************************************************* * Copyright 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * //from w w w. j av a 2s . c o m * You may not use this file except in compliance with the License. * You may obtain a copy of the License at: http://aws.amazon.com/apache2.0 * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * ***************************************************************************** */ import java.io.FileNotFoundException; import java.util.List; import java.util.Iterator; import com.amazon.payments.CheckoutByAmazonServiceException; import com.amazon.payments.CBAPurchaseContract; import com.amazon.payments.CheckoutByAmazonServiceRequestException; import com.amazon.payments.model.ShippingAddress; /** * GetAddress class shows how we can retrieve the address selected by the buyer. * Based on the buyer address you can calculate Taxes and Shipping charges to be applied to the order. */ class GetAddress { public static void main(String... args) { //set the PurchaseContract Id String purchaseContractId = "<<Enter Purchase Contract ID here>>"; try { //Create the Amazon Library Object CBAPurchaseContract lib = new CBAPurchaseContract(); //Create an object of Shipping Address which will hold the address returned by getAddress call ShippingAddress shippingAddressRes = new ShippingAddress(); //Call the Library function getAddress to get the address selected by the buyer List<ShippingAddress> shippingAddressList; shippingAddressList = lib.getAddress(purchaseContractId); //Displays all the selected address Iterator<ShippingAddress> shippingAddressIterator = shippingAddressList .iterator(); while (shippingAddressIterator.hasNext()) { shippingAddressRes = (ShippingAddress) shippingAddressIterator .next(); System.out .println("City : " + shippingAddressRes.getCity()); System.out.println("PostalCode : " + shippingAddressRes.getPostalCode()); System.out.println("StateOrProvinceCode : " + shippingAddressRes.getStateOrProvinceCode()); System.out.println("CountryCode : " + shippingAddressRes.getCountryCode()); } } //Catch the internal exceptions catch (CheckoutByAmazonServiceException ex) { System.out.println("Caught Service Exception: " + ex.getMessage()); System.out.println("Response Status Code: " + ex.getStatusCode()); System.out.println("Error Code: " + ex.getErrorCode()); System.out.println("Error Type: " + ex.getErrorType()); System.out.println("Request ID: " + ex.getRequestId()); System.out.print("XML: " + ex.getXML()); } //Catch the request exceptions which will come when there is some error in the //inputs passed while calling the API catch (CheckoutByAmazonServiceRequestException ex) { System.out.println("Caught Request Exception: " + ex.getMessage()); System.out.println("Response Status Code: " + ex.getStatusCode()); System.out.println("Error Code: " + ex.getErrorCode()); System.out.println("Error Type: " + ex.getErrorType()); System.out.println("Request ID: " + ex.getRequestId()); System.out.print("XML: " + ex.getXML()); } //Catch the exceptions which will come when properties file is not found catch (FileNotFoundException ex) { System.out.println("Caught File not found Exception: " + ex.getMessage()); } } }