{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://api-evangelist.github.io/splitit/json-schema/installment-plan.json",
  "title": "Splitit Installment Plan",
  "description": "Schema for a Splitit installment plan created on a shopper's existing credit card",
  "type": "object",
  "properties": {
    "installmentPlanNumber": {
      "type": "string",
      "description": "Unique identifier for the installment plan assigned by Splitit"
    },
    "status": {
      "type": "string",
      "description": "Current status of the installment plan",
      "enum": [
        "Initialized",
        "PendingPayment",
        "Active",
        "Cleared",
        "Cancelled",
        "Refunded",
        "PartiallyRefunded"
      ]
    },
    "planData": {
      "type": "object",
      "description": "Core data for the installment plan",
      "required": ["totalAmount", "numberOfInstallments"],
      "properties": {
        "totalAmount": {
          "$ref": "#/$defs/Money"
        },
        "numberOfInstallments": {
          "type": "integer",
          "description": "Number of monthly installments",
          "minimum": 2,
          "maximum": 36
        },
        "refOrderNumber": {
          "type": "string",
          "description": "Merchant reference order number for cross-referencing"
        },
        "extendedParams": {
          "type": "object",
          "description": "Merchant-defined key-value parameters for custom data",
          "additionalProperties": {
            "type": "string"
          }
        },
        "firstInstallmentAmount": {
          "$ref": "#/$defs/Money"
        },
        "firstChargeDate": {
          "type": "string",
          "format": "date",
          "description": "Scheduled date for the first installment charge"
        }
      }
    },
    "consumerData": {
      "$ref": "#/$defs/ConsumerData"
    },
    "creditCardDetails": {
      "$ref": "#/$defs/CreditCardDetails"
    },
    "installments": {
      "type": "array",
      "description": "Individual installment charge schedule",
      "items": {
        "$ref": "#/$defs/Installment"
      }
    },
    "redirectUrls": {
      "$ref": "#/$defs/RedirectUrls"
    },
    "createdAt": {
      "type": "string",
      "format": "date-time",
      "description": "ISO 8601 timestamp when the plan was created"
    },
    "updatedAt": {
      "type": "string",
      "format": "date-time",
      "description": "ISO 8601 timestamp of the last plan update"
    }
  },
  "required": ["installmentPlanNumber", "status", "planData"],
  "$defs": {
    "Money": {
      "type": "object",
      "description": "A monetary value with currency",
      "required": ["value", "currency"],
      "properties": {
        "value": {
          "type": "number",
          "description": "Monetary amount",
          "minimum": 0
        },
        "currency": {
          "type": "string",
          "description": "ISO 4217 currency code",
          "pattern": "^[A-Z]{3}$",
          "examples": ["USD", "EUR", "GBP", "AUD", "CAD"]
        }
      }
    },
    "ConsumerData": {
      "type": "object",
      "description": "Shopper/consumer information",
      "properties": {
        "fullName": {
          "type": "string",
          "description": "Shopper's full legal name"
        },
        "email": {
          "type": "string",
          "format": "email",
          "description": "Shopper's email address"
        },
        "phoneNumber": {
          "type": "string",
          "description": "Shopper's phone number in international format"
        },
        "civilId": {
          "type": "string",
          "description": "National identification number if applicable"
        },
        "billingAddress": {
          "$ref": "#/$defs/Address"
        }
      }
    },
    "CreditCardDetails": {
      "type": "object",
      "description": "Payment card details (handle with PCI DSS compliance)",
      "properties": {
        "cardNumber": {
          "type": "string",
          "description": "Full credit card number (PAN)",
          "pattern": "^[0-9]{13,19}$"
        },
        "cardExpYear": {
          "type": "integer",
          "description": "Card expiration year (4 digits)",
          "minimum": 2020,
          "maximum": 2099
        },
        "cardExpMonth": {
          "type": "integer",
          "description": "Card expiration month",
          "minimum": 1,
          "maximum": 12
        },
        "cardCvv": {
          "type": "string",
          "description": "Card security code",
          "pattern": "^[0-9]{3,4}$"
        },
        "cardHolderFullName": {
          "type": "string",
          "description": "Name as it appears on the credit card"
        }
      }
    },
    "Address": {
      "type": "object",
      "description": "Physical postal address",
      "properties": {
        "addressLine1": {
          "type": "string",
          "description": "Primary street address"
        },
        "addressLine2": {
          "type": "string",
          "description": "Secondary address information (apt, suite, etc.)"
        },
        "city": {
          "type": "string",
          "description": "City name"
        },
        "state": {
          "type": "string",
          "description": "State, province, or region code"
        },
        "country": {
          "type": "string",
          "description": "ISO 3166-1 alpha-2 country code",
          "pattern": "^[A-Z]{2}$"
        },
        "zip": {
          "type": "string",
          "description": "Postal or ZIP code"
        }
      }
    },
    "Installment": {
      "type": "object",
      "description": "A single installment charge within a plan",
      "properties": {
        "installmentNumber": {
          "type": "integer",
          "description": "Sequential number of this installment (1-indexed)",
          "minimum": 1
        },
        "amount": {
          "$ref": "#/$defs/Money"
        },
        "processDateTime": {
          "type": "string",
          "format": "date-time",
          "description": "Scheduled or actual processing date and time"
        },
        "status": {
          "type": "string",
          "description": "Status of this installment charge",
          "enum": [
            "Pending",
            "Processing",
            "Succeeded",
            "Failed",
            "Refunded"
          ]
        }
      }
    },
    "RedirectUrls": {
      "type": "object",
      "description": "URLs for post-checkout redirection",
      "properties": {
        "succeeded": {
          "type": "string",
          "format": "uri",
          "description": "URL to redirect to on successful plan creation"
        },
        "failed": {
          "type": "string",
          "format": "uri",
          "description": "URL to redirect to on plan creation failure"
        },
        "cancelled": {
          "type": "string",
          "format": "uri",
          "description": "URL to redirect to if the shopper cancels"
        }
      }
    }
  }
}
