{
  "openapi": "3.0.3",
  "info": {
    "title": "MonieFlex Multi-Rail Payment Gateway & Virtual Accounts API",
    "description": "Enterprise API for generating 10-digit CBN Modulo-10 compliant NUBAN virtual accounts across VFD Microfinance Bank (090110), PalmPay (999991), and Paga (100002). Features sub-second credit webhooks, NIP name enquiry, instant transfers, and universal checkout.",
    "version": "2.4.0",
    "contact": {
      "name": "MonieFlex Developer Support",
      "url": "/docs",
      "email": "support@monieflex.co"
    }
  },
  "servers": [
    {
      "url": "/api/v1",
      "description": "Production Multi-Rail Gateway"
    },
    {
      "url": "/api/v1",
      "description": "Sandbox Testing Environment"
    }
  ],
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API Key",
        "description": "Use your MonieFlex Secret Key (sk_live_... or sk_test_...)"
      }
    },
    "schemas": {
      "VirtualAccount": {
        "type": "object",
        "properties": {
          "account_number": { "type": "string", "example": "1147528095", "description": "10-digit CBN Modulo-10 compliant NUBAN" },
          "account_name": { "type": "string", "example": "MonieFlex - Emeka Okonkwo" },
          "bank_name": { "type": "string", "example": "VFD Microfinance Bank" },
          "bank_code": { "type": "string", "example": "090110", "description": "CBN Institution Code" },
          "provider": { "type": "string", "enum": ["vfd", "palmpay", "paga", "auto"], "example": "vfd" },
          "reference": { "type": "string", "example": "CUST_REF_1001" },
          "currency": { "type": "string", "example": "NGN" },
          "status": { "type": "string", "enum": ["active", "suspended", "closed"], "example": "active" }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "status": { "type": "boolean", "example": false },
          "message": { "type": "string", "example": "Invalid or expired API key" },
          "error_code": { "type": "string", "example": "AUTH_INVALID_KEY" }
        }
      }
    }
  },
  "security": [
    {
      "BearerAuth": []
    }
  ],
  "paths": {
    "/virtual-accounts": {
      "post": {
        "summary": "Create Multi-Rail Virtual Account",
        "description": "Provisions a permanent or dynamic 10-digit NUBAN virtual account with automatic banking failover across VFD, PalmPay, and Paga.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["customer_name", "customer_email", "customer_ref"],
                "properties": {
                  "customer_name": { "type": "string", "example": "Emeka Okonkwo" },
                  "customer_email": { "type": "string", "format": "email", "example": "emeka@example.com" },
                  "customer_phone": { "type": "string", "example": "08031234567" },
                  "customer_ref": { "type": "string", "example": "CUST_REF_1001", "description": "Unique merchant customer reference" },
                  "bvn": { "type": "string", "example": "22233344455", "description": "11-digit Bank Verification Number (Tier 2/3)" },
                  "provider": { "type": "string", "enum": ["auto", "vfd", "palmpay", "paga"], "default": "auto" }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Virtual account provisioned successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": { "type": "boolean", "example": true },
                    "message": { "type": "string", "example": "Virtual account provisioned successfully" },
                    "account": { "$ref": "#/components/schemas/VirtualAccount" }
                  }
                }
              }
            }
          },
          "400": { "description": "Invalid input", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } },
          "401": { "description": "Unauthorized", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }
        }
      },
      "get": {
        "summary": "List Virtual Accounts",
        "description": "Retrieves paginated virtual accounts for the authenticated merchant.",
        "parameters": [
          { "name": "page", "in": "query", "schema": { "type": "integer", "default": 1 } },
          { "name": "limit", "in": "query", "schema": { "type": "integer", "default": 20 } },
          { "name": "provider", "in": "query", "schema": { "type": "string", "enum": ["vfd", "palmpay", "paga"] } },
          { "name": "status", "in": "query", "schema": { "type": "string", "enum": ["active", "suspended"] } },
          { "name": "search", "in": "query", "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "List of virtual accounts retrieved",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": { "type": "boolean", "example": true },
                    "data": { "type": "array", "items": { "$ref": "#/components/schemas/VirtualAccount" } }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/virtual-accounts/vfd": {
      "post": {
        "summary": "Create Dedicated VFD Bank Virtual Account",
        "description": "Forces direct account creation on VFD Microfinance Bank rail (CBN Code 090110).",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["customer_name", "customer_email", "customer_ref"],
                "properties": {
                  "customer_name": { "type": "string", "example": "Amaka Nnamdi" },
                  "customer_email": { "type": "string", "example": "amaka@example.com" },
                  "customer_phone": { "type": "string", "example": "08091112233" },
                  "customer_ref": { "type": "string", "example": "USER_VFD_8819" },
                  "bvn": { "type": "string", "example": "22233344455" }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "VFD Virtual account provisioned",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": { "type": "boolean", "example": true },
                    "account": { "$ref": "#/components/schemas/VirtualAccount" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/virtual-accounts/palmpay": {
      "post": {
        "summary": "Create Dedicated PalmPay Reserved Account",
        "description": "Forces direct account creation on PalmPay Limited rail (CBN Code 999991).",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["customer_name", "customer_email", "customer_ref"],
                "properties": {
                  "customer_name": { "type": "string", "example": "Tunde Bakare" },
                  "customer_email": { "type": "string", "example": "tunde@example.com" },
                  "customer_phone": { "type": "string", "example": "08055556677" },
                  "customer_ref": { "type": "string", "example": "USER_PALM_4432" }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "PalmPay account created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": { "type": "boolean", "example": true },
                    "account": { "$ref": "#/components/schemas/VirtualAccount" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/virtual-accounts/simulate-inflow": {
      "post": {
        "summary": "Simulate Inbound Bank Transfer (Sandbox)",
        "description": "Simulates an incoming NIP interbank transfer to credit a virtual account and trigger real-time webhooks.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["account_number", "amount"],
                "properties": {
                  "account_number": { "type": "string", "example": "1147528095" },
                  "amount": { "type": "number", "example": 25000.00 },
                  "sender_name": { "type": "string", "example": "Adewale Johnson" },
                  "sender_bank": { "type": "string", "example": "Access Bank" },
                  "session_id": { "type": "string", "example": "9990012410181420550001" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Simulated credit transfer processed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": { "type": "boolean", "example": true },
                    "message": { "type": "string", "example": "Simulated credit transfer of NGN 25,000.00 processed successfully" },
                    "data": {
                      "type": "object",
                      "properties": {
                        "account_number": { "type": "string" },
                        "amount": { "type": "number" },
                        "fee": { "type": "number" },
                        "net_amount": { "type": "number" },
                        "session_id": { "type": "string" },
                        "payment_reference": { "type": "string" }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/kyc/resolve-account": {
      "get": {
        "summary": "NIBSS NUBAN Account Resolution",
        "description": "Performs real-time name enquiry on any Nigerian 10-digit NUBAN across commercial banks and virtual accounts.",
        "parameters": [
          { "name": "account_number", "in": "query", "required": true, "schema": { "type": "string", "example": "1147528095" } },
          { "name": "bank_code", "in": "query", "required": true, "schema": { "type": "string", "example": "090110" } }
        ],
        "responses": {
          "200": {
            "description": "Account resolved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": { "type": "boolean", "example": true },
                    "data": {
                      "type": "object",
                      "properties": {
                        "account_number": { "type": "string", "example": "1147528095" },
                        "account_name": { "type": "string", "example": "MonieFlex - Emeka Okonkwo" },
                        "bank_code": { "type": "string", "example": "090110" },
                        "bank_name": { "type": "string", "example": "VFD Microfinance Bank" },
                        "resolution_source": { "type": "string", "example": "internal_virtual_account" }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/checkout/initialize": {
      "post": {
        "summary": "Initialize Universal Hosted Checkout",
        "description": "Initializes a checkout session supporting Card, Bank Transfer, Virtual Account, and USSD payments.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["amount", "email", "reference"],
                "properties": {
                  "amount": { "type": "number", "example": 50000.00 },
                  "email": { "type": "string", "format": "email", "example": "customer@example.com" },
                  "currency": { "type": "string", "default": "NGN" },
                  "reference": { "type": "string", "example": "ORDER_TX_881923" },
                  "callback_url": { "type": "string", "format": "uri", "example": "https://merchant.com/callback" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Checkout initialized",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": { "type": "boolean", "example": true },
                    "data": {
                      "type": "object",
                      "properties": {
                        "checkout_url": { "type": "string", "example": "/pay/sess_99a81b2" },
                        "reference": { "type": "string", "example": "ORDER_TX_881923" }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/transfers": {
      "post": {
        "summary": "Initiate Instant Payout / Bank Transfer",
        "description": "Dispatches funds instantly to any Nigerian commercial bank or mobile money account via NIP.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["amount", "recipient_account", "recipient_bank_code", "reference"],
                "properties": {
                  "amount": { "type": "number", "example": 10000.00 },
                  "recipient_account": { "type": "string", "example": "0123456789" },
                  "recipient_bank_code": { "type": "string", "example": "058" },
                  "reference": { "type": "string", "example": "PAYOUT_REF_0099" },
                  "narration": { "type": "string", "example": "Vendor Settlement" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Transfer queued or processed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": { "type": "boolean", "example": true },
                    "message": { "type": "string", "example": "Transfer initiated successfully" },
                    "transfer": {
                      "type": "object",
                      "properties": {
                        "reference": { "type": "string" },
                        "amount": { "type": "number" },
                        "fee": { "type": "number" },
                        "status": { "type": "string", "enum": ["successful", "pending", "failed"] }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
