# Link paymentStatus changed

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: ''
  description: ''
  version: 1.0.0
paths: {}
webhooks:
  payment_link.payment_status_changed:
    post:
      summary: Link paymentStatus changed
      deprecated: false
      description: >
        Sent when the aggregated paymentStatus of a link changes: NOT_STARTED →
        PENDING (payment created) or PENDING → COMPLETED (payment completed).


        Payload includes:

        - `paymentStatus` and `previousPaymentStatus`

        - `summary` with `totalPayments` and `completedPayments`

        - `paymentLink` payload (id, URLs, metadata, paymentStatus)

        - `latestPayment` when a payment triggered the change (id, status,
        timestamps, quote)
      tags:
        - Webhooks
        - Webhooks
      parameters:
        - name: User-Agent
          in: header
          description: Delivery user agent. Always sent as `SXPay-Webhook/1.0`.
          required: true
          example: SXPay-Webhook/1.0
          schema:
            type: string
        - name: x-sxpay-signature
          in: header
          description: >
            HMAC-SHA256 hex digest of "{timestamp}.{rawBody}" using the payment
            link webhookSecret. Sent only when a webhookSecret is configured.
          required: false
          example: ''
          schema:
            type: string
        - name: x-sxpay-timestamp
          in: header
          description: >-
            Unix epoch timestamp in milliseconds used with signature
            verification.
          required: false
          example: ''
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/WebhookPaymentLinkPaymentStatusChangedEvent'
            example:
              id: 1f2e3d4c-5b6a-7d8c-9e0f-1a2b3c4d5e6f
              type: payment_link.payment_status_changed
              createdAt: '2024-12-05T18:35:00.000Z'
              data:
                previousPaymentStatus: PENDING
                paymentStatus: COMPLETED
                summary:
                  totalPayments: 2
                  completedPayments: 1
                paymentLink:
                  id: 01KDKM3H65KCYAVMJTM8TBV8Y6
                  title: Payment Title
                  description: Payment Description
                  externalReference: 1b4db7eb-4057-5ddf-91e0-36dec72071f5
                  status: INACTIVE
                  isMultiUse: false
                  expiresAt: '2025-01-31T23:59:59.000Z'
                  amount: 129.9
                  currency: USD
                  paymentStatus: COMPLETED
                  url: >-
                    https://app.sxdigitalpay.com/quote/[merchantShortName]/[paymentLinkId]
                  shortUrl: https://sxpay.me/[paymentLinkShortId]
                  metadata: null
                  createdAt: '2024-12-05T18:20:00.000Z'
                latestPayment:
                  id: 01KDKM4KWRZKBGJWS08VTTPWNN
                  status: COMPLETED
                  createdAt: '2024-12-05T18:20:00.000Z'
                  completedAt: '2024-12-05T18:35:00.000Z'
                  availableAt: '2024-12-07T12:00:00.000Z'
                  paymentLinkId: 01KDKM3H65KCYAVMJTM8TBV8Y6
                  paymentLinkExternalReference: 1b4db7eb-4057-5ddf-91e0-36dec72071f5
                  quote:
                    amount: 129.9
                    currency: USD
                    paymentMethod: CREDIT_CARD
                    installments: 1
                    totalBRL: 658.35
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties: {}
                x-apidog-orders: []
                x-apidog-ignore-properties: []
          headers: {}
          x-apidog-name: Success
      security:
        - ApiKeyAuth: []
          x-apidog:
            schemeGroups:
              - id: aSabarTaLKMkoazJDLTtw
                schemeIds:
                  - ApiKeyAuth
            required: true
            use:
              id: aSabarTaLKMkoazJDLTtw
            scopes:
              aSabarTaLKMkoazJDLTtw:
                ApiKeyAuth: []
      x-apidog-folder: Webhooks
      x-apidog-status: released
      x-run-in-apidog: https://app.apidog.com/web/project/1147027/apis/api-25254368-run
components:
  schemas:
    WebhookPaymentLinkPaymentStatusChangedEvent:
      type: object
      properties:
        id:
          type: string
          format: uuid
        type:
          type: string
          enum:
            - payment_link.payment_status_changed
        createdAt:
          type: string
          format: date-time
        data:
          $ref: '#/components/schemas/WebhookLinkPaymentStatusEventData'
      required:
        - id
        - type
        - createdAt
        - data
      x-apidog-orders:
        - id
        - type
        - createdAt
        - data
      x-apidog-ignore-properties: []
      x-apidog-folder: ''
    WebhookLinkPaymentStatusEventData:
      type: object
      properties:
        paymentStatus: &ref_0
          $ref: '#/components/schemas/PaymentLinkPaymentStatus'
        previousPaymentStatus:
          oneOf:
            - *ref_0
            - type: 'null'
        summary:
          type: object
          properties:
            totalPayments:
              type: integer
            completedPayments:
              type: integer
          required:
            - totalPayments
            - completedPayments
          x-apidog-orders:
            - totalPayments
            - completedPayments
          x-apidog-ignore-properties: []
        paymentLink:
          $ref: '#/components/schemas/WebhookLinkPaymentStatusPayload'
        latestPayment:
          oneOf:
            - $ref: '#/components/schemas/WebhookPaymentPayload'
            - type: 'null'
      required:
        - paymentStatus
        - summary
        - paymentLink
      x-apidog-orders:
        - paymentStatus
        - previousPaymentStatus
        - summary
        - paymentLink
        - latestPayment
      x-apidog-ignore-properties: []
      x-apidog-folder: ''
    WebhookPaymentPayload:
      type: object
      properties:
        id:
          type: string
        status:
          $ref: '#/components/schemas/PaymentStatus'
        createdAt:
          type: string
          format: date-time
        completedAt:
          type:
            - string
            - 'null'
          format: date-time
        availableAt:
          type:
            - string
            - 'null'
          format: date-time
        paymentLinkId:
          type:
            - string
            - 'null'
        paymentLinkExternalReference:
          type:
            - string
            - 'null'
        quote:
          oneOf:
            - $ref: '#/components/schemas/PaymentQuote'
            - type: 'null'
      required:
        - id
        - status
        - createdAt
      x-apidog-orders:
        - id
        - status
        - createdAt
        - completedAt
        - availableAt
        - paymentLinkId
        - paymentLinkExternalReference
        - quote
      x-apidog-ignore-properties: []
      x-apidog-folder: ''
    PaymentQuote:
      type: object
      properties:
        amount:
          type: number
        currency:
          type: string
        paymentMethod:
          $ref: '#/components/schemas/PaymentMethod'
        installments:
          type: integer
        totalBRL:
          type:
            - number
            - 'null'
      x-apidog-orders:
        - amount
        - currency
        - paymentMethod
        - installments
        - totalBRL
      x-apidog-ignore-properties: []
      x-apidog-folder: ''
    PaymentMethod:
      type: string
      enum:
        - PIX
        - CREDIT_CARD
      x-apidog-folder: ''
    PaymentStatus:
      type: string
      enum:
        - PENDING
        - COMPLETED
        - DISPUTED
        - REFUNDED
      x-apidog-folder: ''
    WebhookLinkPaymentStatusPayload:
      allOf:
        - $ref: '#/components/schemas/WebhookLinkPayloadBase'
        - type: object
          properties:
            paymentStatus: *ref_0
          required:
            - paymentStatus
          x-apidog-orders:
            - paymentStatus
          x-apidog-ignore-properties: []
      x-apidog-folder: ''
    WebhookLinkPayloadBase:
      type: object
      properties:
        id:
          type: string
        title:
          type: string
        description:
          type:
            - string
            - 'null'
        externalReference:
          type:
            - string
            - 'null'
        status:
          $ref: '#/components/schemas/PaymentLinkStatus'
        isMultiUse:
          type: boolean
          description: Always false for this API.
        expiresAt:
          type:
            - string
            - 'null'
          format: date-time
        amount:
          type: number
        currency:
          type: string
        url:
          type: string
          format: uri
        shortUrl:
          type: string
          format: uri
        metadata:
          type:
            - object
            - 'null'
          additionalProperties: true
          properties: {}
          x-apidog-orders: []
          x-apidog-ignore-properties: []
        createdAt:
          type: string
          format: date-time
      required:
        - id
        - title
        - status
        - isMultiUse
        - amount
        - currency
        - url
        - shortUrl
      x-apidog-orders:
        - id
        - title
        - description
        - externalReference
        - status
        - isMultiUse
        - expiresAt
        - amount
        - currency
        - url
        - shortUrl
        - metadata
        - createdAt
      x-apidog-ignore-properties: []
      x-apidog-folder: ''
    PaymentLinkStatus:
      type: string
      enum:
        - ACTIVE
        - INACTIVE
        - EXPIRED
      x-apidog-folder: ''
    PaymentLinkPaymentStatus:
      type: string
      description: >-
        Aggregated view of payments for the link (NOT_STARTED = no payments;
        PENDING = payments exist but none completed; COMPLETED = at least one
        completed payment, even if later disputed or refunded).
      enum:
        - NOT_STARTED
        - PENDING
        - COMPLETED
      x-apidog-folder: ''
  securitySchemes:
    ApiKeyAuth:
      type: apikey
      in: header
      name: x-api-key
      description: >-
        API key provisioned per merchant. Authorization: Bearer <api-key> is
        also accepted.
    WebhookSignature:
      type: apikey
      in: header
      name: x-sxpay-signature
      description: >
        HMAC-SHA256 signature calculated over "{timestamp}.{rawBody}" using the
        link's webhookSecret. Includes header x-sxpay-timestamp (epoch ms) for
        replay protection. These headers are only sent when a webhookSecret is
        configured for the link.
servers:
  - url: https://sandbox.sxdigitalpay.com/api/v1
    description: Sandbox
  - url: https://app.sxdigitalpay.com/api/v1
    description: Prod
security:
  - ApiKeyAuth: []
    x-apidog:
      schemeGroups:
        - id: aSabarTaLKMkoazJDLTtw
          schemeIds:
            - ApiKeyAuth
      required: true
      use:
        id: aSabarTaLKMkoazJDLTtw
      scopes:
        aSabarTaLKMkoazJDLTtw:
          ApiKeyAuth: []

```
