{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schemas.opencityitalia.it/payments/payment/v1.json",
  "title": "Pagamento",
  "description": "Ciclo di vita di un pagamento (PagoPA o bollo) gestito da OC Payments. Modello di riferimento: oc_python_sdk.models.payment.Payment (python_sdk), record del topic Kafka `payments`. Il campo event_version (versionamento interno del producer, oggi fisso a 2.0) è indipendente dal numero di versione in questo URL, che versiona il contratto pubblicato: v1 è la prima pubblicazione di questo schema e descrive i soli payload con event_version 2.0.",
  "type": "object",
  "properties": {
    "id": {
      "title": "Identificativo",
      "description": "UUID dell'evento di pagamento (una nuova versione del pagamento genera un nuovo id).",
      "type": "string",
      "format": "uuid"
    },
    "user_id": {
      "title": "Utente",
      "type": "string",
      "format": "uuid"
    },
    "type": {
      "title": "Tipo pagamento",
      "description": "es. PAGOPA, STAMP",
      "type": "string"
    },
    "tenant_id": {
      "title": "Ente",
      "type": "string",
      "format": "uuid"
    },
    "service_id": {
      "title": "Servizio",
      "type": "string",
      "format": "uuid"
    },
    "created_at": {
      "title": "Data creazione",
      "type": "string",
      "format": "date-time"
    },
    "updated_at": {
      "title": "Data aggiornamento",
      "type": "string",
      "format": "date-time"
    },
    "status": {
      "title": "Stato",
      "type": "string",
      "enum": [
        "CREATION_PENDING",
        "CREATION_FAILED",
        "PAYMENT_PENDING",
        "PAYMENT_STARTED",
        "PAYMENT_CONFIRMED",
        "PAYMENT_FAILED",
        "NOTIFICATION_PENDING",
        "COMPLETE",
        "EXPIRED",
        "CANCELED"
      ]
    },
    "reason": {
      "title": "Causale",
      "type": [
        "string",
        "null"
      ],
      "maxLength": 140
    },
    "remote_id": {
      "title": "Pratica collegata",
      "description": "UUID della pratica/applicazione a cui il pagamento si riferisce.",
      "type": "string",
      "format": "uuid"
    },
    "payment": {
      "title": "Dettaglio pagamento",
      "type": "object",
      "properties": {
        "transaction_id": {
          "type": [
            "string",
            "null"
          ]
        },
        "paid_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "expire_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "amount": {
          "title": "Importo",
          "description": "Importo totale in euro, 2 decimali.",
          "type": [
            "number",
            "null"
          ]
        },
        "currency": {
          "type": "string",
          "enum": [
            "EUR"
          ]
        },
        "type": {
          "title": "Tipo",
          "type": [
            "string",
            "null"
          ],
          "enum": [
            "PAGOPA",
            "STAMP",
            null
          ]
        },
        "notice_code": {
          "type": [
            "string",
            "null"
          ]
        },
        "iud": {
          "title": "IUD",
          "type": "string"
        },
        "iuv": {
          "title": "IUV",
          "type": [
            "string",
            "null"
          ]
        },
        "receiver": {
          "title": "Beneficiario",
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "tax_identification_number": {
              "type": "string"
            },
            "name": {
              "type": "string"
            },
            "iban": {
              "type": [
                "string",
                "null"
              ]
            },
            "address": {
              "type": [
                "string",
                "null"
              ]
            },
            "building_number": {
              "type": [
                "string",
                "null"
              ]
            },
            "postal_code": {
              "type": [
                "string",
                "null"
              ]
            },
            "town_name": {
              "type": [
                "string",
                "null"
              ]
            },
            "country_subdivision": {
              "type": [
                "string",
                "null"
              ]
            },
            "country": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          "required": [
            "tax_identification_number",
            "name"
          ]
        },
        "due_type": {
          "type": [
            "string",
            "null"
          ]
        },
        "pagopa_category": {
          "type": [
            "string",
            "null"
          ]
        },
        "document": {
          "title": "Documento collegato",
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "id": {
              "type": [
                "string",
                "null"
              ]
            },
            "ref": {
              "type": [
                "string",
                "null"
              ]
            },
            "hash": {
              "type": "string"
            }
          },
          "required": [
            "hash"
          ]
        },
        "split": {
          "title": "Ripartizione importo",
          "description": "Suddivisione dell'importo tra più beneficiari/capitoli. Somma degli importi = amount (oppure somma dei pesi = 1.00).",
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "amount": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "meta": {
                "type": "object"
              }
            },
            "required": [
              "code",
              "meta"
            ]
          }
        }
      },
      "required": [
        "currency",
        "iud",
        "split"
      ]
    },
    "links": {
      "title": "Link operativi",
      "type": "object",
      "properties": {
        "online_payment_begin": {
          "$ref": "#/$defs/link_action"
        },
        "online_payment_landing": {
          "$ref": "#/$defs/link_action"
        },
        "offline_payment": {
          "$ref": "#/$defs/link_action"
        },
        "receipt": {
          "$ref": "#/$defs/link_action"
        },
        "notify": {
          "title": "Notifiche inviate",
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "object",
            "properties": {
              "url": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "method": {
                "$ref": "#/$defs/http_method"
              },
              "sent_at": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              }
            }
          }
        },
        "update": {
          "title": "Controllo periodico stato",
          "type": "object",
          "properties": {
            "url": {
              "type": [
                "string",
                "null"
              ]
            },
            "last_check_at": {
              "type": [
                "string",
                "null"
              ],
              "format": "date-time"
            },
            "next_check_at": {
              "type": [
                "string",
                "null"
              ],
              "format": "date-time"
            },
            "method": {
              "$ref": "#/$defs/http_method"
            }
          }
        },
        "confirm": {
          "$ref": "#/$defs/link_action"
        },
        "cancel": {
          "$ref": "#/$defs/link_action"
        }
      },
      "required": [
        "online_payment_begin",
        "online_payment_landing",
        "offline_payment",
        "receipt",
        "update",
        "confirm",
        "cancel"
      ]
    },
    "payer": {
      "title": "Pagatore",
      "type": "object",
      "$ref": "#/$defs/payment_party"
    },
    "debtor": {
      "title": "Debitore",
      "description": "Presente quando il pagatore agisce per conto di un altro soggetto (es. legale rappresentante per persona giuridica).",
      "type": [
        "object",
        "null"
      ],
      "$ref": "#/$defs/payment_party"
    },
    "locale": {
      "title": "Lingua",
      "type": [
        "string",
        "null"
      ]
    },
    "event_id": {
      "title": "Identificativo evento",
      "type": "string",
      "format": "uuid"
    },
    "event_version": {
      "title": "Versione evento",
      "type": "string",
      "const": "2.0"
    },
    "event_created_at": {
      "title": "Data creazione evento",
      "type": "string",
      "format": "date-time"
    },
    "app_id": {
      "title": "Applicativo produttore",
      "type": "string"
    }
  },
  "required": [
    "id",
    "user_id",
    "type",
    "tenant_id",
    "service_id",
    "created_at",
    "updated_at",
    "status",
    "remote_id",
    "payment",
    "links",
    "payer",
    "event_id",
    "event_version",
    "event_created_at",
    "app_id"
  ],
  "$defs": {
    "http_method": {
      "type": [
        "string",
        "null"
      ],
      "enum": [
        "GET",
        "POST",
        "PUT",
        "PATCH",
        "DELETE",
        null
      ]
    },
    "link_action": {
      "type": "object",
      "properties": {
        "url": {
          "type": [
            "string",
            "null"
          ]
        },
        "last_opened_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "method": {
          "$ref": "#/$defs/http_method"
        }
      }
    },
    "payment_party": {
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "human",
            "legal"
          ]
        },
        "tax_identification_number": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "family_name": {
          "type": [
            "string",
            "null"
          ]
        },
        "street_name": {
          "type": [
            "string",
            "null"
          ]
        },
        "building_number": {
          "type": [
            "string",
            "null"
          ]
        },
        "postal_code": {
          "type": [
            "string",
            "null"
          ]
        },
        "town_name": {
          "type": [
            "string",
            "null"
          ]
        },
        "country_subdivision": {
          "type": [
            "string",
            "null"
          ]
        },
        "country": {
          "type": [
            "string",
            "null"
          ]
        },
        "email": {
          "type": [
            "string",
            "null"
          ]
        }
      },
      "required": [
        "type",
        "tax_identification_number",
        "name"
      ]
    }
  }
}
