openapi: 3.0.3
info:
  title: Payment Connector Contract - Reauthorise
  description:
    Recommended pattern for building the reauthorise flow of a connector between a Payment Service Providers and the Fluent platform.
  version: 1.0.0
paths:
  /connector:
    description: Webhooks recieved by the connector
    post:
      summary: Payment Connector webhook receiver
      tags:
        - Connector
      requestBody:
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/payment-reauthorise-request'
      responses:
        200:
          description: "Successful Operation"
        500:
          description: "Server-side error, please retry later"
      servers:
        - description: The custom connector instance (not a Fluent API URL)
          url: https://example.com
  /api/v4.1/event/async:
    post:
      summary: Payment Reauthorise response event
      tags:
        - Fluent Commerce
      security:
        - BearerAuth: [admin]   # Use OAuth with a different scope
      requestBody:
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/payment-reauthorise-success'
                - $ref: '#/components/schemas/payment-reauthorise-error'
      responses:
        200:
          description: "Successful Operation"
        401:
          description: "Authorization Error - Invalid Bearer Token / No permission"
        400:
          description: "Client Error - Bad Request"
      servers:
        - description: Fluent Commerce Sandbox
          url: https://{account}.sandbox.api.fluentretail.com
          variables:
            account:
              default: fluent
              description: The name of the Fluent account
        - description: Fluent Commerce Production
          url: https://{account}.api.fluentretail.com
          variables:
            account:
              default: fluent
              description: The name of the Fluent account
components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
  schemas:
    event-base:
      title: Event
      type: object
      required: [name, retailerId, entityType, entityId, entityRef, rootEntityType, rootEntityId, rootEntityRef]
      properties:
        name:
          type: string
        retailerId:
          type: string
        entityType:
          type: string
          pattern: 'INVOICE'
        entityId:
          type: string
        entityRef:
          type: string
        rootEntityType:
          type: string
          pattern: 'BILLING_ACCOUNT'
        rootEntityId:
          type: string
        rootEntityRef:
          type: string
        attributes:
          type: object
          required: [ transactionRef ]
          properties:
            transactionRef:
              type: string
    payment-reauthorise-request:
      type: object
      title: Payment Reauthorise Request
      description: Describes the payload of payment authorise request
      allOf:
        - $ref: '#/components/schemas/event-base'
      properties:
        name:
          type: string
          pattern: fc\.connect\.payment\.reauthorise
    payment-reauthorise-success:
      type: object
      title: Payment Reauthorise Response (Success)
      description: Register a payment reauthorise success
      allOf:
        - $ref: '#/components/schemas/event-base'
      properties:
        name:
          type: string
          pattern: fc\.connect\.payment\.reauthorise\.success
    payment-reauthorise-error:
      type: object
      title: Payment Reauthorise Response (Error)
      description: Register a payment reauthorise error
      allOf:
        - $ref: '#/components/schemas/event-base'
      properties:
        name:
          type: string
          pattern: fc\.connect\.payment\.authorise\.error
        attributes:
          type: object
          required: [transactionRef, errorCode]
          properties:
            transactionRef:
              type: string
            errorCode:
              type: string
            errorMessage:
              type: string

