{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://raw.githubusercontent.com/api-evangelist/instamojo/main/json-schema/payment-request.json",
  "title": "Instamojo Payment Request",
  "description": "Schema for creating and representing an Instamojo payment request",
  "type": "object",
  "required": ["purpose", "amount"],
  "properties": {
    "id": {
      "type": "string",
      "description": "Unique payment request ID assigned by Instamojo",
      "readOnly": true
    },
    "purpose": {
      "type": "string",
      "description": "Purpose or description of the payment request",
      "maxLength": 255
    },
    "amount": {
      "type": "string",
      "description": "Amount to be paid in INR",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "examples": ["499.00", "1000.00"]
    },
    "status": {
      "type": "string",
      "description": "Current status of the payment request",
      "enum": ["Pending", "Completed", "Failed", "Expired"],
      "readOnly": true
    },
    "buyer_name": {
      "type": "string",
      "description": "Name of the buyer for prefilling the payment form",
      "maxLength": 100
    },
    "email": {
      "type": "string",
      "format": "email",
      "description": "Buyer's email address"
    },
    "phone": {
      "type": "string",
      "description": "Buyer's phone number with country code",
      "examples": ["+919876543210"]
    },
    "send_email": {
      "type": "boolean",
      "description": "Whether to send the payment link to buyer via email",
      "default": false
    },
    "send_sms": {
      "type": "boolean",
      "description": "Whether to send the payment link to buyer via SMS",
      "default": false
    },
    "redirect_url": {
      "type": "string",
      "format": "uri",
      "description": "URL to redirect the buyer after payment completion or failure"
    },
    "webhook": {
      "type": "string",
      "format": "uri",
      "description": "Webhook URL to receive server-to-server payment notifications"
    },
    "allow_repeated_payments": {
      "type": "boolean",
      "description": "Whether to allow multiple successful payments on this request",
      "default": true
    },
    "longurl": {
      "type": "string",
      "format": "uri",
      "description": "The shareable payment URL for the buyer",
      "readOnly": true
    },
    "payments": {
      "type": "array",
      "description": "List of payments made against this payment request (returned on detail endpoint)",
      "items": {
        "$ref": "#/$defs/Payment"
      },
      "readOnly": true
    },
    "created_at": {
      "type": "string",
      "format": "date-time",
      "description": "Timestamp when the payment request was created",
      "readOnly": true
    },
    "modified_at": {
      "type": "string",
      "format": "date-time",
      "description": "Timestamp when the payment request was last modified",
      "readOnly": true
    }
  },
  "$defs": {
    "Payment": {
      "type": "object",
      "description": "A payment made against a payment request",
      "properties": {
        "payment_id": {
          "type": "string",
          "description": "Unique payment ID",
          "examples": ["MOJO5a06005J21512345"]
        },
        "status": {
          "type": "string",
          "enum": ["Credit", "Failed", "Pending"],
          "description": "Payment status"
        },
        "currency": {
          "type": "string",
          "description": "Currency code",
          "const": "INR"
        },
        "amount": {
          "type": "string",
          "description": "Amount paid",
          "pattern": "^\\d+(\\.\\d{1,2})?$"
        },
        "buyer_name": {
          "type": "string",
          "description": "Name of the buyer"
        },
        "buyer_email": {
          "type": "string",
          "format": "email"
        },
        "buyer_phone": {
          "type": "string"
        },
        "instrument_type": {
          "type": "string",
          "enum": ["CREDIT_CARD", "DEBIT_CARD", "NET_BANKING", "WALLET", "UPI", "EMI"],
          "description": "Payment instrument used"
        },
        "billing_instrument": {
          "type": "string",
          "description": "Specific billing instrument details"
        },
        "failure_reason": {
          "type": ["string", "null"],
          "description": "Reason for payment failure"
        },
        "payment_request": {
          "type": "string",
          "description": "ID of the associated payment request"
        },
        "created_at": {
          "type": "string",
          "format": "date-time"
        }
      }
    }
  }
}
