{
  "openapi": "3.0.3",
  "info": {
    "title": "SwiftUPI Payments API",
    "contact": {"name": "Nexadly Technologies Private Limited"},
    "version": "1.0.0",
    "description": "Create UPI payments that settle straight to your own UPI account, check their status, record refunds and receive signed webhooks.\n\nUse `sk_test_` keys for simulated payments and `sk_live_` keys for real ones."
  },
  "servers": [
    {
      "url": "https://app.swiftupi.com"
    }
  ],
  "security": [
    {
      "ApiKey": []
    }
  ],
  "paths": {
    "/api/orders": {
      "post": {
        "summary": "Create a payment",
        "operationId": "createOrder",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 100
            },
            "description": "Retry-safe: the same key returns the same order"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateOrder"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Order"
                }
              }
            }
          },
          "200": {
            "description": "Existing order returned (same client_order_id or Idempotency-Key)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Order"
                }
              }
            }
          },
          "401": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/orders/{id}": {
      "get": {
        "summary": "Get a payment",
        "description": "`id` is the order_id or your client_order_id. Also re-checks the provider for pending payments.",
        "operationId": "getOrder",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Order"
                }
              }
            }
          },
          "404": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/orders/{id}/refunds": {
      "get": {
        "summary": "List refunds",
        "operationId": "listRefunds",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "refunds": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Refund"
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Record a refund",
        "description": "Records a refund you already sent to the customer (UPI refunds are made from your own app).",
        "operationId": "createRefund",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "amount"
                ],
                "properties": {
                  "amount": {
                    "type": "string",
                    "example": "100.00"
                  },
                  "reason": {
                    "type": "string"
                  },
                  "reference": {
                    "type": "string",
                    "description": "Refund UTR"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Recorded"
          },
          "422": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/orders/{id}/status": {
      "get": {
        "summary": "Public payment status",
        "description": "No API key needed. Used by the checkout page.",
        "security": [],
        "operationId": "getStatus",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string"
                    },
                    "expires_at": {
                      "type": "integer"
                    },
                    "method": {
                      "type": "string"
                    },
                    "receipt": {
                      "type": "object",
                      "nullable": true
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/me": {
      "get": {
        "summary": "Check your key",
        "operationId": "me",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "merchant": {
                      "type": "string"
                    },
                    "status": {
                      "type": "string"
                    },
                    "mode": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "Your secret key. `Authorization: Bearer <key>` also works."
      }
    },
    "schemas": {
      "CreateOrder": {
        "type": "object",
        "required": [
          "amount"
        ],
        "properties": {
          "amount": {
            "type": "string",
            "example": "499.00"
          },
          "client_order_id": {
            "type": "string",
            "pattern": "^[\\w-]{1,64}$"
          },
          "note": {
            "type": "string",
            "maxLength": 50
          },
          "customer_name": {
            "type": "string"
          },
          "customer_mobile": {
            "type": "string"
          },
          "customer_email": {
            "type": "string"
          },
          "redirect_url": {
            "type": "string",
            "format": "uri",
            "description": "Where the customer goes after paying"
          },
          "expiry_minutes": {
            "type": "integer",
            "minimum": 2,
            "maximum": 10080
          },
          "account_id": {
            "type": "integer",
            "description": "Pick a specific UPI account"
          }
        }
      },
      "Order": {
        "type": "object",
        "properties": {
          "order_id": {
            "type": "string",
            "example": "ORD7F5A1C2B3D4E5F60"
          },
          "client_order_id": {
            "type": "string",
            "nullable": true
          },
          "mode": {
            "type": "string",
            "enum": [
              "live",
              "test"
            ]
          },
          "amount": {
            "type": "string",
            "example": "499.00",
            "description": "Amount the customer pays (may include unique paise for auto-matching)"
          },
          "requested_amount": {
            "type": "string"
          },
          "refunded_amount": {
            "type": "string"
          },
          "currency": {
            "type": "string",
            "example": "INR"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "review",
              "cash",
              "cod",
              "paid",
              "failed",
              "expired",
              "cancelled"
            ]
          },
          "method": {
            "type": "string",
            "enum": [
              "upi",
              "cash",
              "cod"
            ]
          },
          "mobile_verified": {
            "type": "boolean"
          },
          "utr": {
            "type": "string",
            "nullable": true
          },
          "txn_id": {
            "type": "string",
            "nullable": true
          },
          "failure_reason": {
            "type": "string",
            "nullable": true
          },
          "note": {
            "type": "string",
            "nullable": true
          },
          "customer": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "mobile": {
                "type": "string"
              },
              "email": {
                "type": "string"
              }
            }
          },
          "payee_vpa": {
            "type": "string"
          },
          "created_at": {
            "type": "integer"
          },
          "expires_at": {
            "type": "integer"
          },
          "paid_at": {
            "type": "integer",
            "nullable": true
          },
          "payment_url": {
            "type": "string",
            "format": "uri"
          },
          "qr_url": {
            "type": "string",
            "format": "uri"
          },
          "upi_intent": {
            "type": "string"
          }
        }
      },
      "Refund": {
        "type": "object",
        "properties": {
          "amount": {
            "type": "string"
          },
          "reason": {
            "type": "string"
          },
          "reference": {
            "type": "string"
          },
          "created_at": {
            "type": "integer"
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          }
        }
      },
      "WebhookEvent": {
        "type": "object",
        "description": "POSTed to your webhook URL. Verify `X-Gateway-Signature` = hex HMAC-SHA256 of `X-Gateway-Timestamp + '.' + raw body` with your webhook secret.",
        "properties": {
          "event": {
            "type": "string",
            "enum": [
              "payment.success",
              "payment.failed",
              "payment.review",
              "payment.refunded",
              "test"
            ]
          },
          "mode": {
            "type": "string"
          },
          "data": {
            "$ref": "#/components/schemas/Order"
          }
        }
      }
    }
  }
}