{
 "openapi": "3.1.0",
 "info": {
  "title": "Pulses Pay API",
  "version": "1.0.0",
  "description": "Crypto payments for merchants: invoices, static wallets, subscriptions, payouts and signed webhooks.\n\nAuth: `Authorization: Bearer cpk_...` (live) or `cpk_test_...` (sandbox). Payouts require a dedicated payout key when one is issued.\nWebhooks: POST JSON, `x-cpay-timestamp` + `x-cpay-signature = HMAC-SHA256(secret, timestamp + '.' + raw_body)`.\nStatuses: pending, confirming, partial, paid, paid_over, partial_final, expired, cancelled, hold, refunded.",
  "contact": {
   "name": "Pulses Pay support",
   "email": "support@pulses.exchange",
   "url": "https://pay.pulses.exchange/docs"
  }
 },
 "servers": [
  {
   "url": "https://pay.pulses.exchange",
   "description": "Production"
  }
 ],
 "security": [
  {
   "bearerAuth": []
  }
 ],
 "components": {
  "securitySchemes": {
   "bearerAuth": {
    "type": "http",
    "scheme": "bearer",
    "bearerFormat": "cpk_* or cpk_test_* or cpk_pay_*"
   }
  },
  "parameters": {
   "uuid": {
    "name": "uuid",
    "in": "path",
    "required": true,
    "schema": {
     "type": "string"
    }
   },
   "idempotency": {
    "name": "Idempotency-Key",
    "in": "header",
    "required": false,
    "schema": {
     "type": "string",
     "minLength": 8,
     "maxLength": 128
    }
   }
  },
  "schemas": {
   "Error": {
    "type": "object",
    "properties": {
     "ok": {
      "type": "boolean",
      "const": false
     },
     "error": {
      "type": "string"
     },
     "message": {
      "type": "string"
     }
    },
    "required": [
     "ok",
     "error"
    ]
   },
   "Invoice": {
    "type": "object",
    "properties": {
     "uuid": {
      "type": "string"
     },
     "order_id": {
      "type": [
       "string",
       "null"
      ]
     },
     "status": {
      "type": "string",
      "enum": [
       "pending",
       "confirming",
       "partial",
       "paid",
       "paid_over",
       "partial_final",
       "expired",
       "cancelled",
       "hold",
       "refunded"
      ]
     },
     "is_final": {
      "type": "boolean"
     },
     "test": {
      "type": "boolean"
     },
     "amount": {
      "type": "string"
     },
     "currency": {
      "type": "string"
     },
     "pay_currency": {
      "type": [
       "string",
       "null"
      ]
     },
     "pay_amount": {
      "type": [
       "string",
       "null"
      ]
     },
     "network": {
      "type": [
       "string",
       "null"
      ]
     },
     "asset": {
      "type": [
       "string",
       "null"
      ]
     },
     "address": {
      "type": [
       "string",
       "null"
      ]
     },
     "address_qr_code": {
      "type": [
       "string",
       "null"
      ],
      "description": "PNG data URL when the address is already known"
     },
     "received": {
      "type": "string"
     },
     "pending": {
      "type": "string"
     },
     "fee": {
      "type": "string"
     },
     "commission": {
      "type": "string"
     },
     "merchant_amount": {
      "type": "string"
     },
     "fee_payer": {
      "type": "string",
      "enum": [
       "merchant",
       "payer"
      ]
     },
     "payer_source": {
      "type": "string",
      "nullable": true,
      "enum": [
       "exchange",
       "wallet"
      ]
     },
     "additional_data": {
      "type": [
       "string",
       "null"
      ]
     },
     "url": {
      "type": "string",
      "format": "uri"
     },
     "description": {
      "type": [
       "string",
       "null"
      ]
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "expires_at": {
      "type": "string",
      "format": "date-time"
     },
     "paid_at": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time"
     }
    },
    "required": [
     "uuid",
     "status",
     "amount",
     "currency",
     "url"
    ]
   },
   "InvoiceCreate": {
    "type": "object",
    "required": [
     "amount"
    ],
    "properties": {
     "amount": {
      "type": "string",
      "description": "Decimal string in `currency`"
     },
     "currency": {
      "type": "string",
      "default": "USDT"
     },
     "order_id": {
      "type": "string",
      "description": "Unique per merchant; repeats return the same invoice"
     },
     "pay_currency": {
      "type": "string"
     },
     "to_currency": {
      "type": "string",
      "description": "Alias of pay_currency"
     },
     "network": {
      "type": "string"
     },
     "currencies": {
      "type": "array",
      "items": {
       "type": "string"
      }
     },
     "except_currencies": {
      "type": "array",
      "items": {
       "type": "string"
      }
     },
     "lifetime_min": {
      "type": "integer",
      "minimum": 5,
      "maximum": 1440
     },
     "callback_url": {
      "type": "string",
      "format": "uri"
     },
     "success_url": {
      "type": "string",
      "format": "uri"
     },
     "fail_url": {
      "type": "string",
      "format": "uri"
     },
     "description": {
      "type": "string"
     },
     "customer_email": {
      "type": "string",
      "format": "email"
     },
     "meta": {
      "type": "object"
     },
     "additional_data": {
      "type": "string",
      "maxLength": 255
     },
     "fee_payer": {
      "type": "string",
      "enum": [
       "merchant",
       "payer"
      ]
     },
     "payer_source": {
      "type": "string",
      "enum": [
       "exchange",
       "wallet",
       "ask"
      ],
      "description": "exchange | wallet: address from that pool, payment page does not ask; ask: payment page asks the customer first"
     },
     "subtract": {
      "type": "integer",
      "enum": [
       0,
       100
      ]
     },
     "discount_percent": {
      "type": "number",
      "minimum": -99,
      "maximum": 100
     },
     "accuracy_payment_percent": {
      "type": "number",
      "minimum": 0,
      "maximum": 5
     },
     "is_refresh": {
      "type": "boolean"
     }
    }
   },
   "Payout": {
    "type": "object",
    "properties": {
     "uuid": {
      "type": "string"
     },
     "order_id": {
      "type": [
       "string",
       "null"
      ]
     },
     "status": {
      "type": "string",
      "enum": [
       "pending",
       "approval",
       "processing",
       "done",
       "failed",
       "cancelled"
      ]
     },
     "is_final": {
      "type": "boolean"
     },
     "test": {
      "type": "boolean"
     },
     "currency": {
      "type": "string"
     },
     "amount": {
      "type": "string"
     },
     "fee": {
      "type": "string"
     },
     "total": {
      "type": "string"
     },
     "address": {
      "type": "string"
     },
     "txid": {
      "type": [
       "string",
       "null"
      ]
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "Wallet": {
    "type": "object",
    "properties": {
     "uuid": {
      "type": "string"
     },
     "customer_id": {
      "type": "string"
     },
     "currency": {
      "type": "string"
     },
     "address": {
      "type": "string"
     },
     "status": {
      "type": "string",
      "enum": [
       "active",
       "blocked"
      ]
     },
     "received": {
      "type": "string"
     },
     "test": {
      "type": "boolean"
     },
     "url": {
      "type": "string",
      "format": "uri"
     }
    }
   }
  },
  "responses": {
   "Error": {
    "description": "API error",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   }
  }
 },
 "paths": {
  "/api/v1/balance": {
   "get": {
    "summary": "Merchant balances",
    "operationId": "balance",
    "responses": {
     "200": {
      "description": "OK"
     }
    }
   }
  },
  "/api/v1/currencies": {
   "get": {
    "summary": "Enabled currencies and minimums",
    "operationId": "currencies",
    "responses": {
     "200": {
      "description": "OK"
     }
    }
   }
  },
  "/api/v1/discounts": {
   "get": {
    "summary": "Per-coin discounts and markups",
    "operationId": "listDiscounts",
    "responses": {
     "200": {
      "description": "OK"
     }
    }
   },
   "post": {
    "summary": "Set a per-coin discount or markup (live key only)",
    "operationId": "setDiscount",
    "responses": {
     "200": {
      "description": "OK"
     },
     "403": {
      "$ref": "#/components/responses/Error"
     }
    }
   }
  },
  "/api/v1/invoices": {
   "post": {
    "summary": "Create an invoice",
    "operationId": "createInvoice",
    "parameters": [
     {
      "$ref": "#/components/parameters/idempotency"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/InvoiceCreate"
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Created",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "ok": {
           "const": true
          },
          "result": {
           "$ref": "#/components/schemas/Invoice"
          }
         }
        }
       }
      }
     },
     "200": {
      "description": "Existing invoice for this order_id"
     },
     "400": {
      "$ref": "#/components/responses/Error"
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "403": {
      "$ref": "#/components/responses/Error"
     }
    }
   },
   "get": {
    "summary": "List invoices or fetch one by order_id",
    "operationId": "listInvoices",
    "parameters": [
     {
      "name": "order_id",
      "in": "query",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "maximum": 200
      }
     },
     {
      "name": "offset",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 0
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     }
    }
   }
  },
  "/api/v1/invoices/{uuid}": {
   "get": {
    "summary": "Get an invoice",
    "operationId": "getInvoice",
    "parameters": [
     {
      "$ref": "#/components/parameters/uuid"
     }
    ],
    "responses": {
     "200": {
      "description": "OK"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     }
    }
   }
  },
  "/api/v1/invoices/{uuid}/cancel": {
   "post": {
    "summary": "Cancel an unpaid invoice",
    "operationId": "cancelInvoice",
    "parameters": [
     {
      "$ref": "#/components/parameters/uuid"
     }
    ],
    "responses": {
     "200": {
      "description": "OK"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     }
    }
   }
  },
  "/api/v1/invoices/{uuid}/pay": {
   "post": {
    "summary": "Simulate a payment for a test invoice (sandbox only)",
    "description": "Test key only. Marks the test invoice as paid with an optional amount and returns the updated invoice; no real funds move.",
    "operationId": "simulateInvoicePayment",
    "parameters": [
     {
      "$ref": "#/components/parameters/uuid"
     }
    ],
    "requestBody": {
     "required": false,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "amount": {
          "type": "string",
          "description": "Amount to simulate, defaults to the invoice amount"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "OK"
     },
     "403": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     }
    }
   }
  },
  "/api/v1/invoices/{uuid}/refund": {
   "post": {
    "summary": "Refund a paid invoice to the payer address",
    "operationId": "refundInvoice",
    "parameters": [
     {
      "$ref": "#/components/parameters/uuid"
     },
     {
      "$ref": "#/components/parameters/idempotency"
     }
    ],
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "amount": {
          "type": "string"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "$ref": "#/components/responses/Error"
     },
     "402": {
      "$ref": "#/components/responses/Error"
     }
    }
   }
  },
  "/api/v1/invoices/{uuid}/resend": {
   "post": {
    "summary": "Re-deliver the last webhook",
    "operationId": "resendInvoiceWebhook",
    "parameters": [
     {
      "$ref": "#/components/parameters/uuid"
     }
    ],
    "responses": {
     "200": {
      "description": "OK"
     }
    }
   }
  },
  "/api/v1/ledger": {
   "get": {
    "summary": "Ledger entries",
    "operationId": "ledger",
    "responses": {
     "200": {
      "description": "OK"
     }
    }
   }
  },
  "/api/v1/me": {
   "get": {
    "summary": "Merchant profile and limits",
    "operationId": "me",
    "responses": {
     "200": {
      "description": "OK"
     }
    }
   }
  },
  "/api/v1/payouts": {
   "post": {
    "summary": "Create a payout",
    "operationId": "createPayout",
    "parameters": [
     {
      "$ref": "#/components/parameters/idempotency"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "currency",
         "amount",
         "address"
        ],
        "properties": {
         "currency": {
          "type": "string"
         },
         "amount": {
          "type": "string"
         },
         "address": {
          "type": "string"
         },
         "order_id": {
          "type": "string"
         },
         "memo": {
          "type": "string"
         },
         "is_subtract": {
          "type": "boolean"
         },
         "auto_route": {
          "type": "boolean",
          "description": "Fill a shortfall in the target network by swapping the same asset from the merchant's other networks; the payout waits until the full amount is credited"
         },
         "callback_url": {
          "type": "string"
         },
         "test": {
          "type": "boolean",
          "description": "sandbox payouts only, test key"
         }
        }
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Created"
     },
     "400": {
      "$ref": "#/components/responses/Error"
     },
     "402": {
      "$ref": "#/components/responses/Error"
     },
     "403": {
      "$ref": "#/components/responses/Error"
     }
    }
   },
   "get": {
    "summary": "List payouts",
    "operationId": "listPayouts",
    "responses": {
     "200": {
      "description": "OK"
     }
    }
   }
  },
  "/api/v1/payouts/batch": {
   "post": {
    "summary": "Create up to 200 payouts",
    "operationId": "createPayoutBatch",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "currency": {
          "type": "string"
         },
         "items": {
          "type": "array",
          "maxItems": 200,
          "items": {
           "type": "object",
           "required": [
            "address",
            "amount"
           ],
           "properties": {
            "address": {
             "type": "string"
            },
            "amount": {
             "type": "string"
            },
            "order_id": {
             "type": "string"
            }
           }
          }
         },
         "callback_url": {
          "type": "string"
         }
        }
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Created"
     },
     "400": {
      "$ref": "#/components/responses/Error"
     }
    }
   }
  },
  "/api/v1/payouts/calc": {
   "post": {
    "summary": "Calculate payout fee and total",
    "operationId": "calcPayout",
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "currency": {
          "type": "string"
         },
         "amount": {
          "type": "string"
         },
         "is_subtract": {
          "type": "boolean"
         },
         "auto_route": {
          "type": "boolean",
          "description": "Include the same asset held in other networks and quote the cross-chain fee"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "OK"
     }
    }
   }
  },
  "/api/v1/payouts/{uuid}": {
   "get": {
    "summary": "Get a payout",
    "operationId": "getPayout",
    "parameters": [
     {
      "$ref": "#/components/parameters/uuid"
     }
    ],
    "responses": {
     "200": {
      "description": "OK"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     }
    }
   }
  },
  "/api/v1/payouts/{uuid}/cancel": {
   "post": {
    "summary": "Cancel a queued payout",
    "operationId": "cancelPayout",
    "parameters": [
     {
      "$ref": "#/components/parameters/uuid"
     }
    ],
    "responses": {
     "200": {
      "description": "OK"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     }
    }
   }
  },
  "/api/v1/quote": {
   "post": {
    "summary": "Quote pay amount in a chosen currency",
    "operationId": "quote",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "amount",
         "pay_currency"
        ],
        "properties": {
         "currency": {
          "type": "string",
          "default": "USD"
         },
         "amount": {
          "type": "string"
         },
         "pay_currency": {
          "type": "string"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "$ref": "#/components/responses/Error"
     }
    }
   }
  },
  "/api/v1/rates": {
   "get": {
    "summary": "Exchange rates snapshot",
    "operationId": "rates",
    "responses": {
     "200": {
      "description": "OK"
     }
    }
   }
  },
  "/api/v1/sandbox/topup": {
   "post": {
    "summary": "Top up a test balance (sandbox only)",
    "description": "Test key only. Adds a fixed amount of test money to the merchant's test balance so payout and refund flows can be integrated without real funds. Up to 10 top-ups per day; live balances are never touched.",
    "operationId": "sandboxTopup",
    "requestBody": {
     "required": false,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "currency": {
          "type": "string",
          "description": "Currency id, defaults to USDT (usdt_trc20)"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "OK"
     },
     "403": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/Error"
     }
    }
   }
  },
  "/api/v1/subscriptions": {
   "post": {
    "summary": "Create a subscription",
    "operationId": "createSubscription",
    "responses": {
     "201": {
      "description": "Created"
     }
    }
   },
   "get": {
    "summary": "List subscriptions",
    "operationId": "listSubscriptions",
    "responses": {
     "200": {
      "description": "OK"
     }
    }
   }
  },
  "/api/v1/subscriptions/{uuid}": {
   "get": {
    "summary": "Get one subscription",
    "operationId": "getSubscription",
    "parameters": [
     {
      "$ref": "#/components/parameters/uuid"
     }
    ],
    "responses": {
     "200": {
      "description": "OK"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     }
    }
   }
  },
  "/api/v1/subscriptions/{uuid}/cancel": {
   "post": {
    "summary": "Cancel a subscription",
    "operationId": "cancelSubscription",
    "parameters": [
     {
      "$ref": "#/components/parameters/uuid"
     }
    ],
    "responses": {
     "200": {
      "description": "OK"
     }
    }
   }
  },
  "/api/v1/subscriptions/{uuid}/pause": {
   "post": {
    "summary": "Pause a subscription",
    "operationId": "pauseSubscription",
    "parameters": [
     {
      "$ref": "#/components/parameters/uuid"
     }
    ],
    "responses": {
     "200": {
      "description": "OK"
     }
    }
   }
  },
  "/api/v1/subscriptions/{uuid}/resume": {
   "post": {
    "summary": "Resume a subscription",
    "operationId": "resumeSubscription",
    "parameters": [
     {
      "$ref": "#/components/parameters/uuid"
     }
    ],
    "responses": {
     "200": {
      "description": "OK"
     }
    }
   }
  },
  "/api/v1/wallets": {
   "post": {
    "summary": "Create a static wallet",
    "operationId": "createWallet",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "customer_id",
         "currency"
        ],
        "properties": {
         "customer_id": {
          "type": "string"
         },
         "currency": {
          "type": "string"
         },
         "test": {
          "type": "boolean"
         }
        }
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Created"
     }
    }
   },
   "get": {
    "summary": "List static wallets",
    "operationId": "listWallets",
    "responses": {
     "200": {
      "description": "OK"
     }
    }
   }
  },
  "/api/v1/wallets/{uuid}": {
   "get": {
    "summary": "Get a static wallet with recent transfers",
    "operationId": "getWallet",
    "parameters": [
     {
      "$ref": "#/components/parameters/uuid"
     }
    ],
    "responses": {
     "200": {
      "description": "OK"
     }
    }
   }
  },
  "/api/v1/wallets/{uuid}/block": {
   "post": {
    "summary": "Block deposits to a wallet",
    "operationId": "blockWallet",
    "parameters": [
     {
      "$ref": "#/components/parameters/uuid"
     }
    ],
    "responses": {
     "200": {
      "description": "OK"
     }
    }
   }
  },
  "/api/v1/wallets/{uuid}/unblock": {
   "post": {
    "summary": "Unblock a wallet",
    "operationId": "unblockWallet",
    "parameters": [
     {
      "$ref": "#/components/parameters/uuid"
     }
    ],
    "responses": {
     "200": {
      "description": "OK"
     }
    }
   }
  },
  "/api/v1/webhooks/test": {
   "post": {
    "summary": "Send a test webhook",
    "operationId": "testWebhook",
    "responses": {
     "200": {
      "description": "Queued"
     }
    }
   }
  },
  "/api/v1/webhooks/verify": {
   "post": {
    "summary": "Verify a webhook signature",
    "operationId": "verifyWebhook",
    "responses": {
     "200": {
      "description": "OK"
     }
    }
   }
  }
 },
 "webhooks": {
  "invoice": {
   "post": {
    "summary": "Invoice status change",
    "description": "Body: invoice object + type/event. Headers: x-cpay-timestamp, x-cpay-signature (HMAC-SHA256 of `${timestamp}.${rawBody}`), x-cpay-event, x-cpay-test for sandbox.",
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "allOf": [
         {
          "$ref": "#/components/schemas/Invoice"
         },
         {
          "type": "object",
          "properties": {
           "type": {
            "const": "payment"
           },
           "event": {
            "type": "string"
           }
          }
         }
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Delivered; anything else is retried with backoff"
     }
    }
   }
  },
  "payout": {
   "post": {
    "summary": "Payout status change",
    "description": "Body: payout object + type:\"payout\", event payout.done / payout.failed.",
    "responses": {
     "200": {
      "description": "Delivered"
     }
    }
   }
  },
  "wallet": {
   "post": {
    "summary": "Static wallet deposit",
    "description": "Body: {type:\"wallet\", event:\"wallet.deposit\", wallet:{...}, tx:{txid, amount, from}}.",
    "responses": {
     "200": {
      "description": "Delivered"
     }
    }
   }
  }
 }
}
