Skip to content

create_one_time_checkout_session async

create_one_time_checkout_session(
    app_id: AppId,
    user_id: UserId,
    items: CheckoutItemList,
    return_url: Url,
    scope: RequestScope,
    *,
    config_overrides: Optional[AsyncAppMonetizationClientConfig] = None,
    client_token: Optional[ClientToken] = None,
) -> CreateOneTimeCheckoutSessionResponse

Creates a checkout session for a one-time purchase of usage packs or add-ons against the user's current subscription, or against the app when the user has no subscription. A one-time purchase always requires payment, so the response returns a checkout URL and a checkout session identifier. To subscribe a user to a plan or change the user's plan, use CreateSubscriptionCheckoutSession.

Parameters:

  • app_id (AppId) –

    The ID of the app the purchase is for.

  • user_id (UserId) –

    The ID of the end user making the purchase. Do not include personally identifiable or otherwise sensitive data in this value.

  • items (CheckoutItemList) –

    The purchasables to buy. Each line is a usage pack or add-on and the number of units to buy.

  • return_url (Url) –

    The URL the buyer's browser is sent to after they complete payment at checkout (the checkout page's success-redirect target). A one-time purchase always requires payment, so there is no cancel-redirect field on this operation.

  • client_token (Optional[ClientToken], default: None ) –

    A unique, case-sensitive identifier to ensure that the operation completes no more than one time. If this token matches a previous request, the service ignores the request but does not return an error.

  • scope (RequestScope) –

    Required. The environment: live or sandbox.

Raises:

Source code in docs_src/capo_appmonetization/_services/async_app_monetization.py
async def create_one_time_checkout_session(
    self,
    app_id: "capo_appmonetization.types.app_id.AppId",
    user_id: "capo_appmonetization.types.user_id.UserId",
    items: "capo_appmonetization.types.checkout_item_list.CheckoutItemList",
    return_url: "capo_appmonetization.types.url.Url",
    scope: "capo_appmonetization.types.request_scope.RequestScope",
    *,
    config_overrides: Optional[AsyncAppMonetizationClientConfig] = None,
    client_token: Optional[
        "capo_appmonetization.types.client_token.ClientToken"
    ] = None,
) -> "capo_appmonetization.types.create_one_time_checkout_session_response.CreateOneTimeCheckoutSessionResponse":
    """Creates a checkout session for a one-time purchase of usage packs or add-ons against the user's current subscription, or against the app when the user has no subscription. A one-time purchase always requires payment, so the response returns a checkout URL and a checkout session identifier. To subscribe a user to a plan or change the user's plan, use CreateSubscriptionCheckoutSession.

    Args:
        app_id: The ID of the app the purchase is for.
        user_id: The ID of the end user making the purchase. Do not include personally identifiable or otherwise sensitive data in this value.
        items: The purchasables to buy. Each line is a usage pack or add-on and the number of units to buy.
        return_url: The URL the buyer's browser is sent to after they complete payment at checkout (the checkout page's success-redirect target). A one-time purchase always requires payment, so there is no cancel-redirect field on this operation.
        client_token: A unique, case-sensitive identifier to ensure that the operation completes no more than one time. If this token matches a previous request, the service ignores the request but does not return an error.
        scope: Required. The environment: live or sandbox.

    Raises:
        capo_appmonetization.errors.access_denied_exception.AccessDeniedException: The caller does not have sufficient permission to perform this action.
        capo_appmonetization.errors.conflict_exception.ConflictException: The request conflicts with the current state of the resource, such as a duplicate identifier or a version mismatch. Retrieve the current state of the resource and retry the request.
        capo_appmonetization.errors.internal_server_exception.InternalServerException: An unexpected error occurred while processing the request.
        capo_appmonetization.errors.resource_not_found_exception.ResourceNotFoundException: The referenced resource does not exist.
        capo_appmonetization.errors.service_unavailable_exception.ServiceUnavailableException: The service is temporarily unavailable. Retry the request after the time in retryAfterSeconds.
        capo_appmonetization.errors.throttling_exception.ThrottlingException: The request was denied due to request throttling.
        capo_appmonetization.errors.validation_exception.ValidationException: The request failed input validation.
        capo_appmonetization.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_appmonetization.types.create_one_time_checkout_session_request.CreateOneTimeCheckoutSessionRequest]",
    ) -> AsyncOperationResponse[
        "capo_appmonetization.types.create_one_time_checkout_session_response.CreateOneTimeCheckoutSessionResponse"
    ]:
        import capo_appmonetization._operations.aws_monetization_ai_front_end.create_one_time_checkout_session

        (
            output,
            http_response,
        ) = await capo_appmonetization._operations.aws_monetization_ai_front_end.create_one_time_checkout_session.async_create_one_time_checkout_session(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateOneTimeCheckoutSession")
    )
    input_: capo_appmonetization.types.create_one_time_checkout_session_request.CreateOneTimeCheckoutSessionRequest = {
        "app_id": app_id,
        "user_id": user_id,
        "items": items,
        "return_url": return_url,
        "scope": scope,
    }
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output