AppMonetization / Client / create_subscription_checkout_session

create_subscription_checkout_session

AppMonetization.Client.create_subscription_checkout_session(**kwargs)

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.

See also: AWS API Documentation

Request Syntax

response = client.create_subscription_checkout_session(
    appId='string',
    userId='string',
    planId='string',
    returnUrl='string',
    refreshUrl='string',
    sessionDurationSeconds=123,
    clientToken='string',
    scope='sandbox'|'live'
)
Parameters:
  • appId (string) –

    [REQUIRED]

    The ID of the app the subscription is for.

  • userId (string) –

    [REQUIRED]

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

  • planId (string) – 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.

  • returnUrl (string) –

    [REQUIRED]

    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.

  • refreshUrl (string) –

    [REQUIRED]

    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.

  • sessionDurationSeconds (integer) – 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.

  • clientToken (string) –

    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.

    This field is autopopulated if not provided.

  • scope (string) –

    [REQUIRED]

    Required. The environment: live or sandbox.

Return type:

dict

Returns:

Response Syntax

{
    'outcome': {
        'paymentRequired': {
            'checkoutUrl': 'string',
            'expiresAt': datetime(2015, 1, 1)
        },
        'paymentNotRequired': {
            'effectiveAt': datetime(2015, 1, 1)
        },
        'planSelectionRequired': {
            'pricingUrl': 'string',
            'sessionToken': 'string',
            'expiresAt': datetime(2015, 1, 1)
        }
    }
}

Response Structure

  • (dict) –

    Output for CreateSubscriptionCheckoutSession.

    • outcome (dict) –

      The outcome of the request. Exactly one member of the union is set.

      Note

      This is a Tagged Union structure. Only one of the following top level keys will be set: paymentRequired, paymentNotRequired, planSelectionRequired. If a client receives an unknown member it will set SDK_UNKNOWN_MEMBER as the top level key, which maps to the name or tag of the unknown member. The structure of SDK_UNKNOWN_MEMBER is as follows:

      'SDK_UNKNOWN_MEMBER': {'name': 'UnknownMemberName'}
      
      • paymentRequired (dict) –

        The money must be collected (an upgrade with an amount due now, or a paid target that needs a card captured). Redirect the buyer to checkoutUrl.

        • checkoutUrl (string) –

          An absolute HTTP or HTTPS URL the buyer’s browser is redirected to in order to complete payment.

        • expiresAt (datetime) –

          The time when the checkout session expires.

      • paymentNotRequired (dict) –

        The plan change needs no payment: a scheduled downgrade (effectiveAt is the next period boundary) or a change applied immediately or a no-op (effectiveAt is now).

        • effectiveAt (datetime) –

          The instant the change takes effect: a future period boundary for a scheduled downgrade, or now for a change applied immediately or a no-op.

      • planSelectionRequired (dict) –

        The buyer must select a plan on the hosted pricing page at pricingUrl before checkout can proceed, because no planId was supplied.

        • pricingUrl (string) –

          A hosted pricing page URL that carries a session token or a single-use link in its fragment. The link works once, until expiresAt or the end of the session if sooner.

        • sessionToken (string) –

          The checkout session token carried in the fragment of pricingUrl. Absent when pricingUrl carries a single-use link instead.

        • expiresAt (datetime) –

          The time when the single-use link in pricingUrl expires, 10 minutes after it was created.

Exceptions