{
  "openapi": "3.1.0",
  "info": {
    "title": "Xash Payments",
    "version": "1.0.0",
    "description": "USD EcoCash collections and full refunds. Application tokens select sandbox or production. Webhooks are HMAC signed; acknowledge event IDs after applying the result."
  },
  "servers": [
    {
      "url": "https://payments.xash.co.zw/api/v1"
    }
  ],
  "security": [
    {
      "applicationToken": []
    }
  ],
  "paths": {
    "/payments": {
      "post": {
        "summary": "Create a collection",
        "description": "Scope payments:create. 202 does not prove settlement. Repeat the same key and intent to recover.",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 150
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "reference",
                  "method",
                  "amount_minor",
                  "currency",
                  "customer"
                ],
                "properties": {
                  "reference": {
                    "type": "string",
                    "maxLength": 100,
                    "pattern": "^[A-Za-z0-9._:-]+$"
                  },
                  "method": {
                    "const": "ecocash"
                  },
                  "amount_minor": {
                    "type": "integer",
                    "minimum": 1,
                    "description": "USD cents. Configured maximum applies."
                  },
                  "currency": {
                    "const": "USD"
                  },
                  "customer": {
                    "type": "object",
                    "required": [
                      "phone"
                    ],
                    "properties": {
                      "phone": {
                        "type": "string",
                        "description": "Econet number. Sandbox requires a verified test number."
                      }
                    },
                    "additionalProperties": false
                  },
                  "description": {
                    "type": "string",
                    "maxLength": 140
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted for processing",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Payment"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid token"
          },
          "403": {
            "description": "Missing scope"
          },
          "404": {
            "description": "No owned resource"
          },
          "409": {
            "description": "Reference or refund conflict"
          },
          "422": {
            "description": "Invalid request"
          },
          "429": {
            "description": "Rate limit"
          },
          "503": {
            "description": "Collections paused or provider not configured"
          }
        }
      },
      "get": {
        "summary": "List your payments",
        "description": "Scope payments:read. Paginated, newest first.",
        "parameters": [
          {
            "in": "query",
            "name": "status",
            "schema": {
              "enum": [
                "queued",
                "pending",
                "succeeded",
                "failed",
                "needs_review"
              ]
            }
          },
          {
            "in": "query",
            "name": "page",
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          },
          {
            "in": "query",
            "name": "per_page",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paginated payments",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Payment"
                      }
                    },
                    "links": {
                      "type": "object"
                    },
                    "meta": {
                      "type": "object"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/payments/{id}": {
      "get": {
        "summary": "Read a payment",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Current recorded outcome",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Payment"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid token"
          },
          "403": {
            "description": "Missing scope"
          },
          "404": {
            "description": "No owned resource"
          },
          "409": {
            "description": "Reference or refund conflict"
          },
          "422": {
            "description": "Invalid request"
          },
          "429": {
            "description": "Rate limit"
          },
          "503": {
            "description": "Collections paused or provider not configured"
          }
        }
      }
    },
    "/payments/by-reference/{reference}": {
      "get": {
        "summary": "Recover by caller reference",
        "parameters": [
          {
            "name": "reference",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Current recorded outcome",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Payment"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid token"
          },
          "403": {
            "description": "Missing scope"
          },
          "404": {
            "description": "No owned resource"
          },
          "409": {
            "description": "Reference or refund conflict"
          },
          "422": {
            "description": "Invalid request"
          },
          "429": {
            "description": "Rate limit"
          },
          "503": {
            "description": "Collections paused or provider not configured"
          }
        }
      }
    },
    "/payments/{id}/verify": {
      "post": {
        "summary": "Queue a provider lookup",
        "description": "Scope payments:read. Coalesced to the configured polling interval.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "202": {
            "description": "Accepted for processing",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Payment"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid token"
          },
          "403": {
            "description": "Missing scope"
          },
          "404": {
            "description": "No owned resource"
          },
          "409": {
            "description": "Reference or refund conflict"
          },
          "422": {
            "description": "Invalid request"
          },
          "429": {
            "description": "Rate limit"
          },
          "503": {
            "description": "Collections paused or provider not configured"
          }
        }
      }
    },
    "/payments/{id}/refunds": {
      "post": {
        "summary": "Request a full refund",
        "description": "Scope refunds:create. The application reserve endpoint must acknowledge held funds before dispatch.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 150
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "reason"
                ],
                "properties": {
                  "reason": {
                    "type": "string",
                    "minLength": 3,
                    "maxLength": 255
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted for processing",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Refund"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid token"
          },
          "403": {
            "description": "Missing scope"
          },
          "404": {
            "description": "No owned resource"
          },
          "409": {
            "description": "Reference or refund conflict"
          },
          "422": {
            "description": "Invalid request"
          },
          "429": {
            "description": "Rate limit"
          },
          "503": {
            "description": "Collections paused or provider not configured"
          }
        }
      }
    },
    "/refunds/{id}": {
      "get": {
        "summary": "Read a refund",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Current recorded outcome",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Refund"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid token"
          },
          "403": {
            "description": "Missing scope"
          },
          "404": {
            "description": "No owned resource"
          },
          "409": {
            "description": "Reference or refund conflict"
          },
          "422": {
            "description": "Invalid request"
          },
          "429": {
            "description": "Rate limit"
          },
          "503": {
            "description": "Collections paused or provider not configured"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "applicationToken": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "Payment": {
        "type": "object",
        "required": [
          "id",
          "reference",
          "environment",
          "status",
          "amount_minor",
          "currency",
          "customer"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "reference": {
            "type": "string"
          },
          "environment": {
            "enum": [
              "production",
              "sandbox"
            ]
          },
          "status": {
            "enum": [
              "queued",
              "pending",
              "succeeded",
              "failed",
              "needs_review"
            ]
          },
          "amount_minor": {
            "type": "integer"
          },
          "currency": {
            "const": "USD"
          },
          "customer": {
            "type": "object",
            "properties": {
              "phone": {
                "type": "string"
              }
            }
          },
          "receipt": {
            "type": [
              "string",
              "null"
            ]
          },
          "last_verified_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "next_action": {
            "enum": [
              "wait",
              "check_status",
              "none"
            ]
          },
          "refund": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Refund"
              },
              {
                "type": "null"
              }
            ]
          },
          "links": {
            "type": "object",
            "properties": {
              "self": {
                "type": "string"
              },
              "verify": {
                "type": "string"
              }
            }
          }
        }
      },
      "Refund": {
        "type": "object",
        "required": [
          "id",
          "payment_id",
          "status",
          "amount_minor"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "payment_id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "awaiting_funds",
              "processing",
              "needs_review",
              "succeeded",
              "failed"
            ]
          },
          "amount_minor": {
            "type": "integer"
          },
          "reason": {
            "type": "string"
          },
          "receipt": {
            "type": [
              "string",
              "null"
            ]
          },
          "adjustment_reference": {
            "type": [
              "string",
              "null"
            ]
          },
          "last_verified_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "completed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      }
    }
  }
}
