# Validate Stripe purchase

> Validates a purchase using the provided Stripe token using the credentials of Stripe in your App Settings inside Adapty Dashboard. 
> If the purchase is valid, the transaction history is imported from Stripe to the profile in Adapty with the specified customer_user_id. 
> If there was no profile with this customer_user_id before — it will be created.
>
> Profile events are generated along the way and imported transactions are counted towards MTR.

## OpenAPI

```yaml
/api-specs/adapty-api.yaml post /api/v1/sdk/purchase/stripe/token/validate/
openapi: 3.1.0
info:
  title: Adapty server-side API
  version: 1.0.0
servers:
  - url: https://api.adapty.io
    description: Production server
paths:
  /api/v1/sdk/purchase/stripe/token/validate/:
    post:
      summary: Validate Stripe purchase
      description: |
        Validates a purchase using the provided Stripe token using the credentials of Stripe in your App Settings inside Adapty Dashboard. 
        If the purchase is valid, the transaction history is imported from Stripe to the profile in Adapty with the specified customer_user_id. 
        If there was no profile with this customer_user_id before — it will be created.

        Profile events are generated along the way and imported transactions are counted towards MTR.
      operationId: validateStripePurchase
      tags:
        - Stripe
      security:
        - apikeyAuth: []
      requestBody:
        required: true
        content:
          application/vnd.api+json:
            schema:
              $ref: "#/components/schemas/StripeValidationRequest"
            example:
              data:
                type: stripe_receipt_validation_result
                attributes:
                  customer_user_id: <YOUR_CUSTOMER_USER_ID>
                  stripe_token: <YOUR_STRIPE_TOKEN>
      responses:
        "200":
          description: Purchase validated successfully
          content:
            application/vnd.api+json:
              schema:
                $ref: "#/components/schemas/StripeValidationResponse"
              example:
                data: null
        "400":
          description: Bad request
          content:
            application/vnd.api+json:
              schema:
                $ref: "#/components/schemas/StripeErrorResponse"
              example:
                errors:
                  - detail: none is not an allowed value
                    source:
                      pointer: /data/attributes/stripe_token
                    status: "400"
        "401":
          description: Unauthorized
          content:
            application/vnd.api+json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "500":
          description: Internal server error
          content:
            application/vnd.api+json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
components:
  schemas:
    StripeValidationRequest:
      type: object
      properties:
        data:
          type: object
          properties:
            type:
              type: string
              enum:
                - stripe_receipt_validation_result
              description: The type of the resource
            attributes:
              type: object
              properties:
                customer_user_id:
                  type: string
                  description: The ID of your user in your system
                stripe_token:
                  type: string
                  description: |
                    Token of a Stripe object that represents a unique purchase. 
                    Could either be a token of Stripe's Subscription (sub_XXX) or Payment Intent (pi_XXX)
              required:
                - customer_user_id
                - stripe_token
          required:
            - type
            - attributes
      required:
        - data
    StripeValidationResponse:
      type: object
      properties:
        data:
          type: object
          nullable: true
          description: Response data (null for successful validation)
      required:
        - data
    StripeErrorResponse:
      type: object
      properties:
        errors:
          type: array
          items:
            type: object
            properties:
              detail:
                type: string
                description: Descriptive information about the error
              source:
                type: object
                properties:
                  pointer:
                    type: string
                    description: References the exact location in the request document causing the issue
                required:
                  - pointer
              status:
                type: string
                description: HTTP status code
            required:
              - detail
              - source
              - status
      required:
        - errors
    ErrorResponse:
      type: object
      properties:
        errors:
          type: array
          items:
            type: object
            properties:
              source:
                type: string
                nullable: true
                description: Source of the error
              errors:
                type: array
                items:
                  type: string
                description: Array of error messages
        error_code:
          type: string
          description: Short error name
        status_code:
          type: integer
          description: HTTP status code
      required:
        - errors
        - error_code
        - status_code
  securitySchemes:
    apikeyAuth:
      type: apiKey
      name: Authorization
      in: header
      default: Api-Key {Your secret API key}
      description: |
        API requests must be authenticated by your secret API key as the **Authorization** 
        header with the value `Api-Key {your_secret_api_key}`, for example, 
        `Api-Key secret_live_...`. Find this key in the Adapty Dashboard -> 
        **App Settings** -> **General** tab -> **API keys** section.
```
