components:
  parameters:
    customerId:
      in: query
      name: customerId
      required: true
      schema:
        $ref: '#/components/schemas/Id'
    id:
      in: path
      name: id
      required: true
      schema:
        $ref: '#/components/schemas/Id'
    invitationId:
      in: path
      name: invitationId
      required: true
      schema:
        $ref: '#/components/schemas/Id'
    limit:
      in: query
      name: limit
      required: false
      schema:
        maxLength: 3
        pattern: ^[0-9]+$
        type: string
    nextToken:
      in: query
      name: nextToken
      required: false
      schema:
        $ref: '#/components/schemas/NextToken'
    optionalCustomerId:
      in: query
      name: customerId
      required: false
      schema:
        $ref: '#/components/schemas/Id'
    optionalEmail:
      in: query
      name: email
      required: false
      schema:
        format: email
        type: string
    planId:
      in: query
      name: planId
      required: true
      schema:
        $ref: '#/components/schemas/Id'
    productId:
      in: query
      name: productId
      required: true
      schema:
        $ref: '#/components/schemas/Id'
    status:
      in: query
      name: status
      required: false
      schema:
        $ref: '#/components/schemas/SubscriptionStatus'
    subscriptionId:
      in: path
      name: subscriptionId
      required: true
      schema:
        $ref: '#/components/schemas/Id'
    teamId:
      in: query
      name: teamId
      required: true
      schema:
        $ref: '#/components/schemas/Id'
  responses:
    Error:
      content:
        application/json:
          schema:
            properties:
              code:
                type: string
              details:
                type: object
              message:
                type: string
            required:
              - code
              - message
            type: object
      description: Unexpected error
  schemas:
    AdminPlan:
      allOf:
        - $ref: '#/components/schemas/Plan'
        - properties:
            enabledApplications:
              $ref: '#/components/schemas/IdList'
              description: Application ids for which this plan is enabled.
              minItems: 1
            enabledTenants:
              $ref: '#/components/schemas/IdList'
              description: Tenant ids for which this plan is enabled.
            paymentProcessorId:
              $ref: '#/components/schemas/Id'
            productId:
              $ref: '#/components/schemas/Id'
            renewalLimit:
              description: >-
                Maximum number of renewals. Useful for free tiers or discounted
                plans. No value means unlimited renewals.
              format: int32
              minimum: 0
              type: integer
            status:
              enum:
                - ACTIVE
                - INACTIVE
                - DELETED
              type: string
            subscriptionCount:
              description: Number of currently active subscriptions on this plan.
              minimum: 0
              type: number
            tierId:
              $ref: '#/components/schemas/Id'
          required:
            - productId
            - tierId
            - status
            - enabledApplications
          type: object
    AdminSubscription:
      properties:
        createdDate:
          format: date-time
          maxLength: 27
          type: string
        customerEmail:
          description: Not available in the `AdminListSubscriptions` response.
          type: string
        customerId:
          $ref: '#/components/schemas/Id'
        owners:
          items:
            properties:
              email:
                type: string
              userId:
                $ref: '#/components/schemas/Id'
            required:
              - userId
              - email
            type: object
          type: array
        periodEndDate:
          format: date-time
          maxLength: 27
          type: string
        periodStartDate:
          format: date-time
          maxLength: 27
          type: string
        planId:
          $ref: '#/components/schemas/Id'
        productId:
          $ref: '#/components/schemas/Id'
        renewalCount:
          type: number
        status:
          $ref: '#/components/schemas/SubscriptionStatus'
        subscriptionId:
          $ref: '#/components/schemas/Id'
      required:
        - subscriptionId
        - status
        - periodStartDate
        - periodEndDate
        - createdDate
        - productId
        - planId
        - customerId
        - renewalCount
      type: object
    AdminTier:
      properties:
        cancellationBehaviors:
          description: List of supported cancellation behaviors for this tier
          items:
            $ref: '#/components/schemas/CancellationBehavior'
          minLength: 1
          type: array
        description:
          $ref: '#/components/schemas/Description'
          description: Long form description of the purpose of this tier.
        name:
          $ref: '#/components/schemas/Name'
          description: Display name for plan. Not visible to customer.
        oneTimeSubscription:
          description: >-
            Allow a customer to subscribe only once to plans of this tier.
            Useful for discounted or trial tiers.
          type: boolean
        paymentMethod:
          description: Defines if a payment method is required at checkout
          enum:
            - REQUIRED
            - OPTIONAL
          type: string
        planCount:
          minimum: 0
          readOnly: true
          type: number
        productId:
          $ref: '#/components/schemas/Id'
        prorate:
          description: >-
            If true and a subscription is canceled or a plan is changed,
            pro-rate any licensed usage. Metered usage is unaffected by this
            setting.
          type: boolean
        tierId:
          $ref: '#/components/schemas/Id'
      required:
        - name
        - productId
        - paymentMethod
        - oneTimeSubscription
        - cancellationBehaviors
      type: object
    AdminUsageRecord:
      properties:
        confirmed:
          description: The number of confirmed units.
          minimum: 0
          type: number
        dimension:
          $ref: '#/components/schemas/Name'
        limit:
          description: The limit of the usage.
          minimum: 0
          type: number
        pending:
          description: The number of pending units.
          minimum: 0
          type: number
        periodEndDate:
          description: The end date of the usage period.
          format: date-time
          type: string
        periodStartDate:
          description: The start date of the usage period.
          format: date-time
          type: string
        resourceId:
          $ref: '#/components/schemas/Id'
      required:
        - resourceId
        - dimension
        - pending
        - confirmed
        - periodStartDate
        - periodEndDate
      type: object
    CancellationBehavior:
      enum:
        - CANCEL_AT_END
        - CANCEL_NOW
      type: string
    CreatedDate:
      description: Date when the item was created
      format: date-time
      type: string
    Description:
      maxLength: 1024
      pattern: '[^\n\r]+'
      type: string
    ExternalIdentity:
      properties:
        externalId:
          maxLength: 64
          pattern: '[a-zA-Z0-9_-]+'
          type: string
        providerId:
          $ref: '#/components/schemas/Id'
        providerType:
          $ref: '#/components/schemas/ProviderType'
      required:
        - providerType
        - providerId
        - externalId
      type: object
    Id:
      maxLength: 22
      minLength: 22
      pattern: '[a-zA-Z0-9_-]+'
      type: string
    IdList:
      items:
        type: string
      maxItems: 20
      type: array
    Name:
      maxLength: 200
      pattern: '[^\n\r]+'
      type: string
    NextToken:
      maxLength: 4096
      pattern: ^[a-zA-Z0-9_-]+$
      type: string
    PaymentProcessor:
      properties:
        createdDate:
          $ref: '#/components/schemas/CreatedDate'
        environment:
          $ref: '#/components/schemas/PaymentProcessorEnvironment'
        externalId:
          description: External ID at payment processor (e.g. for Stripe the Account ID).
          maxLength: 128
          minLength: 1
          pattern: '[0-9a-zA-Z_-]+'
          type: string
        name:
          description: Descriptive name of the payment processor
          type: string
        paymentProcessorId:
          $ref: '#/components/schemas/Id'
        type:
          description: Type of payment processor
          enum:
            - STRIPE
          type: string
        updatedDate:
          $ref: '#/components/schemas/UpdatedDate'
      required:
        - name
        - type
        - environment
      type: object
    PaymentProcessorEnvironment:
      description: >-
        Test environment allows for testing the plan with special test credit
        cards.
      enum:
        - TEST
        - LIVE
      type: string
    PerUnitPrice:
      properties:
        billingScheme:
          enum:
            - PER_UNIT
          type: string
        unitAmount:
          minimum: 0
          type: integer
      required:
        - unitAmount
      title: PerUnitPrice
      type: object
    Plan:
      additionalProperties: true
      properties:
        items:
          items:
            $ref: '#/components/schemas/PlanItem'
          maxItems: 50
          minLength: 1
          type: array
        name:
          $ref: '#/components/schemas/Name'
        planId:
          $ref: '#/components/schemas/Id'
        tierId:
          $ref: '#/components/schemas/Id'
      required:
        - name
        - items
      type: object
    PlanItem:
      additionalProperties: false
      properties:
        dimension:
          $ref: '#/components/schemas/Name'
        limit:
          minimum: 1
          type: number
        meteringResourceId:
          $ref: '#/components/schemas/Id'
        name:
          $ref: '#/components/schemas/Name'
        planItemId:
          $ref: '#/components/schemas/Id'
        price:
          $ref: '#/components/schemas/PlanItemPrice'
        usage:
          additionalProperties: false
          properties:
            confirmed:
              example: 5
              minimum: 0
              type: number
            pending:
              example: 3
              minimum: 0
              type: number
          required:
            - confirmed
            - pending
          type: object
      required:
        - name
        - dimension
        - price
      type: object
    PlanItemPrice:
      allOf:
        - properties:
            currency:
              description: >-
                Three-letter ISO currency code, in lowercase. Must be a
                supported currency.
              enum:
                - usd
              example: usd
              type: string
            recurring:
              additionalProperties: false
              properties:
                interval:
                  description: >-
                    The frequency at which a subscription is billed. One of
                    `day`, `week`, `month` or `year`.
                  enum:
                    - day
                    - week
                    - month
                    - year
                  type: string
                intervalCount:
                  default: 1
                  description: >
                    The number of intervals (specified in the `interval`
                    attribute) between subscription billings.

                    For example, `interval=month` and `intervalCount=3` bills
                    every 3 months.
                  minimum: 1
                  type: number
              required:
                - interval
              type: object
          required:
            - recurring
          type: object
        - oneOf:
            - $ref: '#/components/schemas/TieredPrice'
            - $ref: '#/components/schemas/PerUnitPrice'
    Product:
      additionalProperties: false
      properties:
        name:
          $ref: '#/components/schemas/Name'
        productId:
          $ref: '#/components/schemas/Id'
        status:
          $ref: '#/components/schemas/ProductStatus'
        teamId:
          $ref: '#/components/schemas/Id'
      required:
        - name
      type: object
    ProductStatus:
      enum:
        - ACTIVE
        - INACTIVE
        - DELETED
      readOnly: true
      type: string
    Profile:
      properties:
        identities:
          items:
            $ref: '#/components/schemas/ExternalIdentity'
          type: array
      required:
        - identities
      type: object
    ProviderType:
      enum:
        - PAYMENT_PROCESSOR
      type: string
    Subscription:
      additionalProperties: false
      properties:
        meteringKeyId:
          $ref: '#/components/schemas/Id'
        periodEndDate:
          format: date-time
          maxLength: 27
          type: string
        periodStartDate:
          format: date-time
          maxLength: 27
          type: string
        plan:
          $ref: '#/components/schemas/Plan'
        status:
          $ref: '#/components/schemas/SubscriptionStatus'
        subscriptionId:
          $ref: '#/components/schemas/Id'
      required:
        - periodStartDate
        - periodEndDate
        - plan
      type: object
    SubscriptionInvitation:
      properties:
        email:
          format: email
          type: string
        expirationDate:
          format: date-time
          type: string
        invitationId:
          $ref: '#/components/schemas/Id'
          readOnly: true
        meteringResourceId:
          $ref: '#/components/schemas/Id'
        state:
          $ref: '#/components/schemas/SubscriptionInvitationState'
      required:
        - email
        - expirationDate
      type: object
    SubscriptionInvitationState:
      enum:
        - CREATED
        - ACCEPTED
        - EXPIRED
      type: string
    SubscriptionStatus:
      enum:
        - ACTIVE
        - EXPIRING
        - CANCELED
      type: string
    TierItemAttributes:
      additionalProperties: false
      properties:
        cancellationBehaviors:
          description: List of supported cancellation behaviors for this tier
          items:
            $ref: '#/components/schemas/CancellationBehavior'
          minLength: 1
          type: array
        description:
          $ref: '#/components/schemas/Description'
          description: Long form description of the purpose of this tier.
        name:
          $ref: '#/components/schemas/Name'
          description: Display name for plan. Not visible to customer.
        oneTimeSubscription:
          description: >-
            Allow a customer to subscribe only once to plans of this tier.
            Useful for discounted or trial tiers.
          type: boolean
        paymentMethod:
          description: Defines if a payment method is required at checkout
          enum:
            - REQUIRED
            - OPTIONAL
          type: string
        planCount:
          minimum: 0
          readOnly: true
          type: number
        productId:
          $ref: '#/components/schemas/Id'
        prorate:
          description: >-
            If true and a subscription is canceled or a plan is changed,
            pro-rate any licensed usage. Metered usage is unaffected by this
            setting.
          type: boolean
        status:
          enum:
            - ACTIVE
            - DELETED
          type: string
        tierId:
          $ref: '#/components/schemas/Id'
      required:
        - tierId
        - name
        - productId
        - paymentMethod
        - oneTimeSubscription
        - cancellationBehaviors
        - status
        - prorate
      type: object
    TieredPrice:
      properties:
        billingScheme:
          enum:
            - TIERED
          type: string
        tiers:
          description: >
            Each element represents a pricing tier. This parameter requires
            billingScheme

            to be set to tiered. See also the documentation for billingScheme.
          items:
            additionalProperties: false
            properties:
              flatAmount:
                description: >-
                  The flat billing amount for an entire tier, regardless of the
                  number of units in the tier.
                minimum: 0
                type: integer
              unitAmount:
                description: >-
                  The per unit billing amount for each individual unit for which
                  this tier applies.
                minimum: 0
                type: integer
              upTo:
                description: >
                  Specifies the upper bound of this tier. The lower bound of a
                  tier is the upper

                  bound of the previous tier adding one. Use null to define a
                  fallback tier.
                minimum: 0
                nullable: true
                type: integer
            required:
              - upTo
            type: object
          maxItems: 20
          type: array
        tiersMode:
          enum:
            - VOLUME
            - GRADUATED
          type: string
        usageType:
          description: There can only be one LICENSED price per plan.
          enum:
            - METERED
            - LICENSED
          type: string
      required:
        - tiersMode
        - usageType
        - tiers
      title: TieredPrice
      type: object
    UpdateProduct:
      properties:
        name:
          $ref: '#/components/schemas/Name'
        status:
          $ref: '#/components/schemas/ProductStatus'
      type: object
    UpdatedDate:
      description: Date when the item was created
      format: date-time
      type: string
    Url:
      format: uri
      maxLength: 300
      minLength: 4
      type: string
  securitySchemes:
    AdminAuth:
      openIdConnectUrl: https://login.emddigital.com/.well-known/openid-configuration
      type: openIdConnect
    UserAuth:
      in: header
      name: Authorization
      type: apiKey
info:
  description: |
    The portal API organizes `Products`, `Plans`, and `Subscriptions`
    which consume plan item resources.
  title: Portal API
  version: 0.2.0
openapi: 3.0.3
paths:
  /admin/payment-processors:
    get:
      operationId: adminListPaymentProcessors
      responses:
        '200':
          content:
            application/json:
              schema:
                additionalProperties: false
                properties:
                  items:
                    items:
                      $ref: '#/components/schemas/PaymentProcessor'
                    type: array
                required:
                  - items
                type: object
          description: List of products
        '401':
          description: Unauthorized
        '404':
          description: Not Found
        default:
          $ref: '#/components/responses/Error'
      security:
        - AdminAuth: []
      summary: List Payment Processors
      tags:
        - Admin
  /admin/plans:
    get:
      description: List all plans.
      operationId: adminListPlans
      parameters:
        - in: query
          name: productId
          required: true
          schema:
            $ref: '#/components/schemas/Id'
        - in: query
          name: status
          required: false
          schema:
            enum:
              - ACTIVE
              - INACTIVE
              - DELETED
            type: string
      responses:
        '200':
          content:
            application/json:
              schema:
                additionalProperties: false
                properties:
                  items:
                    items:
                      $ref: '#/components/schemas/AdminPlan'
                    type: array
                type: object
          description: Plans
        '401':
          description: Unauthorized
        '404':
          description: Not Found
        default:
          $ref: '#/components/responses/Error'
      security:
        - AdminAuth: []
      summary: List Plans
      tags:
        - Admin
    post:
      description: >
        Create a plan. PlanItem prices must all have the same interval and
        intervalCount.
      operationId: adminCreatePlan
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AdminPlan'
      responses:
        '201':
          content:
            application/json:
              schema:
                additionalProperties: false
                properties:
                  planId:
                    type: string
                required:
                  - planId
                type: object
          description: Created Plan
        '401':
          description: Unauthorized
        default:
          $ref: '#/components/responses/Error'
      security:
        - AdminAuth: []
      summary: Create Plan
      tags:
        - Admin
  /admin/plans/{id}:
    delete:
      description: Delete a plan.
      operationId: adminDeletePlan
      responses:
        '200':
          description: Deleted Plan
        '400':
          description: Bad request.
        '401':
          description: Unauthorized
        '404':
          description: Not Found
        default:
          $ref: '#/components/responses/Error'
      security:
        - AdminAuth: []
      summary: Delete Plan
      tags:
        - Admin
    get:
      description: Describe a plan.
      operationId: adminDescribePlan
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminPlan'
          description: Plan
        '401':
          description: Unauthorized
        '404':
          description: Not Found
        default:
          $ref: '#/components/responses/Error'
      security:
        - AdminAuth: []
      summary: Describe Plan
      tags:
        - Admin
    parameters:
      - $ref: '#/components/parameters/id'
    put:
      description: Update a plan.
      operationId: adminUpdatePlan
      requestBody:
        content:
          application/json:
            schema:
              additionalProperties: false
              properties:
                enabledApplications:
                  $ref: '#/components/schemas/IdList'
                  description: Application ids for which this plan is enabled.
                  minItems: 1
                enabledTenants:
                  $ref: '#/components/schemas/IdList'
                  description: Tenant ids for which this plan is enabled.
                name:
                  $ref: '#/components/schemas/Name'
                status:
                  enum:
                    - ACTIVE
                    - INACTIVE
                  type: string
              type: object
      responses:
        '200':
          description: Updated Plan
        '400':
          description: Bad request.
        '401':
          description: Unauthorized
        '404':
          description: Not Found
        default:
          $ref: '#/components/responses/Error'
      security:
        - AdminAuth: []
      summary: Update Plan
      tags:
        - Admin
  /admin/products:
    get:
      description: Lists products.
      operationId: adminListProducts
      parameters:
        - in: query
          name: teamId
          required: false
          schema:
            $ref: '#/components/schemas/Id'
      responses:
        '200':
          content:
            application/json:
              schema:
                additionalProperties: false
                properties:
                  items:
                    items:
                      $ref: '#/components/schemas/Product'
                    type: array
                type: object
          description: List of products
        '401':
          description: Unauthorized
        '404':
          description: Not Found
        default:
          $ref: '#/components/responses/Error'
      security:
        - AdminAuth: []
      summary: List Products
      tags:
        - Admin
    post:
      description: Create a product.
      operationId: adminCreateProduct
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Product'
      responses:
        '201':
          content:
            application/json:
              schema:
                additionalProperties: false
                properties:
                  productId:
                    $ref: '#/components/schemas/Id'
                type: object
          description: Created Product
        '401':
          description: Unauthorized
        default:
          $ref: '#/components/responses/Error'
      security:
        - AdminAuth: []
      summary: Create Product
      tags:
        - Admin
  /admin/products/{id}:
    delete:
      description: Delete a product. Must not contain any active applications or plans.
      operationId: adminDeleteProduct
      responses:
        '200':
          description: Deleted product
        '401':
          description: Unauthorized
        '404':
          description: Not Found
        default:
          $ref: '#/components/responses/Error'
      security:
        - AdminAuth: []
      summary: Delete Product
      tags:
        - Admin
    get:
      description: Describe an product.
      operationId: adminDescribeProduct
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Product'
          description: Product
        '401':
          description: Unauthorized
        '404':
          description: Not Found
        default:
          $ref: '#/components/responses/Error'
      security:
        - AdminAuth: []
      summary: Describe Product
      tags:
        - Admin
    parameters:
      - $ref: '#/components/parameters/id'
    put:
      description: Update an product.
      operationId: adminUpdateProduct
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateProduct'
      responses:
        '200':
          description: Updated Product
        '401':
          description: Unauthorized
        '404':
          description: Not Found
        default:
          $ref: '#/components/responses/Error'
      security:
        - AdminAuth: []
      summary: Update Product
      tags:
        - Admin
  /admin/subscriptions:
    get:
      operationId: adminListSubscriptions
      parameters:
        - $ref: '#/components/parameters/productId'
        - $ref: '#/components/parameters/planId'
        - $ref: '#/components/parameters/nextToken'
        - $ref: '#/components/parameters/limit'
        - $ref: '#/components/parameters/status'
        - $ref: '#/components/parameters/optionalCustomerId'
        - $ref: '#/components/parameters/optionalEmail'
      responses:
        '200':
          content:
            application/json:
              schema:
                additionalProperties: false
                properties:
                  items:
                    items:
                      $ref: '#/components/schemas/AdminSubscription'
                    type: array
                  nextToken:
                    $ref: '#/components/schemas/NextToken'
                required:
                  - items
                type: object
          description: OK
      security:
        - AdminAuth: []
      summary: List Subscriptions
      tags:
        - Admin
  /admin/subscriptions/{subscriptionId}:
    get:
      operationId: adminDescribeSubscription
      parameters:
        - $ref: '#/components/parameters/subscriptionId'
        - $ref: '#/components/parameters/customerId'
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminSubscription'
          description: OK
      security:
        - AdminAuth: []
      summary: Describe Subscription
      tags:
        - Admin
    put:
      description: >-
        An administrator can update the status of a subscription. The status of
        a `CANCELED` subscription cannot be changed.
      operationId: adminUpdateSubscription
      parameters:
        - $ref: '#/components/parameters/subscriptionId'
        - $ref: '#/components/parameters/customerId'
      requestBody:
        content:
          application/json:
            schema:
              properties:
                owners:
                  items:
                    $ref: '#/components/schemas/Id'
                  maxItems: 5
                  minItems: 1
                  type: array
                status:
                  $ref: '#/components/schemas/SubscriptionStatus'
              type: object
      responses:
        '200':
          description: Subscription was updated successfully.
        '204':
          description: No Content
        '400':
          description: Bad request.
        '401':
          description: Unauthorized
        '404':
          description: Not Found
        '409':
          description: Conflict
        default:
          $ref: '#/components/responses/Error'
      security:
        - AdminAuth: []
      summary: Update Subscription
      tags:
        - Admin
  /admin/subscriptions/{subscriptionId}/usage-records:
    get:
      operationId: adminListUsageRecords
      parameters:
        - $ref: '#/components/parameters/subscriptionId'
        - $ref: '#/components/parameters/customerId'
      responses:
        '200':
          content:
            application/json:
              schema:
                properties:
                  items:
                    items:
                      $ref: '#/components/schemas/AdminUsageRecord'
                    type: array
                  nextToken:
                    $ref: '#/components/schemas/NextToken'
                required:
                  - items
                type: object
          description: OK
      security:
        - AdminAuth: []
      summary: List Usage Records
      tags:
        - Admin
  /admin/tiers:
    get:
      description: List all tiers.
      operationId: adminListTiers
      parameters:
        - $ref: '#/components/parameters/productId'
      responses:
        '200':
          content:
            application/json:
              schema:
                additionalProperties: false
                properties:
                  items:
                    items:
                      $ref: '#/components/schemas/AdminTier'
                    type: array
                required:
                  - items
                type: object
          description: Tiers
        '401':
          description: Unauthorized
        default:
          $ref: '#/components/responses/Error'
      security:
        - AdminAuth: []
      summary: List Tiers
      tags:
        - Admin
    post:
      description: Create a tier.
      operationId: adminCreateTier
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AdminTier'
      responses:
        '201':
          content:
            application/json:
              schema:
                additionalProperties: false
                properties:
                  tierId:
                    type: string
                type: object
          description: Created Tier
        '401':
          description: Unauthorized
        default:
          $ref: '#/components/responses/Error'
      security:
        - AdminAuth: []
      summary: Create Tier
      tags:
        - Admin
  /admin/tiers/{id}:
    delete:
      description: Delete a tier.
      operationId: adminDeleteTier
      responses:
        '200':
          description: Deleted Tier
        '400':
          description: Bad request.
        '401':
          description: Unauthorized
        '404':
          description: Not Found
        default:
          $ref: '#/components/responses/Error'
      security:
        - AdminAuth: []
      summary: Delete Tier
      tags:
        - Admin
    get:
      description: Describe a tier.
      operationId: adminDescribeTier
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminTier'
          description: Tier
        '401':
          description: Unauthorized
        '404':
          description: Not Found
        default:
          $ref: '#/components/responses/Error'
      security:
        - AdminAuth: []
      summary: Describe Tier
      tags:
        - Admin
    parameters:
      - $ref: '#/components/parameters/id'
      - $ref: '#/components/parameters/productId'
    put:
      description: Update a tier.
      operationId: adminUpdateTier
      requestBody:
        content:
          application/json:
            schema:
              properties:
                description:
                  $ref: '#/components/schemas/Description'
                name:
                  $ref: '#/components/schemas/Name'
              type: object
      responses:
        '200':
          description: Updated Tier
        '400':
          description: Bad request.
        '401':
          description: Unauthorized
        '404':
          description: Not Found
        default:
          $ref: '#/components/responses/Error'
      security:
        - AdminAuth: []
      summary: Update Tier
      tags:
        - Admin
  /hooks/stripe/{accountId}:
    parameters:
      - description: Stripe account ID
        in: path
        name: accountId
        required: true
        schema:
          maxLength: 32
          type: string
  /plans:
    get:
      description: List all plans for the current application.
      operationId: listPlans
      responses:
        '200':
          content:
            application/json:
              schema:
                additionalProperties: false
                properties:
                  items:
                    items:
                      $ref: '#/components/schemas/Plan'
                    type: array
                type: object
          description: Plans
        '401':
          description: Unauthorized
        '404':
          description: Not Found
        default:
          $ref: '#/components/responses/Error'
      security:
        - UserAuth: []
      summary: List Plans
      tags:
        - User
  /plans/{id}:
    get:
      description: Describe a plan.
      operationId: describePlan
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Plan'
          description: Plan
        '401':
          description: Unauthorized
        '404':
          description: Not Found
        default:
          $ref: '#/components/responses/Error'
      security:
        - UserAuth: []
      summary: Describe Plan
      tags:
        - User
    parameters:
      - $ref: '#/components/parameters/id'
  /subscriptions:
    get:
      description: |
        List all subscriptions for the user making the request.
      operationId: listSubscriptions
      parameters:
        - in: query
          name: status
          required: false
          schema:
            default: ACTIVE,EXPIRING
            description: Whether to show canceled subscriptions in the returned results.
            pattern: '[ACTIVE|EXPIRING|CANCELED]([,ACTIVE|,EXPIRING|,CANCELED]){0,2}'
            type: string
        - $ref: '#/components/parameters/nextToken'
      responses:
        '200':
          content:
            application/json:
              schema:
                properties:
                  items:
                    items:
                      $ref: '#/components/schemas/Subscription'
                    type: array
                  nextToken:
                    $ref: '#/components/schemas/NextToken'
                required:
                  - items
                type: object
          description: The requested subscription info.
        '401':
          description: Unauthorized
        '404':
          description: No subscription was found for this user.
        default:
          $ref: '#/components/responses/Error'
      security:
        - UserAuth: []
      summary: List Subscriptions
      tags:
        - User
    post:
      description: >
        If the user is currently not subscribed to a plan, this will create a
        new subscription.

        If the plan requires a credit card, the response will include a checkout
        URL to Stripe.

        Otherwise, the user is immediately subscribed to the plan (i.e. a free
        tier plan).


        The parameters `successUrl` and `cancelUrl` are required.


        If the user is already subscribed and the planId does not match the
        current subscription,

        the backend will attempt to place the user on the new plan if permitted
        by the constraints

        provided by the plan and tier.


        If the user has an EXPIRING subscription, passing the same

        planId to which they are subscribed with reactivate their

        subscription. The parameters `successUrl` and `cancelUrl`

        are not required.
      operationId: createSubscription
      requestBody:
        content:
          application/json:
            schema:
              additionalProperties: false
              properties:
                behavior:
                  description: >-
                    If set to `FORCE_NEW`, a new subscription will be created
                    even if the current subscription is on the same plan and
                    could be reactivated instead.
                  enum:
                    - FORCE_NEW
                  type: string
                cancelUrl:
                  $ref: '#/components/schemas/Url'
                  description: >-
                    The URL the customer will be directed to if they decide to
                    cancel payment and return to your website.
                planId:
                  $ref: '#/components/schemas/Id'
                  description: The plan id to subscribe to.
                successUrl:
                  $ref: '#/components/schemas/Url'
                  description: >-
                    The URL to which Stripe should send customers when payment
                    or setup is complete.
              required:
                - planId
              type: object
      responses:
        '200':
          description: User was successfully re-subscribed to their expiring plan.
        '201':
          content:
            application/json:
              schema:
                additionalProperties: false
                properties:
                  checkoutUrl:
                    description: >-
                      Hosted checkout redirect. This will contain the
                      `successUrl` if the subscription was successful without a
                      payment method. Otherwise, contains a URL to the checkout
                      page.
                    type: string
                  sessionId:
                    description: >-
                      The session ID to redirect to for checkout. Only present
                      if the customer needs to provide a payment method.
                    type: string
                  subscriptionId:
                    description: >-
                      If present, the user was subscribed automatically. This is
                      usually the case for free tiers where no payment method is
                      required.
                    type: string
                required:
                  - checkoutUrl
                type: object
          description: Checkout session was created successfully.
        '400':
          description: Bad request.
        '401':
          description: Unauthorized
        '409':
          description: >-
            User cannot subscribe to this plan because they were subscribed to a
            plan in the same tier before.
        '423':
          description: Locked
        default:
          $ref: '#/components/responses/Error'
      security:
        - UserAuth: []
      summary: Create Subscription
      tags:
        - User
  /subscriptions/{id}:
    get:
      description: Describe a subscription
      operationId: describeSubscription
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Subscription'
          description: The requested subscription info.
        '401':
          description: Unauthorized
        '404':
          description: No subscription was found for this user.
        default:
          $ref: '#/components/responses/Error'
      security:
        - UserAuth: []
      summary: Describe Subscription
      tags:
        - User
    parameters:
      - $ref: '#/components/parameters/id'
    put:
      description: >
        Cancel subscription to a plan for the current user. User must have no
        pending transactions.
      operationId: cancelSubscription
      requestBody:
        content:
          application/json:
            schema:
              additionalProperties: false
              properties:
                behavior:
                  default: CANCEL_AT_END
                  enum:
                    - CANCEL_AT_END
                    - CANCEL_NOW
                  type: string
              type: object
      responses:
        '200':
          description: Subscription was canceled successfully.
        '400':
          description: Bad request.
        '401':
          description: Unauthorized
        '404':
          description: Not Found
        '409':
          description: Conflict
        default:
          $ref: '#/components/responses/Error'
      security:
        - UserAuth: []
      summary: Cancel Subscription
      tags:
        - User
  /subscriptions/{id}/invitations:
    get:
      operationId: listSubscriptionInvitations
      parameters:
        - $ref: '#/components/parameters/nextToken'
      responses:
        '200':
          content:
            application/json:
              schema:
                properties:
                  items:
                    items:
                      $ref: '#/components/schemas/SubscriptionInvitation'
                    type: array
                  nextToken:
                    $ref: '#/components/schemas/NextToken'
                type: object
          description: Success
      security:
        - UserAuth: []
    parameters:
      - $ref: '#/components/parameters/id'
    post:
      operationId: createSubscriptionInvitation
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SubscriptionInvitation'
        required: true
      responses:
        '201':
          content:
            application/json:
              schema:
                properties:
                  invitationId:
                    type: string
                required:
                  - invitationId
                type: object
          description: Success
      security:
        - UserAuth: []
  /subscriptions/{id}/invitations/{invitationId}:
    delete:
      operationId: removeSubscriptionInvitation
      responses:
        '200':
          description: OK
      security:
        - UserAuth: []
    get:
      operationId: describeSubscriptionInvitation
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SubscriptionInvitation'
          description: OK
      security:
        - UserAuth: []
    parameters:
      - $ref: '#/components/parameters/id'
      - $ref: '#/components/parameters/invitationId'
    put:
      operationId: acceptSubscriptionInvitation
      responses:
        '200':
          description: OK
      security:
        - UserAuth: []
servers:
  - url: https://portal.emddigital.com/v1/
