文档 AWS SDK 示例 GitHub 存储库中还有更多 S AWS DK 示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
将 SaaS 合同协议替换为基于协议的报价,使用 AWS SDK
以下代码示例说明如何使用基于协议的新报价替换 SaaS 合同协议。
- Java
-
- 适用于 Java 的 SDK 2.x
-
注意
还有更多相关信息 GitHub。在 AWS Marketplace API Reference Code Library
存储库中查找完整示例,了解如何进行设置和运行。 package com.example.awsmarketplace.agreementapi.buyer; 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.AcceptAgreementRequestRequest; import software.amazon.awssdk.services.marketplaceagreement.model.AcceptAgreementRequestResponse; import software.amazon.awssdk.services.marketplaceagreement.model.CreateAgreementRequestRequest; import software.amazon.awssdk.services.marketplaceagreement.model.CreateAgreementRequestResponse; import software.amazon.awssdk.services.marketplaceagreement.model.Intent; import software.amazon.awssdk.services.marketplaceagreement.model.RequestedTerm; import utils.AgreementApiUtils; /** * Demonstrates how to replace an existing SaaS agreement with CONTRACT pricing model with a new * Agreement-Based Offer (ABO) using the AWS Marketplace Agreement Service APIs. * * <p>Scenario: A buyer has an active SaaS agreement with CONTRACT pricing model and receives a private * Agreement-Based Offer from the seller. The buyer replaces the existing agreement * with the new ABO offer, which may include updated pricing terms and payment schedule. * * <p>Note: Unlike other Replace samples, this example starts from an already-active * {@code EXISTING_AGREEMENT_ID} rather than creating a new agreement first. Use this * pattern when you already have an agreement ID and want to replace it directly. * * <p>Before running this sample, replace the placeholder constants below with values from * your AWS Marketplace offers: * <ul> * <li>{@code EXISTING_AGREEMENT_ID} — the agreement ID of the active agreement to replace (starts with {@code agmt-}).</li> * <li>{@code NEW_AGREEMENT_PROPOSAL_IDENTIFIER} — the agreementProposalId from the new ABO offer.</li> * <li>Term IDs (starting with {@code term-}) — found in the new offer's term list.</li> * </ul> */ public class ReplaceSaaSContractWithAgreementBasedOffer { // The agreement ID of the active SaaS agreement with CONTRACT pricing model to replace (starts with "agmt-"). private static final String EXISTING_AGREEMENT_ID = "<your-existing-agreement-id>"; // The agreementProposalId from the new Agreement-Based Offer. private static final String NEW_AGREEMENT_PROPOSAL_IDENTIFIER = "<your-new-agreement-proposal-identifier>"; // Term ID for the LegalTerm in the new offer. private static final String LEGAL_TERM_ID = "<your-legal-term-id>"; // Term ID for the ValidityTerm in the new offer. private static final String VALIDITY_TERM_ID = "<your-validity-term-id>"; // Term ID for the FixedUpfrontPricingTerm in the new offer. private static final String FIXED_UPFRONT_PRICING_TERM_ID = "<your-fixed-upfront-pricing-term-id>"; // Term ID for the PaymentScheduleTerm in the new offer. private static final String PAYMENT_SCHEDULE_TERM_ID = "<your-payment-schedule-term-id>"; public static void main(String[] args) { replaceExistingAgreement(); } /** * Replaces an existing SaaS agreement with CONTRACT pricing model with a new Agreement-Based Offer. * Uses Intent.REPLACE with sourceAgreementIdentifier set to the existing agreement ID. */ private static void replaceExistingAgreement() { MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); RequestedTerm legalTerm = RequestedTerm.builder().id(LEGAL_TERM_ID).build(); RequestedTerm validityTerm = RequestedTerm.builder().id(VALIDITY_TERM_ID).build(); RequestedTerm fixedUpfrontPricingTerm = RequestedTerm.builder().id(FIXED_UPFRONT_PRICING_TERM_ID).build(); RequestedTerm paymentScheduleTerm = RequestedTerm.builder().id(PAYMENT_SCHEDULE_TERM_ID).build(); // Replace the agreement with the new offer CreateAgreementRequestRequest createAgreementRequestRequest = CreateAgreementRequestRequest.builder() .clientToken(AgreementApiUtils.generateClientToken()) .intent(Intent.REPLACE) .requestedTerms(fixedUpfrontPricingTerm, paymentScheduleTerm, legalTerm, validityTerm) .agreementProposalIdentifier(NEW_AGREEMENT_PROPOSAL_IDENTIFIER) .sourceAgreementIdentifier(EXISTING_AGREEMENT_ID) .build(); CreateAgreementRequestResponse createAgreementRequestResponse = marketplaceAgreementClient.createAgreementRequest(createAgreementRequestRequest); System.out.println("Replace agreement request created. AgreementRequestId: " + createAgreementRequestResponse.agreementRequestId()); AcceptAgreementRequestRequest acceptAgreementRequestRequest = AcceptAgreementRequestRequest.builder() .agreementRequestId(createAgreementRequestResponse.agreementRequestId()) .build(); AcceptAgreementRequestResponse acceptAgreementRequestResponse = marketplaceAgreementClient.acceptAgreementRequest(acceptAgreementRequestRequest); System.out.println("Agreement replaced with ABO. New AgreementId: " + acceptAgreementRequestResponse.agreementId()); } }-
有关 API 的详细信息,请参阅 AWS SDK for Java 2.x API 参考CreateAgreementRequest中的。
-
- JavaScript
-
- 适用于 JavaScript (v3) 的软件开发工具包
-
注意
还有更多相关信息 GitHub。在 AWS Marketplace API Reference Code Library
存储库中查找完整示例,了解如何进行设置和运行。 const { MarketplaceAgreementClient, CreateAgreementRequestCommand, AcceptAgreementRequestCommand, } = require("@aws-sdk/client-marketplace-agreement"); const { generateClientToken } = require("./utils/AgreementApiUtils"); /** * Demonstrates how to replace an existing SaaS agreement with CONTRACT pricing model with a new * Agreement-Based Offer (ABO) using the AWS Marketplace Agreement Service APIs. * * Scenario: A buyer has an active SaaS agreement with CONTRACT pricing model and receives a private * Agreement-Based Offer from the seller. The buyer replaces the existing agreement * with the new ABO offer, which may include updated pricing terms and payment schedule. * * Note: Unlike other Replace samples, this example starts from an already-active * EXISTING_AGREEMENT_ID rather than creating a new agreement first. Use this * pattern when you already have an agreement ID and want to replace it directly. * * Before running this sample, replace the placeholder constants below with values from * your AWS Marketplace offers: * - EXISTING_AGREEMENT_ID — the agreement ID of the active agreement to replace (starts with "agmt-"). * - NEW_AGREEMENT_PROPOSAL_IDENTIFIER — the agreementProposalId from the new ABO offer. * - Term IDs (starting with "term-") — found in the new offer's term list. */ // The agreement ID of the active SaaS agreement with CONTRACT pricing model to replace (starts with "agmt-"). const EXISTING_AGREEMENT_ID = "<your-existing-agreement-id>"; // The agreementProposalId from the new Agreement-Based Offer. const NEW_AGREEMENT_PROPOSAL_IDENTIFIER = "<your-new-agreement-proposal-identifier>"; // Term ID for the LegalTerm in the new offer. const LEGAL_TERM_ID = "<your-legal-term-id>"; // Term ID for the ValidityTerm in the new offer. const VALIDITY_TERM_ID = "<your-validity-term-id>"; // Term ID for the FixedUpfrontPricingTerm in the new offer. const FIXED_UPFRONT_PRICING_TERM_ID = "<your-fixed-upfront-pricing-term-id>"; // Term ID for the PaymentScheduleTerm in the new offer. const PAYMENT_SCHEDULE_TERM_ID = "<your-payment-schedule-term-id>"; /** * Replaces an existing SaaS agreement with CONTRACT pricing model with a new Agreement-Based Offer. * Uses Intent.REPLACE with sourceAgreementIdentifier set to the existing agreement ID. */ async function replaceExistingAgreement() { const client = new MarketplaceAgreementClient(); const legalTerm = { id: LEGAL_TERM_ID }; const validityTerm = { id: VALIDITY_TERM_ID }; const fixedUpfrontPricingTerm = { id: FIXED_UPFRONT_PRICING_TERM_ID }; const paymentScheduleTerm = { id: PAYMENT_SCHEDULE_TERM_ID }; // Replace the agreement with the new offer const createAgreementRequestResponse = await client.send( new CreateAgreementRequestCommand({ clientToken: generateClientToken(), intent: "REPLACE", requestedTerms: [fixedUpfrontPricingTerm, paymentScheduleTerm, legalTerm, validityTerm], agreementProposalIdentifier: NEW_AGREEMENT_PROPOSAL_IDENTIFIER, sourceAgreementIdentifier: EXISTING_AGREEMENT_ID, }) ); console.log("Replace agreement request created. AgreementRequestId: " + createAgreementRequestResponse.agreementRequestId); const acceptAgreementRequestResponse = await client.send( new AcceptAgreementRequestCommand({ agreementRequestId: createAgreementRequestResponse.agreementRequestId, }) ); console.log("Agreement replaced with ABO. New AgreementId: " + acceptAgreementRequestResponse.agreementId); } replaceExistingAgreement();-
有关 API 的详细信息,请参阅 适用于 JavaScript 的 AWS SDK API 参考CreateAgreementRequest中的。
-
- Python
-
- 适用于 Python 的 SDK(Boto3)
-
注意
还有更多相关信息 GitHub。在 AWS Marketplace API Reference Code Library
存储库中查找完整示例,了解如何进行设置和运行。 """ Demonstrates how to replace an existing SaaS agreement with CONTRACT pricing model with a new Agreement-Based Offer (ABO) using the AWS Marketplace Agreement Service APIs. Scenario: A buyer has an active SaaS agreement with CONTRACT pricing model and receives a private Agreement-Based Offer from the seller. The buyer replaces the existing agreement with the new ABO offer, which may include updated pricing terms and payment schedule. Note: Unlike other Replace samples, this example starts from an already-active EXISTING_AGREEMENT_ID rather than creating a new agreement first. Use this pattern when you already have an agreement ID and want to replace it directly. Before running this sample, replace the placeholder constants below with values from your AWS Marketplace offers: - EXISTING_AGREEMENT_ID — the agreement ID of the active agreement to replace (starts with agmt-). - NEW_AGREEMENT_PROPOSAL_IDENTIFIER — the agreementProposalId from the new ABO offer. - Term IDs (starting with term-) — found in the new offer's term list. """ import boto3 from utils.agreement_api_utils import generate_client_token class ReplaceSaaSContractWithAgreementBasedOffer: # The agreement ID of the active SaaS agreement with CONTRACT pricing model to replace (starts with "agmt-"). EXISTING_AGREEMENT_ID = "<your-existing-agreement-id>" # The agreementProposalId from the new Agreement-Based Offer. NEW_AGREEMENT_PROPOSAL_IDENTIFIER = "<your-new-agreement-proposal-identifier>" # Term ID for the LegalTerm in the new offer. LEGAL_TERM_ID = "<your-legal-term-id>" # Term ID for the ValidityTerm in the new offer. VALIDITY_TERM_ID = "<your-validity-term-id>" # Term ID for the FixedUpfrontPricingTerm in the new offer. FIXED_UPFRONT_PRICING_TERM_ID = "<your-fixed-upfront-pricing-term-id>" # Term ID for the PaymentScheduleTerm in the new offer. PAYMENT_SCHEDULE_TERM_ID = "<your-payment-schedule-term-id>" @staticmethod def replace_existing_agreement(): """ Replace an existing SaaS agreement with CONTRACT pricing model with a new Agreement-Based Offer. Uses Intent.REPLACE with sourceAgreementIdentifier set to the existing agreement ID. """ client = boto3.client("marketplace-agreement") cls = ReplaceSaaSContractWithAgreementBasedOffer legal_term = {"id": cls.LEGAL_TERM_ID} validity_term = {"id": cls.VALIDITY_TERM_ID} fixed_upfront_pricing_term = {"id": cls.FIXED_UPFRONT_PRICING_TERM_ID} payment_schedule_term = {"id": cls.PAYMENT_SCHEDULE_TERM_ID} # Replace the agreement with the new offer create_response = client.create_agreement_request( clientToken=generate_client_token(), intent="REPLACE", requestedTerms=[fixed_upfront_pricing_term, payment_schedule_term, legal_term, validity_term], agreementProposalIdentifier=cls.NEW_AGREEMENT_PROPOSAL_IDENTIFIER, sourceAgreementIdentifier=cls.EXISTING_AGREEMENT_ID, ) agreement_request_id = create_response["agreementRequestId"] print("Replace agreement request created. AgreementRequestId: " + agreement_request_id) accept_response = client.accept_agreement_request( agreementRequestId=agreement_request_id ) print("Agreement replaced with ABO. New AgreementId: " + accept_response["agreementId"]) if __name__ == "__main__": ReplaceSaaSContractWithAgreementBasedOffer.replace_existing_agreement()-
有关 API 的详细信息,请参阅适用CreateAgreementRequest于 Python 的AWS SDK (Boto3) API 参考。
-
拒绝协议付款请求
将 SaaS 免费试用版替换为 “消费定价合同”