openapi: 3.0.3
info:
  title: LAZISNU Partner External API
  version: 1.0.0
  description: |
    API integrasi mitra eksternal LAZISNU (NU Care CMS).

    Dokumentasi lengkap: `API-LAZISNU-MITRA-EKSTERNAL.md`
  contact:
    name: Tim Integrasi LAZISNU
    email: integrasi@lazisnu.or.id

servers:
  - url: https://{host}/api/v1/partners
    description: Base URL diberikan saat onboarding integrasi
    variables:
      host:
        default: your-api-host.nucare.id
        description: Host production atau staging (hubungi tim integrasi LAZISNU)

tags:
  - name: Partner
    description: Profil mitra
  - name: Catalog
    description: Kategori, campaign, zakat, qurban
  - name: Transactions
    description: Create & query transaksi

security:
  - BearerAuth: []
    PartnerCode: []

paths:
  /me:
    get:
      tags: [Partner]
      summary: Profil mitra & organisasi
      operationId: getPartnerProfile
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PartnerProfileResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'

  /categories:
    get:
      tags: [Catalog]
      summary: List kategori ZISWAF
      operationId: listCategories
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CategoryListResponse'

  /categories/{category_id}/sub-categories:
    get:
      tags: [Catalog]
      summary: List sub-kategori
      operationId: listSubCategories
      parameters:
        - $ref: '#/components/parameters/CategoryId'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SubCategoryListResponse'
        '404':
          $ref: '#/components/responses/NotFound'

  /campaigns:
    get:
      tags: [Catalog]
      summary: List campaign/donasi aktif
      operationId: listCampaigns
      parameters:
        - $ref: '#/components/parameters/CategoryIdQuery'
        - $ref: '#/components/parameters/SubCategoryIdQuery'
        - $ref: '#/components/parameters/OrganizationIdQuery'
        - $ref: '#/components/parameters/SearchQuery'
        - $ref: '#/components/parameters/PageQuery'
        - $ref: '#/components/parameters/PerPageQuery'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CampaignListResponse'

  /campaigns/{id}:
    get:
      tags: [Catalog]
      summary: Detail campaign by ID
      operationId: getCampaignById
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CampaignResponse'
        '404':
          $ref: '#/components/responses/NotFound'

  /campaigns/slug/{slug}:
    get:
      tags: [Catalog]
      summary: Detail campaign by slug
      operationId: getCampaignBySlug
      parameters:
        - name: slug
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CampaignResponse'
        '404':
          $ref: '#/components/responses/NotFound'

  /zakat:
    get:
      tags: [Catalog]
      summary: List program zakat
      operationId: listZakatPrograms
      parameters:
        - name: type
          in: query
          schema:
            type: string
            enum: [zakat_maal, zakat_profesi, zakat_fitrah, zakat]
        - $ref: '#/components/parameters/PageQuery'
        - $ref: '#/components/parameters/PerPageQuery'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ZakatListResponse'

  /qurban/products:
    get:
      tags: [Catalog]
      summary: List produk qurban
      operationId: listQurbanProducts
      parameters:
        - $ref: '#/components/parameters/OrganizationIdQuery'
        - $ref: '#/components/parameters/PageQuery'
        - $ref: '#/components/parameters/PerPageQuery'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/QurbanListResponse'

  /transactions:
    get:
      tags: [Transactions]
      summary: List transaksi mitra
      operationId: listTransactions
      parameters:
        - name: status
          in: query
          schema:
            type: string
            enum: [PENDING, SUCCESS, EXPIRED]
        - name: donation_id
          in: query
          schema:
            type: integer
        - name: partner_reference_id
          in: query
          schema:
            type: string
        - name: trx_id
          in: query
          schema:
            type: string
        - name: date_from
          in: query
          schema:
            type: string
            format: date
        - name: date_to
          in: query
          schema:
            type: string
            format: date
        - $ref: '#/components/parameters/PageQuery'
        - $ref: '#/components/parameters/PerPageQuery'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TransactionListResponse'

    post:
      tags: [Transactions]
      summary: Buat transaksi mitra eksternal
      operationId: createTransaction
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
        - $ref: '#/components/parameters/RequestId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateTransactionRequest'
            examples:
              donation:
                summary: Donasi campaign
                value:
                  donation_id: 9
                  amount: 1000000
                  name: Andi Chan
                  email: andichan@gmail.com
                  phone: "0853981253678"
                  partner_reference_id: SHP-20260603-001
              zakat:
                summary: Zakat maal
                value:
                  donation_id: 58
                  amount: 1000000
                  name: Andi Chan Test
                  email: andichantest@gmail.com
                  phone: "0853981253678"
                  npwp: "1234567891234567"
                  partner_reference_id: SHP-20260603-002
              qurban:
                summary: Qurban
                value:
                  donation_id: 37
                  amount: 2900000
                  name: Andi Chan Test
                  email: andichantest@gmail.com
                  phone: "0853981261336"
                  partner_reference_id: SHP-20260603-003
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TransactionResponse'
        '200':
          description: Idempotent replay
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TransactionResponse'
        '409':
          $ref: '#/components/responses/Conflict'
        '422':
          $ref: '#/components/responses/ValidationError'

  /transactions/history:
    get:
      tags: [Transactions]
      summary: Riwayat transaksi SUCCESS
      operationId: listTransactionHistory
      parameters:
        - $ref: '#/components/parameters/PageQuery'
        - $ref: '#/components/parameters/PerPageQuery'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TransactionListResponse'

  /transactions/{trx_id}:
    get:
      tags: [Transactions]
      summary: Detail transaksi by trx_id
      operationId: getTransactionByTrxId
      parameters:
        - name: trx_id
          in: path
          required: true
          schema:
            type: string
            example: LZNU00011718000000
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TransactionResponse'
        '404':
          $ref: '#/components/responses/NotFound'

components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
    PartnerCode:
      type: apiKey
      in: header
      name: X-Partner-Code
      description: Kode mitra unik (snake_case, diberikan saat onboarding)

  parameters:
    CategoryId:
      name: category_id
      in: path
      required: true
      schema:
        type: integer
    CategoryIdQuery:
      name: category_id
      in: query
      schema:
        type: integer
        default: 3
    SubCategoryIdQuery:
      name: sub_category_id
      in: query
      schema:
        type: integer
    OrganizationIdQuery:
      name: organization_id
      in: query
      schema:
        type: integer
    SearchQuery:
      name: search
      in: query
      schema:
        type: string
    PageQuery:
      name: page
      in: query
      schema:
        type: integer
        default: 1
        minimum: 1
    PerPageQuery:
      name: per_page
      in: query
      schema:
        type: integer
        default: 20
        minimum: 1
        maximum: 100
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: true
      schema:
        type: string
        format: uuid
    RequestId:
      name: X-Request-Id
      in: header
      required: false
      schema:
        type: string
        format: uuid

  responses:
    Unauthorized:
      description: Unauthorized
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    NotFound:
      description: Not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Conflict:
      description: Idempotency conflict
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    ValidationError:
      description: Validation error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ValidationErrorResponse'

  schemas:
    Meta:
      type: object
      required: [code, status, response_date, request_id]
      properties:
        code:
          type: integer
          example: 200
        status:
          type: string
          enum: [success, error]
        message:
          type: string
          nullable: true
        response_date:
          type: string
          format: date-time
          example: '2026-06-03T10:12:07+07:00'
        request_id:
          type: string
          format: uuid

    Pagination:
      type: object
      properties:
        current_page:
          type: integer
        per_page:
          type: integer
        total:
          type: integer
        last_page:
          type: integer

    ErrorResponse:
      type: object
      properties:
        meta:
          $ref: '#/components/schemas/Meta'
        data:
          nullable: true

    ValidationErrorResponse:
      allOf:
        - $ref: '#/components/schemas/ErrorResponse'
        - type: object
          properties:
            errors:
              type: object
              additionalProperties:
                type: array
                items:
                  type: string

    OrganizationSummary:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
        slug:
          type: string
        phone:
          type: string
        email:
          type: string
        address:
          type: string
        npwp:
          type: string

    PartnerProfile:
      type: object
      properties:
        partner_code:
          type: string
          example: your_partner_code
          description: Kode mitra unik. Nilai lengkap diberikan secara privat saat onboarding.
        partner_name:
          type: string
        organization:
          $ref: '#/components/schemas/OrganizationSummary'
        allowed_category_ids:
          type: array
          items:
            type: integer
        webhook_url:
          type: string
          format: uri
          nullable: true

    PartnerProfileResponse:
      type: object
      properties:
        meta:
          $ref: '#/components/schemas/Meta'
        data:
          $ref: '#/components/schemas/PartnerProfile'

    Category:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
        slug:
          type: string

    CategoryListResponse:
      type: object
      properties:
        meta:
          $ref: '#/components/schemas/Meta'
        data:
          type: array
          items:
            $ref: '#/components/schemas/Category'

    SubCategory:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
        slug:
          type: string
        category_id:
          type: integer

    SubCategoryListResponse:
      type: object
      properties:
        meta:
          $ref: '#/components/schemas/Meta'
        data:
          type: array
          items:
            $ref: '#/components/schemas/SubCategory'

    Campaign:
      type: object
      properties:
        id:
          type: integer
        title:
          type: string
        slug:
          type: string
        category:
          $ref: '#/components/schemas/Category'
        sub_category:
          $ref: '#/components/schemas/SubCategory'
        status:
          type: string
          example: open
        target:
          type: number
        total_collected:
          type: integer
        organization:
          $ref: '#/components/schemas/OrganizationSummary'
        started_at:
          type: string
        ended_at:
          type: string

    CampaignResponse:
      type: object
      properties:
        meta:
          $ref: '#/components/schemas/Meta'
        data:
          $ref: '#/components/schemas/Campaign'

    CampaignListResponse:
      type: object
      properties:
        meta:
          $ref: '#/components/schemas/Meta'
        data:
          type: array
          items:
            $ref: '#/components/schemas/Campaign'
        pagination:
          $ref: '#/components/schemas/Pagination'

    ZakatProgram:
      type: object
      properties:
        id:
          type: integer
        title:
          type: string
        slug:
          type: string
        program_type:
          type: string
          example: zakat
        category_id:
          type: integer
          example: 1
        status:
          type: string
          example: open
        minimum_amount:
          type: integer
          example: 10000

    ZakatListResponse:
      type: object
      properties:
        meta:
          $ref: '#/components/schemas/Meta'
        data:
          type: array
          items:
            $ref: '#/components/schemas/ZakatProgram'
        pagination:
          $ref: '#/components/schemas/Pagination'

    QurbanProduct:
      type: object
      properties:
        id:
          type: integer
        title:
          type: string
        slug:
          type: string
        category_id:
          type: integer
          example: 4
        price:
          type: integer
        status:
          type: string
          example: open
        organization:
          $ref: '#/components/schemas/OrganizationSummary'

    QurbanListResponse:
      type: object
      properties:
        meta:
          $ref: '#/components/schemas/Meta'
        data:
          type: array
          items:
            $ref: '#/components/schemas/QurbanProduct'
        pagination:
          $ref: '#/components/schemas/Pagination'

    CreateTransactionRequest:
      type: object
      required: [donation_id, amount, name]
      properties:
        donation_id:
          type: integer
          description: ID program donasi/zakat/qurban
        amount:
          type: integer
          minimum: 5000
        name:
          type: string
          maxLength: 255
        email:
          type: string
          format: email
        phone:
          type: string
          minLength: 8
          maxLength: 15
        npwp:
          type: string
        address:
          type: string
        description:
          type: string
        is_anon:
          type: boolean
          default: false
        partner_reference_id:
          type: string
          description: ID transaksi unik di sisi mitra
        meta_data:
          type: object
          additionalProperties: true

    Transaction:
      type: object
      properties:
        id:
          type: integer
        trx_id:
          type: string
        donation_id:
          type: integer
        donation:
          type: object
          properties:
            id:
              type: integer
            title:
              type: string
            slug:
              type: string
        amount:
          type: integer
        name:
          type: string
        email:
          type: string
        phone:
          type: string
        status:
          type: string
          enum: [PENDING, SUCCESS, EXPIRED]
        via_method:
          type: string
          example: partner
        payment_method:
          type: string
          example: your_partner_code
          description: Di-set server dari partner code mitra
        partner_code:
          type: string
        partner_reference_id:
          type: string
        meta_data:
          type: object
        created_at:
          type: string
          format: date-time
        expired_at:
          type: string
          format: date-time
          nullable: true

    TransactionResponse:
      type: object
      properties:
        meta:
          $ref: '#/components/schemas/Meta'
        data:
          $ref: '#/components/schemas/Transaction'

    TransactionListResponse:
      type: object
      properties:
        meta:
          $ref: '#/components/schemas/Meta'
        data:
          type: array
          items:
            $ref: '#/components/schemas/Transaction'
        pagination:
          $ref: '#/components/schemas/Pagination'
