Java examples for AWS:Payment
call the createPurchaseContract API which returns the PurchaseContract ID in 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 ww . jav 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 com.amazon.payments.CheckoutByAmazonServiceException; import com.amazon.payments.CBAPurchaseContract; import com.amazon.payments.CheckoutByAmazonServiceRequestException; /** * CreatePurchaseContract Class shows how to call the createPurchaseContract API which returns the PurchaseContract ID. * If you use this API, you must pass the Purchase Contract ID as input to the InlineCheckoutWidget. * If no Purchase Contract ID is passed to the InlineCheckoutWidget, the widget will always create * and return a new Purchase Contract ID.For most cases, you don't need to use this API. A * Purchase Contract ID will be returned to you from the InlineCheckoutWidget, which you can then * use with the other APIs. */ class CreatePurchaseContract { public static void main(String... args) { try { //Create an Amazon library object CBAPurchaseContract lib = new CBAPurchaseContract(); //Call the library function createPurchaseContract to create an Amazon Purchase Contract String purchaseContractId = lib.createPurchaseContract(); System.out.println("Amazon Purchase Contract Id : " + purchaseContractId); } //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()); } } }