# Refund Saver の設定を行う

> ユーザーごとに返金設定を個別に設定し、ユーザーがデータ共有に同意したかどうかを記録します。デフォルトでは、Refund Saver は常に Apple にユーザーの返金リクエストを拒否するよう求めます。Adapty ダッシュボードですべてのユーザーに対してこのデフォルト動作を変更するか、ダッシュボード・Adapty SDK・またはサーバーサイド API を使用して特定のユーザー向けに調整できます。

## OpenAPI

```yaml
/api-specs/adapty-api.yaml post /api/v2/server-side-api/purchase/profile/refund-saver/settings/
openapi: 3.1.0
info:
  title: Adapty サーバーサイド API
  version: 1.0.0
servers:
  - url: https://api.adapty.io
    description: 本番サーバー
paths:
  /api/v2/server-side-api/purchase/profile/refund-saver/settings/:
    post:
      summary: Refund Saver の設定を行う
      description: ユーザーごとに返金設定を個別に設定し、ユーザーがデータ共有に同意したかどうかを記録します。デフォルトでは、Refund Saver は常に Apple にユーザーの返金リクエストを拒否するよう求めます。Adapty ダッシュボードですべてのユーザーに対してこのデフォルト動作を変更するか、ダッシュボード・Adapty SDK・またはサーバーサイド API を使用して特定のユーザー向けに調整できます。
      operationId: setRefundSaverSettings
      tags:
        - Refund Saver
      security:
        - apikeyAuth: []
      parameters:
        - name: adapty-customer-user-id
          in: header
          required: false
          schema:
            type: string
          description: お客様のシステムにおける顧客の一意の ID です。`adapty-customer-user-id` または `adapty-profile-id` のいずれかが必須です。
        - name: adapty-profile-id
          in: header
          required: false
          schema:
            type: string
            format: uuid
          description: お客様のシステムにおけるプロファイルの一意の ID です。匿名プロファイルを扱う場合に最適です。`adapty-customer-user-id` または `adapty-profile-id` のいずれかが必須です。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/RefundSaverSettingsRequest"
            example:
              custom_preference: grant
              consent: true
      responses:
        "200":
          description: 設定が正常に更新されました
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/RefundSaverSettingsResponse"
              example:
                profile_id: e5aab402-b1bd-4039-b632-57a91ebc0779
                settings:
                  consent: true
                  custom_preference: grant
        "400":
          description: リクエストが不正です
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                profile_does_not_exist:
                  summary: プロファイルが存在しません
                  value:
                    errors:
                      - Profile does not exist
                    error_code: profile_does_not_exist
                    status_code: 400
                validation_error:
                  summary: バリデーションエラー
                  value:
                    errors:
                      - Profile refund saver settings must have either consent or custom_preference or both
                    error_code: validation_error
                    status_code: 400
        "401":
          description: 認証エラー
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              example:
                errors:
                  - Invalid API key
                error_code: unauthorized
                status_code: 401
        "500":
          description: 内部サーバーエラー
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
components:
  schemas:
    RefundSaverSettingsRequest:
      type: object
      properties:
        custom_preference:
          type: string
          enum:
            - grant
            - no_preference
            - decline
          nullable: true
          description: |
            ユーザーごとに返金設定を個別に指定します。
            - `grant`: 各返金リクエストを承認する
            - `no_preference`: 推奨を提供しない
            - `decline`: 各返金リクエストを拒否する
        consent:
          type: boolean
          nullable: true
          description: |
            ユーザーがデータ共有に同意したかどうかを記録します。
            - `true` は、アプリ内返金リクエストを受け取った場合に Apple にユーザー情報を提供できることを意味します
      example:
        custom_preference: grant
        consent: true
    RefundSaverSettingsResponse:
      type: object
      properties:
        profile_id:
          type: string
          format: uuid
          description: 顧客プロファイル ID
        settings:
          type: object
          properties:
            consent:
              type: boolean
              description: ユーザーがデータ共有に同意したかどうかを示します
            custom_preference:
              type: string
              enum:
                - grant
                - no_preference
                - decline
              description: 返金設定
          description: ユーザーの Refund Saver 設定
      required:
        - profile_id
        - settings
    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** セクションで確認できます。
```
