文档 AWS SDK 示例 GitHub 存储库中还有更多 S AWS DK 示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
将 SaaS 免费试用版替换为 “消费定价合同”,使用 AWS SDK
以下代码示例演示如何将 SaaS 免费试用版替换为消费定价合同 (CCP)。
- 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.GetAgreementEntitlementsResponse; import software.amazon.awssdk.services.marketplaceagreement.model.Intent; import software.amazon.awssdk.services.marketplaceagreement.model.RequestedTerm; import utils.AgreementApiUtils; /** * Demonstrates how to create a SaaS free trial agreement and then replace it with a * paid Contract with Consumption Pricing (CCP) offer using the AWS Marketplace Agreement Service APIs. * * <p>Scenario: A buyer first starts a free trial on a SaaS product. Once the trial is active, * they decide to convert by replacing it with a paid offer that includes a * FixedUpfrontPricingTerm, PaymentScheduleTerm, and UsageBasedPricingTerm. * * <p>Flow: * <ol> * <li>Create a SaaS free trial agreement with freeTrialPricingTerm.</li> * <li>Wait for freeTrialPricingTerm agreement entitlements to become active.</li> * <li>Replace the free trial agreement with the paid CCP offer using Intent.REPLACE.</li> * </ol> * * <p>Before running this sample, replace the placeholder constants below with values from * your AWS Marketplace offers: * <ul> * <li>{@code AGREEMENT_PROPOSAL_IDENTIFIER} — the agreementProposalId from the free trial offer.</li> * <li>{@code NEW_AGREEMENT_PROPOSAL_IDENTIFIER} — the agreementProposalId from the paid CCP offer.</li> * <li>Term IDs (starting with {@code term-}) — found in each offer's term list.</li> * </ul> */ public class ReplaceSaaSFreeTrialWithCCP { // The agreementProposalId from the free trial offer. private static final String AGREEMENT_PROPOSAL_IDENTIFIER = "<your-free-trial-agreement-proposal-identifier>"; // Term ID for the FreeTrialPricingTerm in the free trial offer. private static final String FREE_TRIAL_PRICING_TERM_ID = "<your-free-trial-pricing-term-id>"; // Term ID for the LegalTerm in the free trial offer. private static final String LEGAL_TERM_ID = "<your-legal-term-id>"; // The agreementProposalId from the paid CCP offer to convert to. private static final String NEW_AGREEMENT_PROPOSAL_IDENTIFIER = "<your-ccp-agreement-proposal-identifier>"; // Term ID for the FixedUpfrontPricingTerm in the CCP offer. private static final String FIXED_UPFRONT_PRICING_TERM_ID = "<your-fixed-upfront-pricing-term-id>"; // Term ID for the PaymentScheduleTerm in the CCP offer. private static final String PAYMENT_SCHEDULE_TERM_ID = "<your-payment-schedule-term-id>"; // Term ID for the UsageBasedPricingTerm in the CCP offer. private static final String USAGE_BASED_PRICING_TERM_ID = "<your-usage-based-pricing-term-id>"; // Term ID for the ValidityTerm in the CCP offer. private static final String VALIDITY_TERM_ID = "<your-validity-term-id>"; // Term ID for the LegalTerm in the CCP offer. private static final String NEW_LEGAL_TERM_ID = "<your-new-legal-term-id>"; public static void main(String[] args) { createSaaSFreeTrialAndReplaceWithCCP(); } /** * Full end-to-end flow: * 1. Create a SaaS free trial agreement with freeTrialPricingTerm. * 2. Wait for freeTrialPricingTerm agreement entitlements to become active. * 3. Replace the free trial agreement with the paid CCP offer. */ private static void createSaaSFreeTrialAndReplaceWithCCP() { MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); RequestedTerm legalTerm = RequestedTerm.builder().id(LEGAL_TERM_ID).build(); RequestedTerm freeTrialPricingTerm = RequestedTerm.builder().id(FREE_TRIAL_PRICING_TERM_ID).build(); // --- Step 1: Agreement with freeTrialPricingTerm --- CreateAgreementRequestRequest createAgreementRequestRequest = CreateAgreementRequestRequest.builder() .clientToken(AgreementApiUtils.generateClientToken()) .intent(Intent.NEW) .requestedTerms(freeTrialPricingTerm, legalTerm) .agreementProposalIdentifier(AGREEMENT_PROPOSAL_IDENTIFIER) .build(); CreateAgreementRequestResponse createAgreementRequestResponse = marketplaceAgreementClient.createAgreementRequest(createAgreementRequestRequest); System.out.println("Agreement request with freeTrialPricingTerm created. AgreementRequestId: " + createAgreementRequestResponse.agreementRequestId()); AcceptAgreementRequestRequest acceptAgreementRequestRequest = AcceptAgreementRequestRequest.builder() .agreementRequestId(createAgreementRequestResponse.agreementRequestId()) .build(); AcceptAgreementRequestResponse acceptAgreementRequestResponse = marketplaceAgreementClient.acceptAgreementRequest(acceptAgreementRequestRequest); System.out.println("Agreement request with freeTrialPricingTerm accepted. AgreementId: " + acceptAgreementRequestResponse.agreementId()); // Wait for freeTrialPricingTerm agreement entitlements to become active before replacing. System.out.println("Waiting for freeTrialPricingTerm agreement entitlements to become active..."); GetAgreementEntitlementsResponse entitlementsResponse = AgreementApiUtils.pollUntilEntitlementsAvailable( marketplaceAgreementClient, acceptAgreementRequestResponse.agreementId()); System.out.println("freeTrialPricingTerm agreement entitlements are now active."); AgreementApiUtils.formatOutput(entitlementsResponse); // --- Step 2: Replace Agreement with freeTrialPricingTerm with Paid CCP Offer --- // Use Intent.REPLACE and sourceAgreementIdentifier to replace the free trial agreement. RequestedTerm usageBasedPricingTerm = RequestedTerm.builder().id(USAGE_BASED_PRICING_TERM_ID).build(); RequestedTerm fixedUpfrontPricingTerm = RequestedTerm.builder().id(FIXED_UPFRONT_PRICING_TERM_ID).build(); RequestedTerm paymentScheduleTerm = RequestedTerm.builder().id(PAYMENT_SCHEDULE_TERM_ID).build(); RequestedTerm validityTerm = RequestedTerm.builder().id(VALIDITY_TERM_ID).build(); RequestedTerm newLegalTerm = RequestedTerm.builder().id(NEW_LEGAL_TERM_ID).build(); CreateAgreementRequestRequest carRequest = CreateAgreementRequestRequest.builder() .clientToken(AgreementApiUtils.generateClientToken()) .intent(Intent.REPLACE) .requestedTerms(usageBasedPricingTerm, fixedUpfrontPricingTerm, paymentScheduleTerm, validityTerm, newLegalTerm) .agreementProposalIdentifier(NEW_AGREEMENT_PROPOSAL_IDENTIFIER) .sourceAgreementIdentifier(acceptAgreementRequestResponse.agreementId()) .build(); CreateAgreementRequestResponse carResponse = marketplaceAgreementClient.createAgreementRequest(carRequest); System.out.println("Replace agreement request created. AgreementRequestId: " + carResponse.agreementRequestId()); AcceptAgreementRequestRequest aarRequest = AcceptAgreementRequestRequest.builder() .agreementRequestId(carResponse.agreementRequestId()) .build(); AcceptAgreementRequestResponse aarResponse = marketplaceAgreementClient.acceptAgreementRequest(aarRequest); System.out.println("Agreement with freeTrialPricingTerm replaced with paid CCP offer. New AgreementId: " + aarResponse.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, formatOutput, pollUntilEntitlementsAvailable } = require("./utils/AgreementApiUtils"); /** * Demonstrates how to create a SaaS free trial agreement and then replace it with a * paid Contract with Consumption Pricing (CCP) offer using the AWS Marketplace Agreement Service APIs. * * Scenario: A buyer first starts a free trial on a SaaS product. Once the trial is active, * they decide to convert by replacing it with a paid offer that includes a * FixedUpfrontPricingTerm, PaymentScheduleTerm, and UsageBasedPricingTerm. * * Flow: * 1. Create a SaaS free trial agreement with freeTrialPricingTerm. * 2. Wait for freeTrialPricingTerm agreement entitlements to become active. * 3. Replace the free trial agreement with the paid CCP offer using Intent.REPLACE. * * Before running this sample, replace the placeholder constants below with values from * your AWS Marketplace offers: * - AGREEMENT_PROPOSAL_IDENTIFIER — the agreementProposalId from the free trial offer. * - NEW_AGREEMENT_PROPOSAL_IDENTIFIER — the agreementProposalId from the paid CCP offer. * - Term IDs (starting with "term-") — found in each offer's term list. */ // The agreementProposalId from the free trial offer. const AGREEMENT_PROPOSAL_IDENTIFIER = "<your-free-trial-agreement-proposal-identifier>"; // Term ID for the FreeTrialPricingTerm in the free trial offer. const FREE_TRIAL_PRICING_TERM_ID = "<your-free-trial-pricing-term-id>"; // Term ID for the LegalTerm in the free trial offer. const LEGAL_TERM_ID = "<your-legal-term-id>"; // The agreementProposalId from the paid CCP offer to convert to. const NEW_AGREEMENT_PROPOSAL_IDENTIFIER = "<your-ccp-agreement-proposal-identifier>"; // Term ID for the FixedUpfrontPricingTerm in the CCP offer. const FIXED_UPFRONT_PRICING_TERM_ID = "<your-fixed-upfront-pricing-term-id>"; // Term ID for the PaymentScheduleTerm in the CCP offer. const PAYMENT_SCHEDULE_TERM_ID = "<your-payment-schedule-term-id>"; // Term ID for the UsageBasedPricingTerm in the CCP offer. const USAGE_BASED_PRICING_TERM_ID = "<your-usage-based-pricing-term-id>"; // Term ID for the ValidityTerm in the CCP offer. const VALIDITY_TERM_ID = "<your-validity-term-id>"; // Term ID for the LegalTerm in the CCP offer. const NEW_LEGAL_TERM_ID = "<your-new-legal-term-id>"; /** * Full end-to-end flow: * 1. Create a SaaS free trial agreement with freeTrialPricingTerm. * 2. Wait for freeTrialPricingTerm agreement entitlements to become active. * 3. Replace the free trial agreement with the paid CCP offer. */ async function createSaaSFreeTrialAndReplaceWithCCP() { const client = new MarketplaceAgreementClient(); const legalTerm = { id: LEGAL_TERM_ID }; const freeTrialPricingTerm = { id: FREE_TRIAL_PRICING_TERM_ID }; // --- Step 1: Agreement with freeTrialPricingTerm --- const createAgreementRequestResponse = await client.send( new CreateAgreementRequestCommand({ clientToken: generateClientToken(), intent: "NEW", requestedTerms: [freeTrialPricingTerm, legalTerm], agreementProposalIdentifier: AGREEMENT_PROPOSAL_IDENTIFIER, }) ); console.log("Agreement request with freeTrialPricingTerm created. AgreementRequestId: " + createAgreementRequestResponse.agreementRequestId); const acceptAgreementRequestResponse = await client.send( new AcceptAgreementRequestCommand({ agreementRequestId: createAgreementRequestResponse.agreementRequestId, }) ); console.log("Agreement request with freeTrialPricingTerm accepted. AgreementId: " + acceptAgreementRequestResponse.agreementId); // Wait for freeTrialPricingTerm agreement entitlements to become active before replacing. console.log("Waiting for freeTrialPricingTerm agreement entitlements to become active..."); const entitlementsResponse = await pollUntilEntitlementsAvailable(client, acceptAgreementRequestResponse.agreementId); console.log("freeTrialPricingTerm agreement entitlements are now active."); formatOutput(entitlementsResponse); // --- Step 2: Replace Agreement with freeTrialPricingTerm with Paid CCP Offer --- // Use Intent.REPLACE and sourceAgreementIdentifier to replace the free trial agreement. const usageBasedPricingTerm = { id: USAGE_BASED_PRICING_TERM_ID }; const fixedUpfrontPricingTerm = { id: FIXED_UPFRONT_PRICING_TERM_ID }; const paymentScheduleTerm = { id: PAYMENT_SCHEDULE_TERM_ID }; const validityTerm = { id: VALIDITY_TERM_ID }; const newLegalTerm = { id: NEW_LEGAL_TERM_ID }; const carResponse = await client.send( new CreateAgreementRequestCommand({ clientToken: generateClientToken(), intent: "REPLACE", requestedTerms: [usageBasedPricingTerm, fixedUpfrontPricingTerm, paymentScheduleTerm, validityTerm, newLegalTerm], agreementProposalIdentifier: NEW_AGREEMENT_PROPOSAL_IDENTIFIER, sourceAgreementIdentifier: acceptAgreementRequestResponse.agreementId, }) ); console.log("Replace agreement request created. AgreementRequestId: " + carResponse.agreementRequestId); const aarResponse = await client.send( new AcceptAgreementRequestCommand({ agreementRequestId: carResponse.agreementRequestId, }) ); console.log("Agreement with freeTrialPricingTerm replaced with paid CCP offer. New AgreementId: " + aarResponse.agreementId); } createSaaSFreeTrialAndReplaceWithCCP();-
有关 API 的详细信息,请参阅 适用于 JavaScript 的 AWS SDK API 参考CreateAgreementRequest中的。
-
- Python
-
- 适用于 Python 的 SDK(Boto3)
-
注意
还有更多相关信息 GitHub。在 AWS Marketplace API Reference Code Library
存储库中查找完整示例,了解如何进行设置和运行。 """ Demonstrates how to create a SaaS free trial agreement and then replace it with a paid Contract with Consumption Pricing (CCP) offer using the AWS Marketplace Agreement Service APIs. Scenario: A buyer first starts a free trial on a SaaS product. Once the trial is active, they decide to convert by replacing it with a paid offer that includes a FixedUpfrontPricingTerm, PaymentScheduleTerm, and UsageBasedPricingTerm. Flow: 1. Create a SaaS free trial agreement with freeTrialPricingTerm. 2. Wait for freeTrialPricingTerm agreement entitlements to become active. 3. Replace the free trial agreement with the paid CCP offer using Intent.REPLACE. Before running this sample, replace the placeholder constants below with values from your AWS Marketplace offers: - AGREEMENT_PROPOSAL_IDENTIFIER — the agreementProposalId from the free trial offer. - NEW_AGREEMENT_PROPOSAL_IDENTIFIER — the agreementProposalId from the paid CCP offer. - Term IDs (starting with term-) — found in each offer's term list. """ import boto3 from utils.agreement_api_utils import ( format_output, generate_client_token, poll_until_entitlements_available, ) class ReplaceSaaSFreeTrialWithCCP: # The agreementProposalId from the free trial offer. AGREEMENT_PROPOSAL_IDENTIFIER = "<your-free-trial-agreement-proposal-identifier>" # Term ID for the FreeTrialPricingTerm in the free trial offer. FREE_TRIAL_PRICING_TERM_ID = "<your-free-trial-pricing-term-id>" # Term ID for the LegalTerm in the free trial offer. LEGAL_TERM_ID = "<your-legal-term-id>" # The agreementProposalId from the paid CCP offer to convert to. NEW_AGREEMENT_PROPOSAL_IDENTIFIER = "<your-ccp-agreement-proposal-identifier>" # Term ID for the FixedUpfrontPricingTerm in the CCP offer. FIXED_UPFRONT_PRICING_TERM_ID = "<your-fixed-upfront-pricing-term-id>" # Term ID for the PaymentScheduleTerm in the CCP offer. PAYMENT_SCHEDULE_TERM_ID = "<your-payment-schedule-term-id>" # Term ID for the UsageBasedPricingTerm in the CCP offer. USAGE_BASED_PRICING_TERM_ID = "<your-usage-based-pricing-term-id>" # Term ID for the ValidityTerm in the CCP offer. VALIDITY_TERM_ID = "<your-validity-term-id>" # Term ID for the LegalTerm in the CCP offer. NEW_LEGAL_TERM_ID = "<your-new-legal-term-id>" @staticmethod def create_saas_free_trial_and_replace_with_ccp(): """ Full end-to-end flow: 1. Create a SaaS free trial agreement with freeTrialPricingTerm. 2. Wait for freeTrialPricingTerm agreement entitlements to become active. 3. Replace the free trial agreement with the paid CCP offer. """ client = boto3.client("marketplace-agreement") cls = ReplaceSaaSFreeTrialWithCCP legal_term = {"id": cls.LEGAL_TERM_ID} free_trial_pricing_term = {"id": cls.FREE_TRIAL_PRICING_TERM_ID} # --- Step 1: Agreement with freeTrialPricingTerm --- create_response = client.create_agreement_request( clientToken=generate_client_token(), intent="NEW", requestedTerms=[free_trial_pricing_term, legal_term], agreementProposalIdentifier=cls.AGREEMENT_PROPOSAL_IDENTIFIER, ) agreement_request_id = create_response["agreementRequestId"] print("Agreement request with freeTrialPricingTerm created. AgreementRequestId: " + agreement_request_id) accept_response = client.accept_agreement_request( agreementRequestId=agreement_request_id ) agreement_id = accept_response["agreementId"] print("Agreement request with freeTrialPricingTerm accepted. AgreementId: " + agreement_id) # Wait for freeTrialPricingTerm agreement entitlements to become active before replacing. print("Waiting for freeTrialPricingTerm agreement entitlements to become active...") entitlements_response = poll_until_entitlements_available(client, agreement_id) print("freeTrialPricingTerm agreement entitlements are now active.") format_output(entitlements_response) # --- Step 2: Replace Agreement with freeTrialPricingTerm with Paid CCP Offer --- # Use Intent.REPLACE and sourceAgreementIdentifier to replace the free trial agreement. usage_based_pricing_term = {"id": cls.USAGE_BASED_PRICING_TERM_ID} fixed_upfront_pricing_term = {"id": cls.FIXED_UPFRONT_PRICING_TERM_ID} payment_schedule_term = {"id": cls.PAYMENT_SCHEDULE_TERM_ID} validity_term = {"id": cls.VALIDITY_TERM_ID} new_legal_term = {"id": cls.NEW_LEGAL_TERM_ID} car_response = client.create_agreement_request( clientToken=generate_client_token(), intent="REPLACE", requestedTerms=[ usage_based_pricing_term, fixed_upfront_pricing_term, payment_schedule_term, validity_term, new_legal_term, ], agreementProposalIdentifier=cls.NEW_AGREEMENT_PROPOSAL_IDENTIFIER, sourceAgreementIdentifier=agreement_id, ) print("Replace agreement request created. AgreementRequestId: " + car_response["agreementRequestId"]) aar_response = client.accept_agreement_request( agreementRequestId=car_response["agreementRequestId"] ) print( "Agreement with freeTrialPricingTerm replaced with paid CCP offer. New AgreementId: " + aar_response["agreementId"] ) if __name__ == "__main__": ReplaceSaaSFreeTrialWithCCP.create_saas_free_trial_and_replace_with_ccp()-
有关 API 的详细信息,请参阅适用CreateAgreementRequest于 Python 的AWS SDK (Boto3) API 参考。
-
将 SaaS 合同协议替换为基于协议的报价
替换基于 SaaS 使用量的定价条款并取消之前的协议