Skip to content

create_subscription_checkout_session async

create_subscription_checkout_session(
    app_id: AppId,
    user_id: UserId,
    return_url: Url,
    refresh_url: Url,
    scope: RequestScope,
    *,
    config_overrides: Optional[AsyncAppMonetizationClientConfig] = None,
    plan_id: Optional[PlanId] = None,
    session_duration_seconds: Optional[SessionDurationSeconds] = None,
    client_token: Optional[ClientToken] = None,
) -> CreateSubscriptionCheckoutSessionResponse

Subscribes a user to a plan or changes the user's current plan. The response returns exactly one outcome: payment is required (a checkout URL is returned), payment is not required (an effective date is returned), or, when no plan identifier is provided, plan selection is required (the hosted pricing page URL is returned). To make a one-time purchase of usage packs or add-ons, use CreateOneTimeCheckoutSession.

Parameters:

  • app_id (AppId) –

    The ID of the app the subscription is for.

  • user_id (UserId) –

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

  • plan_id (Optional[PlanId], default: None ) –

    The plan to subscribe to or change to. Absent to open the hosted pricing page for the buyer to choose; the response then carries planSelectionRequired.pricingUrl.

  • return_url (Url) –

    The URL the buyer's browser is sent to after they complete payment at checkout. If the buyer is sent to a hosted checkout page, this is that page's success-redirect target. If you omit planId, the buyer chooses a plan on a hosted pricing page. After that checkout, the buyer returns to the hosted pages, not to this URL.

  • refresh_url (Url) –

    The URL the buyer's browser is sent to if they cancel or abandon the hosted checkout page without completing payment (the checkout page's cancel-redirect target). Point it at a page where the buyer can retry. If you omit planId, the buyer chooses a plan on a hosted pricing page. After that checkout, the buyer returns to the hosted pages, not to this URL.

  • session_duration_seconds (Optional[SessionDurationSeconds], default: None ) –

    The lifetime of the hosted session, in seconds, counted from this call. Omit to use the service default. It does not set how long pricingUrl works; see expiresAt.

  • 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_subscription_checkout_session(
    self,
    app_id: "capo_appmonetization.types.app_id.AppId",
    user_id: "capo_appmonetization.types.user_id.UserId",
    return_url: "capo_appmonetization.types.url.Url",
    refresh_url: "capo_appmonetization.types.url.Url",
    scope: "capo_appmonetization.types.request_scope.RequestScope",
    *,
    config_overrides: Optional[AsyncAppMonetizationClientConfig] = None,
    plan_id: Optional["capo_appmonetization.types.plan_id.PlanId"] = None,
    session_duration_seconds: Optional[
        "capo_appmonetization.types.session_duration_seconds.SessionDurationSeconds"
    ] = None,
    client_token: Optional[
        "capo_appmonetization.types.client_token.ClientToken"
    ] = None,
) -> "capo_appmonetization.types.create_subscription_checkout_session_response.CreateSubscriptionCheckoutSessionResponse":
    """Subscribes a user to a plan or changes the user's current plan. The response returns exactly one outcome: payment is required (a checkout URL is returned), payment is not required (an effective date is returned), or, when no plan identifier is provided, plan selection is required (the hosted pricing page URL is returned). To make a one-time purchase of usage packs or add-ons, use CreateOneTimeCheckoutSession.

    Args:
        app_id: The ID of the app the subscription is for.
        user_id: The ID of the end user being subscribed. Do not include personally identifiable or otherwise sensitive data in this value.
        plan_id: The plan to subscribe to or change to. Absent to open the hosted pricing page for the buyer to choose; the response then carries planSelectionRequired.pricingUrl.
        return_url: The URL the buyer's browser is sent to after they complete payment at checkout. If the buyer is sent to a hosted checkout page, this is that page's success-redirect target. If you omit `planId`, the buyer chooses a plan on a hosted pricing page. After that checkout, the buyer returns to the hosted pages, not to this URL.
        refresh_url: The URL the buyer's browser is sent to if they cancel or abandon the hosted checkout page without completing payment (the checkout page's cancel-redirect target). Point it at a page where the buyer can retry. If you omit `planId`, the buyer chooses a plan on a hosted pricing page. After that checkout, the buyer returns to the hosted pages, not to this URL.
        session_duration_seconds: The lifetime of the hosted session, in seconds, counted from this call. Omit to use the service default. It does not set how long pricingUrl works; see expiresAt.
        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_subscription_checkout_session_request.CreateSubscriptionCheckoutSessionRequest]",
    ) -> AsyncOperationResponse[
        "capo_appmonetization.types.create_subscription_checkout_session_response.CreateSubscriptionCheckoutSessionResponse"
    ]:
        import capo_appmonetization._operations.aws_monetization_ai_front_end.create_subscription_checkout_session

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

    def _redact_output(
        output: "capo_appmonetization.types.create_subscription_checkout_session_response.CreateSubscriptionCheckoutSessionResponse",
    ) -> dict[str, Any]:
        import capo_appmonetization.types.create_subscription_checkout_session_response

        return capo_appmonetization.types.create_subscription_checkout_session_response.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "CreateSubscriptionCheckoutSession", redact_output=_redact_output
        ),
    )
    input_: capo_appmonetization.types.create_subscription_checkout_session_request.CreateSubscriptionCheckoutSessionRequest = {
        "app_id": app_id,
        "user_id": user_id,
        "return_url": return_url,
        "refresh_url": refresh_url,
        "scope": scope,
    }
    if plan_id is not None:
        input_["plan_id"] = plan_id
    if session_duration_seconds is not None:
        input_["session_duration_seconds"] = session_duration_seconds
    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