# Stripe の購入を検証する

> Adapty ダッシュボードのアプリ設定に登録された Stripe の認証情報を使用して、指定された Stripe トークンで購入を検証します。
> 購入が有効な場合、Stripe からトランザクション履歴が、指定された customer_user_id を持つ Adapty のプロファイルにインポートされます。
> この customer_user_id を持つプロファイルが存在しない場合は、新たに作成されます。
>
> プロファイルイベントはその過程で生成され、インポートされたトランザクションは MTR に計上されます。

## OpenAPI

```yaml
/api-specs/adapty-api.yaml post /api/v1/sdk/purchase/stripe/token/validate/
openapi: 3.1.0
info:
  title: Adapty サーバーサイド API
  version: 1.0.0
servers:
  - url: https://api.adapty.io
    description: 本番サーバー
paths:
  /api/v1/sdk/purchase/stripe/token/validate/:
    post:
      summary: Stripe の購入を検証する
      description: |
        Adapty ダッシュボードのアプリ設定に登録された Stripe の認証情報を使用して、指定された Stripe トークンで購入を検証します。
        購入が有効な場合、Stripe からトランザクション履歴が、指定された customer_user_id を持つ Adapty のプロファイルにインポートされます。
        この customer_user_id を持つプロファイルが存在しない場合は、新たに作成されます。

        プロファイルイベントはその過程で生成され、インポートされたトランザクションは 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: 購入が正常に検証されました
          content:
            application/vnd.api+json:
              schema:
                $ref: "#/components/schemas/StripeValidationResponse"
              example:
                data: null
        "400":
          description: リクエストが不正です
          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: 認証エラー
          content:
            application/vnd.api+json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "500":
          description: 内部サーバーエラー
          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: リソースの種別
            attributes:
              type: object
              properties:
                customer_user_id:
                  type: string
                  description: お客様のシステムにおけるユーザーの ID
                stripe_token:
                  type: string
                  description: |
                    一意の購入を表す Stripe オブジェクトのトークン。
                    Stripe のサブスクリプション（sub_XXX）または支払いインテント（pi_XXX）のトークンが使用できます
              required:
                - customer_user_id
                - stripe_token
          required:
            - type
            - attributes
      required:
        - data
    StripeValidationResponse:
      type: object
      properties:
        data:
          type: object
          nullable: true
          description: レスポンスデータ（検証成功時は null）
      required:
        - data
    StripeErrorResponse:
      type: object
      properties:
        errors:
          type: array
          items:
            type: object
            properties:
              detail:
                type: string
                description: エラーの詳細情報
              source:
                type: object
                properties:
                  pointer:
                    type: string
                    description: 問題の原因となったリクエストドキュメント内の正確な場所への参照
                required:
                  - pointer
              status:
                type: string
                description: HTTP ステータスコード
            required:
              - detail
              - source
              - status
      required:
        - errors
    ErrorResponse:
      type: object
      properties:
        errors:
          type: array
          items:
            type: object
            properties:
              source:
                type: string
                nullable: true
                description: エラーの発生源
              errors:
                type: array
                items:
                  type: string
                description: エラーメッセージの配列
        error_code:
          type: string
          description: エラーの短縮名
        status_code:
          type: integer
          description: HTTP ステータスコード
      required:
        - errors
        - error_code
        - status_code
  securitySchemes:
    apikeyAuth:
      type: apiKey
      name: Authorization
      in: header
      default: Api-Key {Your secret API key}
      description: |
        API リクエストは、**Authorization** ヘッダーにシークレット API キーを `Api-Key {your_secret_api_key}` の形式（例: `Api-Key secret_live_...`）で指定して認証する必要があります。このキーは Adapty ダッシュボード → **App Settings** → **General** タブ → **API keys** セクションで確認できます。
```
