There are more AWS SDK examples available in the AWS Doc SDK Examples
Get the payment schedule of an agreement using an AWS SDK
The following code examples show how to get the payment schedule of an agreement.
- Java
-
- SDK for Java 2.x
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Marketplace API Reference Code Library
repository. // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 package com.example.awsmarketplace.agreementapi; import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider; import software.amazon.awssdk.http.apache.ApacheHttpClient; import software.amazon.awssdk.services.marketplaceagreement.MarketplaceAgreementClient; import software.amazon.awssdk.services.marketplaceagreement.model.AcceptedTerm; import software.amazon.awssdk.services.marketplaceagreement.model.GetAgreementTermsRequest; import software.amazon.awssdk.services.marketplaceagreement.model.GetAgreementTermsResponse; import software.amazon.awssdk.services.marketplaceagreement.model.PaymentScheduleTerm; import software.amazon.awssdk.services.marketplaceagreement.model.ScheduleItem; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import static com.example.awsmarketplace.utils.ReferenceCodesConstants.*; import com.example.awsmarketplace.utils.ReferenceCodesUtils; public class GetAgreementTermsPaymentSchedule { /* * Obtain the payment schedule I have agreed to with the agreement, including the invoice date and invoice amount */ public static void main(String[] args) { String agreementId = args.length > 0 ? args[0] : AGREEMENT_ID; List<Map<String, Object>> paymentScheduleArray = getPaymentSchedules(agreementId); ReferenceCodesUtils.formatOutput(paymentScheduleArray); } public static List<Map<String, Object>> getPaymentSchedules(String agreementId) { MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); GetAgreementTermsRequest getAgreementTermsRequest = GetAgreementTermsRequest.builder().agreementId(agreementId) .build(); GetAgreementTermsResponse getAgreementTermsResponse = marketplaceAgreementClient.getAgreementTerms(getAgreementTermsRequest); List<Map<String, Object>> paymentScheduleArray = new ArrayList<>(); String currencyCode = ""; for (AcceptedTerm acceptedTerm : getAgreementTermsResponse.acceptedTerms()) { if (acceptedTerm.paymentScheduleTerm() != null) { PaymentScheduleTerm paymentScheduleTerm = acceptedTerm.paymentScheduleTerm(); if (paymentScheduleTerm.currencyCode() != null) { currencyCode = paymentScheduleTerm.currencyCode(); } if (paymentScheduleTerm.hasSchedule()) { for (ScheduleItem schedule : paymentScheduleTerm.schedule()) { if (schedule.chargeDate() != null) { String chargeDate = schedule.chargeDate().toString(); String chargeAmount = schedule.chargeAmount(); Map<String, Object> scheduleMap = new HashMap<>(); scheduleMap.put(ATTRIBUTE_CURRENCY_CODE, currencyCode); scheduleMap.put(ATTRIBUTE_CHARGE_DATE, chargeDate); scheduleMap.put(ATTRIBUTE_CHARGE_AMOUNT, chargeAmount); paymentScheduleArray.add(scheduleMap); } } } } } return paymentScheduleArray; } }
-
For API details, see GetAgreementTerms in AWS SDK for Java 2.x API Reference.
-
- Python
-
- SDK for Python (Boto3)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Marketplace API Reference Code Library
repository. # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 """ Purpose Obtain the payment schedule I have agreed to with the agreement, including the invoice date and invoice amount AG-17 """ import json import logging import os import boto3 import utils.helpers as helper from botocore.exceptions import ClientError logger = logging.getLogger(__name__) # agreement id AGREEMENT_ID = "agmt-1111111111111111111111111" # to use sample file or not USE_SAMPLE_FILE = False SAMPLE_FILE_NAME = "mockup_agreement_terms.json" # attribute name ROOT_ELEM = "acceptedTerms" TERM_NAME = "paymentScheduleTerm" CONFIG_ELEM = "configuration" ATTRIBUTE_NAME = "selectorValue" def get_agreement_information(mp_client, entity_id): """ Returns customer AWS Account id about a given agreement Args: entity_id str: Entity to return Returns: dict: Dictionary of agreement information """ try: if USE_SAMPLE_FILE: sample_file = os.path.join(os.path.dirname(__file__), SAMPLE_FILE_NAME) terms = open_json_file(sample_file) else: terms = mp_client.get_agreement_terms(agreementId=entity_id) paymentScheduleArray = [] currencyCode = "" for term in terms[ROOT_ELEM]: if TERM_NAME in term: paymentSchedule = term[TERM_NAME] if "currencyCode" in paymentSchedule: currencyCode = paymentSchedule["currencyCode"] if "schedule" in paymentSchedule: for sch in paymentSchedule["schedule"]: if "chargeDate" in sch: chargeDate = sch["chargeDate"] chargeAmount = sch["chargeAmount"] # print(f"chargeDate: {chargeDate}, chargeAmount: {chargeAmount}") schedule = { "currencyCode": currencyCode, "chargeDate": chargeDate, "chargeAmount": chargeAmount, } paymentScheduleArray.append(schedule) return paymentScheduleArray except ClientError as e: if e.response["Error"]["Code"] == "ResourceNotFoundException": logger.error("Agreement with ID %s not found.", entity_id) else: logger.error("Unexpected error: %s", e) def usage_demo(): logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Looking for an agreement in the AWS Marketplace.") print("-" * 88) mp_client = boto3.client("marketplace-agreement") helper.pretty_print_datetime(get_agreement_information(mp_client, AGREEMENT_ID)) # open json file from path def open_json_file(filename): with open(filename, "r") as f: return json.load(f) if __name__ == "__main__": usage_demo()
-
For API details, see GetAgreementTerms in AWS SDK for Python (Boto3) API Reference.
-