文档 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.ConfigurableUpfrontPricingTermConfiguration; import software.amazon.awssdk.services.marketplaceagreement.model.CreateAgreementRequestRequest; import software.amazon.awssdk.services.marketplaceagreement.model.CreateAgreementRequestResponse; import software.amazon.awssdk.services.marketplaceagreement.model.Dimension; import software.amazon.awssdk.services.marketplaceagreement.model.Intent; import software.amazon.awssdk.services.marketplaceagreement.model.RequestedTerm; import software.amazon.awssdk.services.marketplaceagreement.model.RequestedTermConfiguration; import software.amazon.awssdk.services.marketplaceagreement.model.TaxConfiguration; import utils.AgreementApiUtils; /** * Demonstrates how to create a SaaS agreement with CONTRACT pricing model with upfront payment * using the AWS Marketplace Agreement Service APIs. * * <p>Scenario: A buyer subscribes to a SaaS product using a ConfigurableUpfrontPricingTerm, * selecting an agreement duration and specifying quantities for multiple dimensions. * Tax estimation is enabled at the time of agreement creation. * * <p>Before running this sample, replace the placeholder constants below with values from * your AWS Marketplace offer: * <ul> * <li>{@code AGREEMENT_PROPOSAL_IDENTIFIER} — the agreementProposalId from the offer.</li> * <li>Term IDs (starting with {@code term-}) — found in the offer's term list.</li> * <li>{@code SELECTOR_VALUE} — duration for the agreement (e.g., {@code P12M} for 12 months).</li> * <li>{@code DIMENSION_1_KEY}, {@code DIMENSION_2_KEY} — dimension keys defined in the offer.</li> * <li>{@code DIMENSION_1_VALUE}, {@code DIMENSION_2_VALUE} — quantities for each dimension.</li> * </ul> */ public class NewSaaSContractWithUpfrontPayment { // The agreementProposalId from the offer. private static final String AGREEMENT_PROPOSAL_IDENTIFIER = "<your-agreement-proposal-identifier>"; // Term ID for the ConfigurableUpfrontPricingTerm in your offer. private static final String CONFIGURABLE_UPFRONT_PRICING_TERM_ID = "<your-configurable-upfront-pricing-term-id>"; // Duration for the agreement (e.g., "P12M" for 12 months). private static final String SELECTOR_VALUE = "<your-selector-value>"; // First dimension key and quantity defined in your offer. private static final String DIMENSION_1_KEY = "<your-dimension-1-key>"; private static final int DIMENSION_1_VALUE = 10; // Second dimension key and quantity defined in your offer. private static final String DIMENSION_2_KEY = "<your-dimension-2-key>"; private static final int DIMENSION_2_VALUE = 20; // Term ID for the LegalTerm in your offer. private static final String LEGAL_TERM_ID = "<your-legal-term-id>"; // Tax estimation setting: "ENABLED" to include estimated taxes in the agreement. private static final String TAX_ESTIMATION = "ENABLED"; public static void main(String[] args) { createSaaSContractAgreement(); } /** * Creates a SaaS agreement with CONTRACT pricing model with configurable upfront pricing * for multiple dimensions and tax estimation. */ private static void createSaaSContractAgreement() { MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); RequestedTerm configurableUpfrontPricingTerm = RequestedTerm.builder() .id(CONFIGURABLE_UPFRONT_PRICING_TERM_ID) .configuration(RequestedTermConfiguration.fromConfigurableUpfrontPricingTermConfiguration( ConfigurableUpfrontPricingTermConfiguration.builder() .selectorValue(SELECTOR_VALUE) .dimensions(Dimension.builder() .dimensionKey(DIMENSION_1_KEY) .dimensionValue(DIMENSION_1_VALUE) .build(), Dimension.builder() .dimensionKey(DIMENSION_2_KEY) .dimensionValue(DIMENSION_2_VALUE) .build()) .build())) .build(); RequestedTerm legalTerm = RequestedTerm.builder() .id(LEGAL_TERM_ID) .build(); CreateAgreementRequestRequest createAgreementRequestRequest = CreateAgreementRequestRequest.builder() .clientToken(AgreementApiUtils.generateClientToken()) .intent(Intent.NEW) .requestedTerms(configurableUpfrontPricingTerm, legalTerm) .taxConfiguration(TaxConfiguration.builder().taxEstimation(TAX_ESTIMATION).build()) .agreementProposalIdentifier(AGREEMENT_PROPOSAL_IDENTIFIER) .build(); CreateAgreementRequestResponse createAgreementRequestResponse = marketplaceAgreementClient.createAgreementRequest(createAgreementRequestRequest); System.out.println("Agreement request created. AgreementRequestId: " + createAgreementRequestResponse.agreementRequestId()); AcceptAgreementRequestRequest acceptAgreementRequestRequest = AcceptAgreementRequestRequest.builder() .agreementRequestId(createAgreementRequestResponse.agreementRequestId()) .build(); AcceptAgreementRequestResponse acceptAgreementRequestResponse = marketplaceAgreementClient.acceptAgreementRequest(acceptAgreementRequestRequest); System.out.println("SaaS agreement request with CONTRACT pricing model accepted. 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 create a SaaS agreement with CONTRACT pricing model with upfront payment * using the AWS Marketplace Agreement Service APIs. * * Scenario: A buyer subscribes to a SaaS product using a ConfigurableUpfrontPricingTerm, * selecting an agreement duration and specifying quantities for multiple dimensions. * Tax estimation is enabled at the time of agreement creation. * * Before running this sample, replace the placeholder constants below with values from * your AWS Marketplace offer: * - AGREEMENT_PROPOSAL_IDENTIFIER — the agreementProposalId from the offer. * - Term IDs (starting with "term-") — found in the offer's term list. * - SELECTOR_VALUE — duration for the agreement (e.g., "P12M" for 12 months). * - DIMENSION_1_KEY, DIMENSION_2_KEY — dimension keys defined in the offer. * - DIMENSION_1_VALUE, DIMENSION_2_VALUE — quantities for each dimension. */ // The agreementProposalId from the offer. const AGREEMENT_PROPOSAL_IDENTIFIER = "<your-agreement-proposal-identifier>"; // Term ID for the ConfigurableUpfrontPricingTerm in your offer. const CONFIGURABLE_UPFRONT_PRICING_TERM_ID = "<your-configurable-upfront-pricing-term-id>"; // Duration for the agreement (e.g., "P12M" for 12 months). const SELECTOR_VALUE = "<your-selector-value>"; // First dimension key and quantity defined in your offer. const DIMENSION_1_KEY = "<your-dimension-1-key>"; const DIMENSION_1_VALUE = 10; // Second dimension key and quantity defined in your offer. const DIMENSION_2_KEY = "<your-dimension-2-key>"; const DIMENSION_2_VALUE = 20; // Term ID for the LegalTerm in your offer. const LEGAL_TERM_ID = "<your-legal-term-id>"; // Tax estimation setting: "ENABLED" to include estimated taxes in the agreement. const TAX_ESTIMATION = "ENABLED"; /** * Creates a SaaS agreement with CONTRACT pricing model with configurable upfront pricing * for multiple dimensions and tax estimation. */ async function createSaaSContractAgreement() { const client = new MarketplaceAgreementClient(); const configurableUpfrontPricingTerm = { id: CONFIGURABLE_UPFRONT_PRICING_TERM_ID, configuration: { configurableUpfrontPricingTermConfiguration: { selectorValue: SELECTOR_VALUE, dimensions: [ { dimensionKey: DIMENSION_1_KEY, dimensionValue: DIMENSION_1_VALUE }, { dimensionKey: DIMENSION_2_KEY, dimensionValue: DIMENSION_2_VALUE }, ], }, }, }; const legalTerm = { id: LEGAL_TERM_ID }; const createAgreementRequestResponse = await client.send( new CreateAgreementRequestCommand({ clientToken: generateClientToken(), intent: "NEW", requestedTerms: [configurableUpfrontPricingTerm, legalTerm], taxConfiguration: { taxEstimation: TAX_ESTIMATION }, agreementProposalIdentifier: AGREEMENT_PROPOSAL_IDENTIFIER, }) ); console.log("Agreement request created. AgreementRequestId: " + createAgreementRequestResponse.agreementRequestId); const acceptAgreementRequestResponse = await client.send( new AcceptAgreementRequestCommand({ agreementRequestId: createAgreementRequestResponse.agreementRequestId, }) ); console.log("SaaS agreement request with CONTRACT pricing model accepted. AgreementId: " + acceptAgreementRequestResponse.agreementId); } createSaaSContractAgreement();-
有关 API 的详细信息,请参阅 AWS SDK for JavaScript API 参考CreateAgreementRequest中的。
-
- Python
-
- 适用于 Python 的 SDK(Boto3)
-
注意
还有更多相关信息 GitHub。在 AWS Marketplace API Reference Code Library
存储库中查找完整示例,了解如何进行设置和运行。 """ Demonstrates how to create a SaaS agreement with CONTRACT pricing model with upfront payment using the AWS Marketplace Agreement Service APIs. Scenario: A buyer subscribes to a SaaS product using a ConfigurableUpfrontPricingTerm, selecting an agreement duration and specifying quantities for multiple dimensions. Tax estimation is enabled at the time of agreement creation. Before running this sample, replace the placeholder constants below with values from your AWS Marketplace offer: - AGREEMENT_PROPOSAL_IDENTIFIER — the agreementProposalId from the offer. - Term IDs (starting with term-) — found in the offer's term list. - SELECTOR_VALUE — duration for the agreement (e.g., P12M for 12 months). - DIMENSION_1_KEY, DIMENSION_2_KEY — dimension keys defined in the offer. - DIMENSION_1_VALUE, DIMENSION_2_VALUE — quantities for each dimension. """ import boto3 from utils.agreement_api_utils import generate_client_token class NewSaaSContractWithUpfrontPayment: # The agreementProposalId from the offer. AGREEMENT_PROPOSAL_IDENTIFIER = "<your-agreement-proposal-identifier>" # Term ID for the ConfigurableUpfrontPricingTerm in your offer. CONFIGURABLE_UPFRONT_PRICING_TERM_ID = "<your-configurable-upfront-pricing-term-id>" # Duration for the agreement (e.g., "P12M" for 12 months). SELECTOR_VALUE = "<your-selector-value>" # First dimension key and quantity defined in your offer. DIMENSION_1_KEY = "<your-dimension-1-key>" DIMENSION_1_VALUE = 10 # Second dimension key and quantity defined in your offer. DIMENSION_2_KEY = "<your-dimension-2-key>" DIMENSION_2_VALUE = 20 # Term ID for the LegalTerm in your offer. LEGAL_TERM_ID = "<your-legal-term-id>" # Tax estimation setting: "ENABLED" to include estimated taxes in the agreement. TAX_ESTIMATION = "ENABLED" @staticmethod def create_saas_contract_agreement(): """ Create a SaaS agreement with CONTRACT pricing model with configurable upfront pricing for multiple dimensions and tax estimation. """ client = boto3.client("marketplace-agreement") configurable_upfront_pricing_term = { "id": NewSaaSContractWithUpfrontPayment.CONFIGURABLE_UPFRONT_PRICING_TERM_ID, "configuration": { "configurableUpfrontPricingTermConfiguration": { "selectorValue": NewSaaSContractWithUpfrontPayment.SELECTOR_VALUE, "dimensions": [ { "dimensionKey": NewSaaSContractWithUpfrontPayment.DIMENSION_1_KEY, "dimensionValue": NewSaaSContractWithUpfrontPayment.DIMENSION_1_VALUE, }, { "dimensionKey": NewSaaSContractWithUpfrontPayment.DIMENSION_2_KEY, "dimensionValue": NewSaaSContractWithUpfrontPayment.DIMENSION_2_VALUE, }, ], } }, } legal_term = {"id": NewSaaSContractWithUpfrontPayment.LEGAL_TERM_ID} create_response = client.create_agreement_request( clientToken=generate_client_token(), intent="NEW", requestedTerms=[configurable_upfront_pricing_term, legal_term], taxConfiguration={"taxEstimation": NewSaaSContractWithUpfrontPayment.TAX_ESTIMATION}, agreementProposalIdentifier=NewSaaSContractWithUpfrontPayment.AGREEMENT_PROPOSAL_IDENTIFIER, ) agreement_request_id = create_response["agreementRequestId"] print("Agreement request created. AgreementRequestId: " + agreement_request_id) accept_response = client.accept_agreement_request( agreementRequestId=agreement_request_id ) print( "SaaS agreement request with CONTRACT pricing model accepted. AgreementId: " + accept_response["agreementId"] ) if __name__ == "__main__": NewSaaSContractWithUpfrontPayment.create_saas_contract_agreement()-
有关 API 的详细信息,请参阅适用CreateAgreementRequest于 Python 的AWS SDK (Boto3) API 参考。
-
创建新的 AMI 免费试用协议
获取所有协议 ID