{
  "openapi": "3.1.0",
  "info": {
    "title": "Heartswill for NGOs API",
    "version": "1.0.0",
    "description": "Donations, receipts, projects, deliveries and impact for an Indian NGO on Heartswill.",
    "contact": {
      "url": "https://heartswill.com/ngos/developers"
    }
  },
  "servers": [
    {
      "url": "https://app.ngo.heartswill.com/api/v1"
    }
  ],
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "Secret key starting hwn_live_. Server side only."
      }
    },
    "responses": {
      "Error": {
        "description": "Error",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "string",
                      "enum": [
                        "unauthorized",
                        "forbidden",
                        "not_found",
                        "invalid_request",
                        "rate_limited",
                        "server_error"
                      ]
                    },
                    "message": {
                      "type": "string"
                    },
                    "docs": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "schemas": {
      "DonationIn": {
        "type": "object",
        "required": [
          "external_ref",
          "amount_inr",
          "donor"
        ],
        "properties": {
          "external_ref": {
            "type": "string",
            "maxLength": 120
          },
          "amount_inr": {
            "type": "number",
            "exclusiveMinimum": 0
          },
          "mode": {
            "type": "string",
            "enum": [
              "online",
              "upi",
              "bank",
              "cheque",
              "cash",
              "kind"
            ],
            "default": "online"
          },
          "received_on": {
            "type": "string",
            "format": "date"
          },
          "donation_type": {
            "type": "string",
            "enum": [
              "others",
              "corpus",
              "specific"
            ],
            "default": "others"
          },
          "purpose": {
            "type": "string"
          },
          "notes": {
            "type": "string"
          },
          "payment_reference": {
            "type": "string"
          },
          "fcra": {
            "type": "boolean",
            "default": false
          },
          "issue_receipt": {
            "type": "boolean",
            "default": true
          },
          "donor": {
            "type": "object",
            "required": [
              "name"
            ],
            "properties": {
              "name": {
                "type": "string"
              },
              "kind": {
                "type": "string",
                "enum": [
                  "individual",
                  "organisation"
                ]
              },
              "email": {
                "type": "string"
              },
              "phone": {
                "type": "string"
              },
              "pan": {
                "type": "string",
                "pattern": "^[A-Z]{5}[0-9]{4}[A-Z]$"
              },
              "aadhaar": {
                "type": "string",
                "pattern": "^[0-9]{12}$"
              },
              "address": {
                "type": "string"
              },
              "city": {
                "type": "string"
              },
              "state": {
                "type": "string"
              },
              "pincode": {
                "type": "string"
              },
              "consent_comm": {
                "type": "boolean"
              }
            }
          }
        }
      },
      "Receipt": {
        "type": "object",
        "properties": {
          "number": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "issued",
              "cancelled"
            ]
          },
          "eligible_for_deduction": {
            "type": "boolean"
          },
          "verify_code": {
            "type": "string"
          },
          "verify_url": {
            "type": "string"
          },
          "issued_on": {
            "type": "string",
            "format": "date"
          }
        }
      },
      "DonationOut": {
        "type": "object",
        "properties": {
          "donation_id": {
            "type": "string",
            "format": "uuid"
          },
          "duplicate": {
            "type": "boolean"
          },
          "external_ref": {
            "type": "string"
          },
          "receipt": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Receipt"
              },
              {
                "type": "null"
              }
            ]
          }
        }
      }
    }
  },
  "paths": {
    "/org": {
      "get": {
        "summary": "Organisation and key details",
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/donations": {
      "post": {
        "summary": "Record a donation and issue a receipt",
        "security": [
          {
            "bearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DonationIn"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DonationOut"
                }
              }
            }
          },
          "200": {
            "description": "Duplicate external_ref; original returned",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DonationOut"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "422": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "get": {
        "summary": "List donations",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "until",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 50
            }
          },
          {
            "name": "before",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/receipts/{number}": {
      "get": {
        "summary": "Get a receipt",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "number",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/projects": {
      "get": {
        "summary": "List projects",
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/deliveries": {
      "get": {
        "summary": "List deliveries",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "project",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "before",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/impact": {
      "get": {
        "summary": "Impact totals for the current financial year",
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/verify/{code}": {
      "get": {
        "summary": "Public receipt verification",
        "security": [],
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    }
  }
}