openapi: 3.0.3
info:
  version: '0.1'
  title: ABB v0.1 REST API
  license:
    name: MIT
    url: 'https://spdx.org/licenses/MIT'
  termsOfService: 'https://docs.ibar.az/articles/abb-terms-of-service'
  contact:
    name: Support
    url: 'https://support.ibar.az/contact'
tags:
  - name: edv
    description: Endpoints to manage EDV using the REST API.
servers:
  - url: 'https://api.ibar.az/v0.1'
    description: Production URL
  - url: 'http://localhost:8080'
    description: Local URL
externalDocs:
  description: ABB v0.1 REST API
  url: 'https://docs.ibar.az/rest'
paths:
  '/edv/info':
    get:
      summary: Get current information of edv
      security:
        - openId:
            - edv_info_read
      description: This returns the total counts and amounts by authendticated-user
      tags:
        - edv
      operationId: getEdvInfo
      externalDocs:
        description: API method documentation
        url: 'https://docs.ibar.az/rest/reference/edv/#get-users-edv-info'
      responses:
        '200':
          description: Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EdvInfo'
        '304':
          description: Not modified
        '401':
          description: Requires authentication
          content: &ref_0
            application/json:
              schema:
                title: Basic Error
                description: Basic Error
                type: object
                properties:
                  message:
                    type: string
                  documentation_url:
                    type: string
                  url:
                    type: string
                  status:
                    type: string
        '403':
          description: Forbidden
          content: *ref_0
  '/edv/receipts':
    post:
      summary: Add a receipt
      security:
        - openId:
            - receipts_write
      description: |-
        Allows you to add a new receipt.

        **Note:** Notes for receipt adding.
      operationId: addReceipt
      tags:
        - edv
      externalDocs:
        description: API method documentation
        url: 'https://docs.ibar.az/rest/reference/edv/#add-a-receipt'
      parameters: []
      requestBody:
        content:
          application/json:
            schema:
              properties:
                fiscalId:
                  description: uid for receipt
                  example: '321321231231'
                  pattern: '^[a-zA-Z0-9]{12}$'
                  type: string
              type: object
      responses:
        '201':
          description: Response
          content:
            application/json:
              schema:
                  $ref: '#/components/schemas/Receipt'
        '401':
          description: Requires authentication
          content: *ref_0
        '403':
          description: Forbidden
          content: *ref_0
        '404':
          description: Resource not found
          content: *ref_0
        '422':
          description: Validation failed
          content: &ref_1
            application/json:
              schema:
                title: Validation Error
                description: Validation Error
                type: object
                required:
                  - message
                  - documentation_url
                properties:
                  message:
                    type: string
                  documentation_url:
                    type: string
                  errors:
                    type: array
                    items:
                      type: object
                      required:
                        - code
                      properties:
                        resource:
                          type: string
                        field:
                          type: string
                        message:
                          type: string
                        code:
                          type: string
                        index:
                          type: integer
                        value:
                          oneOf:
                            - type: string
                              nullable: true
                            - type: integer
                              nullable: true
                            - type: array
                              nullable: true
                              items:
                                type: string
  '/edv/payments/mobile/azercell':
    post:
      summary: Pay to azercell mobile
      security:
        - openId:
            - edv_pay_azercell_write
      description: >-
        Pay to azercell mobile with given amount and phone prefix, the payment
        occurs from edv balance
      tags:
        - edv
      operationId: payToAzercell
      externalDocs:
        description: API method documentation
        url: 'https://docs.ibar.az/rest/reference/edv/#pay-to-azercell'
      parameters:
        - in: header
          name: X-Idempotency-Key
          description: >-
            make payment idempotent with client-generated X-Idempotency-Key value
          schema:
            type: string
            format: uuid
          required: true
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AzercellPayment'
      responses:
        '201':
          description: Response
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    description: Unique identifier for payment operation
        '401':
          description: Requires authentication
          content: *ref_0
        '403':
          description: Forbidden
          content: *ref_0
        '404':
          description: Resource not found
          content: *ref_0
        '422':
          description: Validation failed
          content: *ref_1
components:
  schemas:
    Receipt:
      title: Receipt
      description: Simple receipt object
      type: object
      properties:
        id:
          type: integer
        fiscalId:
          type: string
          description: Scanned/entered fiscal id of receipt
        status:
          type: string
          description: Current status of added receipt
          enum:
            - WAITING
            - PREPAY
            - PREPAID
            - REFUNDING
            - REFUNDED
            - CANCELLED
            - SCANNING
        transactionDate:
          type: string
          format: date-time
          description: Transaction date of receipt
        amount:
          type: number
          format: decimal
          description: Payment amount of receipt
        returnAmount:
          type: number
          format: decimal
        storeAddress:
          type: string
        createdAt:
          type: string
          format: date-time
          description: Uploading date of receipt to the system
        vatAmount:
          type: number
          format: decimal
          description: VAT amount of receipt
    UserReceiptSummary:
      title: UserReceiptSummary
      description: User's receipt summary with status counts
      type: object
      properties:
        totalWaitingCount:
          type: integer
          description: Total waiting receipt count of authenticated user
          example: 10
        totalRefundedCount:
          type: integer
          description: Total refunded receipt count of authenticated user
        totalCancelledCount:
          type: integer
          description: Total cancelled receipt count of authenticated user
    AzercellPayment:
      type: object
      title: AzercellPayment
      properties:
        phone:
          description: Sink details for payment
          type: object
          properties:
            prefix:
              type: string
              description: Phone prefix
              enum:
                - '050'
                - '053'
                - '054'
            no:
              type: string
        amount:
          description: Amount to pay to azercell mobile
          type: number
          format: decimal
    EdvInfo:
      allOf:
        - $ref: '#/components/schemas/UserReceiptSummary'
        - type: object
          title: EdvInfo
          properties:
            totalWaitingAmount:
              type: number
              format: decimal
            totalRefundedAmount:
              type: number
              format: decimal
            totalCancelledAmount:
              type: number
              format: decimal
            balance:
              type: number
              format: decimal
    WebookReceiptPayload:
      title: Webhook Receipt Payload
      type: object
      properties:
        id:
          type: string
          description: Receipt Id
        fiscalId:
          type: string
          description: Scanned/entered fiscal id of receipt
        status:
          type: string
          description: Status of Receipt
          enum:
            - REFUNDED
            - CANCELLED
        cancelledReason:
          type: string
          description: Receipt cancellation reason
        userId:
          type: string
          description: Authenticated User Id
    WebookPaymentPayload:
      title: Webhook AzercellPayment Payload
      type: object
      properties:
        id:
          type: string
          description: Payment id
        status:
          type: string
          description: Current status of the payment operation
          enum:
            - CANCELLED
            - COMPLETED
        cancelledReason:
          type: string
          description: Receipt cancellation reason
        phone:
          description: Sink details for payment
          type: object
          properties:
            prefix:
              type: string
              description: Phone prefix
              enum:
                - '050'
                - '053'
                - '054'
            no:
              type: string
        amount:
          description: Amount to pay to azercell mobile
          type: number
          format: decimal
        userId:
          type: string
          description: Authenticated User Id
  securitySchemes:
    openId:
      type: openIdConnect
      openIdConnectUrl: /auth/realms/iba-open-banking/.well-known/openid-configuration
