{
  "$id": "common",
  "title": "[common] Definitions",
  "definitions": {
    "owner": {
      "type": "string",
      "minLength": 1,
      "title": "Payment owner",
      "description": "Identification of owner"
    },
    "chargeId": {
      "type": "string",
      "format": "uuid",
      "title": "Charge id",
      "description": "Identification of charge"
    },
    "currency": {
      "type": "object",
      "description": "Generic currency object",
      "required": [
        "currency",
        "value"
      ],
      "properties": {
        "currency": {
          "type": "string",
          "minLength": 3,
          "maxLength": 3
        },
        "value": {
          "type": "string",
          "pattern": "\\d{1,7}(\\.\\d{1,2})?$"
        }
      }
    },
    "links": {
      "title": "Payment system provided links",
      "type": "object",
      "properties": {
        "href": {
          "type": "string",
          "minLength": 1
        },
        "rel": {
          "type": "string",
          "minLength": 1
        },
        "method": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "term": {
      "title": "Term",
      "type": "object",
      "required": [
        "type",
        "max_billing_amount",
        "occurences",
        "amount_range",
        "buyer_editable"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "type": {
          "type": "string",
          "minLength": 1
        },
        "max_billing_amount": {
          "$ref": "common#/definitions/currency"
        },
        "occurences": {
          "type": "string",
          "minLength": 1
        },
        "amount_range": {
          "$ref": "common#/definitions/currency"
        },
        "buyer_editable": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "payment_definition": {
      "title": "Payment definition",
      "type": "object",
      "required": [
        "name",
        "type",
        "frequency_interval",
        "frequency",
        "cycles",
        "amount"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "name": {
          "type": "string",
          "minLength": 1
        },
        "type": {
          "type": "string",
          "minLength": 1,
          "enum": [
            "trial",
            "regular",
            "TRIAL",
            "REGULAR"
          ]
        },
        "frequency_interval": {
          "type": "string",
          "minLength": 1
        },
        "frequency": {
          "type": "string",
          "minLength": 1
        },
        "cycles": {
          "type": "string",
          "minLength": 1
        },
        "amount": {
          "$ref": "common#/definitions/currency"
        },
        "charge_models": {
          "title": "Charge models",
          "type": "array",
          "items": {
            "title": "Charge model",
            "type": "object",
            "required": [
              "type",
              "amount"
            ],
            "properties": {
              "id": {
                "type": "string",
                "minLength": 1
              },
              "type": {
                "type": "string",
                "minLength": 1
              },
              "amount": {
                "$ref": "common#/definitions/currency"
              }
            }
          }
        }
      }
    },
    "merchant_preferences": {
      "title": "Merchant preferences",
      "type": "object",
      "required": [
        "cancel_url",
        "return_url"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "setup_fee": {
          "$ref": "common#/definitions/currency"
        },
        "cancel_url": {
          "type": "string",
          "minLength": 1
        },
        "return_url": {
          "type": "string",
          "minLength": 1
        },
        "notify_url": {
          "type": "string",
          "minLength": 1
        },
        "max_fail_attempts": {
          "type": "string",
          "minLength": 1
        },
        "auto_bull_amount": {
          "type": "string",
          "minLength": 1
        },
        "initial_fail_amount_action": {
          "type": "string",
          "minLength": 1
        },
        "accepted_payment_type": {
          "type": "string",
          "minLength": 1
        },
        "char_set": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "agreement_details": {
      "title": "Agreement details",
      "type": "object",
      "properties": {
        "outstanding_balance": {
          "$ref": "common#/definitions/currency"
        },
        "cycles_remaining": {
          "type": "string",
          "minLength": 1
        },
        "cycles_completed": {
          "type": "string",
          "minLength": 1
        },
        "next_billing_date": {
          "type": "string",
          "minLength": 1
        },
        "last_payment_date": {
          "type": "string",
          "minLength": 1
        },
        "last_payment_amount": {
          "$ref": "common#/definitions/currency"
        },
        "final_payment_date": {
          "type": "string",
          "minLength": 1
        },
        "failed_payment_count": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "payer": {
      "title": "Payer information",
      "type": "object",
      "required": [
        "payment_method"
      ],
      "properties": {
        "payment_method": {
          "type": "string",
          "enum": [
            "credit_card",
            "bank",
            "paypal"
          ]
        },
        "status": {
          "type": "string",
          "minLength": 1
        },
        "account_type": {
          "type": "string",
          "enum": [
            "business",
            "personal",
            "premier"
          ]
        },
        "account_age": {
          "type": "string"
        },
        "funding_instruments": {
          "title": "Funding instruments",
          "type": "array",
          "items": {
            "$ref": "common#/definitions/funding_instrument"
          }
        },
        "funding_option_id": {
          "type": "string"
        },
        "payer_info": {
          "$ref": "common#/definitions/payer_info"
        }
      }
    },
    "funding_instrument": {
      "title": "Funding instruments",
      "type": "object",
      "properties": {
        "credit_card": {
          "$ref": "common#/definitions/credit_card"
        },
        "credit_card_token": {
          "$ref": "common#/definitions/credit_card_token"
        }
      }
    },
    "credit_card": {
      "title": "Credit card information",
      "type": "object",
      "required": [
        "number",
        "type",
        "expire_month",
        "expire_year"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "payer_id": {
          "type": "string",
          "minLength": 1
        },
        "number": {
          "type": "string",
          "minLength": 1
        },
        "type": {
          "type": "string",
          "minLength": 1
        },
        "expire_month": {
          "type": "integer"
        },
        "expire_year": {
          "type": "integer"
        },
        "cvv2": {
          "type": "string",
          "minLength": 3,
          "maxLength": 4
        },
        "first_name": {
          "type": "string",
          "minLength": 1
        },
        "last_name": {
          "type": "string",
          "minLength": 1
        },
        "billing_address": {
          "$ref": "common#/definitions/address"
        },
        "external_customer_id": {
          "type": "string",
          "minLength": 1
        },
        "merchant_id": {
          "type": "string",
          "minLength": 1
        },
        "external_card_id": {
          "type": "string",
          "minLength": 1
        },
        "create_time": {
          "type": "string",
          "format": "date-time"
        },
        "update_time": {
          "type": "string",
          "format": "date-time"
        },
        "state": {
          "type": "string",
          "minLength": 1
        },
        "valid_until": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "credit_card_token": {
      "title": "Credit card token",
      "type": "object",
      "required": [
        "credit_card_id"
      ],
      "properties": {
        "credit_card_id": {
          "type": "string",
          "minLength": 1
        },
        "payer_id": {
          "type": "string",
          "minLength": 1
        },
        "last4": {
          "type": "string",
          "minLength": 4,
          "maxLength": 4
        },
        "type": {
          "type": "string",
          "minLength": 1
        },
        "expire_year": {
          "type": "integer"
        },
        "expire_month": {
          "type": "integer"
        }
      }
    },
    "payer_info": {
      "title": "Payer information",
      "type": "object",
      "properties": {
        "email": {
          "type": "string",
          "minLength": 1,
          "maxLength": 127
        },
        "salutation": {
          "type": "string",
          "minLength": 1
        },
        "first_name": {
          "type": "string",
          "minLength": 1
        },
        "middle_name": {
          "type": "string",
          "minLength": 1
        },
        "last_name": {
          "type": "string",
          "minLength": 1
        },
        "suffix": {
          "type": "string",
          "minLength": 1
        },
        "payer_id": {
          "type": "string",
          "minLength": 1
        },
        "phone": {
          "type": "string",
          "minLength": 1
        },
        "country_code": {
          "type": "string",
          "minLength": 1
        },
        "shipping_address": {
          "$ref": "common#/definitions/shipping_address"
        },
        "tax_id_type": {
          "type": "string",
          "minLength": 1
        },
        "tax_id": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "address": {
      "title": "Address",
      "type": "object",
      "required": [
        "line1",
        "city",
        "country_code"
      ],
      "properties": {
        "line1": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100
        },
        "line2": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100
        },
        "city": {
          "type": "string",
          "minLength": 1,
          "maxLength": 50
        },
        "country_code": {
          "type": "string",
          "minLength": 1,
          "maxLength": 2
        },
        "postal_code": {
          "type": "string",
          "minLength": 1,
          "maxLength": 20
        },
        "state": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100
        },
        "phone": {
          "type": "string",
          "minLength": 1,
          "maxLength": 50
        }
      }
    },
    "shipping_address": {
      "title": "Shipping address",
      "allOf": [
        {
          "$ref": "common#/definitions/address"
        },
        {
          "properties": {
            "recipient_name": {
              "type": "string",
              "minLength": 0
            },
            "type": {
              "type": "string",
              "minLength": 1
            }
          }
        }
      ]
    },
    "override_charge_model": {
      "title": "Override charge model",
      "type": "object",
      "required": [
        "charge_id",
        "amount"
      ],
      "properties": {
        "charge_id": {
          "type": "string",
          "minLength": 1
        },
        "amount": {
          "$ref": "common#/definitions/currency"
        }
      }
    },
    "item": {
      "title": "Purchase item",
      "type": "object",
      "required": [
        "quantity",
        "name",
        "price",
        "currency"
      ],
      "properties": {
        "quantity": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "price": {
          "type": "string"
        },
        "tax": {
          "type": "string"
        },
        "currency": {
          "type": "string"
        },
        "sku": {
          "type": "string"
        },
        "url": {
          "type": "string"
        },
        "category": {
          "type": "string",
          "enum": [
            "digital",
            "physical"
          ]
        },
        "supplementary_data": {
          "title": "Supplemetary data",
          "type": "array",
          "items": {
            "$ref": "common#/definitions/kv"
          }
        },
        "postback_data": {
          "title": "Postback data",
          "type": "array",
          "items": {
            "$ref": "common#/definitions/kv"
          }
        }
      }
    },
    "kv": {
      "title": "KeyValue object",
      "type": "object",
      "required": [
        "name",
        "value"
      ],
      "properties": {
        "name": {
          "type": "string"
        },
        "value": {
          "type": "string"
        }
      }
    },
    "planId": {
      "title": "Payment plan id",
      "type": "string",
      "minLength": 1,
      "oneOf": [
        {
          "pattern": "^P-.+(\\|P-.+)?$"
        },
        {
          "const": "free"
        }
      ]
    },
    "paymentId": {
      "title": "Payment id",
      "type": "string",
      "minLength": 1,
      "pattern": "^PAYID-.+(\\|PAYID-.+)?"
    },
    "filter": {
      "description": "Search filter",
      "type": "object",
      "properties": {
        "#multi": {
          "title": "`#multi` query",
          "description": "See `redis-filtered-sort`",
          "type": "object",
          "required": [
            "fields",
            "match"
          ],
          "properties": {
            "fields": {
              "description": "Fields list used in search",
              "type": "array",
              "minItems": 1,
              "items": {
                "type": "string",
                "minLength": 1
              }
            },
            "match": {
              "type": "string",
              "description": "Match used in search",
              "minLength": 1
            }
          }
        }
      },
      "additionalProperties": {
        "oneOf": [
          {
            "type": "string",
            "minLength": 1
          },
          {
            "title": "Query",
            "type": "object",
            "minProperties": 1,
            "maxProperties": 2,
            "patternProperties": {
              "^(ne|eq|match)$": {
                "type": "string",
                "minLength": 1
              },
              "^(gte|lte)$": {
                "type": "number"
              },
              "^(some)$": {
                "title": "Some filter",
                "type": "array",
                "uniqueItems": true,
                "items": {
                  "type": "string",
                  "minLength": 1
                }
              }
            }
          }
        ]
      }
    },
    "cart": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "shipping_type",
        "shipping_price",
        "printing_price",
        "service_price",
        "user_price"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "shipping_type": {
          "type": "string",
          "minLength": 1
        },
        "shipping_price": {
          "type": "number",
          "minimum": 0,
          "maximum": 999999
        },
        "printing_price": {
          "type": "number",
          "minimum": 0,
          "maximum": 999999
        },
        "service_price": {
          "type": "number",
          "minimum": 0,
          "maximum": 999999
        },
        "user_price": {
          "type": "number",
          "minimum": 0,
          "maximum": 999999
        }
      }
    }
  }
}
