# Create single-use payment link

## OpenAPI Specification

```yaml
openapi: 3.0.1
info:
  title: ''
  description: ''
  version: 1.0.0
paths:
  /payment-links:
    post:
      summary: Create single-use payment link
      deprecated: false
      description: >
        Creates a single-use payment link. Currency comes from the authenticated
        merchant and isMultiUse is always false.


        Validation rules:

        - title is required and cannot be empty.

        - amount must be a number greater than 25.

        - expiresAt, if sent, must be a future ISO 8601 date-time.

        - externalReference, if sent, must be unique per merchant (409 if it
        already exists).

        - webhookUrl, if sent, must be http(s); webhookSecret is optional and if
        omitted a secure secret is generated and returned only on creation.

        - callbackUrl, if sent, must be a valid http(s) URL. After a successful
        payment the customer is redirected to it.

        - metadata accepts only JSON objects; other types are ignored and stored
        as null.
      tags:
        - PaymentLinks
        - PaymentLinks
      parameters: []
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreatePaymentLinkRequest'
            example:
              title: Payment title
              description: Payment Description
              amount: 129.9
              expiresAt: '{{$date.future}}'
              externalReference: '{{$string.uuid}}'
              metadata: null
              webhookUrl: https://merchant.com/webhooks/sxpay
              webhookSecret: WebhookSecretForWebhookValidation
              callbackUrl: https://merchant.com/checkout/success
      responses:
        '201':
          description: Link created successfully.
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  paymentLink:
                    $ref: '#/components/schemas/PaymentLinkCreated'
                required:
                  - success
                  - paymentLink
                x-apidog-orders:
                  - success
                  - paymentLink
                x-apidog-ignore-properties: []
              example:
                success: true
                paymentLink:
                  id: pl_123
                  externalReference: 1b4db7eb-4057-5ddf-91e0-36dec72071f5
                  title: Payment Title
                  description: Payment Description
                  amount: 129.9
                  currency: USD
                  status: ACTIVE
                  isMultiUse: false
                  isActive: true
                  isExpired: false
                  expiresAt: '2025-01-31T23:59:59.000Z'
                  url: >-
                    https://app.sxdigitalpay.com/quote/[merchantShortName]/[paymentLinkId]
                  shortUrl: https://sxpay.me/[paymentLinkShortId]
                  metadata: null
                  callbackUrl: https://merchant.com/checkout/success
                  paymentStatus: NOT_STARTED
                  paymentsSummary:
                    total: 0
                    byStatus: {}
                  payments: []
                  webhookUrl: https://merchant.com/webhooks/sxpay
                  webhookSecret: 8f2c58c1c9a34f7e8b1a2c3d4e5f6789
          headers:
            X-RateLimit-Limit:
              schema:
                type: string
            X-RateLimit-Remaining:
              schema:
                type: string
            X-RateLimit-Reset:
              schema:
                type: string
          x-apidog-name: ''
        '400':
          description: Invalid request.
          content:
            application/json:
              schema: &ref_0
                $ref: '#/components/schemas/Error'
              examples:
                '3':
                  summary: invalidJson
                  value:
                    error: Invalid JSON
                '4':
                  summary: invalidTitle
                  value:
                    error: Title is required
                '5':
                  summary: invalidAmount
                  value:
                    error: Invalid amount
                '6':
                  summary: invalidDate
                  value:
                    error: Invalid expiration date
                '7':
                  summary: pastDate
                  value:
                    error: Expiration date must be future
                '8':
                  summary: invalidWebhook
                  value:
                    error: >-
                      webhookUrl must be a valid URL and cannot target
                      private/internal addresses
          headers: {}
          x-apidog-name: BadRequest
        '401':
          description: Missing or invalid API key.
          content:
            application/json:
              schema: *ref_0
              examples:
                '9':
                  summary: missing
                  value:
                    error: API Key not found
                '10':
                  summary: invalid
                  value:
                    error: Invalid API Key
          headers: {}
          x-apidog-name: Unauthorized
        '403':
          description: Merchant is not active.
          content:
            application/json:
              schema: *ref_0
              example:
                error: Inactive Merchant
          headers: {}
          x-apidog-name: Forbidden
        '409':
          description: externalReference already exists for this merchant.
          content:
            application/json:
              schema: *ref_0
              example:
                error: externalReference already exists to this merchant
                paymentLinkId: pl_existing
          headers: {}
          x-apidog-name: ''
        '429':
          description: Rate limit exceeded.
          content:
            application/json:
              schema: *ref_0
              example:
                error: Too many requests. Try again in 60 seconds.
          headers:
            X-RateLimit-Limit:
              schema:
                type: string
            X-RateLimit-Remaining:
              schema:
                type: string
            X-RateLimit-Reset:
              schema:
                type: string
            Retry-After:
              schema:
                type: string
          x-apidog-name: TooManyRequests
      security:
        - ApiKeyAuth: []
          x-apidog:
            schemeGroups:
              - id: yKht1omofir3b5Osp4ctd
                schemeIds:
                  - ApiKeyAuth
            required: true
            use:
              id: yKht1omofir3b5Osp4ctd
            scopes:
              yKht1omofir3b5Osp4ctd:
                ApiKeyAuth: []
      x-apidog-folder: PaymentLinks
      x-apidog-status: released
      x-run-in-apidog: https://app.apidog.com/web/project/1147027/apis/api-25254364-run
components:
  schemas:
    CreatePaymentLinkRequest:
      type: object
      properties:
        title:
          type: string
        description:
          type: string
        amount:
          type: number
          format: double
          exclusiveMinimum: true
          description: Amount must be greater than 25.
          minimum: 25
        expiresAt:
          type: string
          format: date-time
          description: Must be a future ISO 8601 date-time if sent.
        externalReference:
          type: string
          description: Merchant's own reference (must be unique per merchant).
        metadata:
          description: >-
            Only JSON objects are persisted; other types are ignored and stored
            as null.
          type: object
          additionalProperties: true
          properties: {}
          x-apidog-orders: []
          x-apidog-ignore-properties: []
          nullable: true
        webhookUrl:
          type: string
          format: uri
          description: HTTP(S) URL to receive webhooks for this link.
        webhookSecret:
          type: string
          description: >-
            Optional secret to sign webhooks; if omitted, a secure value is
            generated.
        callbackUrl:
          type: string
          format: uri
          description: Optional redirect URL after a successful payment.
      required:
        - title
        - amount
      x-apidog-orders:
        - title
        - description
        - amount
        - expiresAt
        - externalReference
        - metadata
        - webhookUrl
        - webhookSecret
        - callbackUrl
      x-apidog-ignore-properties: []
      x-apidog-folder: ''
    PaymentLinkCreated:
      allOf:
        - $ref: '#/components/schemas/PaymentLinkWithPayments'
        - type: object
          properties:
            webhookSecret:
              type: string
              description: Returned only at creation time when webhookUrl is provided.
              nullable: true
          x-apidog-orders:
            - webhookSecret
          x-apidog-ignore-properties: []
      x-apidog-folder: ''
    PaymentLinkWithPayments:
      allOf:
        - $ref: '#/components/schemas/PaymentLinkWithWebhook'
        - type: object
          properties:
            paymentStatus: &ref_1
              $ref: '#/components/schemas/PaymentLinkPaymentStatus'
            paymentsSummary:
              $ref: '#/components/schemas/PaymentsSummary'
            payments:
              type: array
              items:
                $ref: '#/components/schemas/Payment'
          x-apidog-orders:
            - paymentStatus
            - paymentsSummary
            - payments
          x-apidog-ignore-properties: []
      required:
        - paymentStatus
        - payments
        - paymentsSummary
      x-apidog-folder: ''
    Payment:
      type: object
      properties:
        id:
          type: string
        status:
          $ref: '#/components/schemas/PaymentStatus'
        createdAt:
          type: string
          format: date-time
        completedAt:
          type: string
          format: date-time
          nullable: true
        availableAt:
          type: string
          format: date-time
          nullable: true
        customer:
          oneOf:
            - $ref: '#/components/schemas/PaymentCustomer'
            - type: 'null'
        quote:
          oneOf:
            - $ref: '#/components/schemas/PaymentQuote'
            - type: 'null'
      required:
        - id
        - status
        - createdAt
      x-apidog-orders:
        - id
        - status
        - createdAt
        - completedAt
        - availableAt
        - customer
        - 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
          nullable: true
      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: ''
    PaymentCustomer:
      type: object
      properties:
        name:
          type: string
        email:
          type: string
          format: email
      required:
        - name
        - email
      x-apidog-orders:
        - name
        - email
      x-apidog-ignore-properties: []
      x-apidog-folder: ''
    PaymentStatus:
      type: string
      enum:
        - PENDING
        - COMPLETED
        - DISPUTED
        - REFUNDED
      x-apidog-folder: ''
    PaymentsSummary:
      type: object
      description: Aggregated counts of payments grouped by their current status.
      properties:
        total:
          type: integer
          description: Total number of payments for the link.
        byStatus:
          type: object
          additionalProperties:
            type: integer
          description: >-
            Keys are payment status values (PENDING, COMPLETED, DISPUTED,
            REFUNDED).
          properties: {}
          x-apidog-orders: []
          x-apidog-ignore-properties: []
      required:
        - total
        - byStatus
      x-apidog-orders:
        - total
        - byStatus
      x-apidog-ignore-properties: []
      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: ''
    PaymentLinkWithWebhook:
      allOf:
        - $ref: '#/components/schemas/PaymentLinkBase'
        - type: object
          properties:
            webhookUrl:
              type: string
              format: uri
              nullable: true
            paymentStatus: *ref_1
          x-apidog-orders:
            - webhookUrl
            - paymentStatus
          x-apidog-ignore-properties: []
      x-apidog-folder: ''
    PaymentLinkBase:
      type: object
      properties:
        id:
          type: string
        externalReference:
          type: string
          nullable: true
        title:
          type: string
        description:
          type: string
          nullable: true
        amount:
          type: number
          format: double
          description: Amount in the merchant's currency.
        currency:
          type: string
          description: Merchant currency (e.g., USD, EUR, GBP).
        status:
          $ref: '#/components/schemas/PaymentLinkStatus'
        isMultiUse:
          type: boolean
          description: Always false for this API.
        isActive:
          type: boolean
          description: True only if status is ACTIVE and expiresAt has not passed.
        isExpired:
          type: boolean
        expiresAt:
          type: string
          format: date-time
          nullable: true
        url:
          type: string
          format: uri
          description: >-
            The complete URL of the quotation page to which the user should be
            directed to proceed with the payment.
        shortUrl:
          type: string
          format: uri
          description: Short URL for the `url` field.
        metadata:
          description: JSON object stored with the link.
          type: object
          additionalProperties: true
          properties: {}
          x-apidog-orders: []
          x-apidog-ignore-properties: []
          nullable: true
        callbackUrl:
          type: string
          format: uri
          description: Optional redirect URL after a successful payment.
          nullable: true
        createdAt:
          type: string
          format: date-time
      required:
        - id
        - title
        - amount
        - currency
        - status
        - isMultiUse
        - isActive
        - isExpired
        - url
        - shortUrl
      x-apidog-orders:
        - id
        - externalReference
        - title
        - description
        - amount
        - currency
        - status
        - isMultiUse
        - isActive
        - isExpired
        - expiresAt
        - url
        - shortUrl
        - metadata
        - callbackUrl
        - createdAt
      x-apidog-ignore-properties: []
      x-apidog-folder: ''
    PaymentLinkStatus:
      type: string
      enum:
        - ACTIVE
        - INACTIVE
        - EXPIRED
      x-apidog-folder: ''
    Error:
      type: object
      properties:
        error:
          type: string
      required:
        - error
      x-apidog-orders:
        - error
      x-apidog-ignore-properties: []
      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: []

```
