# Đặt cài đặt Refund Saver

> Đặt tùy chọn hoàn tiền riêng lẻ cho người dùng và ghi lại việc người dùng đã đồng ý chia sẻ dữ liệu của họ. Theo mặc định, Refund Saver luôn yêu cầu Apple từ chối yêu cầu hoàn tiền của người dùng. Bạn có thể thay đổi hành vi mặc định này cho tất cả người dùng trong Adapty Dashboard, hoặc điều chỉnh cho một người dùng cụ thể thông qua Dashboard, SDK, hoặc server-side 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 server-side API
  version: 1.0.0
servers:
  - url: https://api.adapty.io
    description: Máy chủ sản xuất
paths:
  /api/v2/server-side-api/purchase/profile/refund-saver/settings/:
    post:
      summary: Đặt cài đặt Refund Saver
      description: Đặt tùy chọn hoàn tiền riêng lẻ cho người dùng và ghi lại việc người dùng đã đồng ý chia sẻ dữ liệu của họ. Theo mặc định, Refund Saver luôn yêu cầu Apple từ chối yêu cầu hoàn tiền của người dùng. Bạn có thể thay đổi hành vi mặc định này cho tất cả người dùng trong Adapty Dashboard, hoặc điều chỉnh cho một người dùng cụ thể thông qua Dashboard, SDK, hoặc server-side API.
      operationId: setRefundSaverSettings
      tags:
        - Refund Saver
      security:
        - apikeyAuth: []
      parameters:
        - name: adapty-customer-user-id
          in: header
          required: false
          schema:
            type: string
          description: ID duy nhất của khách hàng trong hệ thống của bạn. Cần cung cấp `adapty-customer-user-id` hoặc `adapty-profile-id`.
        - name: adapty-profile-id
          in: header
          required: false
          schema:
            type: string
            format: uuid
          description: ID duy nhất của hồ sơ người dùng trong hệ thống của bạn. Lựa chọn tốt nhất khi làm việc với hồ sơ ẩn danh. Cần cung cấp `adapty-customer-user-id` hoặc `adapty-profile-id`.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/RefundSaverSettingsRequest"
            example:
              custom_preference: grant
              consent: true
      responses:
        "200":
          description: Cài đặt được cập nhật thành công
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/RefundSaverSettingsResponse"
              example:
                profile_id: e5aab402-b1bd-4039-b632-57a91ebc0779
                settings:
                  consent: true
                  custom_preference: grant
        "400":
          description: Yêu cầu không hợp lệ
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                profile_does_not_exist:
                  summary: Hồ sơ người dùng không tồn tại
                  value:
                    errors:
                      - Profile does not exist
                    error_code: profile_does_not_exist
                    status_code: 400
                validation_error:
                  summary: Lỗi xác thực
                  value:
                    errors:
                      - Profile refund saver settings must have either consent or custom_preference or both
                    error_code: validation_error
                    status_code: 400
        "401":
          description: Không được phép
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              example:
                errors:
                  - Invalid API key
                error_code: unauthorized
                status_code: 401
        "500":
          description: Lỗi máy chủ nội bộ
          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: |
            Đặt tùy chọn hoàn tiền riêng lẻ cho người dùng.
            - `grant`: chấp thuận từng yêu cầu hoàn tiền
            - `no_preference`: không đưa ra khuyến nghị nào
            - `decline`: từ chối từng yêu cầu hoàn tiền
        consent:
          type: boolean
          nullable: true
          description: |
            Ghi lại việc người dùng đã đồng ý chia sẻ dữ liệu của họ.
            - `true` có nghĩa là nếu bạn nhận được yêu cầu hoàn tiền trong ứng dụng, bạn có thể cung cấp thông tin về người dùng cho Apple
      example:
        custom_preference: grant
        consent: true
    RefundSaverSettingsResponse:
      type: object
      properties:
        profile_id:
          type: string
          format: uuid
          description: ID hồ sơ người dùng
        settings:
          type: object
          properties:
            consent:
              type: boolean
              description: Xác định liệu người dùng có đồng ý chia sẻ dữ liệu của họ hay không
            custom_preference:
              type: string
              enum:
                - grant
                - no_preference
                - decline
              description: Tùy chọn hoàn tiền
          description: Cài đặt Refund Saver cho người dùng
      required:
        - profile_id
        - settings
    ErrorResponse:
      type: object
      properties:
        errors:
          type: array
          items:
            type: object
            properties:
              source:
                type: string
                nullable: true
                description: Nguồn gốc lỗi
              errors:
                type: array
                items:
                  type: string
                description: Mảng thông báo lỗi
        error_code:
          type: string
          description: Tên lỗi rút gọn
        status_code:
          type: integer
          description: Mã trạng thái HTTP
      required:
        - errors
        - error_code
        - status_code
  securitySchemes:
    apikeyAuth:
      type: apiKey
      name: Authorization
      in: header
      default: Api-Key {Your secret API key}
      description: |
        Các yêu cầu API phải được xác thực bằng secret API key của bạn trong header **Authorization**
        với giá trị `Api-Key {your_secret_api_key}`, ví dụ:
        `Api-Key secret_live_...`. Tìm key này trong Adapty Dashboard ->
        **App Settings** -> tab **General** -> phần **API keys**.
```
