{
  "openapi": "3.1.0",
  "info": {
    "title": "TapZup Pay Sandbox",
    "version": "1.2.0",
    "description": "Country-aware staging checkout and fulfilment. Zimbabwe USD uses provider test payments. Other rollout markets use simulated payments."
  },
  "servers": [
    {
      "url": "https://zapzap-api-production.up.railway.app",
      "description": "Public TapZup API. Provider test payments and simulated markets only."
    }
  ],
  "security": [
    {
      "partnerKey": [],
      "clientId": []
    }
  ],
  "paths": {
    "/partner/v1/checkouts": {
      "post": {
        "operationId": "createCheckout",
        "parameters": [
          {
            "in": "header",
            "name": "Idempotency-Key",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 128
            },
            "description": "Stable key for retrying the same order and payload."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateCheckout"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Existing checkout",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Checkout"
                }
              }
            }
          },
          "201": {
            "description": "Checkout request created. Send the seller to sellerApprovalUrl.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Checkout"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Partner key or verified seller session required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Checkout conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Body too large",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Unsupported sandbox market",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/partner/v1/checkouts/{id}": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getCheckout",
        "responses": {
          "200": {
            "description": "Partner checkout status",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Checkout"
                }
              }
            }
          },
          "401": {
            "description": "Partner key or verified seller session required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Checkout unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/partner/v1/checkouts/{id}/delivery": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "assignDeliverer",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AssignDeliverer"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Delivery assignment recorded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeliveryAssignment"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Partner key or verified seller session required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Seller has not authorized partner delivery for this checkout.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Checkout unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Checkout conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Body too large",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/partner/v1/markets": {
      "get": {
        "operationId": "listMarkets",
        "security": [],
        "responses": {
          "200": {
            "description": "Current rollout markets, currencies, minor units and partner checkout modes"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "partnerKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "tzp_test_ followed by 64 hexadecimal characters"
      },
      "clientId": {
        "type": "apiKey",
        "in": "header",
        "name": "X-TapZup-Client-Id",
        "description": "Use the Client ID shown in your API dashboard."
      }
    },
    "schemas": {
      "CreateCheckout": {
        "type": "object",
        "required": [
          "orderReference",
          "itemName",
          "amountMinor",
          "currency",
          "country"
        ],
        "properties": {
          "orderReference": {
            "type": "string",
            "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$"
          },
          "itemName": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "amountMinor": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10000000
          },
          "currency": {
            "pattern": "^[A-Z]{3}$"
          },
          "country": {
            "pattern": "^[A-Z]{2}$"
          }
        }
      },
      "Checkout": {
        "type": "object",
        "required": [
          "id",
          "orderReference",
          "mode",
          "checkoutUrl",
          "state",
          "createdAt",
          "sellerApprovalUrl",
          "partnerDeliveryAllowed"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "orderReference": {
            "type": "string"
          },
          "mode": {
            "const": "sandbox"
          },
          "checkoutUrl": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri"
          },
          "state": {
            "type": "string",
            "enum": [
              "ready",
              "awaiting_seller_approval",
              "expired"
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "paymentStatus": {
            "type": "string"
          },
          "deliveryAssigned": {
            "type": "boolean"
          },
          "deliveryConfirmed": {
            "type": "boolean"
          },
          "buyerDecision": {
            "type": [
              "string",
              "null"
            ]
          },
          "settlementStatus": {
            "type": "string"
          },
          "sellerApprovalUrl": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri"
          },
          "partnerDeliveryAllowed": {
            "type": "boolean"
          },
          "country": {
            "type": "string",
            "pattern": "^[A-Z]{2}$"
          },
          "currency": {
            "type": "string",
            "pattern": "^[A-Z]{3}$"
          },
          "paymentMode": {
            "type": "string",
            "enum": [
              "provider_test",
              "simulation"
            ]
          },
          "fees": {
            "type": [
              "object",
              "null"
            ],
            "description": "Locked platform fee in the checkout currency. Existing checkouts may have no fee snapshot.",
            "properties": {
              "grossMinor": {
                "type": "integer",
                "minimum": 0
              },
              "platformFeeMinor": {
                "type": "integer",
                "minimum": 0
              },
              "sellerNetMinor": {
                "type": "integer",
                "minimum": 0
              },
              "platformBps": {
                "type": "integer",
                "minimum": 0
              },
              "fundingAdminBps": {
                "type": "integer",
                "minimum": 0
              },
              "revision": {
                "type": "integer",
                "minimum": 0
              }
            }
          }
        }
      },
      "AssignDeliverer": {
        "type": "object",
        "required": [
          "channel",
          "contact"
        ],
        "properties": {
          "channel": {
            "type": "string",
            "enum": [
              "email",
              "sms"
            ]
          },
          "contact": {
            "type": "string",
            "maxLength": 254
          }
        }
      },
      "DeliveryAssignment": {
        "type": "object",
        "required": [
          "id",
          "deliveryDelegate"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "deliveryDelegate": {
            "type": [
              "object",
              "null"
            ]
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          }
        }
      }
    }
  },
  "webhooks": {
    "checkout.updated": {
      "post": {
        "summary": "Checkout state changed",
        "description": "Verify HMAC-SHA256 over timestamp + '.' + raw request body and deduplicate using TapZup-Event-Id.",
        "parameters": [
          {
            "name": "TapZup-Timestamp",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "TapZup-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "TapZup-Event-Id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "id",
                  "type",
                  "mode",
                  "data"
                ],
                "properties": {
                  "id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "type": {
                    "const": "checkout.updated"
                  },
                  "mode": {
                    "const": "sandbox"
                  },
                  "data": {
                    "type": "object"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Event accepted"
          }
        }
      }
    }
  }
}
