Skip to content

create_billing_portal_session async

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

Opens the AWS App Monetization hosted customer billing portal for a user. This operation returns the billing portal URL that your application redirects the user's browser to. No state is persisted.

Parameters:

  • app_id (AppId) –

    The ID of the app the portal is for.

  • user_id (UserId) –

    The ID of the end user the portal is for. Do not include personally identifiable or otherwise sensitive data in this value.

  • return_url (Url) –

    A URL in your app. A plan checkout started from the portal doesn't redirect here: after payment, the buyer returns to the portal's My subscription page. Bound into the session and reused for every checkout the buyer launches from the portal.

  • refresh_url (Url) –

    A URL in your app. A plan checkout started from the portal doesn't redirect here: if the buyer cancels, they return to the portal's plans page. Bound into the session alongside returnUrl.

  • 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 billingPortalUrl 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_billing_portal_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,
    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_billing_portal_session_response.CreateBillingPortalSessionResponse":
    """Opens the AWS App Monetization hosted customer billing portal for a user. This operation returns the billing portal URL that your application redirects the user's browser to. No state is persisted.

    Args:
        app_id: The ID of the app the portal is for.
        user_id: The ID of the end user the portal is for. Do not include personally identifiable or otherwise sensitive data in this value.
        return_url: A URL in your app. A plan checkout started from the portal doesn't redirect here: after payment, the buyer returns to the portal's My subscription page. Bound into the session and reused for every checkout the buyer launches from the portal.
        refresh_url: A URL in your app. A plan checkout started from the portal doesn't redirect here: if the buyer cancels, they return to the portal's plans page. Bound into the session alongside returnUrl.
        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 billingPortalUrl 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.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.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_billing_portal_session_request.CreateBillingPortalSessionRequest]",
    ) -> AsyncOperationResponse[
        "capo_appmonetization.types.create_billing_portal_session_response.CreateBillingPortalSessionResponse"
    ]:
        import capo_appmonetization._operations.aws_monetization_ai_front_end.create_billing_portal_session

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

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

        return capo_appmonetization.types.create_billing_portal_session_response.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "CreateBillingPortalSession", redact_output=_redact_output
        ),
    )
    input_: capo_appmonetization.types.create_billing_portal_session_request.CreateBillingPortalSessionRequest = {
        "app_id": app_id,
        "user_id": user_id,
        "return_url": return_url,
        "refresh_url": refresh_url,
        "scope": scope,
    }
    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